Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: MIT |
1e920353 PP |
2 | # |
3 | # Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com> | |
1e920353 PP |
4 | |
5 | from bt2 import native_bt, object | |
786c8e14 | 6 | import bt2 |
1e920353 PP |
7 | |
8 | ||
9 | class Interrupter(object._SharedObject): | |
10 | _get_ref = staticmethod(native_bt.interrupter_get_ref) | |
11 | _put_ref = staticmethod(native_bt.interrupter_put_ref) | |
12 | ||
13 | def __init__(self): | |
14 | ptr = native_bt.interrupter_create() | |
15 | ||
16 | if ptr is None: | |
564f3258 | 17 | raise bt2._MemoryError('cannot create interrupter object') |
1e920353 PP |
18 | |
19 | super().__init__(ptr) | |
20 | ||
21 | @property | |
22 | def is_set(self): | |
23 | return bool(native_bt.interrupter_is_set(self._ptr)) | |
24 | ||
25 | def __bool__(self): | |
26 | return self.is_set | |
27 | ||
28 | def set(self): | |
29 | native_bt.interrupter_set(self._ptr) | |
30 | ||
31 | def reset(self): | |
32 | native_bt.interrupter_reset(self._ptr) |