diff options
Diffstat (limited to 'cython')
| -rw-r--r-- | cython/imobiledevice.pyx | 94 | ||||
| -rw-r--r-- | cython/stdint.pxi | 10 |
2 files changed, 66 insertions, 38 deletions
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index 7190def..befd586 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx | |||
| @@ -18,20 +18,23 @@ cdef extern from "pyerrors.h": | |||
| 18 | cdef class BaseError(Exception): | 18 | cdef class BaseError(Exception): |
| 19 | cdef dict _lookup_table | 19 | cdef dict _lookup_table |
| 20 | cdef int16_t _c_errcode | 20 | cdef int16_t _c_errcode |
| 21 | cpdef get_message(self) | ||
| 22 | 21 | ||
| 23 | def __cinit__(self, int16_t errcode): | 22 | def __cinit__(self, int16_t errcode): |
| 24 | self._c_errcode = errcode | 23 | self._c_errcode = errcode |
| 25 | Exception.__init__(self, errcode) | 24 | |
| 26 | |||
| 27 | def __nonzero__(self): | 25 | def __nonzero__(self): |
| 28 | return self._c_errcode != 0 | 26 | return self._c_errcode != 0 |
| 29 | 27 | ||
| 30 | cpdef get_message(self): | 28 | property message: |
| 31 | return '%s (%s)' % (self._lookup_table[self._c_errcode], self._c_errcode) | 29 | def __get__(self): |
| 30 | return self._lookup_table[self._c_errcode] | ||
| 31 | |||
| 32 | property code: | ||
| 33 | def __get__(self): | ||
| 34 | return self._c_errcode | ||
| 32 | 35 | ||
| 33 | def __str__(self): | 36 | def __str__(self): |
| 34 | return self.get_message() | 37 | return '%s (%s)' % (self.message, self.code) |
| 35 | 38 | ||
| 36 | def __repr__(self): | 39 | def __repr__(self): |
| 37 | return self.__str__() | 40 | return self.__str__() |
| @@ -55,26 +58,18 @@ cdef extern from "libimobiledevice/libimobiledevice.h": | |||
| 55 | idevice_event_type event | 58 | idevice_event_type event |
| 56 | char *uuid | 59 | char *uuid |
| 57 | int conn_type | 60 | int conn_type |
| 58 | ctypedef void (*idevice_event_cb_t) (idevice_event_t *event, void *user_data) | 61 | ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*" |
| 59 | cdef extern idevice_error_t c_idevice_event_subscribe "idevice_event_subscribe" (idevice_event_cb_t callback, void *user_data) | 62 | ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) |
| 60 | cdef extern idevice_error_t c_idevice_event_unsubscribe "idevice_event_unsubscribe" () | 63 | cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) |
| 64 | cdef extern idevice_error_t idevice_event_unsubscribe() | ||
| 65 | idevice_error_t idevice_get_device_list(char ***devices, int *count) | ||
| 66 | idevice_error_t idevice_device_list_free(char **devices) | ||
| 61 | void idevice_set_debug_level(int level) | 67 | void idevice_set_debug_level(int level) |
| 62 | idevice_error_t idevice_new(idevice_t *device, char *uuid) | 68 | idevice_error_t idevice_new(idevice_t *device, char *uuid) |
| 63 | idevice_error_t idevice_free(idevice_t device) | 69 | idevice_error_t idevice_free(idevice_t device) |
| 64 | idevice_error_t idevice_get_uuid(idevice_t device, char** uuid) | 70 | idevice_error_t idevice_get_uuid(idevice_t device, char** uuid) |
| 65 | idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) | 71 | idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) |
| 66 | 72 | ||
| 67 | def set_debug_level(level): | ||
| 68 | idevice_set_debug_level(level) | ||
| 69 | |||
| 70 | #cdef void idevice_event_cb(idevice_event_t *c_event, void *user_data): | ||
| 71 | #event = iDeviceEvent() | ||
| 72 | #event._c_event = c_event | ||
| 73 | #(<object>user_data)(event) | ||
| 74 | |||
| 75 | #def idevice_event_subscribe(callback): | ||
| 76 | #c_idevice_event_subscribe(idevice_event_cb, <void*>callback) | ||
| 77 | |||
| 78 | cdef class iDeviceError(BaseError): | 73 | cdef class iDeviceError(BaseError): |
| 79 | def __cinit__(self, *args, **kwargs): | 74 | def __cinit__(self, *args, **kwargs): |
| 80 | self._lookup_table = { | 75 | self._lookup_table = { |
| @@ -88,8 +83,39 @@ cdef class iDeviceError(BaseError): | |||
| 88 | } | 83 | } |
| 89 | BaseError.__init__(self, *args, **kwargs) | 84 | BaseError.__init__(self, *args, **kwargs) |
| 90 | 85 | ||
| 86 | def set_debug_level(level): | ||
| 87 | idevice_set_debug_level(level) | ||
| 88 | |||
| 91 | cdef class iDeviceEvent: | 89 | cdef class iDeviceEvent: |
| 92 | cdef idevice_event_t* _c_event | 90 | cdef const_idevice_event_t _c_event |
| 91 | |||
| 92 | cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): | ||
| 93 | cdef iDeviceEvent event = iDeviceEvent() | ||
| 94 | event._c_event = c_event | ||
| 95 | (<object>user_data)(event) | ||
| 96 | |||
| 97 | def event_subscribe(callback): | ||
| 98 | cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) | ||
| 99 | if err: raise err | ||
| 100 | |||
| 101 | def event_unsubscribe(): | ||
| 102 | cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) | ||
| 103 | if err: raise err | ||
| 104 | |||
| 105 | def get_device_list(): | ||
| 106 | cdef char** devices | ||
| 107 | cdef int count | ||
| 108 | cdef list result | ||
| 109 | cdef bytes device | ||
| 110 | cdef iDeviceError err = iDeviceError(idevice_get_device_list(&devices, &count)) | ||
| 111 | |||
| 112 | result = [] | ||
| 113 | for i from 0 <= i < count: | ||
| 114 | device = devices[i] | ||
| 115 | result.append(device) | ||
| 116 | |||
| 117 | idevice_device_list_free(devices) | ||
| 118 | return result | ||
| 93 | 119 | ||
| 94 | cdef class iDevice: | 120 | cdef class iDevice: |
| 95 | cdef idevice_t _c_dev | 121 | cdef idevice_t _c_dev |
| @@ -188,7 +214,7 @@ cdef class LockdownClient: | |||
| 188 | err = LockdownError(lockdownd_client_free(self._c_client)) | 214 | err = LockdownError(lockdownd_client_free(self._c_client)) |
| 189 | if err: raise err | 215 | if err: raise err |
| 190 | 216 | ||
| 191 | cpdef start_service(self, service): | 217 | cpdef int start_service(self, service): |
| 192 | cdef uint16_t port | 218 | cdef uint16_t port |
| 193 | err = LockdownError(lockdownd_start_service(self._c_client, service, &port)) | 219 | err = LockdownError(lockdownd_start_service(self._c_client, service, &port)) |
| 194 | if err: raise err | 220 | if err: raise err |
| @@ -231,9 +257,13 @@ cdef class MobileSyncError(BaseError): | |||
| 231 | cdef class MobileSyncClient: | 257 | cdef class MobileSyncClient: |
| 232 | cdef mobilesync_client_t _c_client | 258 | cdef mobilesync_client_t _c_client |
| 233 | 259 | ||
| 234 | def __cinit__(self, iDevice device not None, LockdownClient lockdown not None, *args, **kwargs): | 260 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): |
| 235 | cdef iDevice dev = device | 261 | cdef iDevice dev = device |
| 236 | cdef LockdownClient lckd = lockdown | 262 | cdef LockdownClient lckd |
| 263 | if lockdown is None: | ||
| 264 | lckd = LockdownClient(dev) | ||
| 265 | else: | ||
| 266 | lcdk = lockdown | ||
| 237 | port = lckd.start_service("com.apple.mobilesync") | 267 | port = lckd.start_service("com.apple.mobilesync") |
| 238 | err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) | 268 | err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) |
| 239 | if err: raise err | 269 | if err: raise err |
| @@ -286,9 +316,13 @@ cdef class NotificationProxyError(BaseError): | |||
| 286 | cdef class NotificationProxy: | 316 | cdef class NotificationProxy: |
| 287 | cdef np_client_t _c_client | 317 | cdef np_client_t _c_client |
| 288 | 318 | ||
| 289 | def __cinit__(self, iDevice device not None, LockdownClient lockdown not None, *args, **kwargs): | 319 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): |
| 290 | cdef iDevice dev = device | 320 | cdef iDevice dev = device |
| 291 | cdef LockdownClient lckd = lockdown | 321 | cdef LockdownClient lckd |
| 322 | if lockdown is None: | ||
| 323 | lckd = LockdownClient(dev) | ||
| 324 | else: | ||
| 325 | lckd = lockdown | ||
| 292 | port = lckd.start_service("com.apple.mobile.notification_proxy") | 326 | port = lckd.start_service("com.apple.mobile.notification_proxy") |
| 293 | err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) | 327 | err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) |
| 294 | if err: raise err | 328 | if err: raise err |
| @@ -323,9 +357,13 @@ cdef class SpringboardServicesError(BaseError): | |||
| 323 | cdef class SpringboardServices: | 357 | cdef class SpringboardServices: |
| 324 | cdef sbservices_client_t _c_client | 358 | cdef sbservices_client_t _c_client |
| 325 | 359 | ||
| 326 | def __cinit__(self, iDevice device not None, LockdownClient lockdown not None, *args, **kwargs): | 360 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): |
| 327 | cdef iDevice dev = device | 361 | cdef iDevice dev = device |
| 328 | cdef LockdownClient lckd = lockdown | 362 | cdef LockdownClient lckd |
| 363 | if lockdown is None: | ||
| 364 | lckd = LockdownClient(dev) | ||
| 365 | else: | ||
| 366 | lckd = lockdown | ||
| 329 | port = lockdown.start_service("com.apple.springboardservices") | 367 | port = lockdown.start_service("com.apple.springboardservices") |
| 330 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) | 368 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) |
| 331 | if err: raise err | 369 | if err: raise err |
diff --git a/cython/stdint.pxi b/cython/stdint.pxi deleted file mode 100644 index 518c3d1..0000000 --- a/cython/stdint.pxi +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | cdef extern from "stdint.h": | ||
| 2 | ctypedef unsigned char uint8_t | ||
| 3 | ctypedef short int int16_t | ||
| 4 | ctypedef unsigned short int uint16_t | ||
| 5 | ctypedef unsigned int uint32_t | ||
| 6 | ctypedef int int32_t | ||
| 7 | IF UNAME_MACHINE == 'x86_64': | ||
| 8 | ctypedef unsigned long int uint64_t | ||
| 9 | ELSE: | ||
| 10 | ctypedef unsigned long long int uint64_t | ||
