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