]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhlog: add UI debug to allow run-time updates to the debugging config
authorAdam Sutton <dev@adamsutton.me.uk>
Wed, 10 Apr 2013 15:30:13 +0000 (16:30 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Wed, 10 Apr 2013 15:30:13 +0000 (16:30 +0100)
src/main.c
src/tvhlog.c
src/tvhlog.h
src/webui/extjs.c
src/webui/static/app/tvheadend.js
src/webui/static/app/tvhlog.js [new file with mode: 0644]

index 02ee83a36d61933406555f4f929daab99d42392c..80a66e4a2258d7c6680bd62dc6380de23fc955bc 100644 (file)
@@ -131,6 +131,9 @@ const tvh_caps_t tvheadend_capabilities[] = {
 #endif
 #if ENABLE_TIMESHIFT
   { "timeshift", &timeshift_enabled },
+#endif
+#if ENABLE_TRACE
+  { "trace",     NULL },
 #endif
   { NULL, NULL }
 };
index 342bbb7633f2c4479dd4ff358f80b6fe2172dee7..bbb11d0316792ed3f8215b16e1ac77d35eb6eb81 100644 (file)
@@ -56,6 +56,25 @@ tvhlog_init ( int level, int options, const char *path )
   pthread_mutex_init(&tvhlog_mutex, NULL);
 }
 
+/* Get subsys */
+void tvhlog_get_subsys ( char *subsys, size_t len )
+{
+  size_t c = 0;
+  int first = 1;
+  htsmsg_field_t *f;
+  *subsys = '\0';
+  if (tvhlog_subsys) {
+    HTSMSG_FOREACH(f, tvhlog_subsys) {
+      if (f->hmf_type != HMF_S64) continue;
+      c += snprintf(subsys+c, len-c, "%c%s%s",
+                    f->hmf_s64 ? '+' : '-',
+                    f->hmf_name,
+                    first ? "" : ",");
+      first = 0;
+    }
+  }
+}
+
 /* Set subsys */
 void tvhlog_set_subsys ( const char *subsys )
 {
index c36a3c44f4a3d8ca44ba3e213b4018c62635790c..bde46a50bd5704ca82c3096ae59e450b5bbfad81 100644 (file)
@@ -34,6 +34,7 @@ extern pthread_mutex_t  tvhlog_mutex;
 /* Initialise */
 void tvhlog_init       ( int level, int options, const char *path ); 
 void tvhlog_set_subsys ( const char *subsys );
+void tvhlog_get_subsys ( char *subsys, size_t len );
 void tvhlogv           ( const char *file, int line,
                          int notify, int severity,
                          const char *subsys, const char *fmt, va_list args );
index 6e793562ae50d9dcaaecfa01f26d4f646ef786f6..fd10ef8abd888be7f8102eb332fd6d881af01bcb 100644 (file)
@@ -146,6 +146,7 @@ extjs_root(http_connection_t *hc, const char *remain, void *opaque)
   extjs_load(hq, "static/app/dvr.js");
   extjs_load(hq, "static/app/epggrab.js");
   extjs_load(hq, "static/app/config.js");
+  extjs_load(hq, "static/app/tvhlog.js");
   extjs_load(hq, "static/app/status.js");
 
   /**
@@ -2054,6 +2055,89 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
   return 0;
 }
 
+/**
+ *
+ */
+static int
+extjs_tvhlog(http_connection_t *hc, const char *remain, void *opaque)
+{
+  htsbuf_queue_t *hq = &hc->hc_reply;
+  const char *op = http_arg_get(&hc->hc_req_args, "op");
+  htsmsg_t *out, *m;
+
+  if(op == NULL)
+    return 400;
+
+  pthread_mutex_lock(&global_lock);
+
+  if(http_access_verify(hc, ACCESS_ADMIN)) {
+    pthread_mutex_unlock(&global_lock);
+    return HTTP_STATUS_UNAUTHORIZED;
+  }
+
+  pthread_mutex_unlock(&global_lock);
+
+  /* Basic settings */
+  if(!strcmp(op, "loadSettings")) {
+    char str[2048];
+
+    /* Get config */
+    pthread_mutex_lock(&tvhlog_mutex);
+    m = htsmsg_create_map();
+    htsmsg_add_u32(m, "tvhlog_level",      tvhlog_level);
+    htsmsg_add_u32(m, "tvhlog_trace",      tvhlog_level > LOG_DEBUG);
+    tvhlog_get_subsys(str, sizeof(str));
+    htsmsg_add_str(m, "tvhlog_subsys",     str);
+    htsmsg_add_str(m, "tvhlog_path",       tvhlog_path ?: "");
+    htsmsg_add_u32(m, "tvhlog_options",    tvhlog_options);
+    htsmsg_add_u32(m, "tvhlog_dbg_syslog",
+                   tvhlog_options & TVHLOG_OPT_DBG_SYSLOG);
+    pthread_mutex_unlock(&tvhlog_mutex);
+    
+    if (!m) return HTTP_STATUS_BAD_REQUEST;
+    out = json_single_record(m, "config");
+
+  /* Save settings */
+  } else if (!strcmp(op, "saveSettings") ) {
+    const char *str;
+
+    pthread_mutex_lock(&tvhlog_mutex);
+    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_level")))
+      tvhlog_level = atoi(str);
+    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_trace")))
+      tvhlog_level = LOG_TRACE;
+    else
+      tvhlog_level = LOG_DEBUG;
+    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_path"))) {
+      free(tvhlog_path);
+      if (*str)
+        tvhlog_path  = strdup(str);
+      else
+        tvhlog_path  = NULL;
+    }
+    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_options")))
+      tvhlog_options = atoi(str);
+    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_dbg_syslog")))
+      tvhlog_options |= TVHLOG_OPT_DBG_SYSLOG;
+    else
+      tvhlog_options &= ~TVHLOG_OPT_DBG_SYSLOG;
+    tvhlog_set_subsys(http_arg_get(&hc->hc_req_args, "tvhlog_subsys"));
+    pthread_mutex_unlock(&tvhlog_mutex);
+  
+    out = htsmsg_create_map();
+    htsmsg_add_u32(out, "success", 1);
+
+  } else {
+    return HTTP_STATUS_BAD_REQUEST;
+  }
+
+  htsmsg_json_serialize(out, hq, 0);
+  htsmsg_destroy(out);
+  http_output_content(hc, "text/x-json; charset=UTF-8");
+
+  return 0;
+}
+
 /**
  * Capability check
  */
@@ -2174,6 +2258,7 @@ extjs_start(void)
 #if ENABLE_TIMESHIFT
   http_path_add("/timeshift",        NULL, extjs_timeshift,        ACCESS_ADMIN);
 #endif
+  http_path_add("/tvhlog",           NULL, extjs_tvhlog,           ACCESS_ADMIN);
 
 #if ENABLE_LINUXDVB
   extjs_start_dvb();
index 1db51311d65a0b6b84f804c99bb4db232e575388..761be214c05e4989d52fa70520ed06cc25becada 100644 (file)
@@ -320,6 +320,9 @@ function accessUpdate(o) {
       tabs1.push(tvheadend.conf_csa);
     }
 
+    /* Debug */
+    tabs1.push(new tvheadend.tvhlog);
+
     tvheadend.confpanel = new Ext.TabPanel({
       activeTab : 0,
       autoScroll : true,
diff --git a/src/webui/static/app/tvhlog.js b/src/webui/static/app/tvhlog.js
new file mode 100644 (file)
index 0000000..5737405
--- /dev/null
@@ -0,0 +1,102 @@
+tvheadend.tvhlog = function() {
+       /*
+        * Basic Config
+        */
+       var confreader = new Ext.data.JsonReader({
+               root : 'config'
+       }, [ 'tvhlog_path', 'tvhlog_dbg_syslog', 'tvhlog_subsys', 'tvhlog_trace' ]);
+
+       /* ****************************************************************
+        * Form Fields
+        * ***************************************************************/
+
+       var tvhlogLogPath = new Ext.form.TextField({
+               fieldLabel : 'Debug Log Path',
+               name : 'tvhlog_path',
+               allowBlank : true,
+               width: 400
+       });
+
+  var tvhlogToSyslog = new Ext.form.Checkbox({
+    name: 'tvhlog_dbg_syslog',
+    fieldLabel: 'Debug to syslog'
+  });
+  
+  var tvhlogTrace = new Ext.form.Checkbox({
+    name: 'tvhlog_trace',
+    fieldLabel: 'Debug trace (low-level stuff)'
+  });
+
+       var tvhlogSubsys = new Ext.form.TextField({
+               fieldLabel : 'Debug Subsystems',
+               name : 'tvhlog_subsys',
+               allowBlank : true,
+               width: 400
+       });
+
+       /* ****************************************************************
+        * Form
+        * ***************************************************************/
+
+       var saveButton = new Ext.Button({
+               text : "Save configuration",
+               tooltip : 'Save changes made to configuration below',
+               iconCls : 'save',
+               handler : saveChanges
+       });
+
+       var helpButton = new Ext.Button({
+               text : 'Help',
+               handler : function() {
+                       new tvheadend.help('Debug Configuration', 'config_tvhlog.html');
+               }
+       });
+
+       var confpanel = new Ext.form.FormPanel({
+               title : 'Debugging',
+               iconCls : 'wrench',
+               border : false,
+               bodyStyle : 'padding:15px',
+               labelAlign : 'left',
+               labelWidth : 200,
+               waitMsgTarget : true,
+               reader : confreader,
+               layout : 'form',
+               defaultType : 'textfield',
+               autoHeight : true,
+               items : [ tvhlogLogPath, tvhlogToSyslog,
+              tvhlogTrace, tvhlogSubsys ],
+               tbar : [ saveButton, '->', helpButton ]
+       });
+
+       /* ****************************************************************
+        * Load/Save
+        * ***************************************************************/
+
+       confpanel.on('render', function() {
+               confpanel.getForm().load({
+                       url : 'tvhlog',
+                       params : {
+                               op : 'loadSettings'
+                       },
+                       success : function(form, action) {
+                               confpanel.enable();
+                       }
+               });
+       });
+
+       function saveChanges() {
+               confpanel.getForm().submit({
+                       url : 'tvhlog',
+                       params : {
+                               op : 'saveSettings'
+                       },
+                       waitMsg : 'Saving Data...',
+                       failure : function(form, action) {
+                               Ext.Msg.alert('Save failed', action.result.errormsg);
+                       }
+               });
+       }
+
+       return confpanel;
+}