766d850eb748d3607b7d10c71e00ad00b7ff4ef6
[vuplus_dvbapp] / 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 class iServiceInformation: public iObject
146 {
147 public:
148         virtual RESULT getName(std::string &name)=0;
149 };
150
151 typedef ePtr<iServiceInformation> iServiceInformationPtr;
152
153 class iPauseableService: public iObject
154 {
155 public:
156         virtual RESULT pause()=0;
157         virtual RESULT unpause()=0;
158 };
159
160 typedef ePtr<iPauseableService> iPauseableServicePtr;
161
162 class iPlayableService: public iObject
163 {
164         friend class iServiceHandler;
165 public:
166         enum
167         {
168                 evStart,
169                 evEnd
170         };
171         virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
172         virtual RESULT start()=0;
173         virtual RESULT stop()=0;
174         virtual RESULT getIPausableService(ePtr<iPauseableService> &ptr)=0;
175         virtual RESULT getIServiceInformation(ePtr<iServiceInformation> &ptr)=0;
176 };
177
178 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
179
180 class iRecordableService: public iObject
181 {
182 public:
183         virtual RESULT start()=0;
184         virtual RESULT stop()=0;
185 };
186
187 typedef ePtr<iRecordableService> iRecordableServicePtr;
188
189 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
190 typedef std::list<eServiceReference> eServiceReferenceList;
191
192 class iListableService: public iObject
193 {
194 public:
195         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
196 };
197
198 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
199
200 class iServiceHandler: public iObject
201 {
202 public:
203         virtual RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr)=0;
204         virtual RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr)=0;
205         virtual RESULT list(const eServiceReference &, ePtr<iListableService> &ptr)=0;
206 };
207
208 typedef ePtr<iServiceHandler> iServiceHandlerPtr;
209
210 #endif