Commit | Line | Data |
---|---|---|
5b1830f3 MW |
1 | ### -*-pyrex-*- |
2 | ### | |
3 | ### In-band signals | |
4 | ### | |
5 | ### (c) 2005 Straylight/Edgeware | |
6 | ### | |
579d0169 | 7 | |
5b1830f3 MW |
8 | ###----- Licensing notice --------------------------------------------------- |
9 | ### | |
10 | ### This file is part of the Python interface to mLib. | |
11 | ### | |
12 | ### mLib/Python is free software; you can redistribute it and/or modify | |
13 | ### it under the terms of the GNU General Public License as published by | |
14 | ### the Free Software Foundation; either version 2 of the License, or | |
15 | ### (at your option) any later version. | |
16 | ### | |
17 | ### mLib/Python is distributed in the hope that it will be useful, | |
18 | ### but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ### GNU General Public License for more details. | |
21 | ### | |
22 | ### You should have received a copy of the GNU General Public License | |
23 | ### along with mLib/Python; if not, write to the Free Software Foundation, | |
24 | ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
579d0169 | 25 | |
26 | import signal | |
27 | ||
28 | cdef class SelSignal: | |
29 | cdef sig s | |
30 | cdef int _activep | |
31 | cdef readonly int signal | |
32 | cdef _signalled | |
376ad06d | 33 | def __cinit__(me, int sig, signalledproc = None, *hunoz, **hukairz): |
579d0169 | 34 | if sig < 0 or sig >= signal.NSIG: |
35 | raise ValueError, 'signal number out of range' | |
36 | me.signal = sig | |
bd3ac9d3 | 37 | me._signalled = _checkcallable(signalledproc, 'signalled proc') |
579d0169 | 38 | me._activep = 0 |
39 | def __dealloc__(me): | |
40 | if me._activep: | |
41 | sig_remove(&me.s) | |
42 | property activep: | |
43 | def __get__(me): | |
44 | return _tobool(me._activep) | |
45 | property signalledproc: | |
46 | def __get__(me): | |
47 | return me._signalled | |
48 | def __set__(me, proc): | |
49 | me._signalled = _checkcallable(proc, 'signalled proc') | |
50 | def __del__(me): | |
51 | me._signalled = None | |
52 | def enable(me): | |
53 | if me._activep: | |
54 | raise ValueError, 'already enabled' | |
55 | sig_add(&me.s, me.signal, _sigfunc, <void *>me) | |
56 | me._enabled() | |
57 | return me | |
58 | def disable(me): | |
59 | if not me._activep: | |
60 | raise ValueError, 'already disabled' | |
61 | sig_remove(&me.s) | |
62 | me._disabled() | |
63 | return me | |
64 | cdef _enabled(me): | |
65 | me._activep = 1 | |
66 | me.enabled() | |
67 | cdef _disabled(me): | |
68 | me._activep = 0 | |
69 | me.disabled() | |
70 | def enabled(me): | |
71 | pass | |
72 | def disabled(me): | |
73 | pass | |
74 | def signalled(me): | |
75 | return _maybecall(me._signalled, ()) | |
76 | ||
b51b6cf0 | 77 | cdef void _sigfunc(int sig, void *arg): |
579d0169 | 78 | cdef SelSignal s |
79 | s = <SelSignal>arg | |
80 | s.signalled() | |
81 | ||
82 | sig_init(&_sel) | |
83 | ||
5b1830f3 | 84 | ###----- That's all, folks -------------------------------------------------- |