trunk 20080912
[gitenigma.git] / lib / dvb / service.cpp
bloba56d3aeea19dab32c404622c97192323a87d02af
1 #include <lib/dvb/service.h>
3 #include <lib/base/i18n.h>
4 #include <lib/dvb/dvb.h>
5 #include <lib/system/init.h>
6 #include <lib/system/init_num.h>
7 #include <lib/system/econfig.h>
9 int eServiceHandler::flags=0;
11 eServiceHandler::eServiceHandler(int id): id(id)
15 eServiceHandler::~eServiceHandler()
19 eService *eServiceHandler::createService(const eServiceReference &node)
21 (void)node;
22 return 0;
25 int eServiceHandler::play(const eServiceReference &service, int workaround)
27 (void)service;
28 return -1;
31 int eServiceHandler::serviceCommand(const eServiceCommand &cmd)
33 (void)cmd;
34 return -1;
37 PMT *eServiceHandler::getPMT()
39 return 0;
42 void eServiceHandler::setPID(const PMTEntry *)
44 return;
47 SDT *eServiceHandler::getSDT()
49 return 0;
52 EIT *eServiceHandler::getEIT()
54 return 0;
57 int eServiceHandler::getFlags()
59 return flags;
62 int eServiceHandler::getState()
64 return 0;
67 int eServiceHandler::getAspectRatio()
69 return 0;
72 int eServiceHandler::getErrorInfo()
74 return 0;
77 int eServiceHandler::stop( int workaround )
79 return 0;
82 int eServiceHandler::getPosition(int)
84 return -1;
87 void eServiceHandler::setAudioStream( unsigned int )
91 void eServiceHandler::enterDirectory(const eServiceReference &dir, Signal1<void,const eServiceReference&> &callback)
93 (void)dir;
94 (void)callback;
95 return;
98 void eServiceHandler::leaveDirectory(const eServiceReference &dir)
100 (void)dir;
101 return;
104 eService *eServiceHandler::addRef(const eServiceReference &service)
106 (void)service;
107 return 0;
110 void eServiceHandler::removeRef(const eServiceReference &service)
112 (void)service;
115 eString eServiceHandler::getInfo(int id)
117 (void)id;
118 return "";
121 eServiceInterface *eServiceInterface::instance;
123 eServiceInterface *eServiceInterface::getInstance()
125 return instance;
128 void eServiceInterface::handleServiceEvent(const eServiceEvent &evt)
130 serviceEvent(evt);
133 int eServiceInterface::switchServiceHandler(int id, int workaround )
135 if (currentServiceHandler && (currentServiceHandler->getID() == id))
137 currentServiceHandler->stop(workaround);
138 return 0;
141 stop(workaround);
142 eServiceHandler *handler=getServiceHandler(id);
143 if (!handler)
144 return -1;
146 conn=CONNECT(handler->serviceEvent, eServiceInterface::handleServiceEvent);
147 currentServiceHandler=handler;
148 return 0;
151 eServiceInterface::eServiceInterface()
153 currentServiceHandler = 0;
154 if (!instance)
155 instance = this;
158 eServiceInterface::~eServiceInterface()
160 if (instance == this)
161 instance = 0;
162 stop();
165 int eServiceInterface::registerHandler(int id, eServiceHandler *handler)
167 if (handlers.count(id))
168 return -1;
169 handlers.insert(std::pair<int,eServiceHandler*>(id, handler));
170 return 0;
173 int eServiceInterface::unregisterHandler(int id)
175 std::map<int,eServiceHandler*>::iterator i=handlers.find(id);
176 if (i == handlers.end())
177 return -1;
178 if (i->second == currentServiceHandler)
179 stop();
180 handlers.erase(i);
181 return 0;
184 eServiceHandler *eServiceInterface::getServiceHandler(int id)
186 std::map<int,eServiceHandler*>::iterator i=handlers.find(id);
187 if (i == handlers.end())
188 return 0;
189 return i->second;
192 extern bool checkPin( int pin, const char * text );
194 int eServiceInterface::play(const eServiceReference &s)
196 return play(s,0);
199 int eServiceInterface::play(const eServiceReference &s, int workaround )
201 int pLockActive = eConfig::getInstance()->pLockActive();
202 if ( !workaround && s.isLocked() && pLockActive && !checkPin( eConfig::getInstance()->getParentalPin(), _("parental") ) )
204 eWarning("service is parentallocked... don't play");
205 return -1;
207 if (switchServiceHandler(s.type, workaround))
209 eWarning("couldn't play service type %d", s.type);
210 return -1;
212 service=s;
213 return currentServiceHandler->play(s, workaround);
216 int eServiceInterface::stop(int workaround)
218 if (!currentServiceHandler)
219 return -1;
220 int res=currentServiceHandler->stop(workaround);
221 conn.disconnect();
222 currentServiceHandler=0;
223 service=eServiceReference();
224 return res;
227 void eServiceInterface::enterDirectory(const eServiceReference &dir, Signal1<void,const eServiceReference&> &callback)
229 int pLockActive = eConfig::getInstance()->pLockActive();
230 if ( dir.isLocked() && pLockActive && !checkPin( eConfig::getInstance()->getParentalPin(), _("parental") ) )
232 eWarning("directory is parentallocked... don't enter");
233 return;
235 for (std::map<int,eServiceHandler*>::iterator i(handlers.begin()); i != handlers.end(); ++i)
236 i->second->enterDirectory(dir, callback);
239 void eServiceInterface::leaveDirectory(const eServiceReference &dir)
241 for (std::map<int,eServiceHandler*>::iterator i(handlers.begin()); i != handlers.end(); ++i)
242 i->second->leaveDirectory(dir);
245 eService *eServiceInterface::addRef(const eServiceReference &service)
247 eServiceHandler *handler=getServiceHandler(service.type);
248 if (handler)
249 return handler->addRef(service);
250 else
251 return 0;
254 void eServiceInterface::removeRef(const eServiceReference &service)
256 eServiceHandler *handler=getServiceHandler(service.type);
257 if (handler)
258 return handler->removeRef(service);
261 eAutoInitP0<eServiceInterface> i_eServiceInteface(eAutoInitNumbers::service, "eServiceInterface");