Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tvhlog: move to the simple node system
  • Loading branch information
perexg committed Sep 16, 2015
1 parent eab75c2 commit 9b91e06
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 229 deletions.
2 changes: 2 additions & 0 deletions src/api/api_config.c
Expand Up @@ -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 },
};

Expand Down
3 changes: 3 additions & 0 deletions src/idnode.h
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/prop.c
Expand Up @@ -25,6 +25,8 @@
#include "tvh_locale.h"
#include "lang_str.h"

char prop_sbuf[PROP_SBUF_LEN];

/* **************************************************************************
* Utilities
* *************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/prop.h
Expand Up @@ -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
Expand Down
182 changes: 182 additions & 0 deletions src/tvhlog.c
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <sys/time.h>

#include "libav.h"
#include "webui/webui.h"

time_t dispatch_clock;
Expand Down Expand Up @@ -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,
},
{}
}
};
97 changes: 0 additions & 97 deletions src/webui/extjs.c
Expand Up @@ -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
*/
Expand All @@ -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);
}
5 changes: 2 additions & 3 deletions src/webui/static/app/idnode.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 9b91e06

Please sign in to comment.