]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Initial HTSP async support
authorAndreas Öman <andreas@lonelycoder.com>
Mon, 14 Jan 2008 19:07:46 +0000 (19:07 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Mon, 14 Jan 2008 19:07:46 +0000 (19:07 +0000)
epg.c
htsp.c
htsp.h
rpc.c

diff --git a/epg.c b/epg.c
index de2d5e128e87d2384d332c839f3e67779b526988..d9956fc5a85dc72864e1da0b1028e8dedcd3531f 100644 (file)
--- a/epg.c
+++ b/epg.c
@@ -26,6 +26,7 @@
 #include "epg.h"
 #include "dispatch.h"
 #include "htsclient.h"
+#include "htsp.h"
 
 #define EPG_MAX_AGE 86400
 
@@ -378,6 +379,8 @@ epg_set_current_event(th_channel_t *ch, event_t *e)
   /* Notify clients that a new programme is on */
 
   clients_send_ref(ch->ch_tag);
+
+  htsp_async_channel_update(ch);
 }
 
 static void
diff --git a/htsp.c b/htsp.c
index d0464671dbdf21896ee8be1c2e0c6f81d174520b..ab2b9c35f7fed190671c9f71e1a60e24e6bff5e5 100644 (file)
--- a/htsp.c
+++ b/htsp.c
 #include "htsp.h"
 #include "htsp_muxer.h"
 #include "tcp.h"
+#include "epg.h"
 
 #include <libhts/htsmsg_binary.h>
 
+static LIST_HEAD(, htsp) htsp_sessions;
+
 /*
  *
  */
@@ -64,6 +67,79 @@ htsp_send_msg(htsp_t *htsp, htsmsg_t *m, int media)
 }
 
 
+/**
+ * build a channel message
+ */
+static htsmsg_t *
+htsp_build_channel_msg(th_channel_t *ch, const char *method)
+{
+  htsmsg_t *msg = htsmsg_create();
+  event_t *e;
+
+  htsmsg_add_str(msg, "method", method);
+  htsmsg_add_str(msg, "channelGroupName", ch->ch_group->tcg_name);
+  htsmsg_add_str(msg, "channelName", ch->ch_name);
+  htsmsg_add_u32(msg, "channelTag", ch->ch_tag);
+  if(ch->ch_icon != NULL)
+    htsmsg_add_str(msg, "channelIcon", refstr_get(ch->ch_icon));
+  
+  if((e = epg_event_get_current(ch)) != NULL)
+    htsmsg_add_u32(msg, "currentEvent", e->e_tag);
+
+  return msg;
+}
+
+
+
+
+/**
+ * channels_list
+ */
+static void
+htsp_send_all_channels(htsp_t *htsp)
+{
+  htsmsg_t *msg;
+  th_channel_group_t *tcg;
+  th_channel_t *ch;
+
+  TAILQ_FOREACH(tcg, &all_channel_groups, tcg_global_link) {
+    if(tcg->tcg_hidden)
+      continue;
+
+    msg = htsmsg_create();
+    htsmsg_add_str(msg, "method", "channelGroupAdd");
+    htsmsg_add_str(msg, "channelGroupName", tcg->tcg_name);
+    htsp_send_msg(htsp, msg, 0);
+
+    TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) {
+      if(LIST_FIRST(&ch->ch_transports) == NULL)
+       continue;
+
+      msg = htsp_build_channel_msg(ch, "channelAdd");
+      htsp_send_msg(htsp, msg, 0);
+    }
+  }
+}
+
+/**
+ * 
+ */
+void
+htsp_async_channel_update(th_channel_t *ch)
+{
+  htsp_t *htsp;
+  htsmsg_t *msg;
+
+  LIST_FOREACH(htsp, &htsp_sessions, htsp_global_link) {
+    if(!htsp->htsp_rpc.rs_is_async)
+      continue;
+
+    msg = htsp_build_channel_msg(ch, "channelUpdate");
+    htsp_send_msg(htsp, msg, 0);
+  }
+}
+
+
 /*
  *
  */
@@ -71,7 +147,7 @@ static void
 htsp_input(htsp_t *htsp, const void *buf, int len)
 {
   htsmsg_t *in, *out;
-  int i;
+  int i, was_async;
   const uint8_t *v = buf;
 
   printf("Got %d bytes\n", len);
@@ -83,6 +159,9 @@ htsp_input(htsp_t *htsp, const void *buf, int len)
     printf("deserialize failed\n");
     return;
   }
+
+  was_async = htsp->htsp_rpc.rs_is_async;
+
   printf("INPUT:\n");
   htsmsg_print(in);
 
@@ -94,6 +173,11 @@ htsp_input(htsp_t *htsp, const void *buf, int len)
   htsmsg_print(out);
 
   htsp_send_msg(htsp, out, 0);
+
+  if(!was_async && htsp->htsp_rpc.rs_is_async) {
+    /* Session went into async state */
+    htsp_send_all_channels(htsp);
+  }
 }
 
 
@@ -158,6 +242,8 @@ htsp_data_input(htsp_t *htsp)
 static void
 htsp_disconnect(htsp_t *htsp)
 {
+  LIST_REMOVE(htsp, htsp_global_link);
+
   free(htsp->htsp_buf);
   rpc_deinit(&htsp->htsp_rpc);
 }
@@ -173,6 +259,8 @@ htsp_connect(htsp_t *htsp)
  
   htsp->htsp_bufsize = 1000;
   htsp->htsp_buf = malloc(htsp->htsp_bufsize);
+
+  LIST_INSERT_HEAD(&htsp_sessions, htsp, htsp_global_link);
 }
 
 /*
diff --git a/htsp.h b/htsp.h
index e00a1480deffcec439fc6b20391bef23b045d499..78ed08dde3cc352394fb4aa92162f12332c39b47 100644 (file)
--- a/htsp.h
+++ b/htsp.h
@@ -27,6 +27,8 @@
 typedef struct htsp {
   tcp_session_t htsp_tcp_session; /* Must be first */
 
+  LIST_ENTRY(htsp) htsp_global_link;
+
   int htsp_bufsize;
   int htsp_bufptr;
   int htsp_msglen;
@@ -42,4 +44,6 @@ void htsp_start(int port);
 
 int htsp_send_msg(htsp_t *htsp, htsmsg_t *m, int media);
 
+void htsp_async_channel_update(th_channel_t *ch);
+
 #endif /* HTSP_H_ */
diff --git a/rpc.c b/rpc.c
index 539ee2db3262bd9c766071af525d069393b03852..bc07ee0229db8067457d386d4f7195b4808e4dd2 100644 (file)
--- a/rpc.c
+++ b/rpc.c
@@ -58,26 +58,6 @@ rpc_build_channel_msg(th_channel_t *ch)
 
 
 
-#if 0
-
-/**
- * channels_list
- */
-static void
-htsp_send_all_channels(htsp_connection_t *hc)
-{
-  htsp_msg_t *msg;
-  th_channel_t *ch;
-
-  TAILQ_FOREACH(ch, &channels, ch_global_link) {
-    msg = htsp_build_channel_msg(ch);
-    htsp_add_string(msg, "msgtype", "channelAdd");
-    htsp_send_msg(hc, NULL, msg);
-    htsp_free_msg(msg);
-  }
-}
-
-#endif