summaryrefslogtreecommitdiffstats
path: root/cython/heartbeat.pxi
diff options
context:
space:
mode:
Diffstat (limited to 'cython/heartbeat.pxi')
-rw-r--r--cython/heartbeat.pxi56
1 files changed, 56 insertions, 0 deletions
diff --git a/cython/heartbeat.pxi b/cython/heartbeat.pxi
new file mode 100644
index 0000000..b48fb59
--- /dev/null
+++ b/cython/heartbeat.pxi
@@ -0,0 +1,56 @@
1cdef extern from "libimobiledevice/heartbeat.h":
2 cdef struct heartbeat_client_private:
3 pass
4 ctypedef heartbeat_client_private *heartbeat_client_t
5
6 ctypedef enum heartbeat_error_t:
7 HEARTBEAT_E_SUCCESS = 0
8 HEARTBEAT_E_INVALID_ARG = -1
9 HEARTBEAT_E_PLIST_ERROR = -2
10 HEARTBEAT_E_MUX_ERROR = -3
11 HEARTBEAT_E_SSL_ERROR = -4
12 HEARTBEAT_E_UNKNOWN_ERROR = -256
13
14 heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, heartbeat_client_t * client)
15 heartbeat_error_t heartbeat_client_free(heartbeat_client_t client)
16
17 heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist.plist_t plist)
18 heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist.plist_t * plist)
19 heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist.plist_t * plist, uint32_t timeout_ms)
20
21cdef class HeartbeatError(BaseError):
22 def __init__(self, *args, **kwargs):
23 self._lookup_table = {
24 HEARTBEAT_E_SUCCESS: "Success",
25 HEARTBEAT_E_INVALID_ARG: "Invalid argument",
26 HEARTBEAT_E_PLIST_ERROR: "Property list error",
27 HEARTBEAT_E_MUX_ERROR: "MUX error",
28 HEARTBEAT_E_SSL_ERROR: "SSL Error",
29 HEARTBEAT_E_UNKNOWN_ERROR: "Unknown error"
30 }
31 BaseError.__init__(self, *args, **kwargs)
32
33cdef class HeartbeatClient(PropertyListService):
34 __service_name__ = "com.apple.heartbeat"
35 cdef heartbeat_client_t _c_client
36
37 def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs):
38 self.handle_error(heartbeat_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client))
39
40 def __dealloc__(self):
41 cdef heartbeat_error_t err
42 if self._c_client is not NULL:
43 err = heartbeat_client_free(self._c_client)
44 self.handle_error(err)
45
46 cdef inline int16_t _send(self, plist.plist_t node):
47 return heartbeat_send(self._c_client, node)
48
49 cdef inline int16_t _receive(self, plist.plist_t* node):
50 return heartbeat_receive(self._c_client, node)
51
52 cdef inline int16_t _receive_with_timeout(self, plist.plist_t* node, int timeout_ms):
53 return heartbeat_receive_with_timeout(self._c_client, node, timeout_ms)
54
55 cdef inline BaseError _error(self, int16_t ret):
56 return HeartbeatError(ret)