From b9c1171a7d8372770a0a604fb05c33afb9e33384 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Sun, 18 Aug 2013 11:56:30 +0100 Subject: [PATCH] api: include access to the service mapper --- Makefile | 1 + src/api.c | 1 + src/api.h | 7 +-- src/api/api_service.c | 89 ++++++++++++++++++++++++++++++++++ src/webui/static/app/chconf.js | 3 +- 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/api/api_service.c diff --git a/Makefile b/Makefile index a6786585..72a6ba71 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,7 @@ SRCS = src/version.c \ SRCS += \ src/api.c \ src/api/api_idnode.c \ + src/api/api_service.c \ src/api/api_mpegts.c \ SRCS += \ diff --git a/src/api.c b/src/api.c index 529f6d8f..20a5c775 100644 --- a/src/api.c +++ b/src/api.c @@ -117,4 +117,5 @@ void api_init ( void ) /* Subsystems */ api_idnode_init(); api_mpegts_init(); + api_service_init(); } diff --git a/src/api.h b/src/api.h index 8c69a73a..0933c36e 100644 --- a/src/api.h +++ b/src/api.h @@ -55,9 +55,10 @@ int api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp ); /* * Initialise */ -void api_init ( void ); -void api_idnode_init ( void ); -void api_mpegts_init ( void ); +void api_init ( void ); +void api_idnode_init ( void ); +void api_mpegts_init ( void ); +void api_service_init ( void ); /* * IDnode diff --git a/src/api/api_service.c b/src/api/api_service.c new file mode 100644 index 00000000..89a717f0 --- /dev/null +++ b/src/api/api_service.c @@ -0,0 +1,89 @@ +/* + * API - service related calls + * + * Copyright (C) 2013 Adam Sutton + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TVH_API_SERVICE_H__ +#define __TVH_API_SERVICE_H__ + +#include "tvheadend.h" +#include "service_mapper.h" +#include "access.h" +#include "api.h" + +static int +api_mapper_start + ( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) +{ + service_mapper_conf_t conf = { 0 }; +#define get_u32(x)\ + conf.x = htsmsg_get_u32_or_default(args, #x, 0) + + /* Get config */ + get_u32(check_availability); + get_u32(encrypted); + get_u32(merge_same_name); + get_u32(provider_tags); + + pthread_mutex_lock(&global_lock); + service_mapper_start(&conf); + pthread_mutex_unlock(&global_lock); + + return 0; +} + +static int +api_mapper_stop + ( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) +{ + pthread_mutex_lock(&global_lock); + service_mapper_stop(); + pthread_mutex_unlock(&global_lock); + + return 0; +} + +static int +api_mapper_status + ( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) +{ + int num; + + pthread_mutex_lock(&global_lock); + num = service_mapper_qlen(); + pthread_mutex_unlock(&global_lock); + + *resp = htsmsg_create_map(); + htsmsg_add_u32(*resp, "remain", num); + + return 0; +} + +void api_service_init ( void ) +{ + static api_hook_t ah[] = { + { "service/mapper/start", ACCESS_ADMIN, api_mapper_start, NULL }, + { "service/mapper/stop", ACCESS_ADMIN, api_mapper_stop, NULL }, + { "service/mapper/status", ACCESS_ADMIN, api_mapper_status, NULL }, + { NULL }, + }; + + api_register_all(ah); +} + + +#endif /* __TVH_API_IDNODE_H__ */ diff --git a/src/webui/static/app/chconf.js b/src/webui/static/app/chconf.js index cf723e78..bf1ba0aa 100644 --- a/src/webui/static/app/chconf.js +++ b/src/webui/static/app/chconf.js @@ -90,8 +90,7 @@ tvheadend.mapServices = function() tooltip : 'Begin mapping', handler : function () { panel.getForm().submit({ - url : 'api/service_mapping', - params : { op: 'start' }, + url : 'api/service/mapper/start', waitMessage : 'Mapping services...' }); }