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