summaryrefslogtreecommitdiff
path: root/efl/ecore
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2013-05-13 01:27:00 +0200
committerdavemds <dave@gurumeditation.it>2013-05-13 01:27:00 +0200
commit1c255024d3bcf0f95cf93c067c976f9139d11ef9 (patch)
tree515877b44a5bc3d3ccb73580ca79adf43fcc7497 /efl/ecore
parentfcac9e23ada2ec8551c32d70addd4863c4f9be63 (diff)
Python-EFL: implemented ecore.Poller, with docs and unittest.
Diffstat (limited to 'efl/ecore')
-rw-r--r--efl/ecore/efl.ecore.pyx4
-rw-r--r--efl/ecore/efl.ecore_poller.pxi112
2 files changed, 116 insertions, 0 deletions
diff --git a/efl/ecore/efl.ecore.pyx b/efl/ecore/efl.ecore.pyx
index fb40296..7cb2985 100644
--- a/efl/ecore/efl.ecore.pyx
+++ b/efl/ecore/efl.ecore.pyx
@@ -242,6 +242,9 @@ ECORE_FILE_EVENT_DELETED_SELF = enums.ECORE_FILE_EVENT_DELETED_SELF
242ECORE_FILE_EVENT_MODIFIED = enums.ECORE_FILE_EVENT_MODIFIED 242ECORE_FILE_EVENT_MODIFIED = enums.ECORE_FILE_EVENT_MODIFIED
243ECORE_FILE_EVENT_CLOSED = enums.ECORE_FILE_EVENT_CLOSED 243ECORE_FILE_EVENT_CLOSED = enums.ECORE_FILE_EVENT_CLOSED
244 244
245# Ecore_Poller_Type:
246ECORE_POLLER_CORE = enums.ECORE_POLLER_CORE
247
245 248
246cdef Eina_Bool _ecore_task_cb(void *data) with gil: 249cdef Eina_Bool _ecore_task_cb(void *data) with gil:
247 cdef Eo obj = <Eo>data 250 cdef Eo obj = <Eo>data
@@ -323,6 +326,7 @@ def loop_time_get():
323 326
324include "efl.ecore_animator.pxi" 327include "efl.ecore_animator.pxi"
325include "efl.ecore_timer.pxi" 328include "efl.ecore_timer.pxi"
329include "efl.ecore_poller.pxi"
326include "efl.ecore_idler.pxi" 330include "efl.ecore_idler.pxi"
327include "efl.ecore_fd_handler.pxi" 331include "efl.ecore_fd_handler.pxi"
328include "efl.ecore_events.pxi" 332include "efl.ecore_events.pxi"
diff --git a/efl/ecore/efl.ecore_poller.pxi b/efl/ecore/efl.ecore_poller.pxi
new file mode 100644
index 0000000..2d7713b
--- /dev/null
+++ b/efl/ecore/efl.ecore_poller.pxi
@@ -0,0 +1,112 @@
1# Copyright (C) 2007-2013 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18
19cdef class Poller(Eo):
20 """
21
22 Ecore poller provides infrastructure for the creation of pollers. Pollers
23 are, in essence, callbacks that share a single timer per type. Because not
24 all pollers need to be called at the same frequency the user may specify the
25 frequency in ticks(each expiration of the shared timer is called a tick, in
26 ecore poller parlance) for each added poller. Ecore pollers should only be
27 used when the poller doesn't have specific requirements on the exact times
28 to poll.
29
30 This architecture means that the main loop is only woken up once to handle
31 all pollers of that type, this will save power as the CPU has more of a
32 chance to go into a low power state the longer it is asleep for, so this
33 should be used in situations where power usage is a concern.
34
35 For now only 1 core poller type is supported: ECORE_POLLER_CORE, the default
36 interval for ECORE_POLLER_CORE is 0.125(or 1/8th) second.
37
38 The `interval` must be between 1 and 32768 inclusive, and must be a power of
39 2 (i.e. 1, 2, 4, 8, 16, ... 16384, 32768). The exact tick in which `func`
40 will be called is undefined, as only the interval between calls can be
41 defined. Ecore will endeavor to keep pollers synchronized and to call as
42 many in 1 wakeup event as possible. If `interval` is not a power of two, the
43 closest power of 2 greater than `interval` will be used.
44
45 When the poller `func` is called, it must return a value of either
46 ECORE_CALLBACK_RENEW(or True) or ECORE_CALLBACK_CANCEL(or False). If it
47 returns 1, it will be called again at the next tick, or if it returns
48 0 it will be deleted automatically making any references/handles for it
49 invalid.
50
51 Example::
52
53 def poller_cb():
54 print("Poller")
55 return True
56
57 ecore.Poller(4, poller_cb)
58
59 :param interval: The poll interval
60 :type interval: int
61 :param func: The cunction to call at every intervat
62 :type func: callable
63 :param poll_type: The ticker type to attach the poller to. Must be ECORE_POLLER_CORE
64 :type poll_type: Ecore_Poll_Type
65
66 """
67 def __init__(self, int interval, func, pol_type=0, *args, **kargs):
68 if not callable(func):
69 raise TypeError("Parameter 'func' must be callable")
70 self.func = func
71 self.args = args
72 self.kargs = kargs
73 self._set_obj(ecore_poller_add(pol_type, interval, _ecore_task_cb, <void *>self))
74
75 def __str__(self):
76 return "%s Poller(func=%s, args=%s, kargs=%s)" % (Eo.__str__(self),
77 self.func, self.args, self.kargs)
78
79 def __repr__(self):
80 return "%s Poller(interval=%d, func=%s, args=%s, kargs=%s)" % (Eo.__repr__(self),
81 self.interval if self.obj else -1,
82 self.func, self.args, self.kargs)
83
84 cpdef bint _task_exec(self):
85 return self.func(*self.args, **self.kargs)
86
87 def delete(self):
88 """ Stop callback emission and free internal resources. """
89 ecore_poller_del(self.obj)
90
91
92 property interval:
93 """ The interval (in ticks) between each call of the poller
94
95 :type: int
96
97 """
98 def __get__(self):
99 return ecore_poller_poller_interval_get(self.obj)
100
101 def __set__(self, int t):
102 ecore_poller_poller_interval_set(self.obj, t)
103
104 def interval_set(self, int t):
105 ecore_poller_poller_interval_set(self.obj, t)
106 def interval_get(self):
107 return ecore_poller_poller_interval_get(self.obj)
108
109
110def poller_add(int t, func, *args, **kargs):
111 return Poller(t, func, *args, **kargs)
112