Commit a4dcd27b authored by minus's avatar minus

Use linked list for siso_watch_list elements

parent c9539d27
......@@ -49,10 +49,7 @@ uint32_t siso_watch_get_first_or_default(struct siso_watch *w, uint32_t default_
}
struct siso_watch *siso_add_name(struct siso_watch_list *wl, const char* name) {
wl->len++;
wl->items = realloc(wl->items,
sizeof(struct siso_watch *) * wl->len);
struct siso_watch *item = wl->items[wl->len - 1] = calloc(1, sizeof(struct siso_watch));
struct siso_watch *item = calloc(1, sizeof(struct siso_watch));
item->name = strdup(name);
item->target = -1;
item->mute = true;
......@@ -60,22 +57,24 @@ struct siso_watch *siso_add_name(struct siso_watch_list *wl, const char* name) {
item->sisos.items = NULL;
item->volume_changed = NULL;
item->userdata = NULL;
item->next = wl->head;
wl->head = item;
return item;
}
struct siso_watch *siso_get(struct siso_watch_list *wl, const char *name) {
for (size_t i = 0; i < wl->len; i++) {
int offset = strlen(name) - strlen(wl->items[i]->name);
if (strcmp(wl->items[i]->name, name + offset) == 0) {
return wl->items[i];
for (struct siso_watch *w = wl->head; w != NULL; w = w->next) {
int offset = strlen(name) - strlen(w->name);
if (strcmp(w->name, name + offset) == 0) {
return w;
}
}
return NULL;
}
void siso_remove_index(struct siso_watch_list *wl, uint32_t pa_index) {
for (size_t i = 0; i < wl->len; i++) {
siso_watch_remove_index(wl->items[i], pa_index);
for (struct siso_watch *w = wl->head; w != NULL; w = w->next) {
siso_watch_remove_index(w, pa_index);
}
}
......@@ -14,6 +14,7 @@ struct siso {
};
struct siso_watch {
struct siso_watch *next;
const char *name;
uint32_t target; // sink in case of watching a sink input
bool mute;
......@@ -26,8 +27,7 @@ struct siso_watch {
};
struct siso_watch_list {
size_t len;
struct siso_watch **items;
struct siso_watch *head;
};
void siso_watch_remove_index(struct siso_watch *w, uint32_t pa_index);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment