Committing this for posterity, but going to do a massive u-turn on the whole epggrab setup.

This commit is contained in:
Adam Sutton 2012-06-07 09:41:15 +01:00
parent c51a5856bd
commit 7a09f91ec7
3 changed files with 19 additions and 32 deletions

View file

@ -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);

View file

@ -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 );

View file

@ -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;
}
/*