1 /*
2  *  tvheadend, channel functions
3  *  Copyright (C) 2007 Andreas Öman
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CHANNELS_H
20 #define CHANNELS_H
21 
22 #include "epg.h"
23 #include "idnode.h"
24 
25 struct access;
26 struct bouquet;
27 
28 RB_HEAD(channel_tree, channel);
29 
30 TAILQ_HEAD(channel_tag_queue, channel_tag);
31 
32 extern struct channel_tag_queue channel_tags;
33 extern struct channel_tree      channels;
34 
35 #define CHANNEL_FOREACH(ch) RB_FOREACH(ch, &channels, ch_link)
36 
37 /*
38  * Channel definition
39  */
40 typedef struct channel
41 {
42   idnode_t ch_id;
43 
44   RB_ENTRY(channel)   ch_link;
45 
46   int ch_refcount;
47   int ch_load;
48   int ch_dont_save;
49 
50   /* Channel info */
51   int     ch_enabled;
52   int     ch_autoname;
53   char   *ch_name;                                 /* Note: do not access directly! */
54   int64_t ch_number;
55   char   *ch_icon;
56   idnode_list_head_t ch_ctms;
57   struct bouquet *ch_bouquet;
58 
59   /* Service/subscriptions */
60   idnode_list_head_t           ch_services;
61   LIST_HEAD(, th_subscription) ch_subscriptions;
62 
63   /* EPG fields */
64   char                 *ch_epg_parent;
65   LIST_HEAD(, channel)  ch_epg_slaves;
66   LIST_ENTRY(channel)   ch_epg_slave_link;
67   epg_broadcast_tree_t  ch_epg_schedule;
68   epg_broadcast_t      *ch_epg_now;
69   epg_broadcast_t      *ch_epg_next;
70   gtimer_t              ch_epg_timer;
71   gtimer_t              ch_epg_timer_head;
72   gtimer_t              ch_epg_timer_current;
73 
74   int                   ch_epgauto;
75   idnode_list_head_t    ch_epggrab;                /* 1 = epggrab channel, 2 = channel */
76 
77   /* DVR */
78   int                   ch_dvr_extra_time_pre;
79   int                   ch_dvr_extra_time_post;
80   int                   ch_epg_running;
81   struct dvr_entry_list ch_dvrs;
82   struct dvr_autorec_entry_list ch_autorecs;
83   struct dvr_timerec_entry_list ch_timerecs;
84 
85 } channel_t;
86 
87 
88 /**
89  * Channel tag
90  */
91 typedef struct channel_tag {
92 
93   idnode_t ct_id;
94 
95   TAILQ_ENTRY(channel_tag) ct_link;
96 
97   int ct_enabled;
98   uint32_t ct_index;
99   int ct_internal;
100   int ct_private;
101   int ct_titled_icon;
102   char *ct_name;
103   char *ct_comment;
104   char *ct_icon;
105 
106   idnode_list_head_t ct_ctms;
107 
108   struct dvr_autorec_entry_list ct_autorecs;
109 
110   idnode_list_head_t ct_accesses;
111 
112   int ct_htsp_id;
113 
114 } channel_tag_t;
115 
116 extern const idclass_t channel_class;
117 extern const idclass_t channel_tag_class;
118 
119 void channel_init(void);
120 void channel_done(void);
121 
122 channel_t *channel_create0
123   (channel_t *ch, const idclass_t *idc, const char *uuid, htsmsg_t *conf,
124    const char *name);
125 #define channel_create(u, c, n)\
126   channel_create0(calloc(1, sizeof(channel_t)), &channel_class, u, c, n)
127 
128 void channel_delete(channel_t *ch, int delconf);
129 
130 channel_t *channel_find_by_name(const char *name);
131 #define channel_find_by_uuid(u)\
132   (channel_t*)idnode_find(u, &channel_class, NULL)
133 
134 channel_t *channel_find_by_id(uint32_t id);
135 
136 channel_t *channel_find_by_number(const char *no);
137 
138 #define channel_find channel_find_by_uuid
139 
140 htsmsg_t * channel_class_get_list(void *o, const char *lang);
141 
142 int channel_set_tags_by_list ( channel_t *ch, htsmsg_t *tags );
143 
144 channel_tag_t *channel_tag_create(const char *uuid, htsmsg_t *conf);
145 
146 channel_tag_t *channel_tag_find_by_name(const char *name, int create);
147 
148 channel_tag_t *channel_tag_find_by_identifier(uint32_t id);
149 
channel_tag_find_by_uuid(const char * uuid)150 static inline channel_tag_t *channel_tag_find_by_uuid(const char *uuid)
151   {  return (channel_tag_t*)idnode_find(uuid, &channel_tag_class, NULL); }
152 
153 htsmsg_t * channel_tag_class_get_list(void *o, const char *lang);
154 
155 const char * channel_tag_get_icon(channel_tag_t *ct);
156 
157 int channel_access(channel_t *ch, struct access *a, int disabled);
158 
159 void channel_event_updated(epg_broadcast_t *e);
160 
161 int channel_tag_map(channel_tag_t *ct, channel_t *ch, void *origin);
162 void channel_tag_unmap(channel_t *ch, void *origin);
163 
164 int channel_tag_access(channel_tag_t *ct, struct access *a, int disabled);
165 
166 const char *channel_get_name ( channel_t *ch );
167 int channel_set_name ( channel_t *ch, const char *name );
168 
169 #define CHANNEL_SPLIT ((int64_t)1000000)
170 
channel_get_major(int64_t chnum)171 static inline uint32_t channel_get_major ( int64_t chnum ) { return chnum / CHANNEL_SPLIT; }
channel_get_minor(int64_t chnum)172 static inline uint32_t channel_get_minor ( int64_t chnum ) { return chnum % CHANNEL_SPLIT; }
173 
174 int64_t channel_get_number ( channel_t *ch );
175 int channel_set_number ( channel_t *ch, uint32_t major, uint32_t minor );
176 
177 const char *channel_get_icon ( channel_t *ch );
178 int channel_set_icon ( channel_t *ch, const char *icon );
179 
180 const char *channel_get_epgid ( channel_t *ch );
181 
182 #define channel_get_uuid(ch,ub) idnode_uuid_as_str(&(ch)->ch_id, ub)
183 
184 #define channel_get_id(ch)    idnode_get_short_uuid((&(ch)->ch_id))
185 
186 #endif /* CHANNELS_H */
187