]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cleanup PVR internal API a bit
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 13 Feb 2008 18:55:47 +0000 (18:55 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 13 Feb 2008 18:55:47 +0000 (18:55 +0000)
htmlui.c
htsclient.c
pvr.c
pvr.h
rpc.c

index bd7f0a47648e6c7ae14bedc54b4c8b02fb8d628b..62a4904d3d6ac0df0222f2fa381ccbc8ea85c019 100644 (file)
--- a/htmlui.c
+++ b/htmlui.c
@@ -392,12 +392,15 @@ output_event(http_connection_t *hc, tcp_queue_t *tq, th_channel_t *ch,
   event_t *cur;
   tv_pvr_status_t pvrstatus;
   const char *pvr_txt, *pvr_color;
+  pvr_rec_t *pvrr;
 
   localtime_r(&e->e_start, &a);
   stop = e->e_start + e->e_duration;
   localtime_r(&stop, &b);
 
-  pvrstatus = pvr_prog_status(e);
+
+  pvrr = pvr_get_by_entry(e);
+  pvrstatus = pvrr != NULL ? pvrr->pvrr_status : HTSTV_PVR_STATUS_NONE; 
 
   cur = epg_event_get_current(ch);
 
@@ -672,8 +675,8 @@ page_event(http_connection_t *hc, const char *remain, void *opaque)
   struct tm a, b;
   time_t stop;
   char desc[4000];
-  recop_t cmd = -1;
   tv_pvr_status_t pvrstatus;
+  pvr_rec_t *pvrr;
   const char *pvr_txt, *pvr_color;
   
   if(!html_verify_access(hc, "browse-events"))
@@ -686,35 +689,34 @@ page_event(http_connection_t *hc, const char *remain, void *opaque)
     return 404;
   }
 
+  pvrr = pvr_get_by_entry(e);
 
   if(http_arg_get(&hc->hc_url_args, "rec")) {
     if(!html_verify_access(hc, "record-events")) {
       epg_unlock();
       return HTTP_STATUS_UNAUTHORIZED;
     }
-    cmd = RECOP_ONCE;
+    pvrr = pvr_schedule_by_event(e);
   }
 
-  if(http_arg_get(&hc->hc_url_args, "cancel")) {
+  if(pvrr != NULL && http_arg_get(&hc->hc_url_args, "cancel")) {
     if(!html_verify_access(hc, "record-events")) {
       epg_unlock();
       return HTTP_STATUS_UNAUTHORIZED;
     }
-    cmd = RECOP_ABORT;
+    pvr_abort(pvrr);
   }
 
-  if(http_arg_get(&hc->hc_url_args, "clear")) {
+  if(pvrr != NULL && http_arg_get(&hc->hc_url_args, "clear")) {
     if(!html_verify_access(hc, "record-events")) {
       epg_unlock();
       return HTTP_STATUS_UNAUTHORIZED;
     }
-    cmd = RECOP_CLEAR;
+    pvr_clear(pvrr);
   }
 
-  if(cmd != -1)
-    pvr_event_record_op(e->e_ch, e, cmd);
 
-  pvrstatus = pvr_prog_status(e);
+  pvrstatus = pvrr != NULL ? pvrr->pvrr_status : HTSTV_PVR_STATUS_NONE;
 
   localtime_r(&e->e_start, &a);
   stop = e->e_start + e->e_duration;
@@ -825,7 +827,6 @@ page_pvr(http_connection_t *hc, const char *remain, void *opaque)
   pvr_rec_t **pv;
   int divid = 1;
   int size = 600;
-  recop_t op;
   http_arg_t *ra;
 
   if(!html_verify_access(hc, "record-events"))
@@ -835,23 +836,26 @@ page_pvr(http_connection_t *hc, const char *remain, void *opaque)
     pvr_clear_all_completed();
   }
 
-  op = -1;
   pvrr_tgt = NULL;
   LIST_FOREACH(ra, &hc->hc_url_args, link) {
+    c = 0;
     if(!strncmp(ra->key, "clear_", 6)) {
-      op = RECOP_CLEAR;
       txt = ra->key + 6;
     } else if(!strncmp(ra->key, "desched_", 8)) {
-      op = RECOP_CLEAR;
       txt = ra->key + 8;
     } else if(!strncmp(ra->key, "abort_", 6)) {
-      op = RECOP_ABORT;
+      c = 1;
       txt = ra->key + 6;
     } else {
       continue;
     }
     pvrr_tgt = pvr_get_tag_entry(atoi(txt));
-    pvr_do_op(pvrr_tgt, op);
+    if(pvrr_tgt != NULL) {
+      if(c)
+       pvr_abort(pvrr_tgt);
+      else
+       pvr_clear(pvrr_tgt);
+    }
     break;
   }
 
index f4985de06f31d33c8dff7904d9cb39b7e335ad92..c93ac2276140a17b6a3a30ec9908629317e448eb 100644 (file)
@@ -515,6 +515,7 @@ cr_event_info(client_t *c, char **argv, int argc)
   event_t *e = NULL, *x;
   uint32_t tag, prev, next;
   th_channel_t *ch;
+  pvr_rec_t *pvrr;
 
   if(argc < 2)
     return 1;
@@ -542,6 +543,8 @@ cr_event_info(client_t *c, char **argv, int argc)
   x = TAILQ_NEXT(e, e_link);
   next = x != NULL ? x->e_tag : 0;
 
+  pvrr = pvr_get_by_entry(e);
+
   cprintf(c,
          "start = %ld\n"
          "stop = %ld\n"
@@ -559,7 +562,7 @@ cr_event_info(client_t *c, char **argv, int argc)
          tag,
          prev,
          next,
-         pvr_prog_status(e));
+         pvrr != NULL ? pvrr->pvrr_status : HTSTV_PVR_STATUS_NONE);
 
   epg_unlock();
   return 0;
@@ -573,13 +576,8 @@ static int
 cr_event_record(client_t *c, char **argv, int argc)
 {
   event_t *e;
-  recop_t op;
-
-  if(argc < 2)
-    return 1;
 
-  op = pvr_op2int(argv[1]);
-  if(op == -1)
+  if(argc < 1)
     return 1;
 
   epg_lock();
@@ -590,7 +588,7 @@ cr_event_record(client_t *c, char **argv, int argc)
     return 1;
   }
 
-  pvr_event_record_op(e->e_ch, e, op);
+  pvr_schedule_by_event(e);
 
   epg_unlock();
   return 0;
@@ -616,7 +614,7 @@ cr_channel_record(client_t *c, char **argv, int argc)
 
   duration = atoi(argv[1]);
   
-  pvr_channel_record_op(ch, duration);
+  pvr_schedule_by_channel_and_time(ch, duration);
   return 0;
 }
 
diff --git a/pvr.c b/pvr.c
index ee0498d4430ea5fe069e4352609e362642a7d3b9..b03bdcc06664664cf45a01b03d57672108d40590 100644 (file)
--- a/pvr.c
+++ b/pvr.c
@@ -73,11 +73,11 @@ pvr_init(void)
 
 
 /**
- * For the given event, return pvr-status (if we have a pvr recording
- * entry that matches the event)
+ * For the given event, return pvr recording entry (if we have a pvr
+ * recording entry that matches the event)
  */
-char 
-pvr_prog_status(event_t *e)
+pvr_rec_t *
+pvr_get_by_entry(event_t *e)
 {
   pvr_rec_t *pvrr;
 
@@ -85,14 +85,13 @@ pvr_prog_status(event_t *e)
     if(pvrr->pvrr_start   >= e->e_start &&
        pvrr->pvrr_stop    <= e->e_start + e->e_duration &&
        pvrr->pvrr_channel == e->e_ch) {
-      return pvrr->pvrr_status;
+      return pvrr;
     }
   }
-  return HTSTV_PVR_STATUS_NONE;
+  return NULL;
 }
 
 
-
 /**
  * Find the pvr record entry based on increasing index
  */
@@ -166,17 +165,32 @@ pvr_free(pvr_rec_t *pvrr)
 /**
  * Abort a current recording
  */
-static void
+int
 pvr_abort(pvr_rec_t *pvrr)
 {
   if(pvrr->pvrr_status != HTSTV_PVR_STATUS_RECORDING)
-    return;
+    return -1;
 
   pvrr->pvrr_error = HTSTV_PVR_STATUS_ABORTED;
   pvr_fsm(pvrr);
 
   pvr_database_save(pvrr);
   clients_send_ref(-1);
+  return 0;
+}
+
+/**
+ * Clear current entry (only works if we are not recording)
+ */
+int
+pvr_clear(pvr_rec_t *pvrr)
+{
+  if(pvrr->pvrr_status == HTSTV_PVR_STATUS_RECORDING)
+    return -1;
+
+  pvr_database_erase(pvrr);
+  pvr_free(pvrr);
+  return 0;
 }
 
 
@@ -208,36 +222,11 @@ pvr_link_pvrr(pvr_rec_t *pvrr)
     break;
   }
 
-
   pvr_inform_status_change(pvrr);
   clients_send_ref(-1);
 }
 
 
-/**
- * Execute the given 'op'
- */
-void
-pvr_do_op(pvr_rec_t *pvrr, recop_t op)
-{
-  switch(op) {
-  case RECOP_CLEAR:
-    if(pvrr->pvrr_status != HTSTV_PVR_STATUS_RECORDING) {
-      pvr_database_erase(pvrr);
-      pvr_free(pvrr);
-      break;
-    }
-    return;
-
-  case RECOP_ABORT:
-    pvr_abort(pvrr);
-    return;
-  default:
-    break;
-  }
-}
-
-
 /**
  * Remove log info about all completed recordings
  */
@@ -265,9 +254,10 @@ pvr_clear_all_completed(void)
 /**
  * Create a PVR entry based on a given event
  */
-void
-pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op)
+pvr_rec_t *
+pvr_schedule_by_event(event_t *e)
 {
+  th_channel_t *ch = e->e_ch;
   time_t start = e->e_start;
   time_t stop  = e->e_start + e->e_duration;
   time_t now;
@@ -279,7 +269,7 @@ pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op)
   event_time_txt(start, e->e_duration, buf, sizeof(buf));
 
   if(stop < now)
-    return;
+    return NULL;
 
   /* Try to see if we already have a scheduled or active recording */
 
@@ -289,30 +279,9 @@ pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op)
       break;
   }
 
-  switch(op) {
-  case RECOP_CLEAR:
-    if(pvrr != NULL && pvrr->pvrr_status != HTSTV_PVR_STATUS_RECORDING) {
-      pvr_database_erase(pvrr);
-      pvr_free(pvrr);
-      break;
-    }
-    return;
-
-  case RECOP_ABORT:
-    if(pvrr != NULL)
-      pvr_abort(pvrr);
-    return;
-
-  case RECOP_ONCE:
-    if(pvrr != NULL)
-      return;
-    break;
+  if(pvrr != NULL)
+    return NULL; /* Already exists */
 
-  case RECOP_DAILY:
-  case RECOP_WEEKLY:
-    syslog(LOG_ERR,"Recording type not supported yet");
-    return;
-  }
 
   pvrr = calloc(1, sizeof(pvr_rec_t));
   pvrr->pvrr_status  = HTSTV_PVR_STATUS_SCHEDULED;
@@ -324,6 +293,7 @@ pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op)
 
   pvr_link_pvrr(pvrr);  
   pvr_database_save(pvrr);
+  return pvrr;
 }
 
 
@@ -332,8 +302,8 @@ pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op)
 /**
  * Record based on a channel
  */
-void
-pvr_channel_record_op(th_channel_t *ch, int duration)
+pvr_rec_t *
+pvr_schedule_by_channel_and_time(th_channel_t *ch, int duration)
 {
   time_t now   = dispatch_clock;
   time_t start = now;
@@ -350,6 +320,7 @@ pvr_channel_record_op(th_channel_t *ch, int duration)
 
   pvr_link_pvrr(pvrr);  
   pvr_database_save(pvrr);
+  return pvrr;
 }
 
 
@@ -1157,20 +1128,3 @@ pvr_record_packet(pvr_rec_t *pvrr, th_pkt_t *pkt)
     break;
   }
 }
-
-
-
-
-static struct strtab recoptab[] = {
-  { "once",   RECOP_ONCE },
-  { "daily",  RECOP_DAILY },
-  { "weekly", RECOP_WEEKLY },
-  { "abort",  RECOP_ABORT },
-  { "clear",  RECOP_CLEAR }
-};
-
-int
-pvr_op2int(const char *op)
-{
-  return str2val(op, recoptab);
-}
diff --git a/pvr.h b/pvr.h
index bacfc29e44c83c96d151b7e928e9bc6ac1db0bd7..205aacba7afc1651a9cd9e7141d6dfe66f9849bf 100644 (file)
--- a/pvr.h
+++ b/pvr.h
@@ -89,34 +89,24 @@ typedef struct pvr_rec {
 } pvr_rec_t;
 
 
-
-
-typedef enum {
-  RECOP_ONCE,
-  RECOP_DAILY,
-  RECOP_WEEKLY,
-  RECOP_ABORT,
-  RECOP_CLEAR,
-} recop_t;
-
 void pvr_init(void);
 
-void pvr_event_record_op(th_channel_t *ch, event_t *e, recop_t op);
-
-char pvr_prog_status(event_t *e);
-
 pvr_rec_t *pvr_get_log_entry(int e);
 
 pvr_rec_t *pvr_get_tag_entry(int e);
 
 void pvr_inform_status_change(pvr_rec_t *pvrr);
 
-void pvr_channel_record_op(th_channel_t *ch, int duration);
+void pvr_clear_all_completed(void);
 
-int pvr_op2int(const char *op);
+int pvr_clear(pvr_rec_t *pvrr);
 
-void pvr_do_op(pvr_rec_t *pvrr, recop_t op);
+int pvr_abort(pvr_rec_t *pvrr);
 
-void pvr_clear_all_completed(void);
+pvr_rec_t *pvr_get_by_entry(event_t *e);
+
+pvr_rec_t *pvr_schedule_by_event(event_t *e);
+
+pvr_rec_t *pvr_schedule_by_channel_and_time(th_channel_t *ch, int duration);
 
 #endif /* PVR_H */
diff --git a/rpc.c b/rpc.c
index bc07ee0229db8067457d386d4f7195b4808e4dd2..29dacebf15872b50d51b1ecf5bb336994390d706 100644 (file)
--- a/rpc.c
+++ b/rpc.c
@@ -147,7 +147,8 @@ rpc_event_info(rpc_session_t *ses, htsmsg_t *in, void *opaque)
   uint32_t u32;
   const char *s, *errtxt = NULL;
   event_t *e = NULL, *x;
-  uint32_t tag, prev, next, pvrstatus;
+  uint32_t tag, prev, next;
+  pvr_rec_t *pvrr;
 
   out = htsmsg_create();
   htsmsg_add_u32(out, "seq", ses->rs_seq);
@@ -199,8 +200,8 @@ rpc_event_info(rpc_session_t *ses, htsmsg_t *in, void *opaque)
     if(next)
       htsmsg_add_u32(out, "next", next);
 
-    if((pvrstatus = pvr_prog_status(e)) != 0)
-      htsmsg_add_u32(out, "pvrstatus", pvrstatus);
+    if((pvrr = pvr_get_by_entry(e)) != NULL)
+      htsmsg_add_u32(out, "pvrstatus", pvrr->pvrr_status);
   }
 
   epg_unlock();