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)
62 int eDVBCIInterfaces::reset(int slotid)
66 if( (slot = getSlot(slotid)) == 0 ) {
67 printf("FIXME: request for unknown slot\n");
74 int eDVBCISlot::send(const unsigned char *data, size_t len)
80 // printf("%02x ",data[i]);
83 res = ::write(fd, data, len);
85 //printf("write() %d\n",res);
87 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
92 void eDVBCISlot::data(int what)
94 if(what == eSocketNotifier::Priority) {
95 if(state != stateRemoved) {
97 printf("ci removed\n");
98 notifier->setRequested(eSocketNotifier::Read);
100 eDVBCI_UI::getInstance()->setState(0,0);
107 r = ::read(fd, data, 4096);
109 if(state != stateInserted) {
110 state = stateInserted;
111 eDebug("ci inserted");
114 eDVBCI_UI::getInstance()->setState(0,1);
116 /* enable PRI to detect removal or errors */
117 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
124 // printf("%02x ",data[i]);
126 eDVBCISession::receiveData(this, data, r);
127 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
131 if(what == eSocketNotifier::Write) {
132 if(eDVBCISession::pollAll() == 0) {
133 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
138 DEFINE_REF(eDVBCISlot);
140 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
146 sprintf(filename, "/dev/ci%d", nr);
148 fd = ::open(filename, O_RDWR | O_NONBLOCK);
150 eDebug("eDVBCISlot has fd %d", fd);
152 state = stateInserted;
156 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
157 CONNECT(notifier->activated, eDVBCISlot::data);
164 eDVBCISlot::~eDVBCISlot()
168 int eDVBCISlot::getSlotID()
173 int eDVBCISlot::reset()
175 printf("edvbcislot: reset requested\n");
182 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");