3 #include <lib/base/init.h>
4 #include <lib/base/init_num.h>
6 #include <lib/base/eerror.h>
7 #include <lib/dvb_ci/dvbci.h>
8 #include <lib/dvb_ci/dvbci_session.h>
10 eDVBCIInterfaces::eDVBCIInterfaces()
14 eDebug("scanning for common interfaces..");
20 sprintf(filename, "/dev/ci%d", num_ci);
22 if (stat(filename, &s))
25 ePtr<eDVBCISlot> cislot;
27 cislot = new eDVBCISlot(eApp, num_ci);
28 m_slots.push_back(cislot);
33 eDebug("done, found %d common interface slots", num_ci);
36 eDVBCIInterfaces::~eDVBCIInterfaces()
40 int eDVBCISlot::send(const unsigned char *data, size_t len)
46 // printf("%02x ",data[i]);
49 res = ::write(fd, data, len);
51 //printf("write() %d\n",res);
53 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
58 void eDVBCISlot::data(int what)
60 if(what == eSocketNotifier::Priority) {
61 if(state != stateRemoved) {
63 printf("ci removed\n");
64 notifier->setRequested(eSocketNotifier::Read);
72 r = ::read(fd, data, 4096);
74 if(state != stateInserted) {
75 state = stateInserted;
76 eDebug("ci inserted");
77 /* enable PRI to detect removal or errors */
78 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
85 // printf("%02x ",data[i]);
87 eDVBCISession::receiveData(this, data, r);
88 notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
92 if(what == eSocketNotifier::Write) {
93 if(eDVBCISession::pollAll() == 0) {
94 notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
99 DEFINE_REF(eDVBCISlot);
101 eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
105 sprintf(filename, "/dev/ci%d", nr);
107 fd = ::open(filename, O_RDWR | O_NONBLOCK);
109 eDebug("eDVBCISlot has fd %d", fd);
113 notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
114 CONNECT(notifier->activated, eDVBCISlot::data);
121 eDVBCISlot::~eDVBCISlot()
125 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");