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 )
70 const char *pathstr = c+pathl;
71 const char *namestr = NULL;
72 int found = strlen(pathstr)-1;
73 for(;found >= 0;found--)
75 if(pathstr[found] == ':')
79 namestr = pathstr + found;
82 if (!strncmp(namestr, "://", 3)) // The path is a url (e.g. "http://...")
84 namestr = strchr(namestr, ' ');
87 path.assign(pathstr, namestr - pathstr);
94 if (pathstr != namestr)
95 path.assign(pathstr, namestr-pathstr);
108 std::string eServiceReference::toString() const
113 ret += getNum(flags);
114 for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
115 ret+=":"+ getNum(data[i], 0x10);
116 ret+=":"+encode(path); /* we absolutely have a problem when the path contains a ':' (for example: http://). we need an encoding here. */
118 ret+=":"+encode(name);
122 std::string eServiceReference::toCompareString() const
127 for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
128 ret+=":"+getNum(data[i], 0x10);
129 ret+=":"+encode(path);
133 eServiceCenter *eServiceCenter::instance;
135 eServiceCenter::eServiceCenter()
139 eDebug("settings instance.");
144 eServiceCenter::~eServiceCenter()
146 if (instance == this)
148 eDebug("clear instance");
153 DEFINE_REF(eServiceCenter);
155 RESULT eServiceCenter::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
157 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
158 if (i == handler.end())
163 return i->second->play(ref, ptr);
166 RESULT eServiceCenter::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
168 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
169 if (i == handler.end())
174 return i->second->record(ref, ptr);
177 RESULT eServiceCenter::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
179 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
180 if (i == handler.end())
185 return i->second->list(ref, ptr);
188 RESULT eServiceCenter::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
190 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
191 if (i == handler.end())
196 return i->second->info(ref, ptr);
199 RESULT eServiceCenter::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
201 std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
202 if (i == handler.end())
207 return i->second->offlineOperations(ref, ptr);
210 RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd, std::list<std::string> &extensions)
212 handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
213 this->extensions[id]=extensions;
217 RESULT eServiceCenter::removeServiceFactory(int id)
220 extensions.erase(id);
224 RESULT eServiceCenter::addFactoryExtension(int id, const char *extension)
226 std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
227 if (it == extensions.end())
229 it->second.push_back(extension);
233 RESULT eServiceCenter::removeFactoryExtension(int id, const char *extension)
235 std::map<int, std::list<std::string> >::iterator it = extensions.find(id);
236 if (it == extensions.end())
238 it->second.remove(extension);
243 int eServiceCenter::getServiceTypeForExtension(const char *str)
245 for (std::map<int, std::list<std::string> >::iterator sit(extensions.begin()); sit != extensions.end(); ++sit)
247 for (std::list<std::string>::iterator eit(sit->second.begin()); eit != sit->second.end(); ++eit)
256 int eServiceCenter::getServiceTypeForExtension(const std::string &str)
258 return getServiceTypeForExtension(str.c_str());
261 /* default handlers */
262 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
268 #include <lib/service/event.h>
270 RESULT iStaticServiceInformation::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
276 int iStaticServiceInformation::getLength(const eServiceReference &ref)
281 int iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate)
286 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
292 int iStaticServiceInformation::getInfo(const eServiceReference &ref, int w)
297 std::string iStaticServiceInformation::getInfoString(const eServiceReference &ref, int w)
302 PyObject *iStaticServiceInformation::getInfoObject(const eServiceReference &ref, int w)
307 int iServiceInformation::getInfo(int w)
312 std::string iServiceInformation::getInfoString(int w)
317 PyObject* iServiceInformation::getInfoObject(int w)
322 int iStaticServiceInformation::setInfo(const eServiceReference &ref, int w, int v)
327 int iStaticServiceInformation::setInfoString(const eServiceReference &ref, int w, const char *v)
332 int iServiceInformation::setInfo(int w, int v)
337 int iServiceInformation::setInfoString(int w, const char *v)
342 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");