add a tuxbox plugins plugin to prepare loading of tuxbox plugins when the c++ part...
[enigma2.git] / lib / service / service.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/estring.h>
3 #include <lib/service/service.h>
4 #include <lib/base/init_num.h>
5 #include <lib/base/init.h>
6
7 eServiceReference::eServiceReference(const std::string &string)
8 {
9         const char *c=string.c_str();
10         int pathl=0;
11
12         if ( sscanf(c, "%d:%d:%x:%x:%x:%x:%x:%x:%x:%x:%n", &type, &flags, &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7], &pathl) < 8 )
13         {
14                 memset( data, 0, sizeof(data) );
15                 eDebug("find old format eServiceReference string");
16                 sscanf(c, "%d:%d:%x:%x:%x:%x:%n", &type, &flags, &data[0], &data[1], &data[2], &data[3], &pathl);
17         }
18
19         if (pathl)
20         {
21                 const char *pathstr = c+pathl;
22                 const char *namestr = strchr(pathstr, ':');
23                 if (namestr)
24                 {
25                         if (pathstr != namestr)
26                                 path.assign(pathstr, namestr-pathstr);
27                         if (*(namestr+1))
28                                 name=namestr+1;
29                 }
30                 else
31                         path=pathstr;
32         }
33 }
34
35 std::string eServiceReference::toString() const
36 {
37         std::string ret;
38         ret += getNum(type);
39         ret += ":";
40         ret += getNum(flags);
41         for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
42                 ret+=":"+ getNum(data[i], 0x10);
43         ret+=":"+path;
44         if (name.length())
45                 ret+=":"+name;
46         return ret;
47 }
48
49
50 eServiceCenter *eServiceCenter::instance;
51
52 eServiceCenter::eServiceCenter()
53 {
54         if (!instance)
55         {
56                 eDebug("settings instance.");
57                 instance = this;
58         }
59 }
60
61 eServiceCenter::~eServiceCenter()
62 {
63         if (instance == this)
64         {
65                 eDebug("clear instance");
66                 instance = 0;
67         }
68 }
69
70 DEFINE_REF(eServiceCenter);
71
72 RESULT eServiceCenter::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
73 {
74         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
75         if (i == handler.end())
76         {
77                 ptr = 0;
78                 return -1;
79         }
80         return i->second->play(ref, ptr);
81 }
82
83 RESULT eServiceCenter::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
84 {
85         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
86         if (i == handler.end())
87         {
88                 ptr = 0;
89                 return -1;
90         }
91         return i->second->record(ref, ptr);
92 }
93
94 RESULT eServiceCenter::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
95 {
96         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
97         if (i == handler.end())
98         {
99                 ptr = 0;
100                 return -1;
101         }
102         return i->second->list(ref, ptr);
103 }
104
105 RESULT eServiceCenter::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
106 {
107         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
108         if (i == handler.end())
109         {
110                 ptr = 0;
111                 return -1;
112         }
113         return i->second->info(ref, ptr);
114 }
115
116 RESULT eServiceCenter::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
117 {
118         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
119         if (i == handler.end())
120         {
121                 ptr = 0;
122                 return -1;
123         }
124         return i->second->offlineOperations(ref, ptr);
125 }
126
127 RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd)
128 {
129         handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
130         return 0;
131 }
132
133 RESULT eServiceCenter::removeServiceFactory(int id)
134 {
135         handler.erase(id);
136         return 0;
137 }
138
139         /* default handlers */
140 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
141 {
142         ptr = 0;
143         return -1;
144 }
145
146 #include <lib/service/event.h>
147
148 RESULT iStaticServiceInformation::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
149 {
150         evt = 0;
151         return -1;
152 }
153
154 int iStaticServiceInformation::getLength(const eServiceReference &ref)
155 {
156         return -1;
157 }
158
159 bool iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore)
160 {
161         return true;
162 }
163
164 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
165 {
166         evt = 0;
167         return -1;
168 }
169
170 int iStaticServiceInformation::getInfo(const eServiceReference &ref, int w)
171 {
172         return -1;
173 }
174
175 std::string iStaticServiceInformation::getInfoString(const eServiceReference &ref, int w)
176 {
177         return "";
178 }
179
180 int iServiceInformation::getInfo(int w)
181 {
182         return -1;
183 }
184
185 std::string iServiceInformation::getInfoString(int w)
186 {
187         return "";
188 }
189
190 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");