diff options
Diffstat (limited to 'cython/mobilesync.pxi')
| -rw-r--r-- | cython/mobilesync.pxi | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi new file mode 100644 index 0000000..b9cf951 --- /dev/null +++ b/cython/mobilesync.pxi | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | cdef extern from "libimobiledevice/mobilesync.h": | ||
| 2 | cdef struct mobilesync_client_int: | ||
| 3 | pass | ||
| 4 | ctypedef mobilesync_client_int *mobilesync_client_t | ||
| 5 | |||
| 6 | ctypedef int16_t mobilesync_error_t | ||
| 7 | int16_t MOBILESYNC_E_SUCCESS | ||
| 8 | int16_t MOBILESYNC_E_INVALID_ARG | ||
| 9 | int16_t MOBILESYNC_E_PLIST_ERROR | ||
| 10 | int16_t MOBILESYNC_E_MUX_ERROR | ||
| 11 | int16_t MOBILESYNC_E_BAD_VERSION | ||
| 12 | int16_t MOBILESYNC_E_UNKNOWN_ERROR | ||
| 13 | |||
| 14 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) | ||
| 15 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) | ||
| 16 | mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) | ||
| 17 | mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) | ||
| 18 | |||
| 19 | cdef class MobileSyncError(BaseError): | ||
| 20 | def __init__(self, *args, **kwargs): | ||
| 21 | self._lookup_table = { | ||
| 22 | MOBILESYNC_E_SUCCESS: "Success", | ||
| 23 | MOBILESYNC_E_INVALID_ARG: "Invalid argument", | ||
| 24 | MOBILESYNC_E_PLIST_ERROR: "PList Error", | ||
| 25 | MOBILESYNC_E_MUX_ERROR: "MUX Error", | ||
| 26 | MOBILESYNC_E_BAD_VERSION: "Bad Version", | ||
| 27 | MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" | ||
| 28 | } | ||
| 29 | BaseError.__init__(self, *args, **kwargs) | ||
| 30 | |||
| 31 | cdef class MobileSyncClient(PropertyListService): | ||
| 32 | cdef mobilesync_client_t _c_client | ||
| 33 | |||
| 34 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 35 | cdef iDevice dev = device | ||
| 36 | cdef LockdownClient lckd | ||
| 37 | if lockdown is None: | ||
| 38 | lckd = LockdownClient(dev) | ||
| 39 | else: | ||
| 40 | lckd = lockdown | ||
| 41 | port = lckd.start_service("com.apple.mobilesync") | ||
| 42 | err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 43 | if err: raise err | ||
| 44 | |||
| 45 | def __dealloc__(self): | ||
| 46 | if self._c_client is not NULL: | ||
| 47 | err = MobileSyncError(mobilesync_client_free(self._c_client)) | ||
| 48 | if err: raise err | ||
| 49 | |||
| 50 | cdef _send(self, plist.plist_t node): | ||
| 51 | return MobileSyncError(mobilesync_send(self._c_client, node)) | ||
| 52 | |||
| 53 | cdef _receive(self, plist.plist_t* node): | ||
| 54 | return MobileSyncError(mobilesync_receive(self._c_client, node)) | ||
