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>
14 eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;
16 eDVBCIInterfaces::eDVBCIInterfaces()
22 eDebug("scanning for common interfaces..");
28 sprintf(filename, "/dev/ci%d", num_ci);
30 if (stat(filename, &s))
33 ePtr<eDVBCISlot> cislot;
35 cislot = new eDVBCISlot(eApp, num_ci);
36 m_slots.push_back(cislot);
41 eDebug("done, found %d common interface slots", num_ci);
44 eDVBCIInterfaces::~eDVBCIInterfaces()
48 eDVBCIInterfaces *eDVBCIInterfaces::getInstance()
53 eDVBCISlot *eDVBCIInterfaces::getSlot(int slotid)
55 for(eSmartPtrList<eDVBCISlot>::iterator i(m_slots.begin()); i != m_slots.end(); ++i)
56 if(i->getSlotID() == slotid)
59 printf("FIXME: request for unknown slot\n");
64 int eDVBCIInterfaces::reset(int slotid)
68 if( (slot = getSlot(slotid)) == 0 )
74 int eDVBCIInterfaces::initialize(int slotid)
78 if( (slot = getSlot(slotid)) == 0 )
81 return slot->initialize();
84 int eDVBCIInterfaces::startMMI(int slotid)
88 if( (slot = getSlot(slotid)) == 0 )
91 return slot->startMMI();
94 int eDVBCIInterfaces::answerMMI(int slotid, int answer, char *value)
98 if( (slot = getSlot(slotid)) == 0 )
101 return slot->answerMMI(answer, value);
104 int eDVBCISlot::send(const unsigned char *data, size_t len)
110 // printf("%02x ",data[i]);
113 res = ::write(fd, data, len);
115 //printf("write() %d\n",res);
117 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
122 void eDVBCISlot::data(int what)
124 if(what == eSocketNotifier::Priority) {
125 if(state != stateRemoved) {
126 state = stateRemoved;
127 printf("ci removed\n");
128 notifier->setRequested(eSocketNotifier::Read);
130 eDVBCI_UI::getInstance()->setState(0,0);
137 r = ::read(fd, data, 4096);
139 if(state != stateInserted) {
140 state = stateInserted;
141 eDebug("ci inserted");
144 eDVBCI_UI::getInstance()->setState(0,1);
146 /* enable PRI to detect removal or errors */
147 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
154 // printf("%02x ",data[i]);
156 eDVBCISession::receiveData(this, data, r);
157 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
161 if(what == eSocketNotifier::Write) {
162 if(eDVBCISession::pollAll() == 0) {
163 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
168 DEFINE_REF(eDVBCISlot);
170 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
176 sprintf(filename, "/dev/ci%d", nr);
178 fd = ::open(filename, O_RDWR | O_NONBLOCK);
180 eDebug("eDVBCISlot has fd %d", fd);
182 state = stateInserted;
186 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
187 CONNECT(notifier->activated, eDVBCISlot::data);
194 eDVBCISlot::~eDVBCISlot()
198 int eDVBCISlot::getSlotID()
203 int eDVBCISlot::reset()
205 printf("edvbcislot: reset requested\n");
212 int eDVBCISlot::initialize()
214 printf("edvbcislot: initialize()\n");
218 int eDVBCISlot::startMMI()
220 printf("edvbcislot: startMMI()\n");
224 int eDVBCISlot::answerMMI(int answer, char *value)
226 printf("edvbcislot: answerMMI()\n");
230 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");