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 s[3] = {s[i - 1], s[i], 0};
45 unsigned char r = strtoul(s, 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 int eServiceCenter::getServiceTypeForExtension(const char *str)
206 for (std::map<int, std::list<std::string> >::iterator sit(extensions.begin()); sit != extensions.end(); ++sit)
208 for (std::list<std::string>::iterator eit(sit->second.begin()); eit != sit->second.end(); ++eit)
217 int eServiceCenter::getServiceTypeForExtension(const std::string &str)
219 return getServiceTypeForExtension(str.c_str());
222 /* default handlers */
223 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
229 #include <lib/service/event.h>
231 RESULT iStaticServiceInformation::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
237 int iStaticServiceInformation::getLength(const eServiceReference &ref)
242 int iStaticServiceInformation::isPlayable(const eServiceReference &ref, const eServiceReference &ignore)
247 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
253 int iStaticServiceInformation::getInfo(const eServiceReference &ref, int w)
258 std::string iStaticServiceInformation::getInfoString(const eServiceReference &ref, int w)
263 PyObject *iStaticServiceInformation::getInfoObject(const eServiceReference &ref, int w)
268 int iServiceInformation::getInfo(int w)
273 std::string iServiceInformation::getInfoString(int w)
278 PyObject* iServiceInformation::getInfoObject(int w)
283 int iStaticServiceInformation::setInfo(const eServiceReference &ref, int w, int v)
288 int iStaticServiceInformation::setInfoString(const eServiceReference &ref, int w, const char *v)
293 int iServiceInformation::setInfo(int w, int v)
298 int iServiceInformation::setInfoString(int w, const char *v)
303 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");