]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Committing this for posterity, but going to do a massive u-turn on the whole epggrab...
authorAdam Sutton <dev@adamsutton.me.uk>
Thu, 7 Jun 2012 08:41:15 +0000 (09:41 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 30 Jul 2012 14:47:52 +0000 (15:47 +0100)
src/cron.c
src/cron.h
src/epggrab.c

index 74e4ee9fef1735b303793f9ba3a0198eb4566075..33985976879755274abbc3d51affd878834e46bf 100644 (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);
index b42904c9b4dacfda15846a00c07737ce27ef4ee1..025f664b17fbeb7ac4349e056641a9ee9a7ab167 100644 (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 );
 
index 59d8167303fe35a669394f917daf4effefeace7d..6e8d03ec89e2ba06c54740919e91d7c16381c621 100644 (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;
 }
 
 /*