bedb0d6f583fe148e881e8ad4dda377f37e76e6c
[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 <lib/base/estring.h>
6 #include <list>
7
8 class eServiceReference
9 {
10 public:
11         enum
12         {
13                 idInvalid=-1,
14                 idStructure,    // service_id == 0 is root
15                 idDVB,
16                 idFile,
17                 idUser=0x1000
18         };
19         int type;
20
21         int flags; // flags will NOT be compared.
22         enum
23         {
24                 isDirectory=1,          // SHOULD enter  (implies mustDescent)
25                 mustDescent=2,          // cannot be played directly - often used with "isDirectory" (implies canDescent)
26                 /*
27                         for example:
28                                 normal services have none of them - they can be fed directly into the "play"-handler.
29                                 normal directories have both of them set - you cannot play a directory directly and the UI should descent into it.
30                                 playlists have "mustDescent", but not "isDirectory" - you don't want the user to browse inside the playlist (unless he really wants)
31                                 services with sub-services have none of them, instead the have the "canDecsent" flag (as all of the above)
32                 */
33                 canDescent=4,                   // supports enterDirectory/leaveDirectory
34                 flagDirectory=isDirectory|mustDescent|canDescent,
35                 shouldSort=8,                   // should be ASCII-sorted according to service_name. great for directories.
36                 hasSortKey=16,          // has a sort key in data[3]. not having a sort key implies 0.
37                 sort1=32                                        // sort key is 1 instead of 0
38         };
39
40         inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }
41
42         int data[8];
43         eString path;
44
45         eServiceReference()
46                 : type(idInvalid), flags(0)
47         {
48         }
49
50         eServiceReference(int type, int flags)
51                 : type(type), flags(flags)
52         {
53                 memset(data, 0, sizeof(data));
54         }
55         eServiceReference(int type, int flags, int data0)
56                 : type(type), flags(flags)
57         {
58                 memset(data, 0, sizeof(data));
59                 data[0]=data0;
60         }
61         eServiceReference(int type, int flags, int data0, int data1)
62                 : type(type), flags(flags)
63         {
64                 memset(data, 0, sizeof(data));
65                 data[0]=data0;
66                 data[1]=data1;
67         }
68         eServiceReference(int type, int flags, int data0, int data1, int data2)
69                 : type(type), flags(flags)
70         {
71                 memset(data, 0, sizeof(data));
72                 data[0]=data0;
73                 data[1]=data1;
74                 data[2]=data2;
75         }
76         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
77                 : type(type), flags(flags)
78         {
79                 memset(data, 0, sizeof(data));
80                 data[0]=data0;
81                 data[1]=data1;
82                 data[2]=data2;
83                 data[3]=data3;
84         }
85         eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
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                 data[4]=data4;
94         }
95         eServiceReference(int type, int flags, const eString &path)
96                 : type(type), flags(flags), path(path)
97         {
98                 memset(data, 0, sizeof(data));
99         }
100         eServiceReference(const eString &string);
101         eString toString() const;
102         bool operator==(const eServiceReference &c) const
103         {
104                 if (type != c.type)
105                         return 0;
106                 return /* (flags == c.flags) && */ (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
107         }
108         bool operator!=(const eServiceReference &c) const
109         {
110                 return !(*this == c);
111         }
112         bool operator<(const eServiceReference &c) const
113         {
114                 if (type < c.type)
115                         return 1;
116
117                 if (type > c.type)
118                         return 0;
119                         
120 /*              if (flags < c.flags)
121                         return 1;
122                 if (flags > c.flags)
123                         return 0; */
124
125                 int r=memcmp(data, c.data, sizeof(int)*8);
126                 if (r)
127                         return r < 0;
128                 return path < c.path;
129         }
130         operator bool() const
131         {
132                 return type != idInvalid;
133         }
134 };
135
136 class iPauseableService: public virtual iObject
137 {
138 public:
139         virtual RESULT pause()=0;
140         virtual RESULT unpause()=0;
141 };
142
143 class iPlayableService: public virtual iObject
144 {
145         friend class iServiceHandler;
146 public:
147                 // it's PRIVATE to the class factory
148         virtual RESULT start()=0;
149         virtual RESULT getIPausableService(ePtr<iPauseableService> &ptr)=0;
150 };
151
152 class iRecordableService: public virtual iObject
153 {
154 public:
155         virtual RESULT start()=0;
156         virtual RESULT stop()=0;
157 };
158
159 class iListableService: public virtual iObject
160 {
161 public:
162         virtual RESULT getContent(std::list<eServiceReference> &list)=0;
163 };
164
165 class iServiceHandler: public virtual iObject
166 {
167 public:
168         virtual RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr)=0;
169         virtual RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr)=0;
170         virtual RESULT list(const eServiceReference &, ePtr<iListableService> &ptr)=0;
171 };
172
173 #endif