1 #include <lib/base/eerror.h>
2 #include <lib/base/estring.h>
3 #include <lib/python/python.h>
4 #include <lib/service/service.h>
5 #include <lib/base/init_num.h>
6 #include <lib/base/init.h>
7 #include <lib/python/python.h>
9 static std::string encode(const std::string s)
16 unsigned char c = s[i];
17 if ((c == ':') || (c < 32) || (c == '%'))
21 snprintf(hex, 8, "%02x", c);
29 static std::string decode(const std::string s)
36 unsigned char c = s[i];
44 char t[3] = {s[i - 1], s[i], 0};
45 unsigned char r = strtoul(t, 0, 0x10);
54 eServiceReference::eServiceReference(const std::string &string)
56 const char *c=string.c_str();
61 else 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 )
63 memset( data, 0, sizeof(data) );
64 eDebug("find old format eServiceReference string");
65 if ( sscanf(c, "%d:%d:%x:%x:%x:%x:%n", &type, &flags, &data[0], &data[1], &data[2], &data[3], &pathl) < 2 )
71 const char *pathstr = c+pathl;
72 const char *namestr = strchr(pathstr, ':');
75 if (pathstr != namestr)
76 path.assign(pathstr, namestr-pathstr);
88 std::string eServiceReference::toString() const
94 for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
95 ret+=":"+ getNum(data[i], 0x10);
96 ret+=":"+encode(path); /* we absolutely have a problem when the path contains a ':' (for example: http://). we need an encoding here. */
98 ret+=":"+encode(name);
102 std::string eServiceReference::toCompareString() const
107 for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
108 ret+=":"+getNum(data[i], 0x10);
109 ret+=":"+encode(path);
113 eServiceCenter *eServiceCenter::instance;
115 eServiceCenter::eServiceCenter()
119 eDebug("settings instance.");
124 eServiceCenter::~eServiceCenter()
126 if (instance == this)
128 eDebug("clear instance");
133 DEFINE_REF(eServiceCenter);
135 RESULT eServiceCenter::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
137 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
138 if (i == handler.end())
143 return i->second->play(ref, ptr);
146 RESULT eServiceCenter::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
148 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
149 if (i == handler.end())
154 return i->second->record(ref, ptr);
157 RESULT eServiceCenter::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
159 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
160 if (i == handler.end())
165 return i->second->list(ref, ptr);
168 RESULT eServiceCenter::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
170 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
171 if (i == handler.end())
176 return i->second->info(ref, ptr);
179 RESULT eServiceCenter::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
181 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
182 if (i == handler.end())
187 return i->second->offlineOperations(ref, ptr);
190 RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd, std::list<std::string> &extensions)
192 handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
193 this->extensions[id]=extensions;
197 RESULT eServiceCenter::removeServiceFactory(int id)
200 extensions.erase(id);
204 RESULT eServiceCenter::addFactoryExtension(int id, const char *extension)
206 std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
207 if (it == extensions.end())
209 it->second.push_back(extension);
213 RESULT eServiceCenter::removeFactoryExtension(int id, const char *extension)
215 std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
216 if (it == extensions.end())
218 it->second.remove(extension);
223 int eServiceCenter::getServiceTypeForExtension(const char *str)
225 for (std::map<int, std::list<std::string> >::iterator sit(extensions.begin()); sit != extensions.end(); ++sit)
227 for (std::list<std::string>::iterator eit(sit->second.begin()); eit != sit->second.end(); ++eit)
236 int eServiceCenter::getServiceTypeForExtension(const std::string &str)
238 return getServiceTypeForExtension(str.c_str());
241 /* default handlers */
242 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
248 #include <lib/service/event.h>
250 RESULT iStaticServiceInformation::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
256 int iStaticServiceInformation::getLength(const eServiceReference &ref)
261 int iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate)
266 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
272 int iStaticServiceInformation::getInfo(const eServiceReference &ref, int w)
277 std::string iStaticServiceInformation::getInfoString(const eServiceReference &ref, int w)
282 PyObject *iStaticServiceInformation::getInfoObject(const eServiceReference &ref, int w)
287 int iServiceInformation::getInfo(int w)
292 std::string iServiceInformation::getInfoString(int w)
297 PyObject* iServiceInformation::getInfoObject(int w)
302 int iStaticServiceInformation::setInfo(const eServiceReference &ref, int w, int v)
307 int iStaticServiceInformation::setInfoString(const eServiceReference &ref, int w, const char *v)
312 int iServiceInformation::setInfo(int w, int v)
317 int iServiceInformation::setInfoString(int w, const char *v)
322 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");