From 7a09f91ec78d2f10c8a07ba03b18dd5c9bb908a8 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Thu, 7 Jun 2012 09:41:15 +0100 Subject: [PATCH] Committing this for posterity, but going to do a massive u-turn on the whole epggrab setup. --- src/cron.c | 34 ++++++++++++---------------------- src/cron.h | 4 +--- src/epggrab.c | 13 ++++++------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/cron.c b/src/cron.c index 74e4ee9f..33985976 100644 --- a/src/cron.c +++ b/src/cron.c @@ -7,6 +7,7 @@ typedef struct cron { char *str; ///< String representation + time_t last; ///< Last execution time uint64_t min; ///< Minutes uint32_t hour; ///< Hours uint32_t dom; ///< Day of month @@ -126,16 +127,22 @@ int cron_set_string ( cron_t *cron, const char *str ) return save; } -int cron_is_time ( cron_t *cron ) +time_t cron_run ( cron_t *cron ) { + time_t t; + struct tm now; int ret = 1; uint64_t b = 0x1; /* Get the current time */ - time_t t = time(NULL); - struct tm now; - localtime_r(&t, &now); - + time(&t); + localtime_t(&t, &now); + + /* Find next event */ + if ( now->min == cron->last->min) { + + } + /* Check */ if ( ret && !((b << now.tm_min) & cron->min) ) ret = 0; if ( ret && !((b << now.tm_hour) & cron->hour) ) ret = 0; @@ -146,23 +153,6 @@ int cron_is_time ( cron_t *cron ) return ret; } -// TODO: use this as part of cron_next/cron_is_time -void cron_run ( cron_t *cron ) -{ -} - -// TODO: do proper search for next time -time_t cron_next ( cron_t *cron ) -{ - time_t now; - time(&now); - now += 62; // TODO: hack because timer goes off just before second tick - now /= 60; - now *= 60; - return now; -} - - void cron_serialize ( cron_t *cron, htsmsg_t *msg ) { htsmsg_add_str(msg, "cron", cron->str); diff --git a/src/cron.h b/src/cron.h index b42904c9..025f664b 100644 --- a/src/cron.h +++ b/src/cron.h @@ -17,9 +17,7 @@ cron_t *cron_create ( const char *str ); void cron_destroy ( cron_t *cron ); const char *cron_get_string ( cron_t *cron ); int cron_set_string ( cron_t *cron, const char *str ); -int cron_is_time ( cron_t *cron ); -time_t cron_next ( cron_t *cron ); -void cron_run ( cron_t *cron ); +int cron_run ( cron_t *cron, time_t *next ); void cron_serialize ( cron_t *cron, htsmsg_t *msg ); cron_t *cron_deserialize ( htsmsg_t *msg ); diff --git a/src/epggrab.c b/src/epggrab.c index 59d81673..6e8d03ec 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -486,25 +486,24 @@ static time_t _epggrab_thread_simple ( void ) */ static time_t _epggrab_thread_advanced ( void ) { - time_t ret, now; + time_t now, ret, tmp; epggrab_sched_t *s; /* Determine which to run */ time(&now); - ret = now + 3600; // default + ret = now + 3600; // once an hour if no entries TAILQ_FOREACH(s, &epggrab_schedule, link) { - if ( cron_is_time(s->cron) ) { - cron_run(s->cron); + if ( cron_run(s->cron, &tmp) ) { + ret = now; // re-run immediately _epggrab_module_run(s->mod, s->cmd, s->opts); - return now + 10; // TODO: don't try to interate the list, it'll break due to locking // module (i.e. _epggrab_module_run() unlocks) } else { - ret = MIN(ret, cron_next(s->cron)); + ret = MIN(ret, tmp); } } - return ret;//now + 30; + return ret; } /*