]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhlog: move to the simple node system
authorJaroslav Kysela <perex@perex.cz>
Wed, 16 Sep 2015 09:01:56 +0000 (11:01 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 16 Sep 2015 09:01:56 +0000 (11:01 +0200)
src/api/api_config.c
src/idnode.h
src/prop.c
src/prop.h
src/tvhlog.c
src/webui/extjs.c
src/webui/static/app/idnode.js
src/webui/static/app/tvhlog.js

index d8d37d679d7f82636296bbcf301d70a3bf7b00b2..2a842b10cb9b311266dfb2c00d739135bb4d9935 100644 (file)
@@ -38,6 +38,8 @@ api_config_init ( void )
     { "config/capabilities", ACCESS_WEB_INTERFACE, api_config_capabilities, NULL },
     { "config/load",         ACCESS_ADMIN, api_idnode_load_simple, &config },
     { "config/save",         ACCESS_ADMIN, api_idnode_save_simple, &config },
+    { "tvhlog/config/load",  ACCESS_ADMIN, api_idnode_load_simple, &tvhlog_conf },
+    { "tvhlog/config/save",  ACCESS_ADMIN, api_idnode_save_simple, &tvhlog_conf },
     { NULL },
   };
 
index d545ea9a2f5888bccf9166c50244f02137fe788b..fd082ec32fc5995866442b3c8f46d71cb012de89 100644 (file)
@@ -163,6 +163,9 @@ typedef LIST_HEAD(,idnode_filter_ele) idnode_filter_t;
 
 extern char idnode_uuid_static[UUID_HEX_SIZE];
 
+extern idnode_t tvhlog_conf;
+extern const idclass_t tvhlog_conf_class;
+
 void idnode_init(void);
 void idnode_done(void);
 
index 5eddbac355c64c7c29c0098dfec1213dfa1ca359..cb1cf101c1cd1a927032a93d850bfdaa5c3cf0c6 100644 (file)
@@ -25,6 +25,8 @@
 #include "tvh_locale.h"
 #include "lang_str.h"
 
+char prop_sbuf[PROP_SBUF_LEN];
+
 /* **************************************************************************
  * Utilities
  * *************************************************************************/
index ec5e2cbf1ff604d15aa4e9c1ed5ae1fd0baf6e90..242e47969b96d29a913778fc242f943de3345f91 100644 (file)
@@ -101,6 +101,9 @@ typedef struct property {
 
 } property_t;
 
+#define PROP_SBUF_LEN 4096
+extern char prop_sbuf[PROP_SBUF_LEN];
+
 const property_t *prop_find(const property_t *p, const char *name);
 
 int prop_write_values
index 7056310c5826271c0c4b9c25cbe1e7f033c60cb3..fc42d57138eae27f880a0ca7e3258aad37307020 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+#include "libav.h"
 #include "webui/webui.h"
 
 time_t                   dispatch_clock;
@@ -446,3 +447,184 @@ tvhlog_end ( void )
   htsmsg_destroy(tvhlog_trace);
   closelog();
 }
+
+/*
+ * Configuration
+ */
+
+static void tvhlog_class_save(idnode_t *self)
+{
+}
+
+static const void *
+tvhlog_class_path_get ( void *o )
+{
+  return &tvhlog_path;
+}
+
+static int
+tvhlog_class_path_set ( void *o, const void *v )
+{
+  const char *s = v;
+  if (strcmp(s ?: "", tvhlog_path ?: "")) {
+    pthread_mutex_unlock(&tvhlog_mutex);
+    free(tvhlog_path);
+    tvhlog_path = strdup(s ?: "");
+    if (tvhlog_path && tvhlog_path[0])
+      tvhlog_options |= TVHLOG_OPT_DBG_FILE;
+    else
+      tvhlog_options &= ~TVHLOG_OPT_DBG_FILE;
+    pthread_mutex_lock(&tvhlog_mutex);
+    return 1;
+  }
+  return 0;
+}
+
+static const void *
+tvhlog_class_debugsubs_get ( void *o )
+{
+  static char *p = prop_sbuf;
+  tvhlog_get_debug(prop_sbuf, PROP_SBUF_LEN);
+  return &p;
+}
+
+static int
+tvhlog_class_debugsubs_set ( void *o, const void *v )
+{
+  tvhlog_set_debug((const char *)v);
+  return 1;
+}
+
+static const void *
+tvhlog_class_tracesubs_get ( void *o )
+{
+  static char *p = prop_sbuf;
+  tvhlog_get_trace(prop_sbuf, PROP_SBUF_LEN);
+  return &p;
+}
+
+static int
+tvhlog_class_tracesubs_set ( void *o, const void *v )
+{
+  tvhlog_set_trace((const char *)v);
+  return 1;
+}
+
+static const void *
+tvhlog_class_syslog_get ( void *o )
+{
+  static int si;
+  si = (tvhlog_options & TVHLOG_OPT_DBG_SYSLOG) ? 1 : 0;
+  return &si;
+}
+
+static int
+tvhlog_class_syslog_set ( void *o, const void *v )
+{
+  pthread_mutex_lock(&tvhlog_mutex);
+  if (*(int *)v)
+    tvhlog_options |= TVHLOG_OPT_DBG_SYSLOG;
+  else
+    tvhlog_options &= ~TVHLOG_OPT_DBG_SYSLOG;
+  pthread_mutex_unlock(&tvhlog_mutex);
+  return 1;
+}
+
+static const void *
+tvhlog_class_trace_get ( void *o )
+{
+  static int si;
+  si = tvhlog_level >= LOG_TRACE;
+  return &si;
+}
+
+static int
+tvhlog_class_trace_set ( void *o, const void *v )
+{
+  pthread_mutex_lock(&tvhlog_mutex);
+  if (*(int *)v)
+    tvhlog_level = LOG_TRACE;
+  else
+    tvhlog_level = LOG_DEBUG;
+  pthread_mutex_unlock(&tvhlog_mutex);
+  return 1;
+}
+
+static const void *
+tvhlog_class_libav_get ( void *o )
+{
+  static int si;
+  si = (tvhlog_options & TVHLOG_OPT_LIBAV) ? 1 : 0;
+  return &si;
+}
+
+static int
+tvhlog_class_libav_set ( void *o, const void *v )
+{
+  pthread_mutex_lock(&tvhlog_mutex);
+  if (*(int *)v)
+    tvhlog_options |= TVHLOG_OPT_LIBAV;
+  else
+    tvhlog_options &= ~TVHLOG_OPT_LIBAV;
+  libav_set_loglevel();
+  pthread_mutex_unlock(&tvhlog_mutex);
+  return 1;
+}
+
+idnode_t tvhlog_conf = {
+  .in_class      = &tvhlog_conf_class
+};
+
+const idclass_t tvhlog_conf_class = {
+  .ic_snode      = &tvhlog_conf,
+  .ic_class      = "tvhlog_conf",
+  .ic_caption    = N_("Debugging"),
+  .ic_event      = "tvhlog_conf",
+  .ic_perm_def   = ACCESS_ADMIN,
+  .ic_save       = tvhlog_class_save,
+  .ic_properties = (const property_t[]){
+    {
+      .type   = PT_STR,
+      .id     = "path",
+      .name   = N_("Debug log path"),
+      .get    = tvhlog_class_path_get,
+      .set    = tvhlog_class_path_set,
+    },
+    {
+      .type   = PT_BOOL,
+      .id     = "syslog",
+      .name   = N_("Debug to syslog"),
+      .get    = tvhlog_class_syslog_get,
+      .set    = tvhlog_class_syslog_set,
+    },
+    {
+      .type   = PT_STR,
+      .id     = "debugsubs",
+      .name   = N_("Debug subsystems"),
+      .get    = tvhlog_class_debugsubs_get,
+      .set    = tvhlog_class_debugsubs_set,
+    },
+    {
+      .type   = PT_BOOL,
+      .id     = "trace",
+      .name   = N_("Debug trace (low-level)"),
+      .get    = tvhlog_class_trace_get,
+      .set    = tvhlog_class_trace_set,
+    },
+    {
+      .type   = PT_STR,
+      .id     = "tracesubs",
+      .name   = N_("Trace subsystems"),
+      .get    = tvhlog_class_tracesubs_get,
+      .set    = tvhlog_class_tracesubs_set,
+    },
+    {
+      .type   = PT_BOOL,
+      .id     = "libav",
+      .name   = N_("Debug libav log"),
+      .get    = tvhlog_class_libav_get,
+      .set    = tvhlog_class_libav_set,
+    },
+    {}
+  }
+};
index 7f773360c4b774808c7f489cd6a3934358f194e7..3cee4d28346998c2befd4aea707322e55b92856d 100644 (file)
@@ -379,102 +379,6 @@ extjs_epggrab(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 HTTP_STATUS_BAD_REQUEST;
-
-  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();
-    if (!m) {
-      pthread_mutex_unlock(&tvhlog_mutex);
-      return HTTP_STATUS_BAD_REQUEST;
-    }
-    htsmsg_add_u32(m, "tvhlog_level",      tvhlog_level);
-    htsmsg_add_u32(m, "tvhlog_trace_on",   tvhlog_level > LOG_DEBUG);
-    tvhlog_get_trace(str, sizeof(str));
-    htsmsg_add_str(m, "tvhlog_trace",      str);
-    tvhlog_get_debug(str, sizeof(str));
-    htsmsg_add_str(m, "tvhlog_debug",      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));
-    htsmsg_add_u32(m, "tvhlog_libav",
-                   !!(tvhlog_options & TVHLOG_OPT_LIBAV));
-    pthread_mutex_unlock(&tvhlog_mutex);
-    
-    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_trace_on")))
-      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;
-    if ((str = http_arg_get(&hc->hc_req_args, "tvhlog_libav")))
-      tvhlog_options |= TVHLOG_OPT_LIBAV;
-    else
-      tvhlog_options &= ~TVHLOG_OPT_LIBAV;
-    libav_set_loglevel();
-    if (tvhlog_path && tvhlog_path[0] != '\0')
-      tvhlog_options |= TVHLOG_OPT_DBG_FILE;
-    tvhlog_set_trace(http_arg_get(&hc->hc_req_args, "tvhlog_trace"));
-    tvhlog_set_debug(http_arg_get(&hc->hc_req_args, "tvhlog_debug"));
-    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;
-}
-
 /**
  * WEB user interface
  */
@@ -485,5 +389,4 @@ extjs_start(void)
   http_path_add("/extjs.html",       NULL, extjs_root,             ACCESS_WEB_INTERFACE);
   http_path_add("/tv.html",          NULL, extjs_livetv,           ACCESS_WEB_INTERFACE);
   http_path_add("/epggrab",          NULL, extjs_epggrab,          ACCESS_WEB_INTERFACE);
-  http_path_add("/tvhlog",           NULL, extjs_tvhlog,           ACCESS_ADMIN);
 }
index 7745c20dbb26f4f5946f9abfbf8632072527535a..655bd2df9c1469696c99b281afb5e1d974ba6128 100644 (file)
@@ -2145,9 +2145,9 @@ tvheadend.idnode_simple = function(panel, conf)
 
         /* Top bar */
         abuttons.save = new Ext.Toolbar.Button({
-            tooltip: _('Save pending changes (marked with red border)'),
+            tooltip: conf.saveTooltip || _('Save pending changes (marked with red border)'),
             iconCls: 'save',
-            text: _('Save'),
+            text: conf.saveText || _('Save'),
             disabled: true,
             handler: function() {
                 var node = current.getForm().getFieldValues();
@@ -2213,7 +2213,6 @@ tvheadend.idnode_simple = function(panel, conf)
         function form_build(d) {
 
             var fpanel = new Ext.form.FormPanel({
-                //title: conf.title || null,
                 frame: true,
                 border: true,
                 bodyStyle: 'padding: 5px',
index 96a67525b3f11c0cf455f9867c36221f59d6b5a8..70469f1480953943775dafb4a6ad8ce6bd43c842 100644 (file)
 tvheadend.tvhlog = function(panel, index) {
-    /*
-     * Basic Config
-     */
-    var confreader = new Ext.data.JsonReader({
-        root: 'config'
-    }, ['tvhlog_path', 'tvhlog_dbg_syslog', 'tvhlog_trace_on',
-        'tvhlog_debug', 'tvhlog_trace', 'tvhlog_libav']);
 
-    /* ****************************************************************
-     * 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 tvhlogTraceOn = new Ext.form.Checkbox({
-        name: 'tvhlog_trace_on',
-        fieldLabel: _('Debug trace (low-level stuff)')
-    });
-
-    var tvhlogDebugSubsys = new Ext.form.TextField({
-        fieldLabel: _('Debug subsystems'),
-        name: 'tvhlog_debug',
-        allowBlank: true,
-        width: 400
-    });
-
-    var tvhlogTraceSubsys = new Ext.form.TextField({
-        fieldLabel: _('Trace subsystems'),
-        name: 'tvhlog_trace',
-        allowBlank: true,
-        width: 400
-    });
-
-    var tvhlogLibav = new Ext.form.Checkbox({
-        name: 'tvhlog_libav',
-        fieldLabel: _('Debug libav log')
-    });
-
-
-    /* ****************************************************************
-     * Form
-     * ***************************************************************/
-
-    var saveButton = new Ext.Button({
-        text: _("Apply configuration (run-time only)"),
-        tooltip: _('Apply any changes made below to the run-time configuration.') + '<br/>' +
-                 _('They will be lost when the application next restarts.'),
-        iconCls: 'apply',
-        handler: saveChanges
-    });
-
-    var helpButton = new Ext.Button({
-        text: _('Help'),
-        iconCls: 'help',
-        handler: function() {
-            new tvheadend.help(_('Debug Configuration'), 'config_debugging.html');
-        }
-    });
-
-    items = new Array();
-    items.push(tvhlogLogPath);
-    items.push(tvhlogToSyslog);
-    if (tvheadend.capabilities.indexOf('trace') !== -1)
-      items.push(tvhlogTraceOn);
-    items.push(tvhlogDebugSubsys);
-    if (tvheadend.capabilities.indexOf('trace') !== -1)
-      items.push(tvhlogTraceSubsys);
-    if (tvheadend.capabilities.indexOf('libav') !== -1)
-      items.push(tvhlogLibav);
-
-    var DebuggingPanel = new Ext.form.FieldSet({
-        title: _('Debugging Options'),
-        width: 700,
-        autoHeight: true,
-        collapsible: true,
-        animCollapse : true,
-        items: items
-    });
+    function onchange(form, field, nval, oval) {
+       var f = form.getForm();
+       var trace = f.findField('trace');
+       var tracesubs = f.findField('tracesubs');
+       tracesubs.setDisabled(!trace.getValue());
+    }
 
-    var confpanel = new Ext.form.FormPanel({
+    tvheadend.idnode_simple(panel, {
+        url: 'api/tvhlog/config',
         title: _('Debugging'),
         iconCls: 'debug',
-        border: false,
-        bodyStyle: 'padding:15px',
-        labelAlign: 'left',
-        labelWidth: 200,
-        waitMsgTarget: true,
-        reader: confreader,
-        layout: 'form',
-        defaultType: 'textfield',
-        autoHeight: true,
-        items: [DebuggingPanel],
-        tbar: [saveButton, '->', helpButton]
-    });
-
-    /* ****************************************************************
-     * Load/Save
-     * ***************************************************************/
-
-    confpanel.on('render', function() {
-        confpanel.getForm().load({
-            url: 'tvhlog',
-            params: {
-                op: 'loadSettings'
-            },
-            success: function(form, action) {
-                confpanel.enable();
-            }
-        });
+        tabIndex: index,
+        comet: 'tvhlog_conf',
+        labelWidth: 180,
+        width: 530,
+        onchange: onchange,
+        saveText: _("Apply configuration (run-time only)"),
+        saveTooltip: _('Apply any changes made below to the run-time configuration.') + '<br/>' +
+                     _('They will be lost when the application next restarts.'),
+        help: function() {
+            new tvheadend.help(_('Debug Configuration'), 'config_debug.html');
+        }
     });
 
-    function saveChanges() {
-        confpanel.getForm().submit({
-            url: 'tvhlog',
-            params: {
-                op: 'saveSettings'
-            },
-            waitMsg: _('Applying Data...'),
-            failure: function(form, action) {
-                Ext.Msg.alert(_('Data application failed'), action.result.errormsg);
-            }
-        });
-    }
-
-    tvheadend.paneladd(panel, confpanel, index);
 };