Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wizard: implement tuner / network type dialog
  • Loading branch information
perexg committed Jan 19, 2016
1 parent b261275 commit a0fe071
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 82 deletions.
34 changes: 18 additions & 16 deletions src/api/api_wizard.c
Expand Up @@ -24,14 +24,28 @@
#include "config.h"
#include "wizard.h"

static int
wizard_page ( const char *page )
{
pthread_mutex_lock(&global_lock);
if (strcmp(page, config.wizard ?: "")) {
free(config.wizard);
config.wizard = page[0] ? strdup(page) : NULL;
config_save();
}
pthread_mutex_unlock(&global_lock);
return 0;
}

static int
wizard_idnode_load_simple
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int r;
wizard_build_fcn_t fcn = opaque;
wizard_page_t *page = fcn();
wizard_page_t *page = fcn(perm->aa_lang_ui);
r = api_idnode_load_simple(perm, &page->idnode, op, args, resp);
wizard_page(page->name);
page->free(page);
return r;
}
Expand All @@ -42,36 +56,24 @@ wizard_idnode_save_simple
{
int r;
wizard_build_fcn_t fcn = opaque;
wizard_page_t *page = fcn();
wizard_page_t *page = fcn(perm->aa_lang_ui);
r = api_idnode_save_simple(perm, &page->idnode, op, args, resp);
page->free(page);
return r;
}

static int
wizard_page
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp, const char *page )
{
pthread_mutex_lock(&global_lock);
free(config.wizard);
config.wizard = strdup(page);
config_save();
pthread_mutex_unlock(&global_lock);
return 0;
}

static int
wizard_cancel
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return wizard_page(perm, opaque, op, args, resp, "");
return wizard_page("");
}

static int
wizard_start
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return wizard_page(perm, opaque, op, args, resp, "hello");
return wizard_page("hello");
}

void
Expand Down
4 changes: 3 additions & 1 deletion src/htsmsg.c
Expand Up @@ -935,7 +935,9 @@ htsmsg_copy_i(htsmsg_t *src, htsmsg_t *dst)
htsmsg_t *
htsmsg_copy(htsmsg_t *src)
{
htsmsg_t *dst = src->hm_islist ? htsmsg_create_list() : htsmsg_create_map();
htsmsg_t *dst;
if (src == NULL) return NULL;
dst = src->hm_islist ? htsmsg_create_list() : htsmsg_create_map();
htsmsg_copy_i(src, dst);
return dst;
}
Expand Down
4 changes: 4 additions & 0 deletions src/input.h
Expand Up @@ -22,6 +22,8 @@
#include "idnode.h"
#include "queue.h"

struct htsmsg;

/*
* Type-defs
*/
Expand Down Expand Up @@ -87,6 +89,8 @@ struct tvh_input {

void (*ti_get_streams) (tvh_input_t *, tvh_input_stream_list_t*);
void (*ti_clear_stats) (tvh_input_t *);
struct htsmsg *(*ti_wizard_get) (tvh_input_t *, const char *);
void (*ti_wizard_set) (tvh_input_t *, struct htsmsg *);
};

/*
Expand Down
3 changes: 3 additions & 0 deletions src/input/mpegts.h
Expand Up @@ -302,6 +302,8 @@ struct mpegts_network
*/
char *mn_network_name;
char *mn_provider_network_name;
int mn_wizard;
uint8_t mn_wizard_free;

/*
* Inputs
Expand Down Expand Up @@ -826,6 +828,7 @@ void mpegts_network_delete ( mpegts_network_t *mn, int delconf );
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 );
void mpegts_network_scan ( mpegts_network_t *mn );
void mpegts_network_get_type_str( mpegts_network_t *mn, char *buf, size_t buflen );

mpegts_mux_t *mpegts_mux_create0
( mpegts_mux_t *mm, const idclass_t *class, const char *uuid,
Expand Down
20 changes: 20 additions & 0 deletions src/input/mpegts/mpegts_network.c
Expand Up @@ -251,6 +251,13 @@ const idclass_t mpegts_network_class =
.opts = PO_RDONLY | PO_NOSAVE,
.get = mpegts_network_class_get_scanq_length,
},
{
.type = PT_BOOL,
.id = "wizard",
.name = N_("Wizard"),
.off = offsetof(mpegts_network_t, mn_wizard),
.opts = PO_NOUI
},
{}
}
};
Expand Down Expand Up @@ -449,6 +456,19 @@ mpegts_network_scan ( mpegts_network_t *mn )
mpegts_mux_scan_state_set(mm, MM_SCAN_STATE_PEND);
}

void
mpegts_network_get_type_str( mpegts_network_t *mn, char *buf, size_t buflen )
{
const char *s = "IPTV";
#if ENABLE_MPEGTS_DVB
dvb_fe_type_t ftype;
ftype = dvb_fe_type_by_network_class(mn->mn_id.in_class);
if (ftype != DVB_TYPE_NONE)
s = dvb_type2str(ftype);
#endif
snprintf(buf, buflen, "%s", s);
}

/******************************************************************************
* Network classes/creation
*****************************************************************************/
Expand Down
11 changes: 1 addition & 10 deletions src/input/mpegts/mpegts_service.c
Expand Up @@ -434,16 +434,7 @@ mpegts_service_setsourceinfo(service_t *t, source_info_t *si)

if(m->mm_network->mn_network_name != NULL)
si->si_network = strdup(m->mm_network->mn_network_name);
#if ENABLE_MPEGTS_DVB
dvb_fe_type_t ftype;
ftype = dvb_fe_type_by_network_class(m->mm_network->mn_id.in_class);
if (ftype == DVB_TYPE_NONE)
strcpy(buf, "IPTV");
else
snprintf(buf, sizeof(buf), "%s", dvb_type2str(ftype));
#else
strcpy(buf, "IPTV");
#endif
mpegts_network_get_type_str(m->mm_network, buf, sizeof(buf));
si->si_network_type = strdup(buf);

m->mm_display_name(m, buf, sizeof(buf));
Expand Down
73 changes: 67 additions & 6 deletions src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -1752,8 +1752,69 @@ satip_frontend_input_thread ( void *aux )
* Creation/Config
* *************************************************************************/

static int
satip_frontend_default_positions ( satip_frontend_t *lfe )
{
satip_device_t *sd = lfe->sf_device;

if (!strcmp(sd->sd_info.modelname, "IPLNB"))
return 1;
return sd->sd_info.srcs;
}

static htsmsg_t *
satip_frontend_wizard_get( tvh_input_t *ti, const char *lang )
{
satip_frontend_t *lfe = (satip_frontend_t*)ti;
htsmsg_t *m = htsmsg_create_map(), *l, *e;
satip_satconf_t *sfc;
const idclass_t *idc;
char ubuf[UUID_HEX_SIZE], buf[256];

sfc = TAILQ_FIRST(&lfe->sf_satconf);
if (sfc == NULL || (sfc && sfc->sfc_wizard)) {
lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));
htsmsg_add_str(m, "input_name", buf);
idc = dvb_network_class_by_fe_type(lfe->sf_type);
if (idc) {
l = htsmsg_create_list();
e = htsmsg_create_map();
htsmsg_add_str(e, "key", idc->ic_class);
htsmsg_add_str(e, "val", idclass_get_caption(idc, lang));
htsmsg_add_msg(l, NULL, e);
htsmsg_add_msg(m, "mpegts_network_types", l);
}
if (sfc && sfc->sfc_wizard) {
lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));
htsmsg_add_str(m, "input_name", buf);
htsmsg_add_str(m, "mpegts_network",
idnode_uuid_as_str(sfc->sfc_networks->is_array[0], ubuf));
}
}
return m;
}

static void
satip_frontend_wizard_set( tvh_input_t *ti, htsmsg_t *conf )
{
satip_frontend_t *lfe = (satip_frontend_t*)ti;
const char *uuid = htsmsg_get_str(conf, "mpegts_network_type");
satip_satconf_t *sfc;

sfc = TAILQ_FIRST(&lfe->sf_satconf);
if (uuid && (sfc == NULL || sfc->sfc_wizard)) {
htsmsg_t *conf = htsmsg_create_map();
htsmsg_t *nlist = htsmsg_create_list();
htsmsg_add_str(nlist, NULL, uuid);
htsmsg_add_msg(conf, "networks", nlist);
htsmsg_add_bool(conf, "wizard", 1);
satip_satconf_create(lfe, conf, satip_frontend_default_positions(lfe));
htsmsg_destroy(conf);
}
}

static void
satip_frontend_hacks( satip_frontend_t *lfe, int *def_positions )
satip_frontend_hacks( satip_frontend_t *lfe )
{
satip_device_t *sd = lfe->sf_device;

Expand All @@ -1764,8 +1825,6 @@ satip_frontend_hacks( satip_frontend_t *lfe, int *def_positions )
lfe->sf_play2 = 1;
lfe->sf_tdelay = 250;
lfe->sf_teardown_delay = 1;
} else if (!strcmp(sd->sd_info.modelname, "IPLNB")) {
*def_positions = 1;
} else if (strstr(sd->sd_info.manufacturer, "AVM Berlin") &&
strstr(sd->sd_info.modelname, "FRITZ!")) {
lfe->sf_play2 = 1;
Expand All @@ -1781,7 +1840,7 @@ satip_frontend_create
char id[16], lname[256], nname[60];
satip_frontend_t *lfe;
uint32_t master = 0;
int i, def_positions = sd->sd_info.srcs;
int i;

/* Override type */
snprintf(id, sizeof(id), "override #%d", num);
Expand Down Expand Up @@ -1838,7 +1897,7 @@ satip_frontend_create
lfe->sf_master = master;
lfe->sf_type_override = override ? strdup(override) : NULL;
lfe->sf_pass_weight = 1;
satip_frontend_hacks(lfe, &def_positions);
satip_frontend_hacks(lfe);
TAILQ_INIT(&lfe->sf_satconf);
pthread_mutex_init(&lfe->sf_dvr_lock, NULL);
lfe = (satip_frontend_t*)mpegts_input_create0((mpegts_input_t*)lfe, idc, uuid, conf);
Expand All @@ -1865,6 +1924,8 @@ satip_frontend_create
}

/* Input callbacks */
lfe->ti_wizard_get = satip_frontend_wizard_get;
lfe->ti_wizard_set = satip_frontend_wizard_set;
lfe->mi_is_enabled = satip_frontend_is_enabled;
lfe->mi_start_mux = satip_frontend_start_mux;
lfe->mi_stop_mux = satip_frontend_stop_mux;
Expand All @@ -1879,7 +1940,7 @@ satip_frontend_create

/* Create satconf */
if (lfe->sf_type == DVB_TYPE_S && master == 0)
satip_satconf_create(lfe, conf, def_positions);
satip_satconf_create(lfe, conf, satip_frontend_default_positions(lfe));

/* Slave networks update */
if (master) {
Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/satip/satip_private.h
Expand Up @@ -177,6 +177,7 @@ struct satip_satconf
/*
* Config
*/
int sfc_wizard;
int sfc_enabled;
int sfc_position;
int sfc_priority;
Expand Down
7 changes: 7 additions & 0 deletions src/input/mpegts/satip/satip_satconf.c
Expand Up @@ -183,6 +183,13 @@ const idclass_t satip_satconf_class =
.ic_get_title = satip_satconf_class_get_title,
.ic_save = satip_satconf_class_save,
.ic_properties = (const property_t[]) {
{
.type = PT_BOOL,
.id = "wizard",
.name = N_("Wizard"),
.off = offsetof(satip_satconf_t, sfc_wizard),
.opts = PO_NOUI,
},
{
.type = PT_BOOL,
.id = "enabled",
Expand Down
16 changes: 16 additions & 0 deletions src/queue.h
Expand Up @@ -11,6 +11,22 @@
* Extra LIST-ops
*/

#define LIST_LAST(headname, head, field) ({ \
headname *r; \
for (r = LIST_FIRST(head); \
LIST_NEXT(r, field); \
r = LIST_NEXT(r, field)); \
r; \
})

#define LIST_PREV(elm, headname, head, field) ({ \
headname *r; \
for (r = LIST_FIRST(head); \
r && LIST_NEXT(r, field) != (elm); \
r = LIST_NEXT(r, field)); \
r; \
})

#define LIST_ENTRY_INIT(elm, field) \
(elm)->field.le_next = NULL, (elm)->field.le_prev = NULL

Expand Down

0 comments on commit a0fe071

Please sign in to comment.