From 5f2de3a8a9997ab4001e7d87d35462f0331b250d Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Tue, 11 Jun 2013 20:29:02 +0100 Subject: [PATCH] idnode: Updated all objects to new idnode/prop API --- src/input/mpegts.h | 4 +- src/input/mpegts/linuxdvb.h | 2 +- src/input/mpegts/linuxdvb/linuxdvb_adapter.c | 13 ++- src/input/mpegts/linuxdvb/linuxdvb_device.c | 48 ++++------- src/input/mpegts/linuxdvb/linuxdvb_frontend.c | 70 ++++++++++----- src/input/mpegts/linuxdvb/linuxdvb_hardware.c | 41 +++------ src/input/mpegts/linuxdvb/linuxdvb_mux.c | 86 ++++++++++--------- src/input/mpegts/linuxdvb/linuxdvb_network.c | 15 ++-- src/input/mpegts/linuxdvb/linuxdvb_private.h | 7 +- src/input/mpegts/mpegts_input.c | 34 ++++++-- src/input/mpegts/mpegts_mux.c | 48 ++++++++--- src/input/mpegts/mpegts_network.c | 45 +++++----- src/input/mpegts/mpegts_service.c | 62 ++++++++++--- src/service.c | 36 ++++++-- src/webui/extjs.c | 59 ++----------- src/webui/extjs_dvb.c | 24 ++---- src/webui/webui.h | 3 - 17 files changed, 321 insertions(+), 276 deletions(-) diff --git a/src/input/mpegts.h b/src/input/mpegts.h index 2aa50738..9540df78 100644 --- a/src/input/mpegts.h +++ b/src/input/mpegts.h @@ -419,6 +419,8 @@ mpegts_input_t *mpegts_input_create0 #define mpegts_input_create1(u, c)\ mpegts_input_create0(calloc(1, sizeof(mpegts_input_t)),\ &mpegts_input_class, u, c) + +void mpegts_input_set_network ( mpegts_input_t *mi, mpegts_network_t *mn ); mpegts_network_t *mpegts_network_create0 ( mpegts_network_t *mn, const idclass_t *idc, const char *uuid, @@ -436,8 +438,6 @@ extern const idclass_t mpegts_network_class; void mpegts_network_schedule_initial_scan ( mpegts_network_t *mm ); -void mpegts_network_add_input ( mpegts_network_t *mn, mpegts_input_t *mi ); - int mpegts_network_set_nid ( mpegts_network_t *mn, uint16_t nid ); int mpegts_network_set_network_name ( mpegts_network_t *mn, const char *name ); diff --git a/src/input/mpegts/linuxdvb.h b/src/input/mpegts/linuxdvb.h index 7b45171f..a196882f 100644 --- a/src/input/mpegts/linuxdvb.h +++ b/src/input/mpegts/linuxdvb.h @@ -22,7 +22,7 @@ void linuxdvb_init ( int mask ); -idnode_t **linuxdvb_root ( void ); +idnode_set_t *linuxdvb_root ( void ); #endif /* __TVH_LINUX_DVB_H__ */ diff --git a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c index 05a26c66..4a3d8e96 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c @@ -47,8 +47,13 @@ const idclass_t linuxdvb_adapter_class = .ic_caption = "LinuxDVB Adapter", .ic_save = linuxdvb_adapter_class_save, .ic_properties = (const property_t[]){ - { PROPDEF2("rootpath", "Device Path", - PT_STR, linuxdvb_adapter_t, la_rootpath, 1) }, + { + .type = PT_STR, + .id = "rootpath", + .name = "Device Path", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_adapter_t, la_rootpath), + }, {} } }; @@ -62,7 +67,7 @@ linuxdvb_adapter_save ( linuxdvb_adapter_t *la, htsmsg_t *m ) htsmsg_t *l; linuxdvb_hardware_t *lh; - linuxdvb_hardware_save((linuxdvb_hardware_t*)la, m); + idnode_save(&la->mi_id, m); htsmsg_add_u32(m, "number", la->la_number); if (la->la_rootpath) htsmsg_add_str(m, "rootpath", la->la_rootpath); @@ -121,7 +126,7 @@ linuxdvb_adapter_create0 if (!conf) return la; - linuxdvb_hardware_load((linuxdvb_hardware_t*)la, conf); + idnode_load(&la->mi_id, conf); if (!htsmsg_get_u32(conf, "number", &u32)) la->la_number = u32; if ((str = htsmsg_get_str(conf, "rootpath"))) diff --git a/src/input/mpegts/linuxdvb/linuxdvb_device.c b/src/input/mpegts/linuxdvb/linuxdvb_device.c index 08eb73c2..bdfa6564 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_device.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_device.c @@ -43,16 +43,8 @@ static struct strtab bustab[] = { { "USB2", BUS_USB2 }, { "USB3", BUS_USB3 } }; -static const char* -devinfo_bus2str ( int p ) -{ - return val2str(p, bustab); -} -static int -devinfo_str2bus ( const char *str ) -{ - return str2val(str, bustab); -} +#define devinfo_bus2str(p) val2str(p, bustab) +#define devinfo_str2bus(p) str2val(p, bustab) /* * Get bus information @@ -183,12 +175,7 @@ void linuxdvb_device_save ( linuxdvb_device_t *ld ) m = htsmsg_create_map(); - linuxdvb_hardware_save((linuxdvb_hardware_t*)ld, m); - if (ld->ld_devid.di_id) { - htsmsg_add_str(m, "devid", ld->ld_devid.di_id); - htsmsg_add_str(m, "devbus", devinfo_bus2str(ld->ld_devid.di_bus)); - htsmsg_add_str(m, "devpath", ld->ld_devid.di_path); - } + idnode_save(&ld->mi_id, m); /* Adapters */ l = htsmsg_create_map(); @@ -211,15 +198,20 @@ const idclass_t linuxdvb_device_class = .ic_caption = "LinuxDVB Device", .ic_save = linuxdvb_device_class_save, .ic_properties = (const property_t[]){ - { PROPDEF2("devid", "Device ID", - PT_STR, linuxdvb_device_t, ld_devid.di_id, 1) }, + { + .type = PT_STR, + .id = "devid", + .name = "Device ID", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_device_t, ld_devid.di_id) + }, {} } }; static linuxdvb_hardware_list_t linuxdvb_device_all; -idnode_t ** +idnode_set_t * linuxdvb_root ( void ) { return linuxdvb_hardware_enumerate(&linuxdvb_device_all); @@ -228,8 +220,6 @@ linuxdvb_root ( void ) linuxdvb_device_t * linuxdvb_device_create0 ( const char *uuid, htsmsg_t *conf ) { - uint32_t u32; - const char *str; linuxdvb_device_t *ld; htsmsg_t *e; htsmsg_field_t *f; @@ -247,17 +237,7 @@ linuxdvb_device_create0 ( const char *uuid, htsmsg_t *conf ) return ld; /* Load config */ - linuxdvb_hardware_load((linuxdvb_hardware_t*)ld, conf); - if (!htsmsg_get_u32(conf, "enabled", &u32) && u32) - ld->mi_enabled = 1; - if ((str = htsmsg_get_str(conf, "displayname"))) - ld->lh_displayname = strdup(str); - if ((str = htsmsg_get_str(conf, "devid"))) - ld->ld_devid.di_id = strdup(str); - if ((str = htsmsg_get_str(conf, "devbus"))) - ld->ld_devid.di_bus = devinfo_str2bus(str); - if ((str = htsmsg_get_str(conf, "devpath"))) - strncpy(ld->ld_devid.di_path, str, sizeof(ld->ld_devid.di_path)); + idnode_load(&ld->mi_id, conf); get_min_dvb_adapter(&ld->ld_devid); /* Adapters */ @@ -293,8 +273,10 @@ linuxdvb_device_find_by_adapter ( int a ) get_device_info(&dev, a); /* Find existing */ - if ((ld = linuxdvb_device_find_by_hwid(dev.di_id))) + if ((ld = linuxdvb_device_find_by_hwid(dev.di_id))) { + memcpy(&ld->ld_devid, &dev, sizeof(dev)); return ld; + } /* Create new */ if (!(ld = linuxdvb_device_create0(NULL, NULL))) { diff --git a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c index 6f3f6561..5f4658ae 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c @@ -70,16 +70,40 @@ const idclass_t linuxdvb_frontend_class = .ic_get_title = linuxdvb_frontend_class_get_title, .ic_save = linuxdvb_frontend_class_save, .ic_properties = (const property_t[]) { - { PROPDEF2("fe_path", "Frontend Path", - PT_STR, linuxdvb_frontend_t, lfe_fe_path, 1) }, - { PROPDEF2("dvr_path", "Input Path", - PT_STR, linuxdvb_frontend_t, lfe_dvr_path, 1) }, - { PROPDEF2("dmx_path", "Demux Path", - PT_STR, linuxdvb_frontend_t, lfe_dmx_path, 1) }, - { PROPDEF2("number", "FE Number", - PT_INT, linuxdvb_frontend_t, lfe_number, 1) }, - { PROPDEF1("fullmux", "Full Mux Mode", - PT_BOOL, linuxdvb_frontend_t, lfe_fullmux) }, + { + .type = PT_STR, + .id = "fe_path", + .name = "Frontend Path", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_frontend_t, lfe_fe_path), + }, + { + .type = PT_STR, + .id = "dvr_path", + .name = "Input Path", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_frontend_t, lfe_dvr_path), + }, + { + .type = PT_STR, + .id = "dmx_path", + .name = "Demux Path", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_frontend_t, lfe_dmx_path), + }, + { + .type = PT_INT, + .id = "fe_number", + .name = "Frontend Number", + .opts = PO_RDONLY, + .off = offsetof(linuxdvb_frontend_t, lfe_number), + }, + { + .type = PT_BOOL, + .id = "fullmux", + .name = "Full Mux RX mode", + .off = offsetof(linuxdvb_frontend_t, lfe_fullmux), + }, {} } }; @@ -93,13 +117,17 @@ linuxdvb_frontend_class_network_get(void *o) return NULL; } -static void +static int linuxdvb_frontend_class_network_set(void *o, const char *s) { - mpegts_input_t *mi = o; - mpegts_network_t *mn = mpegts_network_find(s); - if (mn) - mpegts_network_add_input(mn, mi); + mpegts_input_t *mi = o; + mpegts_network_t *mn = mi->mi_network; + + if (mi->mi_network && !strcmp(idnode_uuid_as_str(&mn->mn_id), s ?: "")) + return 0; + + mpegts_input_set_network(mi, s ? mpegts_network_find(s) : NULL); + return 1; } static htsmsg_t * @@ -131,10 +159,12 @@ const idclass_t linuxdvb_frontend_dvbt_class = .ic_caption = "Linux DVB-T Frontend", .ic_properties = (const property_t[]){ { - PROPDEF0("network", "Network", PT_STR, 0), - .str_get = linuxdvb_frontend_class_network_get, - .str_set = linuxdvb_frontend_class_network_set, - .str_enum2 = linuxdvb_frontend_class_network_enum + .type = PT_STR, + .id = "network", + .name = "Network", + .str_get = linuxdvb_frontend_class_network_get, + .str_set = linuxdvb_frontend_class_network_set, + .str_enum = linuxdvb_frontend_class_network_enum }, {} } @@ -763,7 +793,7 @@ linuxdvb_frontend_create0 linuxdvb_network_t *ln = linuxdvb_network_find_by_uuid(str); if (ln) { if (ln->ln_type == lfe->lfe_info.type) { - mpegts_network_add_input((mpegts_network_t*)ln, (mpegts_input_t*)lfe); + mpegts_input_set_network((mpegts_input_t*)lfe, (mpegts_network_t*)ln); } else tvhlog(LOG_WARNING, "linuxdvb", "attempt to add network %s of wrong type %s to %s (%s)", diff --git a/src/input/mpegts/linuxdvb/linuxdvb_hardware.c b/src/input/mpegts/linuxdvb/linuxdvb_hardware.c index d73c7714..ac640033 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_hardware.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_hardware.c @@ -29,37 +29,14 @@ #include #include -idnode_t ** +idnode_set_t * linuxdvb_hardware_enumerate ( linuxdvb_hardware_list_t *list ) { linuxdvb_hardware_t *lh; - idnode_t **v; - int cnt = 1; + idnode_set_t *set = idnode_set_create(); LIST_FOREACH(lh, list, lh_parent_link) - cnt++; - v = malloc(sizeof(idnode_t *) * cnt); - cnt = 0; - LIST_FOREACH(lh, list, lh_parent_link) - v[cnt++] = &lh->mi_id; - v[cnt] = NULL; - return v; -} - -void linuxdvb_hardware_save ( linuxdvb_hardware_t *lh, htsmsg_t *m ) -{ - htsmsg_add_u32(m, "enabled", lh->mi_enabled); - if (lh->lh_displayname) - htsmsg_add_str(m, "displayname", lh->lh_displayname); -} - -void linuxdvb_hardware_load ( linuxdvb_hardware_t *lh, htsmsg_t *conf ) -{ - uint32_t u32; - const char *str; - if (!htsmsg_get_u32(conf, "enabled", &u32) && u32) - lh->mi_enabled = 1; - if ((str = htsmsg_get_str(conf, "displayname"))) - lh->lh_displayname = strdup(str); + idnode_set_add(set, &lh->mi_id, NULL); + return set; } static const char * @@ -68,7 +45,7 @@ linuxdvb_hardware_class_get_title ( idnode_t *in ) return ((linuxdvb_hardware_t*)in)->lh_displayname; } -static idnode_t ** +static idnode_set_t * linuxdvb_hardware_class_get_childs ( idnode_t *in ) { return linuxdvb_hardware_enumerate(&((linuxdvb_hardware_t*)in)->lh_children); @@ -83,8 +60,12 @@ const idclass_t linuxdvb_hardware_class = .ic_get_title = linuxdvb_hardware_class_get_title, .ic_get_childs = linuxdvb_hardware_class_get_childs, .ic_properties = (const property_t[]){ - { PROPDEF1("displayname", "Name", - PT_STR, linuxdvb_hardware_t, lh_displayname) }, + { + .type = PT_STR, + .id = "displayname", + .name = "Name", + .off = offsetof(linuxdvb_hardware_t, lh_displayname), + }, {} } }; diff --git a/src/input/mpegts/linuxdvb/linuxdvb_mux.c b/src/input/mpegts/linuxdvb/linuxdvb_mux.c index aa380552..ca61727c 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_mux.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_mux.c @@ -48,30 +48,30 @@ linuxdvb_mux_##c##_class_##l##_get (void *o)\ linuxdvb_mux_t *lm = o;\ return dvb_##l##2str(lm->lm_tuning.dmc_fe_params.u.f.p);\ }\ -static void \ +static int \ linuxdvb_mux_##c##_class_##l##_set (void *o, const char *s)\ {\ linuxdvb_mux_t *lm = o;\ lm->lm_tuning.dmc_fe_params.u.f.p = dvb_str2##l (s);\ + return 1;\ }\ -static const char **\ +static htsmsg_t *\ linuxdvb_mux_##c##_class_##l##_enum (void *o)\ {\ static const int t[] = { __VA_ARGS__ };\ - static const char ** r = NULL;\ - if (!r) {\ - int i, n = ARRAY_SIZE(t);\ - r = calloc(n+1, sizeof(char*));\ - for (i = 0; i < n; i++)\ - r[i] = dvb_##l##2str(t[i]);\ - }\ - return r;\ + int i;\ + htsmsg_t *m = htsmsg_create_list();\ + for (i = 0; i < ARRAY_SIZE(t); i++)\ + htsmsg_add_str(m, NULL, dvb_##l##2str(t[i]));\ + return m;\ } -#define MUX_PROP_STR(p, c, t, l)\ - PROPDEF0(p, c, PT_STR, PO_WRONCE),\ +#define MUX_PROP_STR(_id, _name, t, l)\ + .type = PT_STR,\ + .id = _id,\ + .name = _name,\ .str_get = linuxdvb_mux_##t##_class_##l##_get,\ .str_set = linuxdvb_mux_##t##_class_##l##_set,\ - .str_enum = linuxdvb_mux_##t##_class_##l##_enum\ + .str_enum = linuxdvb_mux_##t##_class_##l##_enum const idclass_t linuxdvb_mux_class = { @@ -142,9 +142,11 @@ const idclass_t linuxdvb_mux_dvbt_class = .ic_caption = "Linux DVB-T Multiplex", .ic_properties = (const property_t[]){ { - PROPDEF3("frequency", "Frequency (kHz)", PT_U32, - linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency, - PO_WRONCE) + .type = PT_U32, + .id = "frequency", + .name = "Frequency (MHz)", + .opts = PO_WRONCE, + .off = offsetof(linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency), }, { MUX_PROP_STR("bandwidth", "Bandwidth", dvbt, bw) @@ -192,14 +194,18 @@ const idclass_t linuxdvb_mux_dvbc_class = .ic_caption = "Linux DVB-C Multiplex", .ic_properties = (const property_t[]){ { - PROPDEF3("frequency", "Frequency (kHz)", PT_U32, - linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency, - PO_WRONCE) + .type = PT_U32, + .id = "frequency", + .name = "Frequency (MHz)", + .opts = PO_WRONCE, + .off = offsetof(linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency), }, { - PROPDEF3("symbol_rate", "Symbol Rate", PT_U32, - linuxdvb_mux_t, lm_tuning.dmc_fe_params.u.qam.symbol_rate, - PO_WRONCE) + .type = PT_U32, + .id = "symbolrate", + .name = "Symbol Rate", + .opts = PO_WRONCE, + .off = offsetof(linuxdvb_mux_t, lm_tuning.dmc_fe_params.u.qam.symbol_rate), }, { MUX_PROP_STR("constellation", "Constellation", dvbc, qam) @@ -231,24 +237,22 @@ linuxdvb_mux_dvbs_class_polarity_get (void *o) linuxdvb_mux_t *lm = o; return dvb_pol2str(lm->lm_tuning.dmc_fe_polarisation); } -static void +static int linuxdvb_mux_dvbs_class_polarity_set (void *o, const char *s) { linuxdvb_mux_t *lm = o; lm->lm_tuning.dmc_fe_polarisation = dvb_str2pol(s); + return 1; } -static const char **\ +static htsmsg_t * linuxdvb_mux_dvbs_class_polarity_enum (void *o) { - static const char **r = NULL; - if (!r) { - r = calloc(4+1, sizeof(char*));\ - r[0] = dvb_pol2str(POLARISATION_VERTICAL); - r[1] = dvb_pol2str(POLARISATION_HORIZONTAL); - r[2] = dvb_pol2str(POLARISATION_CIRCULAR_LEFT); - r[3] = dvb_pol2str(POLARISATION_CIRCULAR_RIGHT); - } - return r; + htsmsg_t *list = htsmsg_create_list(); + htsmsg_add_str(list, NULL, dvb_pol2str(POLARISATION_VERTICAL)); + htsmsg_add_str(list, NULL, dvb_pol2str(POLARISATION_HORIZONTAL)); + htsmsg_add_str(list, NULL, dvb_pol2str(POLARISATION_CIRCULAR_LEFT)); + htsmsg_add_str(list, NULL, dvb_pol2str(POLARISATION_CIRCULAR_RIGHT)); + return list; } const idclass_t linuxdvb_mux_dvbs_class = @@ -258,14 +262,18 @@ const idclass_t linuxdvb_mux_dvbs_class = .ic_caption = "Linux DVB-S Multiplex", .ic_properties = (const property_t[]){ { - PROPDEF3("frequency", "Frequency (kHz)", PT_U32, - linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency, - PO_WRONCE) + .type = PT_U32, + .id = "frequency", + .name = "Frequency (MHz)", + .opts = PO_WRONCE, + .off = offsetof(linuxdvb_mux_t, lm_tuning.dmc_fe_params.frequency), }, { - PROPDEF3("symbol_rate", "Symbol Rate", PT_U32, - linuxdvb_mux_t, lm_tuning.dmc_fe_params.u.qpsk.symbol_rate, - PO_WRONCE) + .type = PT_U32, + .id = "symbolrate", + .name = "Symbol Rate", + .opts = PO_WRONCE, + .off = offsetof(linuxdvb_mux_t, lm_tuning.dmc_fe_params.u.qpsk.symbol_rate), }, { MUX_PROP_STR("polarisation", "Polarisation", dvbs, polarity) diff --git a/src/input/mpegts/linuxdvb/linuxdvb_network.c b/src/input/mpegts/linuxdvb/linuxdvb_network.c index d02c8cb6..b2fbed51 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_network.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_network.c @@ -43,11 +43,12 @@ mpegts_network_class_get_lntype return dvb_type2str(((linuxdvb_network_t*)ptr)->ln_type); } -static void +static int mpegts_network_class_set_lntype ( void *ptr, const char *str ) { ((linuxdvb_network_t*)ptr)->ln_type = dvb_str2type(str); + return 1; } const idclass_t linuxdvb_network_class = @@ -56,10 +57,14 @@ const idclass_t linuxdvb_network_class = .ic_class = "linuxdvb_network", .ic_caption = "LinuxDVB Network", .ic_properties = (const property_t[]){ - { PROPDEF2("type", "Network Type", - PT_STR, linuxdvb_network_t, ln_type, 1), - .str_get = mpegts_network_class_get_lntype, - .str_set = mpegts_network_class_set_lntype }, + { + .type = PT_STR, + .id = "type", + .name = "Network Type", + .opts = PO_RDONLY, + .str_get = mpegts_network_class_get_lntype, + .str_set = mpegts_network_class_set_lntype, + }, {} } }; diff --git a/src/input/mpegts/linuxdvb/linuxdvb_private.h b/src/input/mpegts/linuxdvb/linuxdvb_private.h index ca47d702..3d8627c3 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_private.h +++ b/src/input/mpegts/linuxdvb/linuxdvb_private.h @@ -67,11 +67,8 @@ struct linuxdvb_hardware extern const idclass_t linuxdvb_hardware_class; -idnode_t ** -linuxdvb_hardware_enumerate ( linuxdvb_hardware_list_t *list ); -void linuxdvb_hardware_save ( linuxdvb_hardware_t *lh, htsmsg_t *m ); -void linuxdvb_hardware_load ( linuxdvb_hardware_t *lh, htsmsg_t *m ); - +idnode_set_t *linuxdvb_hardware_enumerate + ( linuxdvb_hardware_list_t *list ); struct linuxdvb_device { diff --git a/src/input/mpegts/mpegts_input.c b/src/input/mpegts/mpegts_input.c index 94d47f46..31aab241 100644 --- a/src/input/mpegts/mpegts_input.c +++ b/src/input/mpegts/mpegts_input.c @@ -30,7 +30,6 @@ * Class definition * *************************************************************************/ -#if 0 static const char * mpegts_input_class_get_name ( void *in ) { @@ -42,7 +41,6 @@ mpegts_input_class_get_name ( void *in ) *buf = 0; return buf; } -#endif const idclass_t mpegts_input_class = { @@ -50,15 +48,18 @@ const idclass_t mpegts_input_class = .ic_caption = "MPEGTS Input", .ic_properties = (const property_t[]){ { - PROPDEF1("enabled", "Enabled", PT_BOOL, - mpegts_input_t, mi_enabled) + .type = PT_BOOL, + .id = "enabled", + .name = "Enabled", + .off = offsetof(mpegts_input_t, mi_enabled), }, -#if 0 { - PROPDEF0("displayname", "Name", PT_STR, PO_NOSAVE | PO_RDONLY), - .str_get = mpegts_input_class_get_name + .type = PT_STR, + .id = "displayname", + .name = "Name", + .opts = PO_NOSAVE | PO_RDONLY, + .str_get = mpegts_input_class_get_name, }, -#endif {} } }; @@ -308,7 +309,7 @@ mpegts_input_create0 { idnode_insert(&mi->mi_id, uuid, class); if (c) - idnode_load(&mi->mi_id, c, 0); + idnode_load(&mi->mi_id, c); /* Defaults */ mi->mi_is_enabled = mpegts_input_is_enabled; @@ -347,6 +348,21 @@ mpegts_input_save ( mpegts_input_t *mi, htsmsg_t *m ) idnode_save(&mi->mi_id, m); } +void +mpegts_input_set_network ( mpegts_input_t *mi, mpegts_network_t *mn ) +{ + char buf1[256], buf2[265]; + mi->mi_display_name(mi, buf1, sizeof(buf1)); + if (mi->mi_network) { + mi->mi_network->mn_display_name(mi->mi_network, buf2, sizeof(buf2)); + LIST_REMOVE(mi, mi_network_link); + tvhdebug("mpegts", "%s - remove network %s", buf1, buf2); + } + mi->mi_network = mn; + LIST_INSERT_HEAD(&mn->mn_inputs, mi, mi_network_link); + tvhdebug("mpegts", "%s - added network %s", buf1, buf2); +} + /****************************************************************************** * Editor Configuration * diff --git a/src/input/mpegts/mpegts_mux.c b/src/input/mpegts/mpegts_mux.c index e3aa93e8..629d3c1a 100644 --- a/src/input/mpegts/mpegts_mux.c +++ b/src/input/mpegts/mpegts_mux.c @@ -34,8 +34,6 @@ const idclass_t mpegts_mux_instance_class = { .ic_class = "mpegts_mux_instance", .ic_caption = "MPEGTS Multiplex Phy", - .ic_properties = (const property_t[]){ - } }; mpegts_mux_instance_t * @@ -116,16 +114,40 @@ const idclass_t mpegts_mux_class = .ic_caption = "MPEGTS Multiplex", .ic_save = mpegts_mux_class_save, .ic_properties = (const property_t[]){ - { PROPDEF1("enabled", "Enabled", - PT_BOOL, mpegts_mux_t, mm_enabled) }, - { PROPDEF1("onid", "Original Network ID", - PT_U16, mpegts_mux_t, mm_onid) }, - { PROPDEF1("tsid", "Transport Stream ID", - PT_U16, mpegts_mux_t, mm_tsid) }, - { PROPDEF2("crid_authority", "CRID Authority", - PT_STR, mpegts_mux_t, mm_crid_authority, 1) }, - { PROPDEF2("init_scan_done", "Initial Scan Complete", - PT_BOOL, mpegts_mux_t, mm_initial_scan_done, 1) }, + { + .type = PT_BOOL, + .id = "enabled", + .name = "Enabled", + .off = offsetof(mpegts_mux_t, mm_enabled), + }, + { + .type = PT_U16, + .id = "onid", + .name = "Original Network ID", + .opts = PO_RDONLY, + .off = offsetof(mpegts_mux_t, mm_onid), + }, + { + .type = PT_U16, + .id = "tsid", + .name = "Transport Stream ID", + .opts = PO_RDONLY, + .off = offsetof(mpegts_mux_t, mm_tsid), + }, + { + .type = PT_STR, + .id = "cridauth", + .name = "CRID Authority", + .opts = PO_RDONLY, + .off = offsetof(mpegts_mux_t, mm_crid_authority), + }, + { + .type = PT_BOOL, + .id = "initscan", + .name = "Initial Scan Complete", + .opts = PO_RDONLY, + .off = offsetof(mpegts_mux_t, mm_initial_scan_done), + }, {} } }; @@ -426,7 +448,7 @@ mpegts_mux_create0 /* Configuration */ if (conf) - idnode_load(&mm->mm_id, conf, 0); + idnode_load(&mm->mm_id, conf); /* Initial scan */ if (!mm->mm_initial_scan_done || !mn->mn_skipinitscan) diff --git a/src/input/mpegts/mpegts_network.c b/src/input/mpegts/mpegts_network.c index dd2553e5..3dde5208 100644 --- a/src/input/mpegts/mpegts_network.c +++ b/src/input/mpegts/mpegts_network.c @@ -39,14 +39,30 @@ const idclass_t mpegts_network_class = .ic_caption = "MPEGTS Network", .ic_save = mpegts_network_class_save, .ic_properties = (const property_t[]){ - { PROPDEF1("networkname", "Network Name", - PT_STR, mpegts_network_t, mn_network_name) }, - { PROPDEF1("nid", "Network ID (limit scanning)", - PT_U16, mpegts_network_t, mn_nid) }, - { PROPDEF1("autodiscovery", "Network Discovery", - PT_BOOL, mpegts_network_t, mn_autodiscovery) }, - { PROPDEF1("skipinitscan", "Skip Initial Scan", - PT_BOOL, mpegts_network_t, mn_skipinitscan) }, + { + .type = PT_STR, + .id = "networkname", + .name = "Network Name", + .off = offsetof(mpegts_network_t, mn_network_name), + }, + { + .type = PT_U16, + .id = "nid", + .name = "Network ID (limit scanning)", + .off = offsetof(mpegts_network_t, mn_nid), + }, + { + .type = PT_BOOL, + .id = "autodiscovery", + .name = "Network Discovery", + .off = offsetof(mpegts_network_t, mn_autodiscovery), + }, + { + .type = PT_BOOL, + .id = "skipinitscan", + .name = "Skip Initial Scan", + .off = offsetof(mpegts_network_t, mn_skipinitscan), + }, {} } }; @@ -140,7 +156,7 @@ mpegts_network_create0 /* Setup idnode */ idnode_insert(&mn->mn_id, uuid, idc); if (conf) - idnode_load(&mn->mn_id, conf, 0); + idnode_load(&mn->mn_id, conf); /* Default callbacks */ mn->mn_display_name = mpegts_network_display_name; @@ -165,17 +181,6 @@ mpegts_network_create0 return mn; } -void -mpegts_network_add_input ( mpegts_network_t *mn, mpegts_input_t *mi ) -{ - char buf1[256], buf2[265]; - mi->mi_network = mn; - LIST_INSERT_HEAD(&mn->mn_inputs, mi, mi_network_link); - mn->mn_display_name(mn, buf1, sizeof(buf1)); - mi->mi_display_name(mi, buf2, sizeof(buf2)); - tvhdebug("mpegts", "%s - added input %s", buf1, buf2); -} - int mpegts_network_set_nid ( mpegts_network_t *mn, uint16_t nid ) diff --git a/src/input/mpegts/mpegts_service.c b/src/input/mpegts/mpegts_service.c index d32b1f96..7197ad2f 100644 --- a/src/input/mpegts/mpegts_service.c +++ b/src/input/mpegts/mpegts_service.c @@ -31,20 +31,54 @@ const idclass_t mpegts_service_class = .ic_class = "mpegts_service", .ic_caption = "MPEGTS Service", .ic_properties = (const property_t[]){ - { PROPDEF2("sid", "Service ID", - PT_U16, mpegts_service_t, s_dvb_service_id, 1) }, - { PROPDEF2("lcn", "Local Channel Number", - PT_U16, mpegts_service_t, s_dvb_channel_num, 1) }, - { PROPDEF2("svcname", "Service Name", - PT_STR, mpegts_service_t, s_dvb_svcname, 1) }, - { PROPDEF2("provider", "Provider", - PT_STR, mpegts_service_t, s_dvb_provider, 1) }, - { PROPDEF2("cridauth", "CRID Authority", - PT_STR, mpegts_service_t, s_dvb_cridauth, 1) }, - { PROPDEF2("servicetype", "Service Type", - PT_U16, mpegts_service_t, s_dvb_servicetype, 1) }, - { PROPDEF2("charset", "Character Set", - PT_STR, mpegts_service_t, s_dvb_charset, 0) }, + { + .type = PT_STR, + .id = "sid", + .name = "Service ID", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_service_id), + }, + { + .type = PT_U16, + .id = "lcn", + .name = "Local Channel Number", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_channel_num), + }, + { + .type = PT_STR, + .id = "svcname", + .name = "Service Name", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_svcname), + }, + { + .type = PT_STR, + .id = "provider", + .name = "Provider", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_provider), + }, + { + .type = PT_STR, + .id = "cridauth", + .name = "CRID Authority", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_cridauth), + }, + { + .type = PT_U16, + .id = "servicetype", + .name = "Service Type", + .opts = PO_RDONLY, + .off = offsetof(mpegts_service_t, s_dvb_servicetype), + }, + { + .type = PT_STR, + .id = "charset", + .name = "Character Set", + .off = offsetof(mpegts_service_t, s_dvb_charset), + }, {}, } }; diff --git a/src/service.c b/src/service.c index 2a52ad81..8b0c8972 100644 --- a/src/service.c +++ b/src/service.c @@ -46,21 +46,38 @@ static void service_data_timeout(void *aux); static const char *service_class_channel_get(void *obj); -static void service_class_channel_set(void *obj, const char *str); +static int service_class_channel_set(void *obj, const char *str); static void service_class_save(struct idnode *self); +static htsmsg_t *service_class_channel_enum(void *p) +{ + channel_t *ch; + htsmsg_t *list = htsmsg_create_list(); + RB_FOREACH(ch, &channel_name_tree, ch_name_link) + if (ch->ch_name) + htsmsg_add_str(list, NULL, ch->ch_name); + return list; +} + const idclass_t service_class = { .ic_class = "service", .ic_caption = "Service", .ic_save = service_class_save, .ic_properties = (const property_t[]){ - { - "channel", "Channel", PT_STR, - .str_get = service_class_channel_get, - .str_set = service_class_channel_set, + { + .type = PT_BOOL, + .id = "enabled", + .name = "Enabled", + .off = offsetof(service_t, s_enabled), + }, + { + .type = PT_STR, + .id = "channel", + .name = "Channel", + .str_get = service_class_channel_get, + .str_set = service_class_channel_set, + .str_enum = service_class_channel_enum }, - { PROPDEF1("enabled", "Enabled", - PT_BOOL, service_t, s_enabled) }, {} } }; @@ -680,10 +697,11 @@ service_class_channel_get(void *obj) /** * */ -static void +static int service_class_channel_set(void *obj, const char *str) { service_map_channel(obj, str ? channel_find_by_name(str, 1, 0) : NULL, 0); + return 1; // TODO: sort this! } @@ -1447,7 +1465,7 @@ void service_load ( service_t *t, htsmsg_t *c ) streaming_component_type_t type; const char *v; - idnode_load(&t->s_id, c, 0); + idnode_load(&t->s_id, c); if(!htsmsg_get_u32(c, "pcr", &u32)) t->s_pcr_pid = u32; diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 6d46e521..d4bc04c5 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -2204,7 +2204,7 @@ extjs_idnode const char *c = http_arg_get(&hc->hc_req_args, "conf"); htsmsg_t *conf = htsmsg_json_deserialize(c); if(conf) { - idnode_load(node, conf, 1); + idnode_update(node, conf); htsmsg_destroy(conf); } out = htsmsg_create_map(); @@ -2224,9 +2224,9 @@ extjs_idnode /** * */ -int +static int extjs_get_idnode(http_connection_t *hc, const char *remain, void *opaque, - idnode_t **(*rootfn)(void)) + idnode_set_t *(*rootfn)(void)) { htsbuf_queue_t *hq = &hc->hc_reply; const char *s = http_arg_get(&hc->hc_req_args, "node"); @@ -2243,7 +2243,7 @@ extjs_get_idnode(http_connection_t *hc, const char *remain, void *opaque, } out = htsmsg_create_list(); - idnode_t **v; + idnode_set_t *v; if(!strcmp(s, "root")) { v = rootfn(); @@ -2253,16 +2253,16 @@ extjs_get_idnode(http_connection_t *hc, const char *remain, void *opaque, if(v != NULL) { int i; - for(i = 0; v[i] != NULL; i++) { - htsmsg_t *m = idnode_serialize(v[i]); - htsmsg_add_u32(m, "leaf", idnode_is_leaf(v[i])); + for(i = 0; i < v->is_count; i++) { + htsmsg_t *m = idnode_serialize(v->is_array[i]); + htsmsg_add_u32(m, "leaf", idnode_is_leaf(v->is_array[i])); htsmsg_add_msg(out, NULL, m); } } pthread_mutex_unlock(&global_lock); - free(v); + idnode_set_free(v); htsmsg_json_serialize(out, hq, 0); htsmsg_destroy(out); @@ -2270,48 +2270,6 @@ extjs_get_idnode(http_connection_t *hc, const char *remain, void *opaque, return 0; } - -static const char * -get_prop_value(void *opaque, const char *key) -{ - http_connection_t *hc = opaque; - return http_arg_get(&hc->hc_req_args, key); -} - -/** - * - */ -static int -extjs_item_update(http_connection_t *hc, const char *remain, void *opaque) -{ - htsbuf_queue_t *hq = &hc->hc_reply; - htsmsg_t *out = NULL; - - if(remain == NULL) - return HTTP_STATUS_BAD_REQUEST; - - pthread_mutex_lock(&global_lock); - - idnode_t *n = idnode_find(remain, NULL); - - if(n == NULL) { - pthread_mutex_unlock(&global_lock); - return 404; - } - - idnode_update_all_props(n, get_prop_value, hc); - - pthread_mutex_unlock(&global_lock); - - out = htsmsg_create_map(); - htsmsg_add_u32(out, "success", 1); - htsmsg_json_serialize(out, hq, 0); - htsmsg_destroy(out); - http_output_content(hc, "text/x-json; charset=UTF-8"); - return 0; -} - - /** * */ @@ -2446,7 +2404,6 @@ extjs_start(void) http_path_add("/timeshift", NULL, extjs_timeshift, ACCESS_ADMIN); #endif http_path_add("/tvhlog", NULL, extjs_tvhlog, ACCESS_ADMIN); - http_path_add("/item/update", NULL, extjs_item_update, ACCESS_ADMIN); http_path_add("/tvadapters", NULL, extjs_tvadapters, ACCESS_ADMIN); diff --git a/src/webui/extjs_dvb.c b/src/webui/extjs_dvb.c index 10c0ec45..a4dc707e 100644 --- a/src/webui/extjs_dvb.c +++ b/src/webui/extjs_dvb.c @@ -108,18 +108,6 @@ extjs_grid_conf conf->sort.key = NULL; } -// TODO: move this -static htsmsg_t * -extjs_idnode_class ( const idclass_t *idc ) -{ - htsmsg_t *ret = htsmsg_create_list(); - while (idc) { - prop_add_params_to_msg(NULL, idc->ic_properties, ret); - idc = idc->ic_super; - } - return ret; -} - static void extjs_idnode_grid (idnode_set_t *ins, extjs_grid_conf_t *conf, htsmsg_t *out) @@ -168,7 +156,7 @@ extjs_mpegts_service } extjs_idnode_grid(&ins, &conf, out); } else if (!strcmp(op, "class")) { - htsmsg_t *list = extjs_idnode_class(&mpegts_service_class); + htsmsg_t *list = idclass_serialize(&mpegts_service_class); htsmsg_add_msg(out, "entries", list); } @@ -202,7 +190,7 @@ extjs_mpegts_mux } extjs_idnode_grid(&ins, &conf, out); } else if (!strcmp(op, "class")) { - htsmsg_t *list = extjs_idnode_class(&mpegts_mux_class); + htsmsg_t *list = idclass_serialize(&mpegts_mux_class); htsmsg_add_msg(out, "entries", list); } @@ -232,7 +220,7 @@ extjs_mpegts_network } extjs_idnode_grid(&ins, &conf, out); } else if (!strcmp(op, "class")) { - htsmsg_t *c = extjs_idnode_class(&mpegts_network_class); + htsmsg_t *c = idclass_serialize(&mpegts_network_class); htsmsg_add_msg(out, "entries", c); } else if (!strcmp(op, "mux_class")) { const idclass_t *idc; @@ -247,7 +235,7 @@ extjs_mpegts_network pthread_mutex_unlock(&global_lock); return HTTP_STATUS_BAD_REQUEST; } - htsmsg_t *c = extjs_idnode_class(idc); + htsmsg_t *c = idclass_serialize(idc); htsmsg_add_msg(out, "entries", c); pthread_mutex_unlock(&global_lock); } else if (!strcmp(op, "mux_create")) { @@ -303,14 +291,14 @@ extjs_mpegts_input idnode_set_add(&ins, (idnode_t*)mi, &conf.filter); extjs_idnode_grid(&ins, &conf, out); } else if (!strcmp(op, "class")) { - htsmsg_t *list= extjs_idnode_class(&mpegts_input_class); + htsmsg_t *list= idclass_serialize(&mpegts_input_class); htsmsg_add_msg(out, "entries", list); } else if (!strcmp(op, "network_class")) { const char *uuid = http_arg_get(&hc->hc_req_args, "uuid"); if (!uuid) return 404; mpegts_input_t *mi = idnode_find(uuid, &mpegts_input_class); if (!mi) return 404; - htsmsg_t *list= extjs_idnode_class(mi->mi_network_class(mi)); + htsmsg_t *list= idclass_serialize(mi->mi_network_class(mi)); htsmsg_add_msg(out, "entries", list); } else if (!strcmp(op, "network_create")) { const char *uuid = http_arg_get(&hc->hc_req_args, "uuid"); diff --git a/src/webui/webui.h b/src/webui/webui.h index 9605c3c5..bf4efcda 100644 --- a/src/webui/webui.h +++ b/src/webui/webui.h @@ -47,9 +47,6 @@ void extjs_service_update(htsmsg_t *in); void extjs_service_delete(htsmsg_t *in); -int extjs_get_idnode(http_connection_t *hc, const char *remain, void *opaque, - idnode_t **(*rootfn)(void)); - /** * */