]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Allow subscription weight to be set on subscription and later changed via subscriptio...
authorAndreas Öman <andreas@lonelycoder.com>
Fri, 28 May 2010 12:44:45 +0000 (12:44 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Fri, 28 May 2010 12:44:45 +0000 (12:44 +0000)
src/htsp.c
src/subscriptions.c
src/subscriptions.h

index 849a1a68ef0838a7a36b9bf18b7284cd40d59c85..bcb34829cc976512d12a2240099f7e35b07f4de0 100644 (file)
@@ -739,7 +739,7 @@ htsp_method_getSysTime(htsp_connection_t *htsp, htsmsg_t *in)
 static htsmsg_t *
 htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
 {
-  uint32_t chid, sid;
+  uint32_t chid, sid, weight;
   channel_t *ch;
   htsp_subscription_t *hs;
 
@@ -752,6 +752,7 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
   if((ch = channel_find_by_identifier(chid)) == NULL)
     return htsp_error("Requested channel does not exist");
 
+  weight = htsmsg_get_u32_or_default(in, "weight", 150);
 
   /*
    * We send the reply now to avoid the user getting the 'subscriptionStart'
@@ -770,7 +771,8 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
   LIST_INSERT_HEAD(&htsp->htsp_subscriptions, hs, hs_link);
   streaming_target_init(&hs->hs_input, htsp_streaming_input, hs, 0);
 
-  hs->hs_s = subscription_create_from_channel(ch, 150, htsp->htsp_logname,
+  hs->hs_s = subscription_create_from_channel(ch, weight,
+                                             htsp->htsp_logname,
                                              &hs->hs_input, 0);
   return NULL;
 }
@@ -806,6 +808,34 @@ htsp_method_unsubscribe(htsp_connection_t *htsp, htsmsg_t *in)
 }
 
 
+/**
+ * Change weight for a subscription
+ */
+static htsmsg_t *
+htsp_method_change_weight(htsp_connection_t *htsp, htsmsg_t *in)
+{
+  htsp_subscription_t *hs;
+  uint32_t sid, weight;
+
+  if(htsmsg_get_u32(in, "subscriptionId", &sid))
+    return htsp_error("Missing argument 'subscriptionId'");
+
+ weight = htsmsg_get_u32_or_default(in, "weight", 150);
+
+  LIST_FOREACH(hs, &htsp->htsp_subscriptions, hs_link)
+    if(hs->hs_sid == sid)
+      break;
+  
+  if(hs == NULL)
+    return htsp_error("Requested subscription does not exist");
+
+  htsp_reply(htsp, in, htsmsg_create_map());
+
+  subscription_change_weight(hs->hs_s, weight);
+  return NULL;
+}
+
+
 /**
  * Try to authenticate
  */
@@ -888,6 +918,7 @@ struct {
   { "getSysTime", htsp_method_getSysTime, ACCESS_STREAMING},
   { "subscribe", htsp_method_subscribe, ACCESS_STREAMING},
   { "unsubscribe", htsp_method_unsubscribe, ACCESS_STREAMING},
+  { "subscriptionChangeWeight", htsp_method_change_weight, ACCESS_STREAMING},
   { "addDvrEntry", htsp_method_addDvrEntry, ACCESS_RECORDER},
   { "deleteDvrEntry", htsp_method_deleteDvrEntry, ACCESS_RECORDER},
   { "epgQuery", htsp_method_epgQuery, ACCESS_STREAMING},
index 7b0a11b7518ae7daf499e76ec7b616ea9f3bd793..7dabc53785e49dd65f679254961e166944d640ef 100644 (file)
@@ -394,6 +394,24 @@ subscription_create_from_transport(th_transport_t *t, const char *name,
 }
 
 
+/**
+ *
+ */
+void
+subscription_change_weight(th_subscription_t *s, int weight)
+{
+  if(s->ths_weight == weight)
+    return;
+
+  LIST_REMOVE(s, ths_global_link);
+
+  s->ths_weight = weight;
+  LIST_INSERT_SORTED(&subscriptions, s, ths_global_link, subscription_sort);
+
+  subscription_reschedule();
+}
+
+
 /**
  *
  */
index ca7b9059c109f2f0293da408e30463d890c46524..65f147a3d0b00ac820e5c618b4e951234ad3b38b 100644 (file)
@@ -79,6 +79,8 @@ th_subscription_t *subscription_create_from_transport(th_transport_t *t,
                                                      streaming_target_t *st,
                                                      int flags);
 
+void subscription_change_weight(th_subscription_t *s, int weight);
+
 void subscription_stop(th_subscription_t *s);
 
 void subscription_unlink_transport(th_subscription_t *s, int reason);