diff options
Diffstat (limited to 'cython/heartbeat.pxi')
| -rw-r--r-- | cython/heartbeat.pxi | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/cython/heartbeat.pxi b/cython/heartbeat.pxi new file mode 100644 index 0000000..2f58909 --- /dev/null +++ b/cython/heartbeat.pxi | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | cdef 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_NOT_ENOUGH_DATA = -5 | ||
| 13 | HEARTBEAT_E_TIMEOUT = -6 | ||
| 14 | HEARTBEAT_E_UNKNOWN_ERROR = -256 | ||
| 15 | |||
| 16 | heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, heartbeat_client_t * client) | ||
| 17 | heartbeat_error_t heartbeat_client_free(heartbeat_client_t client) | ||
| 18 | |||
| 19 | heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist.plist_t plist) | ||
| 20 | heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist.plist_t * plist) | ||
| 21 | heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist.plist_t * plist, uint32_t timeout_ms) | ||
| 22 | |||
| 23 | cdef class HeartbeatError(BaseError): | ||
| 24 | def __init__(self, *args, **kwargs): | ||
| 25 | self._lookup_table = { | ||
| 26 | HEARTBEAT_E_SUCCESS: "Success", | ||
| 27 | HEARTBEAT_E_INVALID_ARG: "Invalid argument", | ||
| 28 | HEARTBEAT_E_PLIST_ERROR: "Property list error", | ||
| 29 | HEARTBEAT_E_MUX_ERROR: "MUX error", | ||
| 30 | HEARTBEAT_E_SSL_ERROR: "SSL Error", | ||
| 31 | HEARTBEAT_E_NOT_ENOUGH_DATA: 'Not enough data', | ||
| 32 | HEARTBEAT_E_TIMEOUT: 'Connection timeout', | ||
| 33 | HEARTBEAT_E_UNKNOWN_ERROR: "Unknown error" | ||
| 34 | } | ||
| 35 | BaseError.__init__(self, *args, **kwargs) | ||
| 36 | |||
| 37 | cdef class HeartbeatClient(PropertyListService): | ||
| 38 | __service_name__ = "com.apple.heartbeat" | ||
| 39 | cdef heartbeat_client_t _c_client | ||
| 40 | |||
| 41 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
| 42 | self.handle_error(heartbeat_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
| 43 | |||
| 44 | def __dealloc__(self): | ||
| 45 | cdef heartbeat_error_t err | ||
| 46 | if self._c_client is not NULL: | ||
| 47 | err = heartbeat_client_free(self._c_client) | ||
| 48 | self.handle_error(err) | ||
| 49 | |||
| 50 | cdef inline int16_t _send(self, plist.plist_t node): | ||
| 51 | return heartbeat_send(self._c_client, node) | ||
| 52 | |||
| 53 | cdef inline int16_t _receive(self, plist.plist_t* node): | ||
| 54 | return heartbeat_receive(self._c_client, node) | ||
| 55 | |||
| 56 | cdef inline int16_t _receive_with_timeout(self, plist.plist_t* node, int timeout_ms): | ||
| 57 | return heartbeat_receive_with_timeout(self._c_client, node, timeout_ms) | ||
| 58 | |||
| 59 | cdef inline BaseError _error(self, int16_t ret): | ||
| 60 | return HeartbeatError(ret) | ||
