Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
satips: webui/api - move to the simple node system
  • Loading branch information
perexg committed Sep 10, 2015
1 parent 4528915 commit 4844b32
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 204 deletions.
31 changes: 2 additions & 29 deletions src/api/api_satip.c
Expand Up @@ -25,39 +25,12 @@

#if ENABLE_SATIP_SERVER

static int
api_satip_server_load
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *l;
pthread_mutex_lock(&global_lock);
*resp = htsmsg_create_map();
l = htsmsg_create_list();
htsmsg_add_msg(l, NULL, satip_server_get_config());
htsmsg_add_msg(*resp, "entries", l);
pthread_mutex_unlock(&global_lock);
return 0;
}

static int
api_satip_server_save
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
pthread_mutex_lock(&global_lock);
if (satip_server_set_config(args))
satip_server_save();
pthread_mutex_unlock(&global_lock);
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "success", 1);
return 0;
}

void
api_satip_server_init ( void )
{
static api_hook_t ah[] = {
{ "satips/config/load", ACCESS_ADMIN, api_satip_server_load, NULL },
{ "satips/config/save", ACCESS_ADMIN, api_satip_server_save, NULL },
{ "satips/config/load", ACCESS_ADMIN, api_idnode_load_simple, &satip_server_conf },
{ "satips/config/save", ACCESS_ADMIN, api_idnode_save_simple, &satip_server_conf },
{ NULL },
};

Expand Down
4 changes: 0 additions & 4 deletions src/satip/rtsp.c
Expand Up @@ -29,10 +29,6 @@
#define RTP_BUFSIZE (256*1024)
#define RTCP_BUFSIZE (16*1024)

#define MUXCNF_AUTO 0
#define MUXCNF_KEEP 1
#define MUXCNF_REJECT 2

#define STATE_DESCRIBE 0
#define STATE_SETUP 1
#define STATE_PLAY 2
Expand Down
160 changes: 124 additions & 36 deletions src/satip/server.c
Expand Up @@ -34,6 +34,8 @@ static int satip_server_rtsp_port;
static int satip_server_rtsp_port_locked;
static upnp_service_t *satips_upnp_discovery;

static void satip_server_save(void);

/*
*
*/
Expand Down Expand Up @@ -526,10 +528,126 @@ static void satip_server_info(const char *prefix, int descramble, int muxcnf)
config_get_int("satip_dvbcb", 0));
}

/*
* Node Simple Class
*/
struct satip_server_conf satip_server_conf = {
.idnode.in_class = &satip_server_class
};

static void satip_server_class_save(idnode_t *self)
{
htsmsg_field_t *f;
int64_t s64;
htsmsg_t *c = htsmsg_create_map();
idnode_save(self, c);
HTSMSG_FOREACH(f, c) {
if (f->hmf_type == HMF_S64 && !htsmsg_field_get_s64(f, &s64))
config_set_int(f->hmf_name, s64);
}
satip_server_save();
htsmsg_destroy(c);
}

static htsmsg_t *satip_server_class_muxcfg_list ( void *o, const char *lang )
{
static const struct strtab tab[] = {
{ N_("Auto"), MUXCNF_AUTO },
{ N_("Keep"), MUXCNF_KEEP },
{ N_("Reject"), MUXCNF_REJECT }
};
return strtab2htsmsg(tab, 1, lang);
}

const idclass_t satip_server_class = {
.ic_snode = (idnode_t *)&satip_server_conf,
.ic_class = "satip_server",
.ic_caption = N_("SAT>IP Server"),
.ic_event = "satip_server",
.ic_perm_def = ACCESS_ADMIN,
.ic_save = satip_server_class_save,
.ic_properties = (const property_t[]){
{
.type = PT_INT,
.id = "satip_rtsp",
.name = N_("RTSP Port (554 or 9983), 0 = disable"),
.off = offsetof(struct satip_server_conf, satip_rtsp),
},
{
.type = PT_INT,
.id = "satip_weight",
.name = N_("Subscription Weight"),
.off = offsetof(struct satip_server_conf, satip_weight),
},
{
.type = PT_INT,
.id = "satip_descramble",
.name = N_("Descramble Services (Limit Per Mux)"),
.off = offsetof(struct satip_server_conf, satip_descramble),
},
{
.type = PT_INT,
.id = "satip_muxcnf",
.name = N_("Mux Handling"),
.off = offsetof(struct satip_server_conf, satip_muxcnf),
.list = satip_server_class_muxcfg_list,
},
{
.type = PT_INT,
.id = "satip_dvbs",
.name = N_("Exported DVB-S Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbs),
},
{
.type = PT_INT,
.id = "satip_dvbs2",
.name = N_("Exported DVB-S2 Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbs2),
},
{
.type = PT_INT,
.id = "satip_dvbt",
.name = N_("Exported DVB-T Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbt),
},
{
.type = PT_INT,
.id = "satip_dvbt2",
.name = N_("Exported DVB-T2 Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbt2),
},
{
.type = PT_INT,
.id = "satip_dvbc",
.name = N_("Exported DVB-C Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbc),
},
{
.type = PT_INT,
.id = "satip_dvbc2",
.name = N_("Exported DVB-C2 Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbc2),
},
{
.type = PT_INT,
.id = "satip_atsc",
.name = N_("Exported ATSC Tuners"),
.off = offsetof(struct satip_server_conf, satip_atsc),
},
{
.type = PT_INT,
.id = "satip_dvbc2",
.name = N_("Exported DVB-Cable/AnnexB Tuners"),
.off = offsetof(struct satip_server_conf, satip_dvbcb),
},
{}
},
};

/*
*
*/
void satip_server_save(void)
static void satip_server_save(void)
{
int descramble, muxcnf;

Expand All @@ -554,41 +672,6 @@ void satip_server_save(void)
}
}

htsmsg_t *satip_server_get_config(void)
{
return config_get_all(1);
}

static int satip_server_set_int(htsmsg_t *conf, const char *name)
{
const char *str;
if ((str = htsmsg_get_str(conf, name)))
return config_set_int(name, atoi(str));
return 0;
}

int satip_server_set_config(htsmsg_t *conf)
{
static const char *names[] = {
"satip_rtsp",
"satip_weight",
"satip_descramble",
"satip_muxcnf",
"satip_dvbs",
"satip_dvbs2",
"satip_dvbt",
"satip_dvbt2",
"satip_dvbc",
"satip_dvbc2",
"satip_atsc",
"satip_dvbcb",
NULL
};
int i, save = 0;
for (i = 0; i < ARRAY_SIZE(names); i++)
save |= satip_server_set_int(conf, names[i]);
return save;
}
/*
* Initialization
*/
Expand Down Expand Up @@ -632,10 +715,15 @@ void satip_server_register(void)
char uu[UUID_HEX_SIZE + 4];
tvh_uuid_t u;
int save = 0;
htsmsg_t *msg;

if (http_server_ip == NULL)
return;

msg = config_get_all(1);
idnode_load(&satip_server_conf.idnode, msg);
htsmsg_destroy(msg);

if (config_set_int("satip_rtsp", satip_server_rtsp_port))
save = 1;

Expand Down
28 changes: 24 additions & 4 deletions src/satip/server.h
Expand Up @@ -29,6 +29,30 @@
#include "udp.h"
#include "http.h"

#define MUXCNF_AUTO 0
#define MUXCNF_KEEP 1
#define MUXCNF_REJECT 2

struct satip_server_conf {
idnode_t idnode;
int satip_rtsp;
int satip_weight;
int satip_descramble;
int satip_muxcnf;
int satip_dvbs;
int satip_dvbs2;
int satip_dvbt;
int satip_dvbt2;
int satip_dvbc;
int satip_dvbc2;
int satip_atsc;
int satip_dvbcb;
};

extern struct satip_server_conf satip_server_conf;

extern const idclass_t satip_server_class;

void satip_rtp_queue(void *id, th_subscription_t *subs,
streaming_queue_t *sq,
struct sockaddr_storage *peer, int port,
Expand Down Expand Up @@ -58,10 +82,6 @@ int satip_server_http_page(http_connection_t *hc,

int satip_server_match_uuid(const char *uuid);

void satip_server_save(void);
htsmsg_t *satip_server_get_config(void);
int satip_server_set_config(htsmsg_t *conf);

void satip_server_init(int rtsp_port);
void satip_server_register(void);
void satip_server_done(void);
Expand Down

0 comments on commit 4844b32

Please sign in to comment.