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