]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
config: make server name configureable (avahi, satips)
authorDamjan Marion <damjan.marion@gmail.com>
Sun, 31 May 2015 15:21:36 +0000 (17:21 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 2 Jun 2015 13:40:33 +0000 (15:40 +0200)
src/avahi.c
src/avahi.h
src/config.c
src/config.h
src/satip/server.c
src/webui/extjs.c
src/webui/static/app/config.js

index 4cd000de9caff4f68d24e56d12292dcc78fb08a2..43dba8b4015146d75ee21adb88934048d362ac97 100644 (file)
 
 #include "tvheadend.h"
 #include "avahi.h"
+#include "config.h"
 
 static AvahiEntryGroup *group = NULL;
 static char *name = NULL;
 static AvahiSimplePoll *avahi_asp = NULL;
 static const AvahiPoll *avahi_poll = NULL;
+static int avahi_do_restart = 0;
 
 static void create_services(AvahiClient *c);
 
@@ -261,20 +263,34 @@ avahi_thread(void *aux)
   AvahiClient *ac;
   char *name2;
 
-  name = name2 = avahi_strdup("Tvheadend");
+  do {
+    if (avahi_poll)
+        avahi_simple_poll_free((AvahiSimplePoll *)avahi_poll);
 
-  ac = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, NULL);
-  while(avahi_simple_poll_iterate(avahi_asp, -1) == 0);
+    avahi_asp = avahi_simple_poll_new();
+    avahi_poll = avahi_simple_poll_get(avahi_asp);
 
-  avahi_client_free(ac);
+    if(avahi_do_restart) {
+      tvhlog(LOG_INFO, "AVAHI", "Service restarted.");
+      avahi_do_restart = 0;
+      group = NULL;
+    }
 
-  name = NULL;
-  free(name2);
+    name = name2 = avahi_strdup(config_get_server_name());
 
-  return NULL;
-  
+    ac = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, NULL);
+
+    while((avahi_do_restart == 0) &&
+          (avahi_simple_poll_iterate(avahi_asp, -1) == 0));
+
+    avahi_client_free(ac);
+
+    name = NULL;
+    free(name2);
+
+  } while (tvheadend_running && avahi_do_restart);
 
+  return NULL;
 }
 
 /**
@@ -285,8 +301,6 @@ pthread_t avahi_tid;
 void
 avahi_init(void)
 {
-  avahi_asp = avahi_simple_poll_new();
-  avahi_poll = avahi_simple_poll_get(avahi_asp);
   tvhthread_create(&avahi_tid, NULL, avahi_thread, NULL);
 }
 
@@ -298,3 +312,10 @@ avahi_done(void)
   pthread_join(avahi_tid, NULL);
   avahi_simple_poll_free((AvahiSimplePoll *)avahi_poll);
 }
+
+void
+avahi_restart(void)
+{
+  avahi_do_restart = 1;
+  avahi_simple_poll_quit(avahi_asp);
+}
index ca10aa01d03b7e0d45b222dffecc81a6a47e33ac..0aa0a2cd77f2e29b7cf116a7f4096f58c8482810 100644 (file)
@@ -1,7 +1,9 @@
 #ifdef CONFIG_AVAHI
 void avahi_init(void);
 void avahi_done(void);
+void avahi_restart(void);
 #else
 static inline void avahi_init(void) { }
 static inline void avahi_done(void) { }
+static inline void avahi_restart(void) {}
 #endif
index 0de63576afbe854d53016a58dd925ce502290c61..e3b4472bd823e5ce4f070f19e30b5e36ef646d20 100644 (file)
@@ -28,6 +28,7 @@
 #include "spawn.h"
 #include "lock.h"
 #include "profile.h"
+#include "avahi.h"
 
 /* *************************************************************************
  * Global data
@@ -1520,6 +1521,7 @@ config_init ( int backup )
   if (config_newcfg) {
     htsmsg_set_u32(config, "version", ARRAY_SIZE(config_migrate_table));
     htsmsg_set_str(config, "fullversion", tvheadend_version);
+    htsmsg_set_str(config, "server_name", "Tvheadend");
     config_save();
   
   /* Perform migrations */
@@ -1589,6 +1591,21 @@ config_set_int ( const char *fld, int val )
   return 0;
 }
 
+const char *config_get_server_name ( void )
+{
+  const char *s = htsmsg_get_str(config, "server_name");
+  if (s == NULL || *s == '\0')
+    return "Tvheadend";
+  return s;
+}
+
+int config_set_server_name ( const char *name )
+{
+  int r = config_set_str("server_name", name);
+  avahi_restart();
+  return r;
+}
+
 const char *config_get_language ( void )
 {
   const char *s = htsmsg_get_str(config, "language");
index 3add6b9ce6afac3ecaf2348334405e1eb7318f34..5c3c78da55e877ff1567f2468163e5db44c15457 100644 (file)
@@ -36,6 +36,10 @@ int         config_set_str ( const char *fld, const char *val );
 int         config_get_int ( const char *fld, int dflt );
 int         config_set_int ( const char *fld, int val );
 
+const char *config_get_server_name ( void );
+int         config_set_server_name ( const char *str )
+  __attribute__((warn_unused_result));
+
 const char *config_get_muxconfpath ( void );
 int         config_set_muxconfpath ( const char *str )
   __attribute__((warn_unused_result));
index 62ea072774716ca827cacb4f5e610cc26cee2df4..5ca1152b0100319a8b84c1b5588c950c81d08675 100644 (file)
@@ -61,7 +61,7 @@ satip_server_http_xml(http_connection_t *hc)
 <specVersion><major>1</major><minor>1</minor></specVersion>\n\
 <device>\n\
 <deviceType>urn:ses-com:device:SatIPServer:1</deviceType>\n\
-<friendlyName>TVHeadend%s</friendlyName>\n\
+<friendlyName>%s%s</friendlyName>\n\
 <manufacturer>TVHeadend Team</manufacturer>\n\
 <manufacturerURL>http://tvheadend.org</manufacturerURL>\n\
 <modelDescription>TVHeadend %s</modelDescription>\n\
@@ -172,6 +172,7 @@ satip_server_http_xml(http_connection_t *hc)
     snprintf(buf2, sizeof(buf2), " %s", satip_server_uuid + 26);
 
   snprintf(buf, sizeof(buf), MSG,
+           config_get_server_name(),
            buf2, tvheadend_version,
            satip_server_uuid,
            http_server_ip, http_server_port,
index 45206dcd8d19b566ae5e22a070d3f1e2f57816e3..f0b0332785d6c041da5873eccbece65e3db5b538 100644 (file)
@@ -478,6 +478,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
 
     /* Misc settings */
     pthread_mutex_lock(&global_lock);
+    if ((str = http_arg_get(&hc->hc_req_args, "server_name")))
+      save |= config_set_server_name(str);
     if ((str = http_arg_get(&hc->hc_req_args, "muxconfpath")))
       save |= config_set_muxconfpath(str);
     if ((str = http_arg_get(&hc->hc_req_args, "language")))
index b4c120a6ac3337190ac8bd260a3a10fc89d2d2ac..ecbabe20d53a938c95e951e561caff92ae8d901f 100644 (file)
@@ -41,7 +41,7 @@ tvheadend.miscconf = function(panel, index) {
         root: 'config'
     },
     [
-        'muxconfpath', 'language',
+        'server_name', 'muxconfpath', 'language',
         'tvhtime_update_enabled', 'tvhtime_ntp_enabled',
         'tvhtime_tolerance',
         'prefer_picon', 'chiconpath', 'piconpath',
@@ -58,6 +58,22 @@ tvheadend.miscconf = function(panel, index) {
     * DVB path
     */
 
+    var serverName = new Ext.form.TextField({
+        fieldLabel: 'Tvheadend server name',
+        name: 'server_name',
+        allowBlank: true,
+        width: 400
+    });
+
+    var serverWrap = new Ext.form.FieldSet({
+        title: 'Server',
+        width: 700,
+        autoHeight: true,
+        collapsible: true,
+        animCollapse: true,
+        items : [ serverName ]
+    });
+
     var dvbscanPath = new Ext.form.TextField({
         fieldLabel: 'DVB scan files path',
         name: 'muxconfpath',
@@ -322,7 +338,7 @@ tvheadend.miscconf = function(panel, index) {
         }
     });
 
-    var _items = [languageWrap, dvbscanWrap, tvhtimePanel, piconPanel];
+    var _items = [serverWrap, languageWrap, dvbscanWrap, tvhtimePanel, piconPanel];
 
     if (satipPanel)
       _items.push(satipPanel);