de->de_bcast = e;
e->getref(e);
save = 1;
-
}
/* Episode */
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);
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
{
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);
* 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
*/
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;
}
}
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
*
#include "trap.h"
#include "settings.h"
#include "config.h"
+#include "notify.h"
#include "idnode.h"
#include "imagecache.h"
#include "timeshift.h"
SSL_library_init();
/* Initialise configuration */
+ notify_init();
idnode_init();
spawn_init();
config_init(opt_nobackup == 0);
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");
#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)
{
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);
+}
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_ */