c93c84a547fa26ce7de16a4085145ac4609be472
[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/python/python.h>
6 #include <lib/base/object.h>
7 #include <string>
8 #include <connection.h>
9 #include <list>
10
11 class eServiceEvent;
12
13 class eServiceReference
14 {
15 public:
16         enum
17         {
18                 idInvalid=-1,
19                 idStructure,    // service_id == 0 is root
20                 idDVB,
21                 idFile,
22                 idUser=0x1000
23         };
24         int type;
25
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         int flags; // flags will NOT be compared.
44
45         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
46
47 #ifndef SWIG
48         int data[8];
49         std::string path;
50 #endif
51         std::string getPath() { return path; }
52         void setPath( const std::string &n ) { path=n; }
53
54         unsigned int getUnsignedData(unsigned int num) const
55         {
56                 if ( num < sizeof(data)/sizeof(int) )
57                         return data[num];
58                 return 0;
59         }
60
61         int getData(unsigned int num) const
62         {
63                 if ( num < sizeof(data)/sizeof(int) )
64                         return data[num];
65                 return 0;
66         }
67
68         void setUnsignedData(unsigned int num, unsigned int val)
69         {
70                 if ( num < sizeof(data)/sizeof(int) )
71                         data[num] = val;
72         }
73
74         void setData(unsigned int num, int val)
75         {
76                 if ( num < sizeof(data)/sizeof(int) )
77                         data[num] = val;
78         }
79
80 // only for override service names in bouquets or to give servicerefs a name which not have a
81 // real existing service ( for dvb eServiceDVB )
82 #ifndef SWIG
83         std::string name;
84 #endif
85         std::string getName() { return name; }
86         void setName( const std::string &n ) { name=n; }
87
88         eServiceReference()
89                 : type(idInvalid), flags(0)
90         {
91                 memset(data, 0, sizeof(data));
92         }
93 #ifndef SWIG
94         eServiceReference(int type, int flags)
95                 : type(type), flags(flags)
96         {
97                 memset(data, 0, sizeof(data));
98         }
99         eServiceReference(int type, int flags, int data0)
100                 : type(type), flags(flags)
101         {
102                 memset(data, 0, sizeof(data));
103                 data[0]=data0;
104         }
105         eServiceReference(int type, int flags, int data0, int data1)
106                 : type(type), flags(flags)
107         {
108                 memset(data, 0, sizeof(data));
109                 data[0]=data0;
110                 data[1]=data1;
111         }
112         eServiceReference(int type, int flags, int data0, int data1, int data2)
113                 : type(type), flags(flags)
114         {
115                 memset(data, 0, sizeof(data));
116                 data[0]=data0;
117                 data[1]=data1;
118                 data[2]=data2;
119         }
120         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
121                 : type(type), flags(flags)
122         {
123                 memset(data, 0, sizeof(data));
124                 data[0]=data0;
125                 data[1]=data1;
126                 data[2]=data2;
127                 data[3]=data3;
128         }
129         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
130                 : type(type), flags(flags)
131         {
132                 memset(data, 0, sizeof(data));
133                 data[0]=data0;
134                 data[1]=data1;
135                 data[2]=data2;
136                 data[3]=data3;
137                 data[4]=data4;
138         }
139         eServiceReference(int type, int flags, const std::string &path)
140                 : type(type), flags(flags), path(path)
141         {
142                 memset(data, 0, sizeof(data));
143         }
144 #endif
145         eServiceReference(const std::string &string);
146         std::string toString() const;
147         bool operator==(const eServiceReference &c) const
148         {
149                 if (type != c.type)
150                         return 0;
151                 return (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
152         }
153         bool operator!=(const eServiceReference &c) const
154         {
155                 return !(*this == c);
156         }
157         bool operator<(const eServiceReference &c) const
158         {
159                 if (type < c.type)
160                         return 1;
161
162                 if (type > c.type)
163                         return 0;
164
165                 int r=memcmp(data, c.data, sizeof(int)*8);
166                 if (r)
167                         return r < 0;
168                 return path < c.path;
169         }
170         operator bool() const
171         {
172                 return valid();
173         }
174         
175         int valid() const
176         {
177                 return type != idInvalid;
178         }
179 };
180
181 SWIG_ALLOW_OUTPUT_SIMPLE(eServiceReference);
182
183 extern PyObject *New_eServiceReference(const eServiceReference &ref); // defined in enigma_python.i
184
185 typedef long long pts_t;
186
187         /* the reason we have the servicereference as additional argument is
188            that we don't have to create one object for every entry in a possibly
189            large list, provided that no state information is nessesary to deliver
190            the required information. Anyway - ref *must* be the same as the argument
191            to the info() or getIServiceInformation call! */
192
193         /* About the usage of SWIG_VOID:
194            SWIG_VOID(real_returntype_t) hides a return value from swig. This is used for
195            the "superflouus" RESULT return values.
196            
197            Python code has to check the returned pointer against 0. This works,
198            as all functions returning instances in smartpointers AND having a 
199            RESULT have to BOTH return non-zero AND set the pointer to zero.
200            
201            Python code thus can't check for the reason, but the reason isn't
202            user-servicable anyway. If you want to return a real reason which
203            goes beyong "it just doesn't work", use extra variables for this,
204            not the RESULT.
205            
206            Hide the result only if there is another way to check for failure! */
207            
208 class iStaticServiceInformation: public iObject
209 {
210 #ifdef SWIG
211         iStaticServiceInformation();
212         ~iStaticServiceInformation();
213 #endif
214 public:
215         virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
216         
217                 // doesn't need to be implemented, should return -1 then.
218         virtual int getLength(const eServiceReference &ref);
219         virtual SWIG_VOID(RESULT) getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &SWIG_OUTPUT, time_t start_time=-1);
220                 // returns true when not implemented
221         virtual bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
222
223         virtual int getInfo(const eServiceReference &ref, int w);
224         virtual std::string getInfoString(const eServiceReference &ref,int w);
225 };
226
227 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
228
229 TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
230
231 class iServiceInformation: public iObject
232 {
233 #ifdef SWIG
234         iServiceInformation();
235         ~iServiceInformation();
236 #endif
237 public:
238         virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
239         virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
240
241         enum {
242                 sIsCrypted,  /* is encrypted (no indication if decrypt was possible) */
243                 sAspect,     /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */
244                 sIsMultichannel, /* multichannel *available* (probably not selected) */
245                 
246                         /* "user serviceable info" - they are not reliable. Don't use them for anything except the service menu!
247                            that's also the reason why they are so globally defined. 
248                            
249                            
250                            again - if somebody EVER tries to use this information for anything else than simply displaying it,
251                            i will change this to return a user-readable text like "zero x zero three three" (and change the
252                            exact spelling in every version) to stop that!
253                         */
254                 sVideoPID,
255                 sAudioPID,
256                 sPCRPID,
257                 sPMTPID,
258                 sTXTPID,
259                 
260                 sSID,
261                 sONID,
262                 sTSID,
263                 sNamespace,
264                 sProvider,
265                 
266                 sDescription,
267                 sServiceref,
268                 sTimeCreate,    // unix time or string
269                 
270                 sTitle,
271                 sArtist,
272                 sAlbum,
273                 sComment,
274                 sTracknumber,
275                 sGenre,
276                 sCAIDs,
277                 sVideoType  // MPEG2 MPEG4
278         };
279         enum { resNA = -1, resIsString = -2, resIsPyObject = -3 };
280
281         virtual int getInfo(int w);
282         virtual std::string getInfoString(int w);
283         virtual PyObject *getInfoObject(int w);
284 };
285
286 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
287
288 class iFrontendStatusInformation: public iObject
289 {
290 #ifdef SWIG
291         iFrontendStatusInformation();
292         ~iFrontendStatusInformation();
293 #endif
294 public:
295         enum {
296                 bitErrorRate,
297                 signalPower,
298                 signalQuality,
299                 LockState,
300                 SyncState
301         };
302         virtual int getFrontendInfo(int w)=0;
303         virtual PyObject *getFrontendData(bool original=false)=0;
304 };
305
306 TEMPLATE_TYPEDEF(ePtr<iFrontendStatusInformation>, iFrontendStatusInformationPtr);
307
308 class iPauseableService: public iObject
309 {
310 #ifdef SWIG
311         iPausableService();
312         ~iPausableService();
313 #endif
314 public:
315         virtual RESULT pause()=0;
316         virtual RESULT unpause()=0;
317         
318                 /* hm. */
319         virtual RESULT setSlowMotion(int ratio=0)=0;
320         virtual RESULT setFastForward(int ratio=0)=0;
321 };
322
323 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
324
325 class iSeekableService: public iObject
326 {
327 #ifdef SWIG
328         iSeekableService();
329         ~iSeekableService();
330 #endif
331 public:
332         virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
333         virtual RESULT seekTo(pts_t to)=0;
334         enum { dirForward = +1, dirBackward = -1 };
335         virtual RESULT seekRelative(int direction, pts_t to)=0;
336         virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
337                 /* if you want to do several seeks in a row, you can enable the trickmode. 
338                    audio will be switched off, sync will be disabled etc. */
339         virtual RESULT setTrickmode(int trick=0)=0;
340         virtual RESULT isCurrentlySeekable()=0;
341 };
342
343 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
344
345 struct iAudioTrackInfo
346 {
347 #ifdef SWIG
348 private:
349         iAudioTrackInfo();
350         ~iAudioTrackInfo();
351 public:
352 #endif
353 #ifndef SWIG
354         std::string m_description;
355         std::string m_language; /* iso639 */
356 #endif
357         std::string getDescription() { return m_description; }
358         std::string getLanguage() { return m_language; }
359 };
360
361 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
362
363 class iAudioTrackSelection: public iObject
364 {
365 #ifdef SWIG
366         iAudioTrackSelection();
367         ~iAudioTrackSelection();
368 #endif
369 public:
370         virtual int getNumberOfTracks()=0;
371         virtual RESULT selectTrack(unsigned int i)=0;
372         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
373 };
374
375 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
376
377 class iSubserviceList: public iObject
378 {
379 #ifdef SWIG
380         iSubserviceList();
381         ~iSubserviceList();
382 #endif
383 public:
384         virtual int getNumberOfSubservices()=0;
385         virtual SWIG_VOID(RESULT) getSubservice(eServiceReference &SWIG_OUTPUT, unsigned int n)=0;
386 };
387
388 TEMPLATE_TYPEDEF(ePtr<iSubserviceList>, iSubserviceListPtr);
389
390 class iTimeshiftService: public iObject
391 {
392 #ifdef SWIG
393         iTimeshiftService();
394         ~iTimeshiftService();
395 #endif
396 public:
397         virtual RESULT startTimeshift()=0;
398         virtual RESULT stopTimeshift()=0;
399         
400         virtual int isTimeshiftActive()=0;
401                         /* this essentially seeks to the relative end of the timeshift buffer */
402         virtual RESULT activateTimeshift()=0;
403 };
404
405 TEMPLATE_TYPEDEF(ePtr<iTimeshiftService>, iTimeshiftServicePtr);
406
407         /* not related to eCueSheet */
408 class iCueSheet: public iObject
409 {
410 #ifdef SWIG
411         iCueSheet();
412         ~iCueSheet();
413 #endif
414 public:
415                         /* returns a list of (pts, what)-tuples */
416         virtual PyObject *getCutList() = 0;
417         virtual void setCutList(PyObject *list) = 0;
418         virtual void setCutListEnable(int enable) = 0;
419         enum { cutIn = 0, cutOut = 1, cutMark = 2 };
420 };
421
422 TEMPLATE_TYPEDEF(ePtr<iCueSheet>, iCueSheetPtr);
423
424 class iPlayableService: public iObject
425 {
426 #ifdef SWIG
427         iPlayableService();
428         ~iPlaybleService();
429 #endif
430         friend class iServiceHandler;
431 public:
432         enum
433         {
434                         /* these first two events are magical, and should only
435                            be generated if you know what you're doing. */
436                 evStart,
437                 evEnd,
438                 
439                 evTuneFailed,
440                         // when iServiceInformation is implemented:
441                 evUpdatedEventInfo,
442                 evUpdatedInfo,
443
444                         /* when seek() is implemented: */               
445                 evSeekableStatusChanged, /* for example when timeshifting */
446                 
447                 evEOF,
448                 evSOF, /* bounced against start of file (when seeking backwards) */
449                 
450                         /* only when cueSheet is implemented */
451                 evCuesheetChanged,
452         };
453         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
454         virtual RESULT start()=0;
455         virtual RESULT stop()=0;
456                         /* might have to be changed... */
457         virtual RESULT setTarget(int target)=0;
458         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
459         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
460         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
461         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
462         virtual SWIG_VOID(RESULT) subServices(ePtr<iSubserviceList> &SWIG_OUTPUT)=0;
463         virtual SWIG_VOID(RESULT) frontendStatusInfo(ePtr<iFrontendStatusInformation> &SWIG_OUTPUT)=0;
464         virtual SWIG_VOID(RESULT) timeshift(ePtr<iTimeshiftService> &SWIG_OUTPUT)=0;
465         virtual SWIG_VOID(RESULT) cueSheet(ePtr<iCueSheet> &SWIG_OUTPUT)=0;
466 };
467
468 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
469
470 class iRecordableService: public iObject
471 {
472 #ifdef SWIG
473         iRecordableService();
474         ~iRecordableService();
475 #endif
476 public:
477         virtual RESULT prepare(const char *filename, time_t begTime=-1, time_t endTime=-1, int eit_event_id=-1)=0;
478         virtual RESULT start()=0;
479         virtual RESULT stop()=0;
480 };
481
482 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
483
484 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
485
486 class iMutableServiceList: public iObject
487 {
488 #ifdef SWIG
489         iMutableServiceList();
490         ~iMutableServiceList();
491 #endif
492 public:
493                 /* flush changes */
494         virtual RESULT flushChanges()=0;
495                 /* adds a service to a list */
496         virtual RESULT addService(eServiceReference &ref)=0;
497                 /* removes a service from a list */
498         virtual RESULT removeService(eServiceReference &ref)=0;
499                 /* moves a service in a list, only if list suppports a specific sort method. */
500                 /* pos is the new, absolute position from 0..size-1 */
501         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
502                 /* set name of list, for bouquets this is the visible bouquet name */
503         virtual RESULT setListName(const std::string &name)=0;
504 };
505
506 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
507
508 class iListableService: public iObject
509 {
510 #ifdef SWIG
511         iListableService();
512         ~iListableService();
513 #endif
514 public:
515                 /* legacy interface: get a list */
516         virtual RESULT getContent(std::list<eServiceReference> &list, bool sorted=false)=0;
517         virtual PyObject *getContent(const char* format, bool sorted=false)=0;
518
519                 /* new, shiny interface: streaming. */
520         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
521         
522                 /* use this for sorting. output is not sorted because of either
523                  - performance reasons: the whole list must be buffered or
524                  - the interface would be restricted to a list. streaming
525                    (as well as a future "active" extension) won't be possible.
526                 */
527         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
528         
529         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
530 };
531
532 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
533
534 #ifndef SWIG
535         /* a helper class which can be used as argument to stl's sort(). */
536 class iListableServiceCompare
537 {
538         ePtr<iListableService> m_list;
539 public:
540         iListableServiceCompare(iListableService *list): m_list(list) { }
541         bool operator()(const eServiceReference &a, const eServiceReference &b)
542         {
543                 return m_list->compareLessEqual(a, b);
544         }
545 };
546 #endif
547
548 class iServiceOfflineOperations: public iObject
549 {
550 #ifdef SWIG
551         iServiceOfflineOperations();
552         ~iServiceOfflineOperations();
553 #endif
554 public:
555                 /* to delete a service, forever. */
556         virtual RESULT deleteFromDisk(int simulate=1)=0;
557         
558                 /* for transferring a service... */
559         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
560         
561                 // TODO: additional stuff, like a conversion interface?
562 };
563
564 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
565
566 class iServiceHandler: public iObject
567 {
568 #ifdef SWIG
569         iServiceHandler();
570         ~iServiceHandler();
571 #endif
572 public:
573         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
574         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
575         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
576         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
577         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
578 };
579
580 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
581
582 #endif