Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
channel: migrated channel_t to an idnode
Also since the channel name is no longer unique various other things have
had to be updated.
  • Loading branch information
adamsutton committed Aug 22, 2013
1 parent b9c1171 commit 65c304f
Show file tree
Hide file tree
Showing 32 changed files with 691 additions and 885 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -112,6 +112,7 @@ SRCS = src/version.c \
SRCS += \
src/api.c \
src/api/api_idnode.c \
src/api/api_channel.c \
src/api/api_service.c \
src/api/api_mpegts.c \

Expand Down
1 change: 1 addition & 0 deletions src/api.c
Expand Up @@ -118,4 +118,5 @@ void api_init ( void )
api_idnode_init();
api_mpegts_init();
api_service_init();
api_channel_init();
}
4 changes: 4 additions & 0 deletions src/api.h
Expand Up @@ -59,6 +59,7 @@ void api_init ( void );
void api_idnode_init ( void );
void api_mpegts_init ( void );
void api_service_init ( void );
void api_channel_init ( void );

/*
* IDnode
Expand All @@ -85,4 +86,7 @@ int api_idnode_class
int api_idnode_tree
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_load_by_class
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

#endif /* __TVH_API_H__ */
74 changes: 74 additions & 0 deletions src/api/api_channel.c
@@ -0,0 +1,74 @@
/*
* API - channel 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 <http://www.gnu.org/licenses/>.
*/

#ifndef __TVH_API_SERVICE_H__
#define __TVH_API_SERVICE_H__

#include "tvheadend.h"
#include "channels.h"
#include "access.h"
#include "api.h"

// TODO: this will need converting to an idnode system
static int
api_channel_list
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
channel_t *ch;
htsmsg_t *l, *e;

l = htsmsg_create_list();
pthread_mutex_lock(&global_lock);
CHANNEL_FOREACH(ch) {
e = htsmsg_create_map();
htsmsg_add_str(e, "key", idnode_uuid_as_str(&ch->ch_id));
htsmsg_add_str(e, "val", ch->ch_name ?: "");
htsmsg_add_msg(l, NULL, e);
}
pthread_mutex_unlock(&global_lock);
*resp = htsmsg_create_map();
htsmsg_add_msg(*resp, "entries", l);

return 0;
}

static void
api_channel_grid
( idnode_set_t *ins, api_idnode_grid_conf_t *conf )
{
channel_t *ch;

CHANNEL_FOREACH(ch)
idnode_set_add(ins, (idnode_t*)ch, &conf->filter);
}

void api_channel_init ( void )
{
static api_hook_t ah[] = {
{ "channel/class", ACCESS_ANONYMOUS, api_idnode_class, (void*)&channel_class },
{ "channel/grid", ACCESS_ANONYMOUS, api_idnode_grid, api_channel_grid },
{ "channel/list", ACCESS_ANONYMOUS, api_channel_list, NULL },
{ NULL },
};

api_register_all(ah);
}


#endif /* __TVH_API_IDNODE_H__ */
24 changes: 15 additions & 9 deletions src/api/api_idnode.c
Expand Up @@ -133,9 +133,9 @@ api_idnode_grid
return 0;
}

static int
int
api_idnode_load_by_class
( const char *class, htsmsg_t *args, htsmsg_t **resp )
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int i, _enum;
const idclass_t *idc;
Expand All @@ -149,10 +149,8 @@ api_idnode_load_by_class
pthread_mutex_lock(&global_lock);

/* Find class */
if (!(idc = idclass_find(class))) {
pthread_mutex_unlock(&global_lock);
return EINVAL;
}
idc = opaque;
assert(idc);

l = htsmsg_create_list();
if ((is = idnode_find_all(idc))) {
Expand All @@ -162,7 +160,7 @@ api_idnode_load_by_class
/* Name/UUID only */
if (_enum) {
e = htsmsg_create_map();
htsmsg_add_str(e, "key", idnode_uuid_as_str(in));
htsmsg_add_str(e, "key", idnode_uuid_as_str(in));
htsmsg_add_str(e, "val", idnode_get_title(in));

/* Full record */
Expand Down Expand Up @@ -192,8 +190,16 @@ api_idnode_load
const char *uuid, *class;

/* Class based */
if ((class = htsmsg_get_str(args, "class")))
return api_idnode_load_by_class(class, args, resp);
if ((class = htsmsg_get_str(args, "class"))) {
const idclass_t *idc;
pthread_mutex_lock(&global_lock);
idc = idclass_find(class);
pthread_mutex_unlock(&global_lock);
if (!idc)
return EINVAL;
// TODO: bit naff that 2 locks are required here
return api_idnode_load_by_class((void*)idc, NULL, args, resp);
}

/* UUIDs */
if (!(f = htsmsg_field_find(args, "uuid")))
Expand Down
4 changes: 4 additions & 0 deletions src/api/api_service.c
Expand Up @@ -21,6 +21,7 @@
#define __TVH_API_SERVICE_H__

#include "tvheadend.h"
#include "service.h"
#include "service_mapper.h"
#include "access.h"
#include "api.h"
Expand Down Expand Up @@ -75,10 +76,13 @@ api_mapper_status

void api_service_init ( void )
{
extern const idclass_t service_class;
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 },
{ "service/list", ACCESS_ANONYMOUS, api_idnode_load_by_class,
(void*)&service_class },
{ NULL },
};

Expand Down

0 comments on commit 65c304f

Please sign in to comment.