also parse user private ES streams, handle REGISTRATION_DESCRIPTOR for ac3
[enigma2.git] / lib / base / ebase.cpp
1 #include <lib/base/ebase.h>
2
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <errno.h>
6
7 #include <lib/base/eerror.h>
8 #include <lib/base/elock.h>
9
10 eSocketNotifier::eSocketNotifier(eMainloop *context, int fd, int requested, bool startnow): context(*context), fd(fd), state(0), requested(requested)
11 {
12         if (startnow)   
13                 start();
14 }
15
16 eSocketNotifier::~eSocketNotifier()
17 {
18         stop();
19 }
20
21 void eSocketNotifier::start()
22 {
23         if (state)
24                 stop();
25
26         context.addSocketNotifier(this);
27         state=2;  // running but not in poll yet
28 }
29
30 void eSocketNotifier::stop()
31 {
32         if (state)
33                 context.removeSocketNotifier(this);
34
35         state=0;
36 }
37
38                                         // timer
39 void eTimer::start(long msek, bool singleShot)
40 {
41         if (bActive)
42                 stop();
43
44         bActive = true;
45         bSingleShot = singleShot;
46         interval = msek;
47         clock_gettime(CLOCK_MONOTONIC, &nextActivation);
48 //      eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d msec", this, nextActivation.tv_sec, nextActivation.tv_nsec, msek);
49         nextActivation += (msek<0 ? 0 : msek);
50 //      eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
51         context.addTimer(this);
52 }
53
54 void eTimer::startLongTimer( int seconds )
55 {
56         if (bActive)
57                 stop();
58
59         bActive = bSingleShot = true;
60         interval = 0;
61         clock_gettime(CLOCK_MONOTONIC, &nextActivation);
62 //      eDebug("this = %p\nnow sec = %d, nsec = %d\nadd %d sec", this, nextActivation.tv_sec, nextActivation.tv_nsec, seconds);
63         if ( seconds > 0 )
64                 nextActivation.tv_sec += seconds;
65 //      eDebug("next Activation sec = %d, nsec = %d", nextActivation.tv_sec, nextActivation.tv_nsec );
66         context.addTimer(this);
67 }
68
69 void eTimer::stop()
70 {
71         if (bActive)
72         {
73                 bActive=false;
74                 context.removeTimer(this);
75         }
76 }
77
78 void eTimer::changeInterval(long msek)
79 {
80         if (bActive)  // Timer is running?
81         {
82                 context.removeTimer(this);       // then stop
83                 nextActivation -= interval;  // sub old interval
84         }
85         else
86                 bActive=true; // then activate Timer
87
88         interval = msek;                                                // set new Interval
89         nextActivation += interval;             // calc nextActivation
90
91         context.addTimer(this);                         // add Timer to context TimerList
92 }
93
94 void eTimer::activate()   // Internal Funktion... called from eApplication
95 {
96         context.removeTimer(this);
97
98         if (!bSingleShot)
99         {
100                 nextActivation += interval;
101                 context.addTimer(this);
102         }
103         else
104                 bActive=false;
105
106         /*emit*/ timeout();
107 }
108
109 // mainloop
110 ePtrList<eMainloop> eMainloop::existing_loops;
111
112 eMainloop::~eMainloop()
113 {
114         existing_loops.remove(this);
115         for (std::map<int, eSocketNotifier*>::iterator it(notifiers.begin());it != notifiers.end();++it)
116                 it->second->stop();
117         while(m_timer_list.begin() != m_timer_list.end())
118                 m_timer_list.begin()->stop();
119 }
120
121 void eMainloop::addSocketNotifier(eSocketNotifier *sn)
122 {
123         int fd = sn->getFD();
124         ASSERT(notifiers.find(fd) == notifiers.end());
125         notifiers[fd]=sn;
126 }
127
128 void eMainloop::removeSocketNotifier(eSocketNotifier *sn)
129 {
130         int fd = sn->getFD();
131         std::map<int,eSocketNotifier*>::iterator i(notifiers.find(fd));
132         if (i != notifiers.end())
133                 return notifiers.erase(i);
134         eFatal("removed socket notifier which is not present");
135 }
136
137 int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePyObject additional)
138 {
139         int return_reason = 0;
140                 /* get current time */
141
142         if (additional && !PyDict_Check(additional))
143                 eFatal("additional, but it's not dict");
144
145         if (additional && !res)
146                 eFatal("additional, but no res");
147
148         long poll_timeout = -1; /* infinite in case of empty timer list */
149
150         if (!m_timer_list.empty() || twisted_timeout > 0)
151         {
152                 if (!m_timer_list.empty())
153                 {
154                         /* process all timers which are ready. first remove them out of the list. */
155                         while (!m_timer_list.empty() && (poll_timeout = timeout_usec( m_timer_list.begin()->getNextActivation() ) ) <= 0 )
156                                 m_timer_list.begin()->activate();
157                         if (poll_timeout < 0)
158                                 poll_timeout = 0;
159                         else /* convert us to ms */
160                                 poll_timeout /= 1000;
161                 }
162         }
163
164         if ((twisted_timeout > 0) && (poll_timeout > 0) && ((unsigned int)poll_timeout > twisted_timeout))
165         {
166                 poll_timeout = twisted_timeout;
167                 return_reason = 1;
168         }
169
170         int nativecount=notifiers.size(),
171                 fdcount=nativecount,
172                 ret=0;
173
174         if (additional)
175                 fdcount += PyDict_Size(additional);
176
177                 // build the poll aray
178         pollfd pfd[fdcount];  // make new pollfd array
179         std::map<int,eSocketNotifier*>::iterator it = notifiers.begin();
180         int i=0;
181         for (; i < nativecount; ++i, ++it)
182         {
183                 it->second->state = 1; // running and in poll
184                 pfd[i].fd = it->first;
185                 pfd[i].events = it->second->getRequested();
186         }
187
188         if (additional)
189         {
190 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
191                 typedef int Py_ssize_t;
192 # define PY_SSIZE_T_MAX INT_MAX
193 # define PY_SSIZE_T_MIN INT_MIN
194 #endif
195                 PyObject *key, *val;
196                 Py_ssize_t pos=0;
197                 while (PyDict_Next(additional, &pos, &key, &val)) {
198                         pfd[i].fd = PyObject_AsFileDescriptor(key);
199                         pfd[i++].events = PyInt_AsLong(val);
200                 }
201         }
202
203         m_is_idle = 1;
204
205         if (this == eApp)
206         {
207                 Py_BEGIN_ALLOW_THREADS
208                 ret = ::poll(pfd, fdcount, poll_timeout);
209                 Py_END_ALLOW_THREADS
210         } else
211                 ret = ::poll(pfd, fdcount, poll_timeout);
212
213         m_is_idle = 0;
214
215                         /* ret > 0 means that there are some active poll entries. */
216         if (ret > 0)
217         {
218                 int i=0;
219                 return_reason = 0;
220                 for (; i < nativecount; ++i)
221                 {
222                         if (pfd[i].revents)
223                         {
224                                 it = notifiers.find(pfd[i].fd);
225                                 if (it != notifiers.end()
226                                         && it->second->state == 1) // added and in poll
227                                 {
228                                         int req = it->second->getRequested();
229                                         if (pfd[i].revents & req)
230                                                 it->second->activate(pfd[i].revents & req);
231                                         pfd[i].revents &= ~req;
232                                 }
233                                 if (pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL))
234                                         eDebug("poll: unhandled POLLERR/HUP/NVAL for fd %d(%d)", pfd[i].fd, pfd[i].revents);
235                         }
236                 }
237                 for (; i < fdcount; ++i)
238                 {
239                         if (pfd[i].revents)
240                         {
241                                 if (!*res)
242                                         *res = PyList_New(0);
243                                 ePyObject it = PyTuple_New(2);
244                                 PyTuple_SET_ITEM(it, 0, PyInt_FromLong(pfd[i].fd));
245                                 PyTuple_SET_ITEM(it, 1, PyInt_FromLong(pfd[i].revents));
246                                 PyList_Append(*res, it);
247                                 Py_DECREF(it);
248                         }
249                 }
250         }
251         else if (ret < 0)
252         {
253                         /* when we got a signal, we get EINTR. */
254                 if (errno != EINTR)
255                         eDebug("poll made error (%m)");
256                 else
257                         return_reason = 2; /* don't assume the timeout has passed when we got a signal */
258         }
259
260         return return_reason;
261 }
262
263 void eMainloop::addTimer(eTimer* e)
264 {
265         m_timer_list.insert_in_order(e);
266 }
267
268 void eMainloop::removeTimer(eTimer* e)
269 {
270         m_timer_list.remove(e);
271 }
272
273 int eMainloop::iterate(unsigned int twisted_timeout, PyObject **res, ePyObject dict)
274 {
275         int ret = 0;
276
277         if (twisted_timeout)
278         {
279                 clock_gettime(CLOCK_MONOTONIC, &m_twisted_timer);
280                 m_twisted_timer += twisted_timeout;
281         }
282
283                 /* TODO: this code just became ugly. fix that. */
284         do
285         {
286                 if (m_interrupt_requested)
287                 {
288                         m_interrupt_requested = 0;
289                         return 0;
290                 }
291
292                 if (app_quit_now)
293                         return -1;
294
295                 int to = 0;
296                 if (twisted_timeout)
297                 {
298                         timespec now, timeout;
299                         clock_gettime(CLOCK_MONOTONIC, &now);
300                         if (m_twisted_timer<=now) // timeout
301                                 return 0;
302                         timeout = m_twisted_timer - now;
303                         to = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
304                 }
305                 ret = processOneEvent(to, res, dict);
306         } while ( !ret && !(res && *res) );
307
308         return ret;
309 }
310
311 int eMainloop::runLoop()
312 {
313         while (!app_quit_now)
314                 iterate();
315         return retval;
316 }
317
318 void eMainloop::reset()
319 {
320         app_quit_now=false;
321 }
322
323 PyObject *eMainloop::poll(ePyObject timeout, ePyObject dict)
324 {
325         PyObject *res=0;
326
327         if (app_quit_now)
328                 Py_RETURN_NONE;
329
330         int twisted_timeout = (timeout == Py_None) ? 0 : PyInt_AsLong(timeout);
331
332         iterate(twisted_timeout, &res, dict);
333         if (res)
334                 return res;
335
336         return PyList_New(0); /* return empty list on timeout */
337 }
338
339 void eMainloop::interruptPoll()
340 {
341         m_interrupt_requested = 1;
342 }
343
344 void eMainloop::quit(int ret)
345 {
346         retval = ret;
347         app_quit_now = true;
348 }
349
350 eApplication* eApp = 0;
351
352 #include "structmember.h"
353
354 extern "C" {
355
356 // eTimer replacement
357
358 struct eTimerPy
359 {
360         PyObject_HEAD
361         eTimer *tm;
362         PyObject *in_weakreflist; /* List of weak references */
363 };
364
365 static int
366 eTimerPy_traverse(eTimerPy *self, visitproc visit, void *arg)
367 {
368         PyObject *obj = self->tm->timeout.get();
369         Py_VISIT(obj);
370         return 0;
371 }
372
373 static int
374 eTimerPy_clear(eTimerPy *self)
375 {
376         PyObject *obj = self->tm->timeout.get();
377         Py_CLEAR(obj);
378         return 0;
379 }
380
381 static void
382 eTimerPy_dealloc(eTimerPy* self)
383 {
384         if (self->in_weakreflist != NULL)
385                 PyObject_ClearWeakRefs((PyObject *) self);
386         eTimerPy_clear(self);
387         delete self->tm;
388         self->ob_type->tp_free((PyObject*)self);
389 }
390
391 static PyObject *
392 eTimerPy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
393 {
394         eTimerPy *self = (eTimerPy *)type->tp_alloc(type, 0);
395         self->tm = new eTimer(eApp);
396         self->in_weakreflist = NULL;
397         return (PyObject *)self;
398 }
399
400 static PyObject *
401 eTimerPy_is_active(eTimerPy* self)
402 {
403         PyObject *ret = NULL;
404         ret = self->tm->isActive() ? Py_True : Py_False;
405         Org_Py_INCREF(ret);
406         return ret;
407 }
408
409 static PyObject *
410 eTimerPy_start(eTimerPy* self, PyObject *args)
411 {
412         long v=0;
413         long singleShot=0;
414         if (PyTuple_Size(args) > 1)
415         {
416                 if (!PyArg_ParseTuple(args, "ll", &v, &singleShot)) // when 2nd arg is a value
417                 {
418                         PyObject *obj=0;
419                         if (!PyArg_ParseTuple(args, "lO", &v, &obj)) // get 2nd arg as python object
420                                 return NULL;
421                         else if (obj == Py_True)
422                                 singleShot=1;
423                         else if (obj != Py_False)
424                                 return NULL;
425                 }
426         }
427         else if (!PyArg_ParseTuple(args, "l", &v))
428                 return NULL;
429         self->tm->start(v, singleShot);
430         Py_RETURN_NONE;
431 }
432
433 static PyObject *
434 eTimerPy_start_long(eTimerPy* self, PyObject *args)
435 {
436         long v=0;
437         if (!PyArg_ParseTuple(args, "l", &v)) {
438                 return NULL;
439         }
440         self->tm->startLongTimer(v);
441         Py_RETURN_NONE;
442 }
443
444 static PyObject *
445 eTimerPy_change_interval(eTimerPy* self, PyObject *args)
446 {
447         long v=0;
448         if (!PyArg_ParseTuple(args, "l", &v)) {
449                 return NULL;
450         }
451         self->tm->changeInterval(v);
452         Py_RETURN_NONE;
453 }
454
455 static PyObject *
456 eTimerPy_stop(eTimerPy* self)
457 {
458         self->tm->stop();
459         Py_RETURN_NONE;
460 }
461
462 static PyObject *
463 eTimerPy_get_callback_list(eTimerPy *self)
464 { //used for compatibilty with the old eTimer
465         return self->tm->timeout.get();
466 }
467
468 static PyMethodDef eTimerPy_methods[] = {
469         {"isActive", (PyCFunction)eTimerPy_is_active, METH_NOARGS,
470          "returns the timer state"
471         },
472         {"start", (PyCFunction)eTimerPy_start, METH_VARARGS,
473          "start timer with interval in msecs"
474         },
475         {"startLongTimer", (PyCFunction)eTimerPy_start_long, METH_VARARGS,
476          "start timer with interval in secs"
477         },
478         {"changeInterval", (PyCFunction)eTimerPy_change_interval, METH_VARARGS,
479          "change interval of a timer (in msecs)"
480         },
481         {"stop", (PyCFunction)eTimerPy_stop, METH_NOARGS,
482          "stops the timer"
483         },
484         //used for compatibilty with the old eTimer
485         {"get", (PyCFunction)eTimerPy_get_callback_list, METH_NOARGS,
486          "get timeout callback list"
487         },
488         {NULL}  /* Sentinel */
489 };
490
491 static PyObject *
492 eTimerPy_get_cb_list(eTimerPy *self, void *closure)
493 {
494         return self->tm->timeout.get();
495 }
496
497 static PyObject *
498 eTimerPy_timeout(eTimerPy *self, void *closure) 
499 { //used for compatibilty with the old eTimer
500         Org_Py_INCREF((PyObject*)self);
501         return (PyObject*)self;
502 }
503
504 static PyGetSetDef eTimerPy_getseters[] = {
505         {"callback",
506          (getter)eTimerPy_get_cb_list, (setter)0,
507          "returns the callback python list",
508          NULL},
509
510         {"timeout", //used for compatibilty with the old eTimer
511          (getter)eTimerPy_timeout, (setter)0,
512          "synonym for our self",
513          NULL},
514
515         {NULL} /* Sentinel */
516 };
517
518 static PyTypeObject eTimerPyType = {
519         PyObject_HEAD_INIT(NULL)
520         0, /*ob_size*/
521         "eBaseImpl.eTimer", /*tp_name*/
522         sizeof(eTimerPy), /*tp_basicsize*/
523         0, /*tp_itemsize*/
524         (destructor)eTimerPy_dealloc, /*tp_dealloc*/
525         0, /*tp_print*/
526         0, /*tp_getattr*/
527         0, /*tp_setattr*/
528         0, /*tp_compare*/
529         0, /*tp_repr*/
530         0, /*tp_as_number*/
531         0, /*tp_as_sequence*/
532         0, /*tp_as_mapping*/
533         0, /*tp_hash */
534         0, /*tp_call*/
535         0, /*tp_str*/
536         0, /*tp_getattro*/
537         0, /*tp_setattro*/
538         0, /*tp_as_buffer*/
539         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
540         "eTimer objects", /* tp_doc */
541         (traverseproc)eTimerPy_traverse, /* tp_traverse */
542         (inquiry)eTimerPy_clear, /* tp_clear */
543         0, /* tp_richcompare */
544         offsetof(eTimerPy, in_weakreflist), /* tp_weaklistoffset */
545         0, /* tp_iter */
546         0, /* tp_iternext */
547         eTimerPy_methods, /* tp_methods */
548         0, /* tp_members */
549         eTimerPy_getseters, /* tp_getset */
550         0, /* tp_base */
551         0, /* tp_dict */
552         0, /* tp_descr_get */
553         0, /* tp_descr_set */
554         0, /* tp_dictoffset */
555         0, /* tp_init */
556         0, /* tp_alloc */
557         eTimerPy_new, /* tp_new */
558 };
559
560 // eSocketNotifier replacement
561
562 struct eSocketNotifierPy
563 {
564         PyObject_HEAD
565         eSocketNotifier *sn;
566         PyObject *in_weakreflist; /* List of weak references */
567 };
568
569 static int
570 eSocketNotifierPy_traverse(eSocketNotifierPy *self, visitproc visit, void *arg)
571 {
572         PyObject *obj = self->sn->activated.get();
573         Py_VISIT(obj);
574         return 0;
575 }
576
577 static int
578 eSocketNotifierPy_clear(eSocketNotifierPy *self)
579 {
580         PyObject *obj = self->sn->activated.get();
581         Py_CLEAR(obj);
582         return 0;
583 }
584
585 static void
586 eSocketNotifierPy_dealloc(eSocketNotifierPy* self)
587 {
588         if (self->in_weakreflist != NULL)
589                 PyObject_ClearWeakRefs((PyObject *) self);
590         eSocketNotifierPy_clear(self);
591         delete self->sn;
592         self->ob_type->tp_free((PyObject*)self);
593 }
594
595 static PyObject *
596 eSocketNotifierPy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
597 {
598         eSocketNotifierPy *self = (eSocketNotifierPy *)type->tp_alloc(type, 0);
599         int fd, req, immediate_start = 1, size = PyTuple_Size(args);
600         if (size > 2)
601         {
602                 if (!PyArg_ParseTuple(args, "iii", &fd, &req, &immediate_start))
603                 {
604                         PyObject *obj = NULL;
605                         if (!PyArg_ParseTuple(args, "iiO", &fd, &req, &immediate_start))
606                                 return NULL;
607                         if (obj == Py_False)
608                                 immediate_start = 0;
609                         else if (obj != Py_True)
610                                 return NULL;
611                 }
612         }
613         else if (size < 2 || !PyArg_ParseTuple(args, "ii", &fd, &req))
614                 return NULL;
615         self->sn = new eSocketNotifier(eApp, fd, req, immediate_start);
616         self->in_weakreflist = NULL;
617         return (PyObject *)self;
618 }
619
620 static PyObject *
621 eSocketNotifierPy_is_running(eSocketNotifierPy* self)
622 {
623         PyObject *ret = self->sn->isRunning() ? Py_True : Py_False;
624         Org_Py_INCREF(ret);
625         return ret;
626 }
627
628 static PyObject *
629 eSocketNotifierPy_start(eSocketNotifierPy* self)
630 {
631         self->sn->start();
632         Py_RETURN_NONE;
633 }
634
635 static PyObject *
636 eSocketNotifierPy_stop(eSocketNotifierPy* self)
637 {
638         self->sn->stop();
639         Py_RETURN_NONE;
640 }
641
642 static PyObject *
643 eSocketNotifierPy_get_fd(eSocketNotifierPy* self)
644 {
645         return PyInt_FromLong(self->sn->getFD());
646 }
647
648 static PyObject *
649 eSocketNotifierPy_get_requested(eSocketNotifierPy* self)
650 {
651         return PyInt_FromLong(self->sn->getRequested());
652 }
653
654 static PyObject *
655 eSocketNotifierPy_set_requested(eSocketNotifierPy* self, PyObject *args)
656 {
657         int req;
658         if (PyTuple_Size(args) != 1 || !PyArg_ParseTuple(args, "i", &req))
659                 return NULL;
660         self->sn->setRequested(req);
661         Py_RETURN_NONE;
662 }
663
664 static PyMethodDef eSocketNotifierPy_methods[] = {
665         {"isRunning", (PyCFunction)eSocketNotifierPy_is_running, METH_NOARGS,
666          "returns the running state"
667         },
668         {"start", (PyCFunction)eSocketNotifierPy_start, METH_NOARGS,
669          "start the sn"
670         },
671         {"stop", (PyCFunction)eSocketNotifierPy_stop, METH_NOARGS,
672          "stops the sn"
673         },
674         {"getFD", (PyCFunction)eSocketNotifierPy_get_fd, METH_NOARGS,
675          "get file descriptor"
676         },
677         {"getRequested", (PyCFunction)eSocketNotifierPy_get_requested, METH_NOARGS,
678          "get requested"
679         },
680         {"setRequested", (PyCFunction)eSocketNotifierPy_set_requested, METH_VARARGS,
681          "set requested"
682         },
683         {NULL}  /* Sentinel */
684 };
685
686 static PyObject *
687 eSocketNotifierPy_get_cb_list(eSocketNotifierPy *self, void *closure)
688 {
689         return self->sn->activated.get();
690 }
691
692 static PyGetSetDef eSocketNotifierPy_getseters[] = {
693         {"callback",
694          (getter)eSocketNotifierPy_get_cb_list, (setter)0,
695          "returns the callback python list",
696          NULL},
697         {NULL} /* Sentinel */
698 };
699
700 static PyTypeObject eSocketNotifierPyType = {
701         PyObject_HEAD_INIT(NULL)
702         0, /*ob_size*/
703         "eBaseImpl.eSocketNotifier", /*tp_name*/
704         sizeof(eSocketNotifierPy), /*tp_basicsize*/
705         0, /*tp_itemsize*/
706         (destructor)eSocketNotifierPy_dealloc, /*tp_dealloc*/
707         0, /*tp_print*/
708         0, /*tp_getattr*/
709         0, /*tp_setattr*/
710         0, /*tp_compare*/
711         0, /*tp_repr*/
712         0, /*tp_as_number*/
713         0, /*tp_as_sequence*/
714         0, /*tp_as_mapping*/
715         0, /*tp_hash */
716         0, /*tp_call*/
717         0, /*tp_str*/
718         0, /*tp_getattro*/
719         0, /*tp_setattro*/
720         0, /*tp_as_buffer*/
721         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
722         "eTimer objects", /* tp_doc */
723         (traverseproc)eSocketNotifierPy_traverse, /* tp_traverse */
724         (inquiry)eSocketNotifierPy_clear, /* tp_clear */
725         0, /* tp_richcompare */
726         offsetof(eSocketNotifierPy, in_weakreflist), /* tp_weaklistoffset */
727         0, /* tp_iter */
728         0, /* tp_iternext */
729         eSocketNotifierPy_methods, /* tp_methods */
730         0, /* tp_members */
731         eSocketNotifierPy_getseters, /* tp_getset */
732         0, /* tp_base */
733         0, /* tp_dict */
734         0, /* tp_descr_get */
735         0, /* tp_descr_set */
736         0, /* tp_dictoffset */
737         0, /* tp_init */
738         0, /* tp_alloc */
739         eSocketNotifierPy_new, /* tp_new */
740 };
741
742 static PyMethodDef module_methods[] = {
743         {NULL}  /* Sentinel */
744 };
745
746 void eBaseInit(void)
747 {
748         PyObject* m;
749
750         m = Py_InitModule3("eBaseImpl", module_methods,
751                 "Module that implements some enigma classes with working cyclic garbage collection.");
752
753         if (m == NULL)
754                 return;
755
756         if (!PyType_Ready(&eTimerPyType))
757         {
758                 Org_Py_INCREF((PyObject*)&eTimerPyType);
759                 PyModule_AddObject(m, "eTimer", (PyObject*)&eTimerPyType);
760         }
761         if (!PyType_Ready(&eSocketNotifierPyType))
762         {
763                 Org_Py_INCREF((PyObject*)&eSocketNotifierPyType);
764                 PyModule_AddObject(m, "eSocketNotifier", (PyObject*)&eSocketNotifierPyType);
765         }
766 }
767 }