]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Added checkbox to the epggrab dialog to enable 8Hr flush
authorandyb2000 <andy@broadcast-tech.co.uk>
Thu, 7 Mar 2013 15:27:29 +0000 (15:27 +0000)
committerandyb2000 <andy@broadcast-tech.co.uk>
Thu, 7 Mar 2013 15:27:29 +0000 (15:27 +0000)
to disk EPG data on user request via thread

docs/html/config_epggrab.html
src/epgdb.c
src/epggrab.c
src/epggrab.h
src/webui/extjs.c
src/webui/static/app/epggrab.js

index 2eda58efe8c08a09d400d7608f6c8fa353e5337e..822348fa697639c821355a01d094426a145d8e97 100644 (file)
    <dt>Update channel name
    <dd>Automatically update channel icons using information provided
        by the enabled EPG providers.
+   <dt>Periodic save EPG to disk
+   <dd>Writes the current in-memory EPG database to disk every 8 Hours
+       when checked, so should a crash/unexpected shutdown occur EPG
+       data is saved periodically to the database (Re-read on
+       next startup)
  </dl>
  
  <h3>Internal Grabber</h3>
index 616ab4ed54ac5af40beb217396ee22f51217d5a6..71a3ff269d7f734d004b6edd2b7246314cd34ad4 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <pthread.h>
 
 #include "tvheadend.h"
 #include "queue.h"
@@ -35,6 +36,9 @@ extern epg_object_tree_t epg_brands;
 extern epg_object_tree_t epg_seasons;
 extern epg_object_tree_t epg_episodes;
 extern epg_object_tree_t epg_serieslinks;
+static pthread_cond_t _epgdbsave_cond;
+static void* _epgdbsave_thread ( void *p );
+pthread_mutex_t epgdbsave_mutex;
 
 /* **************************************************************************
  * Load
@@ -135,6 +139,29 @@ static void _epgdb_v2_process ( htsmsg_t *m, epggrab_stats_t *stats )
   }
 }
 
+/*
+ * Thread functions
+ */
+static void *_epgdbsave_thread ( void *p )
+{
+  struct timespec ts;
+  ts.tv_nsec = 0;
+  tvhlog(LOG_DEBUG, "epgdb", "epgdbsave setting: %i", epggrab_epgdb_periodicsave);
+  while (1) {
+    if (epggrab_epgdb_periodicsave) {
+      tvhlog(LOG_DEBUG, "epgdb", "epgdbsave setting: %i", 
+             epggrab_epgdb_periodicsave);
+      epg_save();
+    };
+    pthread_mutex_lock(&epgdbsave_mutex);
+    time(&ts.tv_sec);
+    ts.tv_sec += 28800; /* Every 8 hours */
+    pthread_cond_timedwait(&_epgdbsave_cond, &epgdbsave_mutex, &ts);
+    pthread_mutex_unlock(&epgdbsave_mutex);
+  };
+return NULL;
+}
+
 /*
  * Load data
  */
@@ -227,6 +254,12 @@ void epg_init ( void )
   munmap(mem, st.st_size);
   close(fd);
 
+  /* Create thread */
+  pthread_mutex_init(&epgdbsave_mutex, NULL);
+  pthread_cond_init(&_epgdbsave_cond, NULL);
+  /* Start thread */
+  pthread_t tid;
+  pthread_create(&tid, NULL, _epgdbsave_thread, NULL);
 }
 
 /* **************************************************************************
index 09dfc12209d6ce73d484579b40bd2901be2cd35c..18b97e916500a890d1be0ef607a35c58b8ccf71b 100644 (file)
@@ -49,6 +49,7 @@ epggrab_module_list_t epggrab_modules;
 uint32_t              epggrab_channel_rename;
 uint32_t              epggrab_channel_renumber;
 uint32_t              epggrab_channel_reicon;
+uint32_t              epggrab_epgdb_periodicsave;
 
 /* **************************************************************************
  * Internal Grab Thread
@@ -138,6 +139,7 @@ static void _epggrab_load ( void )
     htsmsg_get_u32(m, "channel_rename",   &epggrab_channel_rename);
     htsmsg_get_u32(m, "channel_renumber", &epggrab_channel_renumber);
     htsmsg_get_u32(m, "channel_reicon",   &epggrab_channel_reicon);
+    htsmsg_get_u32(m, "epgdb_periodicsave", &epggrab_epgdb_periodicsave);
     if (!htsmsg_get_u32(m, old ? "grab-interval" : "interval",
                         &epggrab_interval)) {
       if (old) epggrab_interval *= 3600;
@@ -234,6 +236,7 @@ void epggrab_save ( void )
   htsmsg_add_u32(m, "channel_rename", epggrab_channel_rename);
   htsmsg_add_u32(m, "channel_renumber", epggrab_channel_renumber);
   htsmsg_add_u32(m, "channel_reicon", epggrab_channel_reicon);
+  htsmsg_add_u32(m, "epgdb_periodicsave", epggrab_epgdb_periodicsave);
   htsmsg_add_u32(m, "interval",   epggrab_interval);
   if ( epggrab_module )
     htsmsg_add_str(m, "module", epggrab_module->id);
@@ -299,6 +302,19 @@ int epggrab_set_channel_renumber ( uint32_t e )
   return save;
 }
 
+/*
+ * Config from the webui for period save of db to disk
+ */
+int epggrab_set_periodicsave ( uint32_t e )
+{
+  int save = 0;
+  if ( e != epggrab_epgdb_periodicsave ) {
+    epggrab_epgdb_periodicsave = e;
+    save = 1;
+  }
+  return save;
+}
+
 int epggrab_set_channel_reicon ( uint32_t e )
 {
   int save = 0;
index ddb46a411d9d063b8cdcfcca16238aa7578ab466..d9496f58f0d65244f034bb8c1ba5c2ee3dbd586d 100644 (file)
@@ -226,6 +226,7 @@ extern epggrab_module_int_t* epggrab_module;
 extern uint32_t              epggrab_channel_rename;
 extern uint32_t              epggrab_channel_renumber;
 extern uint32_t              epggrab_channel_reicon;
+extern uint32_t              epggrab_epgdb_periodicsave;
 
 /*
  * Set configuration
@@ -236,6 +237,7 @@ int  epggrab_set_module_by_id     ( const char *id );
 int  epggrab_set_channel_rename   ( uint32_t e );
 int  epggrab_set_channel_renumber ( uint32_t e );
 int  epggrab_set_channel_reicon   ( uint32_t e );
+int  epggrab_set_periodicsave     ( uint32_t e );
 int  epggrab_enable_module        ( epggrab_module_t *mod, uint8_t e );
 int  epggrab_enable_module_by_id  ( const char *id, uint8_t e );
 
index 4d365f81b2f1ed657fb3d6a3f25ceee25702b861..9546ef7b88aee8c6b7a9e5ae99f0e9c31f0a9f74 100644 (file)
@@ -589,6 +589,7 @@ extjs_epggrab(http_connection_t *hc, const char *remain, void *opaque)
     htsmsg_add_u32(r, "channel_rename", epggrab_channel_rename);
     htsmsg_add_u32(r, "channel_renumber", epggrab_channel_renumber);
     htsmsg_add_u32(r, "channel_reicon", epggrab_channel_reicon);
+    htsmsg_add_u32(r, "epgdb_periodicsave", epggrab_epgdb_periodicsave);
     pthread_mutex_unlock(&epggrab_mutex);
 
     out = json_single_record(r, "epggrabSettings");
@@ -619,6 +620,8 @@ extjs_epggrab(http_connection_t *hc, const char *remain, void *opaque)
     save |= epggrab_set_channel_renumber(str ? 1 : 0);
     str = http_arg_get(&hc->hc_req_args, "channel_reicon");
     save |= epggrab_set_channel_reicon(str ? 1 : 0);
+    str = http_arg_get(&hc->hc_req_args, "epgdb_periodicsave");
+    save |= epggrab_set_periodicsave(str ? 1 : 0);
     if ( (str = http_arg_get(&hc->hc_req_args, "interval")) )
       save |= epggrab_set_interval(atoi(str));
     if ( (str = http_arg_get(&hc->hc_req_args, "module")) )
index 8e1a8f6bcb0520629df818af9ad3caf608640063..af18c6dfdc56630ccff2c8dbd9047bbd892e4b71 100644 (file)
@@ -82,7 +82,7 @@ tvheadend.epggrab = function() {
        var confreader = new Ext.data.JsonReader({
                root : 'epggrabSettings'
        }, [ 'module', 'interval', 'channel_rename', 'channel_renumber',
-               'channel_reicon' ]);
+               'channel_reicon', 'epgdb_periodicsave' ]);
 
        /* ****************************************************************
         * Basic Fields
@@ -184,6 +184,11 @@ tvheadend.epggrab = function() {
                fieldLabel : 'Update channel icon'
        });
 
+       var epgPeriodicSave = new Ext.form.Checkbox({
+               name : 'epgdb_periodicsave',
+               fieldLabel : 'Periodic save EPG to disk'
+       });
+
        /*
         * Simple fields
         */
@@ -192,7 +197,7 @@ tvheadend.epggrab = function() {
                width : 700,
                autoHeight : true,
                collapsible : true,
-               items : [ channelRename, channelRenumber, channelReicon ]
+               items : [ channelRename, channelRenumber, channelReicon, epgPeriodicSave ]
        });
 
        /*