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