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);
143 //FIXME; do in deconstructor of the appmgr class
144 application_manager = 0;
152 r = ::read(fd, data, 4096);
154 if(state != stateInserted) {
155 state = stateInserted;
156 eDebug("ci inserted");
159 eDVBCI_UI::getInstance()->setState(0,1);
161 /* enable PRI to detect removal or errors */
162 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
169 // printf("%02x ",data[i]);
171 eDVBCISession::receiveData(this, data, r);
172 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
176 if(what == eSocketNotifier::Write) {
177 if(eDVBCISession::pollAll() == 0) {
178 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
183 DEFINE_REF(eDVBCISlot);
185 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
189 application_manager = 0;
194 sprintf(filename, "/dev/ci%d", nr);
196 fd = ::open(filename, O_RDWR | O_NONBLOCK);
198 eDebug("eDVBCISlot has fd %d", fd);
200 state = stateInserted;
204 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
205 CONNECT(notifier->activated, eDVBCISlot::data);
212 eDVBCISlot::~eDVBCISlot()
216 int eDVBCISlot::getSlotID()
221 int eDVBCISlot::reset()
223 printf("edvbcislot: reset requested\n");
230 int eDVBCISlot::initialize()
232 printf("edvbcislot: initialize()\n");
236 int eDVBCISlot::startMMI()
238 printf("edvbcislot: startMMI()\n");
240 if(application_manager)
241 application_manager->startMMI();
246 int eDVBCISlot::stopMMI()
248 printf("edvbcislot: stopMMI()\n");
251 mmi_session->stopMMI();
256 int eDVBCISlot::answerMMI(int answer, char *value)
258 printf("edvbcislot: answerMMI()\n");
262 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");