{ "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 },
};
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);
#include "tvh_locale.h"
#include "lang_str.h"
+char prop_sbuf[PROP_SBUF_LEN];
+
/* **************************************************************************
* Utilities
* *************************************************************************/
} 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
#include <stdlib.h>
#include <sys/time.h>
+#include "libav.h"
#include "webui/webui.h"
time_t dispatch_clock;
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,
+ },
+ {}
+ }
+};
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
*/
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);
}
/* 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();
function form_build(d) {
var fpanel = new Ext.form.FormPanel({
- //title: conf.title || null,
frame: true,
border: true,
bodyStyle: 'padding: 5px',
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);
};