core, core-scache: Fire hooks for new, changed and removed events

(Refactored by David Henningsson)
This commit is contained in:
Juho Hämäläinen 2015-03-19 13:50:54 +02:00 committed by David Henningsson
parent e0b8966954
commit 7a3ed4af12
2 changed files with 16 additions and 3 deletions

View file

@ -79,6 +79,7 @@ static void free_entry(pa_scache_entry *e) {
pa_namereg_unregister(e->core, e->name); pa_namereg_unregister(e->core, e->name);
pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_REMOVE, e->index); pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_REMOVE, e->index);
pa_hook_fire(&e->core->hooks[PA_CORE_HOOK_SAMPLE_CACHE_UNLINK], e);
pa_xfree(e->name); pa_xfree(e->name);
pa_xfree(e->filename); pa_xfree(e->filename);
if (e->memchunk.memblock) if (e->memchunk.memblock)
@ -88,11 +89,12 @@ static void free_entry(pa_scache_entry *e) {
pa_xfree(e); pa_xfree(e);
} }
static pa_scache_entry* scache_add_item(pa_core *c, const char *name) { static pa_scache_entry* scache_add_item(pa_core *c, const char *name, bool *new_sample) {
pa_scache_entry *e; pa_scache_entry *e;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(new_sample);
if ((e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE))) { if ((e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE))) {
if (e->memchunk.memblock) if (e->memchunk.memblock)
@ -104,6 +106,7 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
pa_assert(e->core == c); pa_assert(e->core == c);
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
*new_sample = false;
} else { } else {
e = pa_xnew(pa_scache_entry, 1); e = pa_xnew(pa_scache_entry, 1);
@ -119,6 +122,7 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
pa_idxset_put(c->scache, e, &e->index); pa_idxset_put(c->scache, e, &e->index);
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index);
*new_sample = true;
} }
e->last_used_time = 0; e->last_used_time = 0;
@ -149,6 +153,7 @@ int pa_scache_add_item(
pa_scache_entry *e; pa_scache_entry *e;
char st[PA_SAMPLE_SPEC_SNPRINT_MAX]; char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
pa_channel_map tmap; pa_channel_map tmap;
bool new_sample;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
@ -163,7 +168,7 @@ int pa_scache_add_item(
if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX) if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
return -1; return -1;
if (!(e = scache_add_item(c, name))) if (!(e = scache_add_item(c, name, &new_sample)))
return -1; return -1;
pa_sample_spec_init(&e->sample_spec); pa_sample_spec_init(&e->sample_spec);
@ -194,6 +199,8 @@ int pa_scache_add_item(
name, e->index, (unsigned long) e->memchunk.length, name, e->index, (unsigned long) e->memchunk.length,
pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec)); pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec));
pa_hook_fire(&e->core->hooks[new_sample ? PA_CORE_HOOK_SAMPLE_CACHE_NEW : PA_CORE_HOOK_SAMPLE_CACHE_CHANGED], e);
return 0; return 0;
} }
@ -232,6 +239,7 @@ int pa_scache_add_file(pa_core *c, const char *name, const char *filename, uint3
int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename, uint32_t *idx) { int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename, uint32_t *idx) {
pa_scache_entry *e; pa_scache_entry *e;
bool new_sample;
#ifdef OS_IS_WIN32 #ifdef OS_IS_WIN32
char buf[MAX_PATH]; char buf[MAX_PATH];
@ -244,7 +252,7 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
pa_assert(name); pa_assert(name);
pa_assert(filename); pa_assert(filename);
if (!(e = scache_add_item(c, name))) if (!(e = scache_add_item(c, name, &new_sample)))
return -1; return -1;
e->lazy = true; e->lazy = true;
@ -258,6 +266,8 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
if (idx) if (idx)
*idx = e->index; *idx = e->index;
pa_hook_fire(&e->core->hooks[new_sample ? PA_CORE_HOOK_SAMPLE_CACHE_NEW : PA_CORE_HOOK_SAMPLE_CACHE_CHANGED], e);
return 0; return 0;
} }

View file

@ -131,6 +131,9 @@ typedef enum pa_core_hook {
PA_CORE_HOOK_MODULE_NEW, PA_CORE_HOOK_MODULE_NEW,
PA_CORE_HOOK_MODULE_PROPLIST_CHANGED, PA_CORE_HOOK_MODULE_PROPLIST_CHANGED,
PA_CORE_HOOK_MODULE_UNLINK, PA_CORE_HOOK_MODULE_UNLINK,
PA_CORE_HOOK_SAMPLE_CACHE_NEW,
PA_CORE_HOOK_SAMPLE_CACHE_CHANGED,
PA_CORE_HOOK_SAMPLE_CACHE_UNLINK,
PA_CORE_HOOK_MAX PA_CORE_HOOK_MAX
} pa_core_hook_t; } pa_core_hook_t;