61695a91e61a25eb43855a82fd25cdfda2cc788c
[enigma2.git] / lib / service / iservice.h
1 #ifndef __lib_dvb_iservice_h
2 #define __lib_dvb_iservice_h
3
4 #include <lib/base/object.h>
5 #include <string>
6 #include <connection.h>
7 #include <list>
8
9 class eServiceReference
10 {
11 public:
12         enum
13         {
14                 idInvalid=-1,
15                 idStructure,    // service_id == 0 is root
16                 idDVB,
17                 idFile,
18                 idUser=0x1000
19         };
20         int type;
21
22         int flags; // flags will NOT be compared.
23         enum
24         {
25                 isDirectory=1,          // SHOULD enter  (implies mustDescent)
26                 mustDescent=2,          // cannot be played directly - often used with "isDirectory" (implies canDescent)
27                 /*
28                         for example:
29                                 normal services have none of them - they can be fed directly into the "play"-handler.
30                                 normal directories have both of them set - you cannot play a directory directly and the UI should descent into it.
31                                 playlists have "mustDescent", but not "isDirectory" - you don't want the user to browse inside the playlist (unless he really wants)
32                                 services with sub-services have none of them, instead the have the "canDecsent" flag (as all of the above)
33                 */
34                 canDescent=4,                   // supports enterDirectory/leaveDirectory
35                 flagDirectory=isDirectory|mustDescent|canDescent,
36                 shouldSort=8,                   // should be ASCII-sorted according to service_name. great for directories.
37                 hasSortKey=16,          // has a sort key in data[3]. not having a sort key implies 0.
38                 sort1=32                                        // sort key is 1 instead of 0
39         };
40
41         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
42
43         int data[8];
44         std::string path;
45
46         eServiceReference()
47                 : type(idInvalid), flags(0)
48         {
49         }
50
51         eServiceReference(int type, int flags)
52                 : type(type), flags(flags)
53         {
54                 memset(data, 0, sizeof(data));
55         }
56         eServiceReference(int type, int flags, int data0)
57                 : type(type), flags(flags)
58         {
59                 memset(data, 0, sizeof(data));
60                 data[0]=data0;
61         }
62         eServiceReference(int type, int flags, int data0, int data1)
63                 : type(type), flags(flags)
64         {
65                 memset(data, 0, sizeof(data));
66                 data[0]=data0;
67                 data[1]=data1;
68         }
69         eServiceReference(int type, int flags, int data0, int data1, int data2)
70                 : type(type), flags(flags)
71         {
72                 memset(data, 0, sizeof(data));
73                 data[0]=data0;
74                 data[1]=data1;
75                 data[2]=data2;
76         }
77         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
78                 : type(type), flags(flags)
79         {
80                 memset(data, 0, sizeof(data));
81                 data[0]=data0;
82                 data[1]=data1;
83                 data[2]=data2;
84                 data[3]=data3;
85         }
86         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
87                 : type(type), flags(flags)
88         {
89                 memset(data, 0, sizeof(data));
90                 data[0]=data0;
91                 data[1]=data1;
92                 data[2]=data2;
93                 data[3]=data3;
94                 data[4]=data4;
95         }
96         eServiceReference(int type, int flags, const std::string &path)
97                 : type(type), flags(flags), path(path)
98         {
99                 memset(data, 0, sizeof(data));
100         }
101         eServiceReference(const std::string &string);
102         std::string toString() const;
103         bool operator==(const eServiceReference &c) const
104         {
105                 if (type != c.type)
106                         return 0;
107                 return /* (flags == c.flags) && */ (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
108         }
109         bool operator!=(const eServiceReference &c) const
110         {
111                 return !(*this == c);
112         }
113         bool operator<(const eServiceReference &c) const
114         {
115                 if (type < c.type)
116                         return 1;
117
118                 if (type > c.type)
119                         return 0;
120                         
121 /*              if (flags < c.flags)
122                         return 1;
123                 if (flags > c.flags)
124                         return 0; */
125
126                 int r=memcmp(data, c.data, sizeof(int)*8);
127                 if (r)
128                         return r < 0;
129                 return path < c.path;
130         }
131         operator bool() const
132         {
133                 return type != idInvalid;
134         }
135 };
136
137 typedef unsigned long long pts_t;
138
139         /* the reason we have the servicereference as additional argument is
140            that we don't have to create one object for every entry in a possibly
141            large list, provided that no state information is nessesary to deliver
142            the required information. Anyway - ref *must* be the same as the argument
143            to the info() or getIServiceInformation call! */
144 class iStaticServiceInformation: public iObject
145 {
146 public:
147         virtual RESULT getName(const eServiceReference &ref, std::string &name)=0;
148         
149                 // doesn't need to be implemented, should return -1 then.
150         virtual int getLength(const eServiceReference &ref)=0;
151
152                 // FOR SWIG
153         std::string getName(const eServiceReference &ref) { std::string temp; getName(ref, temp); return temp; }
154 };
155
156 TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
157
158 class eServiceEvent;
159
160 class iServiceInformation: public iObject
161 {
162 public:
163         virtual RESULT getName(std::string &name)=0;
164                 // FOR SWIG
165         std::string getName() { std::string temp; getName(temp); return temp; }
166         virtual RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
167 };
168
169 TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
170
171 class iPauseableService: public iObject
172 {
173 public:
174         virtual RESULT pause()=0;
175         virtual RESULT unpause()=0;
176 };
177
178 TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
179
180 class iPlayableService: public iObject
181 {
182         friend class iServiceHandler;
183 public:
184         enum
185         {
186                 evStart,
187                 evEnd,
188                 
189                 // when iServiceInformation is implemented:
190                 evUpdatedEventInfo
191         };
192         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
193         virtual RESULT start()=0;
194         virtual RESULT stop()=0;
195         virtual RESULT pause(ePtr<iPauseableService> &ptr)=0;
196         virtual RESULT info(ePtr<iServiceInformation> &ptr)=0;
197 };
198
199 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
200
201 class iRecordableService: public iObject
202 {
203 public:
204         virtual RESULT prepare()=0;
205         virtual RESULT start()=0;
206         virtual RESULT stop()=0;
207 };
208
209 TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
210
211 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
212
213 class iListableService: public iObject
214 {
215 public:
216                 /* legacy interface: get a list */
217         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
218         
219                 /* new, shiny interface: streaming. */
220         virtual RESULT getNext(eServiceReference &ptr)=0;
221 };
222
223 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
224
225 class iServiceHandler: public iObject
226 {
227 public:
228         virtual RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr)=0;
229         virtual RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr)=0;
230         virtual RESULT list(const eServiceReference &, ePtr<iListableService> &ptr)=0;
231         virtual RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
232 };
233
234 TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
235
236 #endif