diff options
| author | 2013-02-27 15:14:01 +0100 | |
|---|---|---|
| committer | 2013-02-27 15:14:01 +0100 | |
| commit | c19978863878a014b5aa2538989b41b864708866 (patch) | |
| tree | 73d40d6cbda5250972239c96b418edeb6fbbbf52 /cython/diagnostics_relay.pxi | |
| parent | 0cac547eb79492e04176ad541fe6fb1d1f576824 (diff) | |
| download | libimobiledevice-c19978863878a014b5aa2538989b41b864708866.tar.gz libimobiledevice-c19978863878a014b5aa2538989b41b864708866.tar.bz2 | |
cython: Add all service protocols which brings Python bindings to 100% coverage
Diffstat (limited to 'cython/diagnostics_relay.pxi')
| -rw-r--r-- | cython/diagnostics_relay.pxi | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/cython/diagnostics_relay.pxi b/cython/diagnostics_relay.pxi new file mode 100644 index 0000000..155e5b7 --- /dev/null +++ b/cython/diagnostics_relay.pxi | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | REQUEST_TYPE_ALL = "All" | ||
| 2 | REQUEST_TYPE_WIFI = "WiFi" | ||
| 3 | REQUEST_TYPE_GAS_GAUGE = "GasGauge" | ||
| 4 | REQUEST_TYPE_NAND = "NAND" | ||
| 5 | |||
| 6 | cdef extern from "libimobiledevice/diagnostics_relay.h": | ||
| 7 | cdef struct diagnostics_relay_client_private: | ||
| 8 | pass | ||
| 9 | ctypedef diagnostics_relay_client_private *diagnostics_relay_client_t | ||
| 10 | |||
| 11 | ctypedef enum diagnostics_relay_error_t: | ||
| 12 | DIAGNOSTICS_RELAY_E_SUCCESS = 0 | ||
| 13 | DIAGNOSTICS_RELAY_E_INVALID_ARG = -1 | ||
| 14 | DIAGNOSTICS_RELAY_E_PLIST_ERROR = -2 | ||
| 15 | DIAGNOSTICS_RELAY_E_MUX_ERROR = -3 | ||
| 16 | DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST = -4 | ||
| 17 | DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR = -256 | ||
| 18 | cdef enum: | ||
| 19 | DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT = (1 << 1) | ||
| 20 | DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS = (1 << 2) | ||
| 21 | DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL = (1 << 3) | ||
| 22 | |||
| 23 | diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, diagnostics_relay_client_t * client) | ||
| 24 | diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client) | ||
| 25 | |||
| 26 | diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client) | ||
| 27 | diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client) | ||
| 28 | diagnostics_relay_error_t diagnostics_relay_restart(diagnostics_relay_client_t client, int flags) | ||
| 29 | diagnostics_relay_error_t diagnostics_relay_shutdown(diagnostics_relay_client_t client, int flags) | ||
| 30 | diagnostics_relay_error_t diagnostics_relay_request_diagnostics(diagnostics_relay_client_t client, char* type, plist.plist_t* diagnostics) | ||
| 31 | diagnostics_relay_error_t diagnostics_relay_query_mobilegestalt(diagnostics_relay_client_t client, plist.plist_t keys, plist.plist_t* result) | ||
| 32 | diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, char* name, char* class_name, plist.plist_t* result) | ||
| 33 | diagnostics_relay_error_t diagnostics_relay_query_ioregistry_plane(diagnostics_relay_client_t client, char* plane, plist.plist_t* result) | ||
| 34 | |||
| 35 | cdef class DiagnosticsRelayError(BaseError): | ||
| 36 | def __init__(self, *args, **kwargs): | ||
| 37 | self._lookup_table = { | ||
| 38 | DIAGNOSTICS_RELAY_E_SUCCESS: "Success", | ||
| 39 | DIAGNOSTICS_RELAY_E_INVALID_ARG: "Invalid argument", | ||
| 40 | DIAGNOSTICS_RELAY_E_PLIST_ERROR: "Property list error", | ||
| 41 | DIAGNOSTICS_RELAY_E_MUX_ERROR: "MUX error", | ||
| 42 | DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST: "Unknown request", | ||
| 43 | DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR: "Unknown error" | ||
| 44 | } | ||
| 45 | BaseError.__init__(self, *args, **kwargs) | ||
| 46 | |||
| 47 | cdef class DiagnosticsRelayClient(PropertyListService): | ||
| 48 | __service_name__ = "com.apple.mobile.diagnostics_relay" | ||
| 49 | cdef diagnostics_relay_client_t _c_client | ||
| 50 | |||
| 51 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
| 52 | self.handle_error(diagnostics_relay_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
| 53 | |||
| 54 | def __dealloc__(self): | ||
| 55 | cdef diagnostics_relay_error_t err | ||
| 56 | if self._c_client is not NULL: | ||
| 57 | err = diagnostics_relay_client_free(self._c_client) | ||
| 58 | self.handle_error(err) | ||
| 59 | |||
| 60 | cdef inline BaseError _error(self, int16_t ret): | ||
| 61 | return DiagnosticsRelayError(ret) | ||
| 62 | |||
| 63 | cpdef goodbye(self): | ||
| 64 | self.handle_error(diagnostics_relay_goodbye(self._c_client)) | ||
| 65 | |||
| 66 | cpdef sleep(self): | ||
| 67 | self.handle_error(diagnostics_relay_sleep(self._c_client)) | ||
| 68 | |||
| 69 | cpdef restart(self, int flags): | ||
| 70 | self.handle_error(diagnostics_relay_restart(self._c_client, flags)) | ||
| 71 | |||
| 72 | cpdef shutdown(self, int flags): | ||
| 73 | self.handle_error(diagnostics_relay_shutdown(self._c_client, flags)) | ||
| 74 | |||
| 75 | cpdef plist.Node request_diagnostics(self, bytes type): | ||
| 76 | cdef: | ||
| 77 | plist.plist_t c_node = NULL | ||
| 78 | diagnostics_relay_error_t err | ||
| 79 | err = diagnostics_relay_request_diagnostics(self._c_client, type, &c_node) | ||
| 80 | try: | ||
| 81 | self.handle_error(err) | ||
| 82 | return plist.plist_t_to_node(c_node) | ||
| 83 | except BaseError, e: | ||
| 84 | if c_node != NULL: | ||
| 85 | plist.plist_free(c_node) | ||
| 86 | raise | ||
| 87 | |||
| 88 | cpdef plist.Node query_mobilegestalt(self, plist.Node keys = None): | ||
| 89 | cdef: | ||
| 90 | plist.plist_t c_node = NULL | ||
| 91 | diagnostics_relay_error_t err | ||
| 92 | plist.plist_t keys_c_node = NULL | ||
| 93 | if keys is not None: | ||
| 94 | keys_c_node = keys._c_node | ||
| 95 | err = diagnostics_relay_query_mobilegestalt(self._c_client, keys_c_node, &c_node) | ||
| 96 | try: | ||
| 97 | self.handle_error(err) | ||
| 98 | return plist.plist_t_to_node(c_node) | ||
| 99 | except BaseError, e: | ||
| 100 | if c_node != NULL: | ||
| 101 | plist.plist_free(c_node) | ||
| 102 | raise | ||
| 103 | |||
| 104 | cpdef plist.Node query_ioregistry_entry(self, bytes name, bytes class_name): | ||
| 105 | cdef: | ||
| 106 | plist.plist_t c_node = NULL | ||
| 107 | diagnostics_relay_error_t err | ||
| 108 | err = diagnostics_relay_query_ioregistry_entry(self._c_client, name, class_name, &c_node) | ||
| 109 | try: | ||
| 110 | self.handle_error(err) | ||
| 111 | return plist.plist_t_to_node(c_node) | ||
| 112 | except BaseError, e: | ||
| 113 | if c_node != NULL: | ||
| 114 | plist.plist_free(c_node) | ||
| 115 | raise | ||
| 116 | |||
| 117 | cpdef plist.Node query_ioregistry_plane(self, bytes plane = None): | ||
| 118 | cdef: | ||
| 119 | plist.plist_t c_node = NULL | ||
| 120 | diagnostics_relay_error_t err | ||
| 121 | err = diagnostics_relay_query_ioregistry_plane(self._c_client, plane, &c_node) | ||
| 122 | try: | ||
| 123 | self.handle_error(err) | ||
| 124 | return plist.plist_t_to_node(c_node) | ||
| 125 | except BaseError, e: | ||
| 126 | if c_node != NULL: | ||
| 127 | plist.plist_free(c_node) | ||
| 128 | raise | ||
