needed for files > 2GB
[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         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         std::string 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 public:
195         virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
196         
197                 // doesn't need to be implemented, should return -1 then.
198         virtual int getLength(const eServiceReference &ref);
199         virtual SWIG_VOID(RESULT) getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &SWIG_OUTPUT, time_t start_time=0);
200                 // returns true when not implemented
201         virtual bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
202
203         virtual int getInfo(const eServiceReference &ref, int w);
204         virtual std::string getInfoString(const eServiceReference &ref,int w);
205 };
206
207 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
208
209 TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
210
211 class iServiceInformation: public iObject
212 {
213 public:
214         virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
215         virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
216
217         enum { 
218                 sIsCrypted,  /* is encrypted (no indication if decrypt was possible) */
219                 sAspect,     /* aspect ratio: 0=4:3, 1=16:9, 2=whatever we need */
220                 sIsMultichannel, /* multichannel *available* (probably not selected) */
221                 
222                         /* "user serviceable info" - they are not reliable. Don't use them for anything except the service menu!
223                            that's also the reason why they are so globally defined. 
224                            
225                            
226                            again - if somebody EVER tries to use this information for anything else than simply displaying it,
227                            i will change this to return a user-readable text like "zero x zero three three" (and change the
228                            exact spelling in every version) to stop that!
229                         */
230                 sVideoPID,
231                 sAudioPID,
232                 sPCRPID,
233                 sPMTPID,
234                 sTXTPID,
235                 
236                 sSID,
237                 sONID,
238                 sTSID,
239                 sNamespace,
240                 sProvider,
241                 
242                 sDescription,
243                 sTimeCreate,    // unix time or string
244         };
245         enum { resNA = -1, resIsString = -2 };
246
247         virtual int getInfo(int w);
248         virtual std::string getInfoString(int w);
249 };
250
251 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
252
253 class iFrontendStatusInformation: public iObject
254 {
255 public:
256         enum {
257                 bitErrorRate,
258                 signalPower,
259                 signalQuality
260         };
261         virtual int getFrontendInfo(int w)=0;
262 };
263
264 TEMPLATE_TYPEDEF(ePtr<iFrontendStatusInformation>, iFrontendStatusInformationPtr);
265
266 class iPauseableService: public iObject
267 {
268 public:
269         virtual RESULT pause()=0;
270         virtual RESULT unpause()=0;
271         
272                 /* hm. */
273         virtual RESULT setSlowMotion(int ratio=0)=0;
274         virtual RESULT setFastForward(int ratio=0)=0;
275 };
276
277 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
278
279 class iSeekableService: public iObject
280 {
281 public:
282         virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
283         virtual RESULT seekTo(pts_t to)=0;
284         enum { dirForward = +1, dirBackward = -1 };
285         virtual RESULT seekRelative(int direction, pts_t to)=0;
286         virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
287                 /* if you want to do several seeks in a row, you can enable the trickmode. 
288                    audio will be switched off, sync will be disabled etc. */
289         virtual RESULT setTrickmode(int trick=0)=0;
290 };
291
292 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
293
294 struct iAudioTrackInfo
295 {
296 #ifndef SWIG
297         std::string m_description;
298         std::string m_language; /* iso639 */
299 #endif
300         std::string getDescription() { return m_description; }
301         std::string getLanguage() { return m_language; }
302 };
303
304 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
305
306 class iAudioTrackSelection: public iObject
307 {
308 public:
309         virtual int getNumberOfTracks()=0;
310         virtual RESULT selectTrack(unsigned int i)=0;
311         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
312 };
313
314 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
315
316 class iSubserviceList: public iObject
317 {
318 public:
319         virtual int getNumberOfSubservices()=0;
320         virtual SWIG_VOID(RESULT) getSubservice(eServiceReference &SWIG_OUTPUT, unsigned int n)=0;
321 };
322
323 TEMPLATE_TYPEDEF(ePtr<iSubserviceList>, iSubserviceListPtr);
324
325 class iTimeshiftService: public iObject
326 {
327 public:
328         virtual RESULT startTimeshift()=0;
329         virtual RESULT stopTimeshift()=0;
330 };
331
332 TEMPLATE_TYPEDEF(ePtr<iTimeshiftService>, iTimeshiftServicePtr);
333
334 class iPlayableService: public iObject
335 {
336         friend class iServiceHandler;
337 public:
338         enum
339         {
340                 evStart,
341                 evEnd,
342                 
343                 evTuneFailed,
344                         // when iServiceInformation is implemented:
345                 evUpdatedEventInfo,
346                 evUpdatedInfo,
347         };
348         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
349         virtual RESULT start()=0;
350         virtual RESULT stop()=0;
351         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
352         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
353         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
354         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
355         virtual SWIG_VOID(RESULT) subServices(ePtr<iSubserviceList> &SWIG_OUTPUT)=0;
356         virtual SWIG_VOID(RESULT) frontendStatusInfo(ePtr<iFrontendStatusInformation> &SWIG_OUTPUT)=0;
357         virtual SWIG_VOID(RESULT) timeshift(ePtr<iTimeshiftService> &SWIG_OUTPUT)=0;
358 };
359
360 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
361
362 class iRecordableService: public iObject
363 {
364 public:
365         virtual RESULT prepare(const char *filename)=0;
366         virtual RESULT start()=0;
367         virtual RESULT stop()=0;
368 };
369
370 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
371
372 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
373
374 class iMutableServiceList: public iObject
375 {
376 public:
377                 /* flush changes */
378         virtual RESULT flushChanges()=0;
379                 /* adds a service to a list */
380         virtual RESULT addService(eServiceReference &ref)=0;
381                 /* removes a service from a list */
382         virtual RESULT removeService(eServiceReference &ref)=0;
383                 /* moves a service in a list, only if list suppports a specific sort method. */
384                 /* pos is the new, absolute position from 0..size-1 */
385         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
386 };
387
388 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
389
390 class iListableService: public iObject
391 {
392 public:
393                 /* legacy interface: get a list */
394         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
395         
396                 /* new, shiny interface: streaming. */
397         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
398         
399                 /* use this for sorting. output is not sorted because of either
400                  - performance reasons: the whole list must be buffered or
401                  - the interface would be restricted to a list. streaming
402                    (as well as a future "active" extension) won't be possible.
403                 */
404         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
405         
406         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
407 };
408
409 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
410
411         /* a helper class which can be used as argument to stl's sort(). */
412 class iListableServiceCompare
413 {
414         ePtr<iListableService> m_list;
415 public:
416         iListableServiceCompare(iListableService *list): m_list(list) { }
417         bool operator()(const eServiceReference &a, const eServiceReference &b)
418         {
419                 return m_list->compareLessEqual(a, b);
420         }
421 };
422
423 class iServiceOfflineOperations: public iObject
424 {
425 public:
426                 /* to delete a service, forever. */
427         virtual RESULT deleteFromDisk(int simulate=1)=0;
428         
429                 /* for transferring a service... */
430         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
431         
432                 // TODO: additional stuff, like a conversion interface?
433 };
434
435 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
436
437 class iServiceHandler: public iObject
438 {
439 public:
440         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
441         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
442         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
443         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
444         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
445 };
446
447 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
448
449 #endif