diff options
| author | 2010-05-13 09:41:12 -0500 | |
|---|---|---|
| committer | 2012-03-20 23:25:55 +0100 | |
| commit | 7d4a26663a812c383738fc6390759266851cf953 (patch) | |
| tree | c765b16c60909f49d935f0705049e6ab155cb9e7 /cython | |
| parent | 3877711296cbfa4a0bcafc3c5560609a1ce2d079 (diff) | |
| download | libimobiledevice-7d4a26663a812c383738fc6390759266851cf953.tar.gz libimobiledevice-7d4a26663a812c383738fc6390759266851cf953.tar.bz2 | |
Python bindings for new sync interface.
Diffstat (limited to 'cython')
| -rw-r--r-- | cython/imobiledevice.pxd | 1 | ||||
| -rw-r--r-- | cython/lockdown.pxi | 23 | ||||
| -rw-r--r-- | cython/mobilesync.pxi | 104 | ||||
| -rw-r--r-- | cython/stdint.pxi | 6 |
4 files changed, 133 insertions, 1 deletions
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd index a699138..048f226 100644 --- a/cython/imobiledevice.pxd +++ b/cython/imobiledevice.pxd | |||
| @@ -89,3 +89,4 @@ cdef class LockdownClient(PropertyListService): | |||
| 89 | cpdef deactivate(self) | 89 | cpdef deactivate(self) |
| 90 | cpdef enter_recovery(self) | 90 | cpdef enter_recovery(self) |
| 91 | cpdef goodbye(self) | 91 | cpdef goodbye(self) |
| 92 | cpdef list get_sync_data_classes(self) | ||
diff --git a/cython/lockdown.pxi b/cython/lockdown.pxi index a904d12..8463738 100644 --- a/cython/lockdown.pxi +++ b/cython/lockdown.pxi | |||
| @@ -41,6 +41,8 @@ cdef extern from "libimobiledevice/lockdown.h": | |||
| 41 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) | 41 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) |
| 42 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) | 42 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) |
| 43 | lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) | 43 | lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) |
| 44 | lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count) | ||
| 45 | lockdownd_error_t lockdownd_data_classes_free(char **classes) | ||
| 44 | 46 | ||
| 45 | cdef class LockdownError(BaseError): | 47 | cdef class LockdownError(BaseError): |
| 46 | def __init__(self, *args, **kwargs): | 48 | def __init__(self, *args, **kwargs): |
| @@ -245,6 +247,27 @@ cdef class LockdownClient(PropertyListService): | |||
| 245 | cpdef goodbye(self): | 247 | cpdef goodbye(self): |
| 246 | self.handle_error(lockdownd_goodbye(self._c_client)) | 248 | self.handle_error(lockdownd_goodbye(self._c_client)) |
| 247 | 249 | ||
| 250 | cpdef list get_sync_data_classes(self): | ||
| 251 | cdef: | ||
| 252 | char **classes = NULL | ||
| 253 | int count = 0 | ||
| 254 | list result = [] | ||
| 255 | bytes data_class | ||
| 256 | |||
| 257 | try: | ||
| 258 | self.handle_error(lockdownd_get_sync_data_classes(self._c_client, &classes, &count)) | ||
| 259 | |||
| 260 | for i from 0 <= i < count: | ||
| 261 | data_class = classes[i] | ||
| 262 | result.append(data_class) | ||
| 263 | |||
| 264 | return result | ||
| 265 | except Exception, e: | ||
| 266 | raise | ||
| 267 | finally: | ||
| 268 | if classes != NULL: | ||
| 269 | lockdownd_data_classes_free(classes) | ||
| 270 | |||
| 248 | cdef inline int16_t _send(self, plist.plist_t node): | 271 | cdef inline int16_t _send(self, plist.plist_t node): |
| 249 | return lockdownd_send(self._c_client, node) | 272 | return lockdownd_send(self._c_client, node) |
| 250 | 273 | ||
diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi index 00b511f..843700b 100644 --- a/cython/mobilesync.pxi +++ b/cython/mobilesync.pxi | |||
| @@ -2,20 +2,54 @@ cdef extern from "libimobiledevice/mobilesync.h": | |||
| 2 | cdef struct mobilesync_client_private: | 2 | cdef struct mobilesync_client_private: |
| 3 | pass | 3 | pass |
| 4 | ctypedef mobilesync_client_private *mobilesync_client_t | 4 | ctypedef mobilesync_client_private *mobilesync_client_t |
| 5 | |||
| 6 | ctypedef enum mobilesync_error_t: | 5 | ctypedef enum mobilesync_error_t: |
| 7 | MOBILESYNC_E_SUCCESS = 0 | 6 | MOBILESYNC_E_SUCCESS = 0 |
| 8 | MOBILESYNC_E_INVALID_ARG = -1 | 7 | MOBILESYNC_E_INVALID_ARG = -1 |
| 9 | MOBILESYNC_E_PLIST_ERROR = -2 | 8 | MOBILESYNC_E_PLIST_ERROR = -2 |
| 10 | MOBILESYNC_E_MUX_ERROR = -3 | 9 | MOBILESYNC_E_MUX_ERROR = -3 |
| 11 | MOBILESYNC_E_BAD_VERSION = -4 | 10 | MOBILESYNC_E_BAD_VERSION = -4 |
| 11 | MOBILESYNC_E_SYNC_REFUSED = -5 | ||
| 12 | MOBILESYNC_E_CANCELLED = -6 | ||
| 13 | MOBILESYNC_E_WRONG_DIRECTION = -7 | ||
| 14 | MOBILESYNC_E_NOT_READY = -8 | ||
| 12 | MOBILESYNC_E_UNKNOWN_ERROR = -256 | 15 | MOBILESYNC_E_UNKNOWN_ERROR = -256 |
| 13 | 16 | ||
| 17 | ctypedef enum mobilesync_sync_type_t: | ||
| 18 | MOBILESYNC_SYNC_TYPE_FAST | ||
| 19 | MOBILESYNC_SYNC_TYPE_SLOW | ||
| 20 | MOBILESYNC_SYNC_TYPE_RESET | ||
| 21 | |||
| 22 | ctypedef struct mobilesync_anchors: | ||
| 23 | char *device_anchor | ||
| 24 | char *host_anchor | ||
| 25 | ctypedef mobilesync_anchors *mobilesync_anchors_t | ||
| 26 | |||
| 14 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) | 27 | 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) | 28 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) |
| 16 | mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) | 29 | 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) | 30 | mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) |
| 18 | 31 | ||
| 32 | mobilesync_error_t mobilesync_session_start(mobilesync_client_t client, char *data_class, mobilesync_anchors_t anchors, mobilesync_sync_type_t *sync_type, uint64_t *data_class_version) | ||
| 33 | mobilesync_error_t mobilesync_session_cancel(mobilesync_client_t client, char* reason) | ||
| 34 | mobilesync_error_t mobilesync_session_finish(mobilesync_client_t client) | ||
| 35 | |||
| 36 | mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client) | ||
| 37 | mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client) | ||
| 38 | mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist.plist_t *entities, uint8_t *is_last_record) | ||
| 39 | mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client) | ||
| 40 | |||
| 41 | mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client) | ||
| 42 | mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist.plist_t changes, uint8_t is_last_record, plist.plist_t actions) | ||
| 43 | mobilesync_error_t mobilesync_receive_remapping(mobilesync_client_t client, plist.plist_t *remapping) | ||
| 44 | |||
| 45 | |||
| 46 | mobilesync_anchors_t mobilesync_anchors_new(char *device_anchor, char *computer_anchor) | ||
| 47 | void mobilesync_anchors_free(mobilesync_anchors_t anchors) | ||
| 48 | |||
| 49 | SYNC_TYPE_FAST = MOBILESYNC_SYNC_TYPE_FAST | ||
| 50 | SYNC_TYPE_SLOW = MOBILESYNC_SYNC_TYPE_SLOW | ||
| 51 | SYNC_TYPE_RESET = MOBILESYNC_SYNC_TYPE_RESET | ||
| 52 | |||
| 19 | cdef class MobileSyncError(BaseError): | 53 | cdef class MobileSyncError(BaseError): |
| 20 | def __init__(self, *args, **kwargs): | 54 | def __init__(self, *args, **kwargs): |
| 21 | self._lookup_table = { | 55 | self._lookup_table = { |
| @@ -24,6 +58,10 @@ cdef class MobileSyncError(BaseError): | |||
| 24 | MOBILESYNC_E_PLIST_ERROR: "Property list error", | 58 | MOBILESYNC_E_PLIST_ERROR: "Property list error", |
| 25 | MOBILESYNC_E_MUX_ERROR: "MUX error", | 59 | MOBILESYNC_E_MUX_ERROR: "MUX error", |
| 26 | MOBILESYNC_E_BAD_VERSION: "Bad version", | 60 | MOBILESYNC_E_BAD_VERSION: "Bad version", |
| 61 | MOBILESYNC_E_SYNC_REFUSED: "Sync refused", | ||
| 62 | MOBILESYNC_E_CANCELLED: "Sync cancelled", | ||
| 63 | MOBILESYNC_E_WRONG_DIRECTION: "Wrong sync direction", | ||
| 64 | MOBILESYNC_E_NOT_READY: "Not ready to receive changes", | ||
| 27 | MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" | 65 | MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" |
| 28 | } | 66 | } |
| 29 | BaseError.__init__(self, *args, **kwargs) | 67 | BaseError.__init__(self, *args, **kwargs) |
| @@ -40,6 +78,70 @@ cdef class MobileSyncClient(DeviceLinkService): | |||
| 40 | if self._c_client is not NULL: | 78 | if self._c_client is not NULL: |
| 41 | err = mobilesync_client_free(self._c_client) | 79 | err = mobilesync_client_free(self._c_client) |
| 42 | self.handle_error(err) | 80 | self.handle_error(err) |
| 81 | |||
| 82 | cpdef tuple session_start(self, bytes data_class, bytes last_sync_time, bytes current_time): | ||
| 83 | cdef: | ||
| 84 | mobilesync_anchors_t anchors = NULL | ||
| 85 | mobilesync_sync_type_t sync_type | ||
| 86 | uint64_t data_class_version | ||
| 87 | |||
| 88 | if last_sync_time is None: | ||
| 89 | anchors = mobilesync_anchors_new(NULL, current_time) | ||
| 90 | else: | ||
| 91 | anchors = mobilesync_anchors_new(last_sync_time, current_time) | ||
| 92 | |||
| 93 | try: | ||
| 94 | self.handle_error(mobilesync_session_start(self._c_client, data_class, anchors, &sync_type, &data_class_version)) | ||
| 95 | return (sync_type, <bint>data_class_version) | ||
| 96 | except Exception, e: | ||
| 97 | raise | ||
| 98 | finally: | ||
| 99 | mobilesync_anchors_free(anchors) | ||
| 100 | |||
| 101 | cpdef session_finish(self): | ||
| 102 | self.handle_error(mobilesync_session_finish(self._c_client)) | ||
| 103 | |||
| 104 | cpdef session_cancel(self, bytes reason): | ||
| 105 | self.handle_error(mobilesync_session_cancel(self._c_client, reason)) | ||
| 106 | |||
| 107 | cpdef get_all_records_from_device(self): | ||
| 108 | self.handle_error(mobilesync_get_all_records_from_device(self._c_client)) | ||
| 109 | |||
| 110 | cpdef get_changes_from_device(self): | ||
| 111 | self.handle_error(mobilesync_get_changes_from_device(self._c_client)) | ||
| 112 | |||
| 113 | cpdef tuple receive_changes(self): | ||
| 114 | cdef: | ||
| 115 | plist.plist_t entities = NULL | ||
| 116 | uint8_t is_last_record = 0 | ||
| 117 | |||
| 118 | try: | ||
| 119 | self.handle_error(mobilesync_receive_changes(self._c_client, &entities, &is_last_record)) | ||
| 120 | return (plist.plist_t_to_node(entities), <bint>is_last_record) | ||
| 121 | except Exception, e: | ||
| 122 | if entities != NULL: | ||
| 123 | plist.plist_free(entities) | ||
| 124 | raise | ||
| 125 | |||
| 126 | cpdef acknowledge_changes_from_device(self): | ||
| 127 | self.handle_error(mobilesync_acknowledge_changes_from_device(self._c_client)) | ||
| 128 | |||
| 129 | cpdef ready_to_send_changes_from_computer(self): | ||
| 130 | self.handle_error(mobilesync_ready_to_send_changes_from_computer(self._c_client)) | ||
| 131 | |||
| 132 | cpdef send_changes(self, plist.Node changes, bint is_last_record, plist.Node actions): | ||
| 133 | self.handle_error(mobilesync_send_changes(self._c_client, changes._c_node, is_last_record, actions._c_node)) | ||
| 134 | |||
| 135 | cpdef receive_remapping(self): | ||
| 136 | cdef plist.plist_t remapping = NULL | ||
| 137 | |||
| 138 | try: | ||
| 139 | self.handle_error(mobilesync_receive_remapping(self._c_client, &remapping)) | ||
| 140 | return plist.plist_t_to_node(remapping) | ||
| 141 | except Exception, e: | ||
| 142 | if remapping != NULL: | ||
| 143 | plist.plist_free(remapping) | ||
| 144 | raise | ||
| 43 | 145 | ||
| 44 | cdef inline int16_t _send(self, plist.plist_t node): | 146 | cdef inline int16_t _send(self, plist.plist_t node): |
| 45 | return mobilesync_send(self._c_client, node) | 147 | return mobilesync_send(self._c_client, node) |
diff --git a/cython/stdint.pxi b/cython/stdint.pxi index 2617dec..f9e5e95 100644 --- a/cython/stdint.pxi +++ b/cython/stdint.pxi | |||
| @@ -4,9 +4,15 @@ cdef extern from *: | |||
| 4 | ctypedef unsigned short int uint16_t | 4 | ctypedef unsigned short int uint16_t |
| 5 | ctypedef unsigned int uint32_t | 5 | ctypedef unsigned int uint32_t |
| 6 | ctypedef int int32_t | 6 | ctypedef int int32_t |
| 7 | ctypedef long int time_t | ||
| 7 | IF UNAME_MACHINE == 'x86_64': | 8 | IF UNAME_MACHINE == 'x86_64': |
| 8 | ctypedef long int int64_t | 9 | ctypedef long int int64_t |
| 9 | ctypedef unsigned long int uint64_t | 10 | ctypedef unsigned long int uint64_t |
| 10 | ELSE: | 11 | ELSE: |
| 11 | ctypedef long long int int64_t | 12 | ctypedef long long int int64_t |
| 12 | ctypedef unsigned long long int uint64_t | 13 | ctypedef unsigned long long int uint64_t |
| 14 | |||
| 15 | cdef extern from "time.h": | ||
| 16 | cdef struct timeval: | ||
| 17 | time_t tv_sec | ||
| 18 | time_t tv_usec | ||
