From 8b8868e5ff37925429e08adb1629eb9ce8c447cd Mon Sep 17 00:00:00 2001 From: andyb2000 Date: Wed, 6 Mar 2013 21:12:42 +0000 Subject: [PATCH 1/5] Adding initial code for periodic saving of epgdb to disk --- src/epgdb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/epgdb.c b/src/epgdb.c index 33e53143..30ee6caa 100644 --- a/src/epgdb.c +++ b/src/epgdb.c @@ -226,6 +226,9 @@ void epg_init ( void ) /* Close file */ munmap(mem, st.st_size); close(fd); + + /* Create timer thread */ + } /* ************************************************************************** From 8925083ea7b74c192d2a9fd9b65ab72c1350b271 Mon Sep 17 00:00:00 2001 From: andyb2000 Date: Wed, 6 Mar 2013 21:17:28 +0000 Subject: [PATCH 2/5] Add flush command to simplewebui to trigger a write to disk of the epgdb --- src/webui/simpleui.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index 1601ab18..af768ae1 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -483,4 +483,5 @@ simpleui_start(void) http_path_add("/eventinfo", NULL, page_einfo, ACCESS_SIMPLE); http_path_add("/pvrinfo", NULL, page_pvrinfo, ACCESS_SIMPLE); http_path_add("/status.xml", NULL, page_status, ACCESS_SIMPLE); + http_path_add("/epgflush", NULL, epg_save, ACCESS_SIMPLE); } From 9b877c90034593e6d1dde426ae290928f1d241b7 Mon Sep 17 00:00:00 2001 From: andyb2000 Date: Thu, 7 Mar 2013 10:12:41 +0000 Subject: [PATCH 3/5] Add /epgsave to the webui so you can trigger a write of the epgdb to disk to help debugging, etc --- src/epgdb.c | 2 -- src/webui/simpleui.c | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/epgdb.c b/src/epgdb.c index 30ee6caa..616ab4ed 100644 --- a/src/epgdb.c +++ b/src/epgdb.c @@ -227,8 +227,6 @@ void epg_init ( void ) munmap(mem, st.st_size); close(fd); - /* Create timer thread */ - } /* ************************************************************************** diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index af768ae1..36dcda10 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -471,6 +471,25 @@ page_status(http_connection_t *hc, return 0; } +/** + * flush epgdb to disk on call + */ +static int +page_epgsave(http_connection_t *hc, + const char *remain, void *opaque) +{ + htsbuf_queue_t *hq = &hc->hc_reply; + + htsbuf_qprintf(hq, "\n" + "1\n"); + + epg_save(); + + http_output_content(hc, "text/xml"); + + return 0; +} + /** @@ -483,5 +502,5 @@ simpleui_start(void) http_path_add("/eventinfo", NULL, page_einfo, ACCESS_SIMPLE); http_path_add("/pvrinfo", NULL, page_pvrinfo, ACCESS_SIMPLE); http_path_add("/status.xml", NULL, page_status, ACCESS_SIMPLE); - http_path_add("/epgflush", NULL, epg_save, ACCESS_SIMPLE); + http_path_add("/epgsave", NULL, page_epgsave, ACCESS_SIMPLE); } From 3752158b92ec20b448badc69f35681bca4134d5b Mon Sep 17 00:00:00 2001 From: andyb2000 Date: Thu, 7 Mar 2013 15:27:29 +0000 Subject: [PATCH 4/5] Added checkbox to the epggrab dialog to enable 8Hr flush to disk EPG data on user request via thread --- docs/html/config_epggrab.html | 5 +++++ src/epgdb.c | 33 +++++++++++++++++++++++++++++++++ src/epggrab.c | 16 ++++++++++++++++ src/epggrab.h | 2 ++ src/webui/extjs.c | 3 +++ src/webui/static/app/epggrab.js | 9 +++++++-- 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/docs/html/config_epggrab.html b/docs/html/config_epggrab.html index 2eda58ef..822348fa 100644 --- a/docs/html/config_epggrab.html +++ b/docs/html/config_epggrab.html @@ -61,6 +61,11 @@
Update channel name
Automatically update channel icons using information provided by the enabled EPG providers. +
Periodic save EPG to disk +
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)

Internal Grabber

diff --git a/src/epgdb.c b/src/epgdb.c index 616ab4ed..71a3ff26 100644 --- a/src/epgdb.c +++ b/src/epgdb.c @@ -20,6 +20,7 @@ #include #include #include +#include #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); } /* ************************************************************************** diff --git a/src/epggrab.c b/src/epggrab.c index 09dfc122..18b97e91 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -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; diff --git a/src/epggrab.h b/src/epggrab.h index ddb46a41..d9496f58 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -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 ); diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 4d365f81..9546ef7b 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -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")) ) diff --git a/src/webui/static/app/epggrab.js b/src/webui/static/app/epggrab.js index 8e1a8f6b..af18c6df 100644 --- a/src/webui/static/app/epggrab.js +++ b/src/webui/static/app/epggrab.js @@ -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 ] }); /* From 4b7ffc058fc1a8222d60fb43b265a79aa40a65e4 Mon Sep 17 00:00:00 2001 From: andyb2000 Date: Thu, 7 Mar 2013 21:35:15 +0000 Subject: [PATCH 5/5] Changed gui parameter to take a numeric value which is the number of hours to write data to disk --- docs/html/config_epggrab.html | 7 ++++--- src/epgdb.c | 4 ++-- src/webui/extjs.c | 4 ++-- src/webui/static/app/epggrab.js | 14 ++++++++++---- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/html/config_epggrab.html b/docs/html/config_epggrab.html index 822348fa..7fbb33c2 100644 --- a/docs/html/config_epggrab.html +++ b/docs/html/config_epggrab.html @@ -61,11 +61,12 @@
Update channel name
Automatically update channel icons using information provided by the enabled EPG providers. -
Periodic save EPG to disk -
Writes the current in-memory EPG database to disk every 8 Hours - when checked, so should a crash/unexpected shutdown occur EPG +
Periodic save EPG to disk Interval +
Writes the current in-memory EPG database to disk every x Hours + (user defined), so should a crash/unexpected shutdown occur EPG data is saved periodically to the database (Re-read on next startup) + Set to 0 to disable.

Internal Grabber

diff --git a/src/epgdb.c b/src/epgdb.c index 71a3ff26..bb61fbc1 100644 --- a/src/epgdb.c +++ b/src/epgdb.c @@ -148,14 +148,14 @@ static void *_epgdbsave_thread ( void *p ) ts.tv_nsec = 0; tvhlog(LOG_DEBUG, "epgdb", "epgdbsave setting: %i", epggrab_epgdb_periodicsave); while (1) { - if (epggrab_epgdb_periodicsave) { + if (epggrab_epgdb_periodicsave != 0) { 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 */ + ts.tv_sec += epggrab_epgdb_periodicsave * 3600; /* User defined in hours */ pthread_cond_timedwait(&_epgdbsave_cond, &epgdbsave_mutex, &ts); pthread_mutex_unlock(&epgdbsave_mutex); }; diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 9546ef7b..07673914 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -620,8 +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, "epgdb_periodicsave")) ) + save |= epggrab_set_periodicsave(atoi(str)); 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")) ) diff --git a/src/webui/static/app/epggrab.js b/src/webui/static/app/epggrab.js index af18c6df..e8fc3738 100644 --- a/src/webui/static/app/epggrab.js +++ b/src/webui/static/app/epggrab.js @@ -184,10 +184,16 @@ tvheadend.epggrab = function() { fieldLabel : 'Update channel icon' }); - var epgPeriodicSave = new Ext.form.Checkbox({ - name : 'epgdb_periodicsave', - fieldLabel : 'Periodic save EPG to disk' - }); + var epgPeriodicSave = new Ext.form.NumberField({ + width : 30, + allowNegative : false, + allowDecimals : false, + minValue : 0, + maxValue : 24, + value : 0, + fieldLabel : 'Periodic save EPG to disk', + name : 'epgdb_periodicsave', + }); /* * Simple fields