4 #include <lib/base/init.h>
5 #include <lib/base/init_num.h>
6 #include <lib/base/ebase.h>
8 #include <lib/base/eerror.h>
9 #include <lib/dvb_ci/dvbci.h>
10 #include <lib/dvb_ci/dvbci_session.h>
12 #include <lib/dvb_ci/dvbci_ui.h>
13 #include <lib/dvb_ci/dvbci_appmgr.h>
14 #include <lib/dvb_ci/dvbci_mmi.h>
16 eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
18 eDVBCIInterfaces::eDVBCIInterfaces()
24 eDebug("scanning for common interfaces..");
30 sprintf(filename, "/dev/ci%d", num_ci);
32 if (stat(filename, &s))
35 ePtr<eDVBCISlot> cislot;
37 cislot = new eDVBCISlot(eApp, num_ci);
38 m_slots.push_back(cislot);
43 eDebug("done, found %d common interface slots", num_ci);
46 eDVBCIInterfaces::~eDVBCIInterfaces()
50 eDVBCIInterfaces *eDVBCIInterfaces::getInstance()
55 eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid)
57 for(eSmartPtrList<eDVBCISlot>::iterator i(m_slots.begin()); i != m_slots.end(); ++i)
58 if(i->getSlotID() == slotid)
61 printf("FIXME: request for unknown slot\n");
66 int eDVBCIInterfaces::reset(int slotid)
70 if( (slot = getSlot(slotid)) == 0 )
76 int eDVBCIInterfaces::initialize(int slotid)
80 if( (slot = getSlot(slotid)) == 0 )
83 return slot->initialize();
86 int eDVBCIInterfaces::startMMI(int slotid)
90 if( (slot = getSlot(slotid)) == 0 )
93 return slot->startMMI();
96 int eDVBCIInterfaces::stopMMI(int slotid)
100 if( (slot = getSlot(slotid)) == 0 )
103 return slot->stopMMI();
106 int eDVBCIInterfaces::answerMMI(int slotid, int answer, char *value)
110 if( (slot = getSlot(slotid)) == 0 )
113 return slot->answerMMI(answer, value);
116 int eDVBCISlot::send(const unsigned char *data, size_t len)
122 // printf("%02x ",data[i]);
125 res = ::write(fd, data, len);
127 //printf("write() %d\n",res);
129 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
134 void eDVBCISlot::data(int what)
136 if(what == eSocketNotifier::Priority) {
137 if(state != stateRemoved) {
138 state = stateRemoved;
139 printf("ci removed\n");
140 notifier->setRequested(eSocketNotifier::Read);
142 eDVBCI_UI::getInstance()->setState(0,0);
149 r = ::read(fd, data, 4096);
151 if(state != stateInserted) {
152 state = stateInserted;
153 eDebug("ci inserted");
156 eDVBCI_UI::getInstance()->setState(0,1);
158 /* enable PRI to detect removal or errors */
159 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
166 // printf("%02x ",data[i]);
168 eDVBCISession::receiveData(this, data, r);
169 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
173 if(what == eSocketNotifier::Write) {
174 if(eDVBCISession::pollAll() == 0) {
175 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
180 DEFINE_REF(eDVBCISlot);
182 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
186 application_manager = 0;
191 sprintf(filename, "/dev/ci%d", nr);
193 fd = ::open(filename, O_RDWR | O_NONBLOCK);
195 eDebug("eDVBCISlot has fd %d", fd);
197 state = stateInserted;
201 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
202 CONNECT(notifier->activated, eDVBCISlot::data);
209 eDVBCISlot::~eDVBCISlot()
213 int eDVBCISlot::getSlotID()
218 int eDVBCISlot::reset()
220 printf("edvbcislot: reset requested\n");
227 int eDVBCISlot::initialize()
229 printf("edvbcislot: initialize()\n");
233 int eDVBCISlot::startMMI()
235 printf("edvbcislot: startMMI()\n");
237 if(application_manager)
238 application_manager->startMMI();
243 int eDVBCISlot::stopMMI()
245 printf("edvbcislot: stopMMI()\n");
248 mmi_session->stopMMI();
253 int eDVBCISlot::answerMMI(int answer, char *value)
255 printf("edvbcislot: answerMMI()\n");
259 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");