e4127fb9443cf20d795a1d50ddb7a89c345a0e74
[enigma2.git] / lib / service / iservice.h
1 #ifndef __lib_dvb_iservice_h
2 #define __lib_dvb_iservice_h
3
4 #include <lib/python/swig.h>
5 #include <lib/base/object.h>
6 #include <string>
7 #include <connection.h>
8 #include <list>
9
10 class eServiceReference
11 {
12 public:
13         enum
14         {
15                 idInvalid=-1,
16                 idStructure,    // service_id == 0 is root
17                 idDVB,
18                 idFile,
19                 idUser=0x1000
20         };
21         int type;
22
23         int flags; // flags will NOT be compared.
24         enum
25         {
26                 isDirectory=1,          // SHOULD enter  (implies mustDescent)
27                 mustDescent=2,          // cannot be played directly - often used with "isDirectory" (implies canDescent)
28                 /*
29                         for example:
30                                 normal services have none of them - they can be fed directly into the "play"-handler.
31                                 normal directories have both of them set - you cannot play a directory directly and the UI should descent into it.
32                                 playlists have "mustDescent", but not "isDirectory" - you don't want the user to browse inside the playlist (unless he really wants)
33                                 services with sub-services have none of them, instead the have the "canDecsent" flag (as all of the above)
34                 */
35                 canDescent=4,                   // supports enterDirectory/leaveDirectory
36                 flagDirectory=isDirectory|mustDescent|canDescent,
37                 shouldSort=8,                   // should be ASCII-sorted according to service_name. great for directories.
38                 hasSortKey=16,          // has a sort key in data[3]. not having a sort key implies 0.
39                 sort1=32                                        // sort key is 1 instead of 0
40         };
41
42         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
43
44         int data[8];
45         std::string path;
46         std::string getPath() { return path; }
47
48 // only for override service names in bouquets or to give servicerefs a name which not have a
49 // real existing service ( for dvb eServiceDVB )
50         std::string name;
51         std::string getName() { return name; }
52
53         eServiceReference()
54                 : type(idInvalid), flags(0)
55         {
56         }
57
58         eServiceReference(int type, int flags)
59                 : type(type), flags(flags)
60         {
61                 memset(data, 0, sizeof(data));
62         }
63         eServiceReference(int type, int flags, int data0)
64                 : type(type), flags(flags)
65         {
66                 memset(data, 0, sizeof(data));
67                 data[0]=data0;
68         }
69         eServiceReference(int type, int flags, int data0, int data1)
70                 : type(type), flags(flags)
71         {
72                 memset(data, 0, sizeof(data));
73                 data[0]=data0;
74                 data[1]=data1;
75         }
76         eServiceReference(int type, int flags, int data0, int data1, int data2)
77                 : type(type), flags(flags)
78         {
79                 memset(data, 0, sizeof(data));
80                 data[0]=data0;
81                 data[1]=data1;
82                 data[2]=data2;
83         }
84         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
85                 : type(type), flags(flags)
86         {
87                 memset(data, 0, sizeof(data));
88                 data[0]=data0;
89                 data[1]=data1;
90                 data[2]=data2;
91                 data[3]=data3;
92         }
93         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
94                 : type(type), flags(flags)
95         {
96                 memset(data, 0, sizeof(data));
97                 data[0]=data0;
98                 data[1]=data1;
99                 data[2]=data2;
100                 data[3]=data3;
101                 data[4]=data4;
102         }
103         eServiceReference(int type, int flags, const std::string &path)
104                 : type(type), flags(flags), path(path)
105         {
106                 memset(data, 0, sizeof(data));
107         }
108         eServiceReference(const std::string &string);
109         std::string toString() const;
110         bool operator==(const eServiceReference &c) const
111         {
112                 if (type != c.type)
113                         return 0;
114                 return (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
115         }
116         bool operator!=(const eServiceReference &c) const
117         {
118                 return !(*this == c);
119         }
120         bool operator<(const eServiceReference &c) const
121         {
122                 if (type < c.type)
123                         return 1;
124
125                 if (type > c.type)
126                         return 0;
127
128                 int r=memcmp(data, c.data, sizeof(int)*8);
129                 if (r)
130                         return r < 0;
131                 return path < c.path;
132         }
133         operator bool() const
134         {
135                 return valid();
136         }
137         
138         int valid() const
139         {
140                 return type != idInvalid;
141         }
142 };
143
144 SWIG_ALLOW_OUTPUT_SIMPLE(eServiceReference);
145
146 typedef long long pts_t;
147
148         /* the reason we have the servicereference as additional argument is
149            that we don't have to create one object for every entry in a possibly
150            large list, provided that no state information is nessesary to deliver
151            the required information. Anyway - ref *must* be the same as the argument
152            to the info() or getIServiceInformation call! */
153
154         /* About the usage of SWIG_VOID:
155            SWIG_VOID(real_returntype_t) hides a return value from swig. This is used for
156            the "superflouus" RESULT return values.
157            
158            Python code has to check the returned pointer against 0. This works,
159            as all functions returning instances in smartpointers AND having a 
160            RESULT have to BOTH return non-zero AND set the pointer to zero.
161            
162            Python code thus can't check for the reason, but the reason isn't
163            user-servicable anyway. If you want to return a real reason which
164            goes beyong "it just doesn't work", use extra variables for this,
165            not the RESULT.
166            
167            Hide the result only if there is another way to check for failure! */
168            
169 class iStaticServiceInformation: public iObject
170 {
171 public:
172         virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
173         
174                 // doesn't need to be implemented, should return -1 then.
175         virtual int getLength(const eServiceReference &ref)=0;
176 };
177
178 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
179
180 class eServiceEvent;
181
182 TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
183
184 class iServiceInformation: public iObject
185 {
186 public:
187         virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
188         virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
189
190         enum { 
191                 sIsCrypted,  /* is encrypted (no indication if decrypt was possible) */
192                 sAspect,     /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */
193                 sIsMultichannel, /* multichannel *available* (probably not selected) */
194                 
195                         /* "user serviceable info" - they are not reliable. Don't use them for anything except the service menu!
196                            that's also the reason why they are so globally defined. 
197                            
198                            
199                            again - if somebody EVER tries to use this information for anything else than simply displaying it,
200                            i will change this to return a user-readable text like "zero x zero three three" (and change the
201                            exact spelling in every version) to stop that!
202                         */
203                 sVideoPID,
204                 sAudioPID,
205                 sPCRPID,
206                 sPMTPID,
207                 sTXTPID,
208                 
209                 sSID,
210                 sONID,
211                 sTSID,
212                 sNamespace,
213                 sProvider,
214         };
215         enum { resNA = -1, resIsString = -2 };
216
217         virtual int getInfo(int w);
218         virtual std::string getInfoString(int w);
219 };
220
221 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
222
223 class iPauseableService: public iObject
224 {
225 public:
226         virtual RESULT pause()=0;
227         virtual RESULT unpause()=0;
228 };
229
230 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
231
232 class iSeekableService: public iObject
233 {
234 public:
235         virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
236         virtual RESULT seekTo(pts_t to)=0;
237         enum { dirForward = +1, dirBackward = -1 };
238         virtual RESULT seekRelative(int direction, pts_t to)=0;
239         virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
240 };
241
242 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
243
244 struct iAudioTrackInfo
245 {
246         std::string m_description;
247         std::string m_language; /* iso639 */
248         
249         std::string getDescription() { return m_description; }
250         std::string getLanguage() { return m_language; }
251 };
252
253 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
254
255 class iAudioTrackSelection: public iObject
256 {
257 public:
258         virtual int getNumberOfTracks()=0;
259         virtual RESULT selectTrack(unsigned int i)=0;
260         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
261 };
262
263 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
264
265
266 class iPlayableService: public iObject
267 {
268         friend class iServiceHandler;
269 public:
270         enum
271         {
272                 evStart,
273                 evEnd,
274                 
275                 evTuneFailed,
276                         // when iServiceInformation is implemented:
277                 evUpdatedEventInfo,
278                 evUpdatedInfo,
279         };
280         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
281         virtual RESULT start()=0;
282         virtual RESULT stop()=0;
283         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
284         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
285         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
286         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
287 };
288
289 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
290
291 class iRecordableService: public iObject
292 {
293 public:
294         virtual RESULT prepare(const char *filename)=0;
295         virtual RESULT start()=0;
296         virtual RESULT stop()=0;
297 };
298
299 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
300
301 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
302
303 class iMutableServiceList: public iObject
304 {
305 public:
306                 /* flush changes */
307         virtual RESULT flushChanges()=0;
308                 /* adds a service to a list */
309         virtual RESULT addService(eServiceReference &ref)=0;
310                 /* removes a service from a list */
311         virtual RESULT removeService(eServiceReference &ref)=0;
312                 /* moves a service in a list, only if list suppports a specific sort method. */
313                 /* pos is the new, absolute position from 0..size-1 */
314         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
315 };
316
317 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
318
319 class iListableService: public iObject
320 {
321 public:
322                 /* legacy interface: get a list */
323         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
324         
325                 /* new, shiny interface: streaming. */
326         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
327         
328                 /* use this for sorting. output is not sorted because of either
329                  - performance reasons: the whole list must be buffered or
330                  - the interface would be restricted to a list. streaming
331                    (as well as a future "active" extension) won't be possible.
332                 */
333         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
334         
335         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
336 };
337
338 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
339
340         /* a helper class which can be used as argument to stl's sort(). */
341 class iListableServiceCompare
342 {
343         ePtr<iListableService> m_list;
344 public:
345         iListableServiceCompare(iListableService *list): m_list(list) { }
346         bool operator()(const eServiceReference &a, const eServiceReference &b)
347         {
348                 return m_list->compareLessEqual(a, b);
349         }
350 };
351
352 class iServiceOfflineOperations: public iObject
353 {
354 public:
355                 /* to delete a service, forever. */
356         virtual RESULT deleteFromDisk(int simulate=1)=0;
357         
358                 /* for transferring a service... */
359         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
360         
361                 // TODO: additional stuff, like a conversion interface?
362 };
363
364 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
365
366 class iServiceHandler: public iObject
367 {
368 public:
369         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
370         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
371         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
372         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
373         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
374 };
375
376 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
377
378 #endif