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