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