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