#include <fcntl.h>
+#include <lib/base/init.h>
+#include <lib/base/init_num.h>
+
#include <lib/base/eerror.h>
#include <lib/dvb_ci/dvbci.h>
#include <lib/dvb_ci/dvbci_session.h>
int num_ci = 0;
eDebug("scanning for common interfaces..");
+
while (1)
{
struct stat s;
++num_ci;
}
- eDebug("done, found %d common interfaces");
+ eDebug("done, found %d common interface slots", num_ci);
+}
+
+eDVBCIInterfaces::~eDVBCIInterfaces()
+{
}
-int eDVBCISlot::write(const unsigned char *data, size_t len)
+int eDVBCISlot::send(const unsigned char *data, size_t len)
{
- return ::write(fd, data, len);
+ int res;
+ //int i;
+ //printf("< ");
+ //for(i=0;i<len;i++)
+ // printf("%02x ",data[i]);
+ //printf("\n");
+
+ res = ::write(fd, data, len);
+
+ //printf("write() %d\n",res);
+
+ notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority | eSocketNotifier::Write);
+
+ return res;
}
-void eDVBCISlot::data(int)
+void eDVBCISlot::data(int what)
{
- eDebug("ci talks to us");
+ if(what == eSocketNotifier::Priority) {
+ if(state != stateRemoved) {
+ state = stateRemoved;
+ printf("ci removed\n");
+ notifier->setRequested(eSocketNotifier::Read);
+ }
+ return;
+ }
+
__u8 data[4096];
int r;
r = ::read(fd, data, 4096);
- if(r < 0)
- eWarning("ERROR reading from CI - %m\n");
- if(!se) {
+ if(state != stateInserted) {
+ state = stateInserted;
eDebug("ci inserted");
- se = new eDVBCISession(this);
-
- /* enable HUP to detect removal or errors */
- notifier_event->start();
+ /* enable PRI to detect removal or errors */
+ notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
}
- if(r > 0)
- se->receiveData(data, r);
-}
+ if(r > 0) {
+ //int i;
+ //printf("> ");
+ //for(i=0;i<r;i++)
+ // printf("%02x ",data[i]);
+ //printf("\n");
+ eDVBCISession::receiveData(this, data, r);
+ notifier->setRequested(eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Write);
+ return;
+ }
-void eDVBCISlot::event(int)
-{
- eDebug("CI removed");
-
- /* kill the TransportConnection */
-
- /* we know about and disable HUP */
- notifier_event->stop();
+ if(what == eSocketNotifier::Write) {
+ if(eDVBCISession::pollAll() == 0) {
+ notifier->setRequested(eSocketNotifier::Read | eSocketNotifier::Priority);
+ }
+ }
}
-eDVBCISlot::eDVBCISlot(eMainloop *context, int nr): se(0)
+DEFINE_REF(eDVBCISlot);
+
+eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
{
char filename[128];
if (fd >= 0)
{
- //read callback
- notifier_data = new eSocketNotifier(context, fd, eSocketNotifier::Read);
- CONNECT(notifier_data->activated, eDVBCISlot::data);
- //remove callback
- notifier_event = new eSocketNotifier(context, fd, eSocketNotifier::Hungup);
- CONNECT(notifier_event->activated, eDVBCISlot::event);
+ notifier = new eSocketNotifier(context, fd, eSocketNotifier::Read | eSocketNotifier::Priority);
+ CONNECT(notifier->activated, eDVBCISlot::data);
} else
{
perror(filename);
}
}
+eDVBCISlot::~eDVBCISlot()
+{
+}
+
+eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");