From: Jaroslav Kysela Date: Tue, 5 May 2015 14:38:02 +0000 (+0200) Subject: notify: move notify_delayed from idnode.c to notify.c (for EPG) X-Git-Tag: v4.1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee54976d3bb2f61db95aef102feedf37ce3bdd2a;p=thirdparty%2Ftvheadend.git notify: move notify_delayed from idnode.c to notify.c (for EPG) --- diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index 7e9846ff9..048c966e1 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -922,7 +922,6 @@ static dvr_entry_t *_dvr_entry_update de->de_bcast = e; e->getref(e); save = 1; - } /* Episode */ diff --git a/src/idnode.c b/src/idnode.c index ba8af4024..76110ec21 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -44,10 +44,6 @@ typedef struct idclass_link static idnodes_rb_t idnodes; static RB_HEAD(,idclass_link) idclasses; static RB_HEAD(,idclass_link) idrootclasses; -static pthread_cond_t idnode_cond; -static pthread_mutex_t idnode_mutex; -static htsmsg_t *idnode_queue; -static void* idnode_thread(void* p); SKEL_DECLARE(idclasses_skel, idclass_link_t); @@ -84,13 +80,9 @@ pthread_t idnode_tid; void idnode_init(void) { - idnode_queue = NULL; RB_INIT(&idnodes); RB_INIT(&idclasses); RB_INIT(&idrootclasses); - pthread_mutex_init(&idnode_mutex, NULL); - pthread_cond_init(&idnode_cond, NULL); - tvhthread_create(&idnode_tid, NULL, idnode_thread, NULL); } void @@ -98,12 +90,6 @@ idnode_done(void) { idclass_link_t *il; - pthread_cond_signal(&idnode_cond); - pthread_join(idnode_tid, NULL); - pthread_mutex_lock(&idnode_mutex); - htsmsg_destroy(idnode_queue); - idnode_queue = NULL; - pthread_mutex_unlock(&idnode_mutex); while ((il = RB_FIRST(&idclasses)) != NULL) { RB_REMOVE(&idclasses, il, link); free(il); @@ -1337,38 +1323,6 @@ idnode_serialize0(idnode_t *self, htsmsg_t *list, int optmask) * Notification * *************************************************************************/ -/** - * Delayed notification - */ -static void -idnode_notify_delayed - ( const char *uuid, const char *event, const char *action ) -{ - htsmsg_t *m = NULL, *e = NULL; - htsmsg_field_t *f; - - pthread_mutex_lock(&idnode_mutex); - if (idnode_queue == NULL) { - idnode_queue = htsmsg_create_map(); - } else { - m = htsmsg_get_map(idnode_queue, event); - } - if (m == NULL) { - m = htsmsg_add_msg(idnode_queue, event, htsmsg_create_map()); - } else { - e = htsmsg_get_list(m, action); - } - if (e == NULL) - e = htsmsg_add_msg(m, action, htsmsg_create_list()); - HTSMSG_FOREACH(f, e) - if (strcmp(htsmsg_field_get_str(f) ?: "", uuid) == 0) - goto skip; - htsmsg_add_str(e, NULL, uuid); - pthread_cond_signal(&idnode_cond); -skip: - pthread_mutex_unlock(&idnode_mutex); -} - /** * Notify about a change */ @@ -1383,7 +1337,7 @@ idnode_notify ( idnode_t *in, const char *action ) while (ic) { if (ic->ic_event) - idnode_notify_delayed(uuid, ic->ic_event, action); + notify_delayed(uuid, ic->ic_event, action); ic = ic->ic_super; } } @@ -1404,47 +1358,6 @@ idnode_notify_title_changed (void *in) idnode_notify_changed(in); } -/* - * Thread for handling notifications - */ -void* -idnode_thread ( void *p ) -{ - htsmsg_t *q = NULL; - htsmsg_field_t *f; - - pthread_mutex_lock(&idnode_mutex); - - while (tvheadend_running) { - - /* Get queue */ - if (!idnode_queue) { - pthread_cond_wait(&idnode_cond, &idnode_mutex); - continue; - } - q = idnode_queue; - idnode_queue = NULL; - pthread_mutex_unlock(&idnode_mutex); - - /* Process */ - pthread_mutex_lock(&global_lock); - - HTSMSG_FOREACH(f, q) - notify_by_msg(f->hmf_name, htsmsg_detach_submsg(f)); - - /* Finished */ - pthread_mutex_unlock(&global_lock); - htsmsg_destroy(q); - - /* Wait */ - usleep(500000); - pthread_mutex_lock(&idnode_mutex); - } - pthread_mutex_unlock(&idnode_mutex); - - return NULL; -} - /****************************************************************************** * Editor Configuration * diff --git a/src/main.c b/src/main.c index 95784a22c..48d27a7e2 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ #include "trap.h" #include "settings.h" #include "config.h" +#include "notify.h" #include "idnode.h" #include "imagecache.h" #include "timeshift.h" @@ -949,6 +950,7 @@ main(int argc, char **argv) SSL_library_init(); /* Initialise configuration */ + notify_init(); idnode_init(); spawn_init(); config_init(opt_nobackup == 0); @@ -1117,6 +1119,7 @@ main(int argc, char **argv) tvhftrace("main", intlconv_done); tvhftrace("main", urlparse_done); tvhftrace("main", idnode_done); + tvhftrace("main", notify_done); tvhftrace("main", spawn_done); tvhlog(LOG_NOTICE, "STOP", "Exiting HTS Tvheadend"); diff --git a/src/notify.c b/src/notify.c index b2d8701a0..42a889ece 100644 --- a/src/notify.c +++ b/src/notify.c @@ -26,6 +26,12 @@ #include "notify.h" #include "webui/webui.h" +static pthread_cond_t notify_cond; +static pthread_mutex_t notify_mutex; +static htsmsg_t *notify_queue; +static pthread_t notify_tid; +static void* notify_thread(void* p); + void notify_by_msg(const char *class, htsmsg_t *m) { @@ -42,3 +48,94 @@ notify_reload(const char *class) htsmsg_add_u32(m, "reload", 1); notify_by_msg(class, m); } + +void +notify_delayed(const char *id, const char *event, const char *action) +{ + htsmsg_t *m = NULL, *e = NULL; + htsmsg_field_t *f; + + if (!tvheadend_running) + return; + + pthread_mutex_lock(¬ify_mutex); + if (notify_queue == NULL) { + notify_queue = htsmsg_create_map(); + } else { + m = htsmsg_get_map(notify_queue, event); + } + if (m == NULL) { + m = htsmsg_add_msg(notify_queue, event, htsmsg_create_map()); + } else { + e = htsmsg_get_list(m, action); + } + if (e == NULL) + e = htsmsg_add_msg(m, action, htsmsg_create_list()); + HTSMSG_FOREACH(f, e) + if (strcmp(htsmsg_field_get_str(f) ?: "", id) == 0) + goto skip; + htsmsg_add_str(e, NULL, id); + pthread_cond_signal(¬ify_cond); +skip: + pthread_mutex_unlock(¬ify_mutex); +} + +void * +notify_thread ( void *p ) +{ + htsmsg_t *q = NULL; + htsmsg_field_t *f; + + pthread_mutex_lock(¬ify_mutex); + + while (tvheadend_running) { + + /* Get queue */ + if (!notify_queue) { + pthread_cond_wait(¬ify_cond, ¬ify_mutex); + continue; + } + q = notify_queue; + notify_queue = NULL; + pthread_mutex_unlock(¬ify_mutex); + + /* Process */ + pthread_mutex_lock(&global_lock); + + HTSMSG_FOREACH(f, q) + notify_by_msg(f->hmf_name, htsmsg_detach_submsg(f)); + + /* Finished */ + pthread_mutex_unlock(&global_lock); + htsmsg_destroy(q); + + /* Wait */ + usleep(500000); + pthread_mutex_lock(¬ify_mutex); + } + pthread_mutex_unlock(¬ify_mutex); + + return NULL; +} + +/* + * + */ + +void notify_init( void ) +{ + notify_queue = NULL; + pthread_mutex_init(¬ify_mutex, NULL); + pthread_cond_init(¬ify_cond, NULL); + tvhthread_create(¬ify_tid, NULL, notify_thread, NULL); +} + +void notify_done( void ) +{ + pthread_cond_signal(¬ify_cond); + pthread_join(notify_tid, NULL); + pthread_mutex_lock(¬ify_mutex); + htsmsg_destroy(notify_queue); + notify_queue = NULL; + pthread_mutex_unlock(¬ify_mutex); +} diff --git a/src/notify.h b/src/notify.h index 1a41a43a1..74738e887 100644 --- a/src/notify.h +++ b/src/notify.h @@ -25,4 +25,9 @@ void notify_by_msg(const char *class, htsmsg_t *m); void notify_reload(const char *class); +void notify_delayed(const char *id, const char *event, const char *action); + +void notify_init(void); +void notify_done(void); + #endif /* NOTIFY_H_ */