show real satellite name in satellite list
[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(int num) const
51         {
52                 if ( num < sizeof(data)/sizeof(int) )
53                         return data[num];
54                 return 0;
55         }
56
57         void setData(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 };
282
283 TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
284
285 struct iAudioTrackInfo
286 {
287         std::string m_description;
288         std::string m_language; /* iso639 */
289         
290         std::string getDescription() { return m_description; }
291         std::string getLanguage() { return m_language; }
292 };
293
294 SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
295
296 class iAudioTrackSelection: public iObject
297 {
298 public:
299         virtual int getNumberOfTracks()=0;
300         virtual RESULT selectTrack(unsigned int i)=0;
301         virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
302 };
303
304 TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
305
306 class iSubserviceList: public iObject
307 {
308 public:
309         virtual int getNumberOfSubservices()=0;
310         virtual SWIG_VOID(RESULT) getSubservice(eServiceReference &SWIG_OUTPUT, unsigned int n)=0;
311 };
312
313 TEMPLATE_TYPEDEF(ePtr<iSubserviceList>, iSubserviceListPtr);
314
315 class iTimeshiftService: public iObject
316 {
317 public:
318         virtual RESULT startTimeshift()=0;
319         virtual RESULT stopTimeshift()=0;
320 };
321
322 TEMPLATE_TYPEDEF(ePtr<iTimeshiftService>, iTimeshiftServicePtr);
323
324 class iPlayableService: public iObject
325 {
326         friend class iServiceHandler;
327 public:
328         enum
329         {
330                 evStart,
331                 evEnd,
332                 
333                 evTuneFailed,
334                         // when iServiceInformation is implemented:
335                 evUpdatedEventInfo,
336                 evUpdatedInfo,
337         };
338         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
339         virtual RESULT start()=0;
340         virtual RESULT stop()=0;
341         virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
342         virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
343         virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
344         virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
345         virtual SWIG_VOID(RESULT) subServices(ePtr<iSubserviceList> &SWIG_OUTPUT)=0;
346         virtual SWIG_VOID(RESULT) frontendStatusInfo(ePtr<iFrontendStatusInformation> &SWIG_OUTPUT)=0;
347         virtual SWIG_VOID(RESULT) timeshift(ePtr<iTimeshiftService> &SWIG_OUTPUT)=0;
348 };
349
350 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
351
352 class iRecordableService: public iObject
353 {
354 public:
355         virtual RESULT prepare(const char *filename)=0;
356         virtual RESULT start()=0;
357         virtual RESULT stop()=0;
358 };
359
360 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
361
362 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
363
364 class iMutableServiceList: public iObject
365 {
366 public:
367                 /* flush changes */
368         virtual RESULT flushChanges()=0;
369                 /* adds a service to a list */
370         virtual RESULT addService(eServiceReference &ref)=0;
371                 /* removes a service from a list */
372         virtual RESULT removeService(eServiceReference &ref)=0;
373                 /* moves a service in a list, only if list suppports a specific sort method. */
374                 /* pos is the new, absolute position from 0..size-1 */
375         virtual RESULT moveService(eServiceReference &ref, int pos)=0;
376 };
377
378 TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
379
380 class iListableService: public iObject
381 {
382 public:
383                 /* legacy interface: get a list */
384         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
385         
386                 /* new, shiny interface: streaming. */
387         virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
388         
389                 /* use this for sorting. output is not sorted because of either
390                  - performance reasons: the whole list must be buffered or
391                  - the interface would be restricted to a list. streaming
392                    (as well as a future "active" extension) won't be possible.
393                 */
394         virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
395         
396         virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
397 };
398
399 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
400
401         /* a helper class which can be used as argument to stl's sort(). */
402 class iListableServiceCompare
403 {
404         ePtr<iListableService> m_list;
405 public:
406         iListableServiceCompare(iListableService *list): m_list(list) { }
407         bool operator()(const eServiceReference &a, const eServiceReference &b)
408         {
409                 return m_list->compareLessEqual(a, b);
410         }
411 };
412
413 class iServiceOfflineOperations: public iObject
414 {
415 public:
416                 /* to delete a service, forever. */
417         virtual RESULT deleteFromDisk(int simulate=1)=0;
418         
419                 /* for transferring a service... */
420         virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
421         
422                 // TODO: additional stuff, like a conversion interface?
423 };
424
425 TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
426
427 class iServiceHandler: public iObject
428 {
429 public:
430         virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
431         virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
432         virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
433         virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
434         virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
435 };
436
437 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
438
439 #endif