]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
notify: move notify_delayed from idnode.c to notify.c (for EPG)
authorJaroslav Kysela <perex@perex.cz>
Tue, 5 May 2015 14:38:02 +0000 (16:38 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 5 May 2015 14:38:02 +0000 (16:38 +0200)
src/dvr/dvr_db.c
src/idnode.c
src/main.c
src/notify.c
src/notify.h

index 7e9846ff937ca01b72ba768193d707d528f50930..048c966e11b726fcf1b01a074f9d95ce2c1c95de 100644 (file)
@@ -922,7 +922,6 @@ static dvr_entry_t *_dvr_entry_update
     de->de_bcast = e;
     e->getref(e);
     save = 1;
-
   }
 
   /* Episode */
index ba8af4024b03f18c414a40fe21c9ea21ee59dfa5..76110ec21e51ec3f3759ffe223c5a993138d5d73 100644 (file)
@@ -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
  *
index 95784a22c05425f76cdedbb060bb2052aa6ebd49..48d27a7e2e511944729c37747c843238d17a5ec5 100644 (file)
@@ -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");
index b2d8701a0ebf84df57b75e83fddb9327e8e96d50..42a889eceaa7df0ce0880d82ac731d535258f1ac 100644 (file)
 #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(&notify_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(&notify_cond);
+skip:
+  pthread_mutex_unlock(&notify_mutex);
+}
+
+void *
+notify_thread ( void *p )
+{
+  htsmsg_t *q = NULL;
+  htsmsg_field_t *f;
+
+  pthread_mutex_lock(&notify_mutex);
+
+  while (tvheadend_running) {
+
+    /* Get queue */
+    if (!notify_queue) {
+      pthread_cond_wait(&notify_cond, &notify_mutex);
+      continue;
+    }
+    q            = notify_queue;
+    notify_queue = NULL;
+    pthread_mutex_unlock(&notify_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(&notify_mutex);
+  }
+  pthread_mutex_unlock(&notify_mutex);
+
+  return NULL;
+}
+
+/*
+ *
+ */
+
+void notify_init( void )
+{
+  notify_queue = NULL;
+  pthread_mutex_init(&notify_mutex, NULL);
+  pthread_cond_init(&notify_cond, NULL);
+  tvhthread_create(&notify_tid, NULL, notify_thread, NULL);
+}
+
+void notify_done( void )
+{
+  pthread_cond_signal(&notify_cond);
+  pthread_join(notify_tid, NULL);
+  pthread_mutex_lock(&notify_mutex);
+  htsmsg_destroy(notify_queue);
+  notify_queue = NULL;
+  pthread_mutex_unlock(&notify_mutex);
+}
index 1a41a43a130ec0d97326d7860d04db5e65638d1a..74738e887f13e28458a502d858652863da03a410 100644 (file)
@@ -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_ */