summaryrefslogtreecommitdiffstats
path: root/cython/imobiledevice.pyx
diff options
context:
space:
mode:
authorGravatar Bryan Forbes2010-03-17 01:12:52 -0500
committerGravatar Martin Szulecki2012-03-20 23:25:54 +0100
commitcfe6244f8954efce4ef12b9b4338cc0d41a9ff40 (patch)
tree8b181941ea31e9f8a16930536b429178ce7d4afe /cython/imobiledevice.pyx
parentbc6886898d03d28dc30c90db18c2a5f90f20c746 (diff)
downloadlibimobiledevice-cfe6244f8954efce4ef12b9b4338cc0d41a9ff40.tar.gz
libimobiledevice-cfe6244f8954efce4ef12b9b4338cc0d41a9ff40.tar.bz2
Moved everything but iDevice and LockdownClient to pxi files.
Added MobileBackupClient and PropertyListService.
Diffstat (limited to 'cython/imobiledevice.pyx')
-rw-r--r--cython/imobiledevice.pyx203
1 files changed, 11 insertions, 192 deletions
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx
index befd586..bbec7b8 100644
--- a/cython/imobiledevice.pyx
+++ b/cython/imobiledevice.pyx
@@ -1,24 +1,4 @@
1cdef extern from *:
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
7IF UNAME_MACHINE == 'x86_64':
8 ctypedef unsigned long int uint64_t
9ELSE:
10 ctypedef unsigned long long int uint64_t
11
12cimport plist
13
14cdef extern from "pyerrors.h":
15 ctypedef class __builtin__.Exception [object PyBaseExceptionObject]:
16 pass
17
18cdef class BaseError(Exception): 1cdef class BaseError(Exception):
19 cdef dict _lookup_table
20 cdef int16_t _c_errcode
21
22 def __cinit__(self, int16_t errcode): 2 def __cinit__(self, int16_t errcode):
23 self._c_errcode = errcode 3 self._c_errcode = errcode
24 4
@@ -40,10 +20,6 @@ cdef class BaseError(Exception):
40 return self.__str__() 20 return self.__str__()
41 21
42cdef extern from "libimobiledevice/libimobiledevice.h": 22cdef extern from "libimobiledevice/libimobiledevice.h":
43 cdef struct idevice_int:
44 pass
45 ctypedef idevice_int* idevice_t
46 ctypedef int16_t idevice_error_t
47 int16_t IDEVICE_E_SUCCESS 23 int16_t IDEVICE_E_SUCCESS
48 int16_t IDEVICE_E_INVALID_ARG 24 int16_t IDEVICE_E_INVALID_ARG
49 int16_t IDEVICE_E_UNKNOWN_ERROR 25 int16_t IDEVICE_E_UNKNOWN_ERROR
@@ -51,14 +27,6 @@ cdef extern from "libimobiledevice/libimobiledevice.h":
51 int16_t IDEVICE_E_NOT_ENOUGH_DATA 27 int16_t IDEVICE_E_NOT_ENOUGH_DATA
52 int16_t IDEVICE_E_BAD_HEADER 28 int16_t IDEVICE_E_BAD_HEADER
53 int16_t IDEVICE_E_SSL_ERROR 29 int16_t IDEVICE_E_SSL_ERROR
54 cdef enum idevice_event_type:
55 IDEVICE_DEVICE_ADD = 1,
56 IDEVICE_DEVICE_REMOVE
57 ctypedef struct idevice_event_t:
58 idevice_event_type event
59 char *uuid
60 int conn_type
61 ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*"
62 ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) 30 ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data)
63 cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) 31 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() 32 cdef extern idevice_error_t idevice_event_unsubscribe()
@@ -83,26 +51,25 @@ cdef class iDeviceError(BaseError):
83 } 51 }
84 BaseError.__init__(self, *args, **kwargs) 52 BaseError.__init__(self, *args, **kwargs)
85 53
86def set_debug_level(level): 54cpdef set_debug_level(int level):
87 idevice_set_debug_level(level) 55 idevice_set_debug_level(level)
88 56
89cdef class iDeviceEvent: 57cdef class iDeviceEvent: pass
90 cdef const_idevice_event_t _c_event
91 58
92cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): 59cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data):
93 cdef iDeviceEvent event = iDeviceEvent() 60 cdef iDeviceEvent event = iDeviceEvent()
94 event._c_event = c_event 61 event._c_event = c_event
95 (<object>user_data)(event) 62 (<object>user_data)(event)
96 63
97def event_subscribe(callback): 64cpdef event_subscribe(object callback):
98 cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) 65 cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback))
99 if err: raise err 66 if err: raise err
100 67
101def event_unsubscribe(): 68cpdef event_unsubscribe():
102 cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) 69 cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe())
103 if err: raise err 70 if err: raise err
104 71
105def get_device_list(): 72cpdef get_device_list():
106 cdef char** devices 73 cdef char** devices
107 cdef int count 74 cdef int count
108 cdef list result 75 cdef list result
@@ -118,8 +85,6 @@ def get_device_list():
118 return result 85 return result
119 86
120cdef class iDevice: 87cdef class iDevice:
121 cdef idevice_t _c_dev
122
123 def __cinit__(self, uuid=None, *args, **kwargs): 88 def __cinit__(self, uuid=None, *args, **kwargs):
124 cdef char* c_uuid = NULL 89 cdef char* c_uuid = NULL
125 if uuid is not None: 90 if uuid is not None:
@@ -202,8 +167,6 @@ cdef class LockdownError(BaseError):
202 BaseError.__init__(self, *args, **kwargs) 167 BaseError.__init__(self, *args, **kwargs)
203 168
204cdef class LockdownClient: 169cdef class LockdownClient:
205 cdef lockdownd_client_t _c_client
206
207 def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs): 170 def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs):
208 cdef iDevice dev = device 171 cdef iDevice dev = device
209 err = LockdownError(lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label)) 172 err = LockdownError(lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label))
@@ -220,155 +183,11 @@ cdef class LockdownClient:
220 if err: raise err 183 if err: raise err
221 return port 184 return port
222 185
223 def goodbye(self): 186 cpdef goodbye(self):
224 pass 187 pass
225
226
227cdef extern from "libimobiledevice/mobilesync.h":
228 cdef struct mobilesync_client_int:
229 pass
230 ctypedef mobilesync_client_int *mobilesync_client_t
231
232 ctypedef int16_t mobilesync_error_t
233 int16_t MOBILESYNC_E_SUCCESS
234 int16_t MOBILESYNC_E_INVALID_ARG
235 int16_t MOBILESYNC_E_PLIST_ERROR
236 int16_t MOBILESYNC_E_MUX_ERROR
237 int16_t MOBILESYNC_E_BAD_VERSION
238 int16_t MOBILESYNC_E_UNKNOWN_ERROR
239
240 mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client)
241 mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)
242 mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist)
243 mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist)
244
245cdef class MobileSyncError(BaseError):
246 def __init__(self, *args, **kwargs):
247 self._lookup_table = {
248 MOBILESYNC_E_SUCCESS: "Success",
249 MOBILESYNC_E_INVALID_ARG: "Invalid argument",
250 MOBILESYNC_E_PLIST_ERROR: "PList Error",
251 MOBILESYNC_E_MUX_ERROR: "MUX Error",
252 MOBILESYNC_E_BAD_VERSION: "Bad Version",
253 MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error"
254 }
255 BaseError.__init__(self, *args, **kwargs)
256
257cdef class MobileSyncClient:
258 cdef mobilesync_client_t _c_client
259
260 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
261 cdef iDevice dev = device
262 cdef LockdownClient lckd
263 if lockdown is None:
264 lckd = LockdownClient(dev)
265 else:
266 lcdk = lockdown
267 port = lckd.start_service("com.apple.mobilesync")
268 err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client)))
269 if err: raise err
270
271 def __dealloc__(self):
272 if self._c_client is not NULL:
273 err = MobileSyncError(mobilesync_client_free(self._c_client))
274 if err: raise err
275
276 cpdef send(self, object obj):
277 cdef plist.Node node
278 cdef plist.plist_t c_node
279 if isinstance(obj, plist.Node):
280 node = obj
281 c_node = node._c_node
282 else:
283 c_node = plist.native_to_plist_t(obj)
284 err = MobileSyncError(mobilesync_send(self._c_client, c_node))
285 if err: raise err
286
287 cpdef receive(self):
288 cdef plist.plist_t c_node = NULL
289 err = MobileSyncError(mobilesync_receive(self._c_client, &(c_node)))
290 if err: raise err
291 188
292 return plist.plist_t_to_node(c_node) 189include "property_list_service.pxi"
293 190include "mobilesync.pxi"
294cdef extern from *: 191include "notification_proxy.pxi"
295 ctypedef char* const_char_ptr "const char*" 192include "sbservices.pxi"
296 193include "mobilebackup.pxi"
297cdef extern from "libimobiledevice/notification_proxy.h":
298 cdef struct np_client_int:
299 pass
300 ctypedef np_client_int *np_client_t
301 ctypedef int16_t np_error_t
302 ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata)
303 np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
304 np_error_t np_client_free(np_client_t client)
305 np_error_t np_post_notification(np_client_t client, char *notification)
306 np_error_t np_observe_notification(np_client_t client, char *notification)
307 np_error_t np_observe_notifications(np_client_t client, char **notification_spec)
308 np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata)
309
310cdef void np_notify_cb(const_char_ptr notification, void *py_callback):
311 (<object>py_callback)(notification)
312
313cdef class NotificationProxyError(BaseError):
314 pass
315
316cdef class NotificationProxy:
317 cdef np_client_t _c_client
318
319 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
320 cdef iDevice dev = device
321 cdef LockdownClient lckd
322 if lockdown is None:
323 lckd = LockdownClient(dev)
324 else:
325 lckd = lockdown
326 port = lckd.start_service("com.apple.mobile.notification_proxy")
327 err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client)))
328 if err: raise err
329
330 def __dealloc__(self):
331 if self._c_client is not NULL:
332 err = NotificationProxyError(np_client_free(self._c_client))
333 if err: raise err
334
335 def set_notify_callback(self, callback):
336 err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback))
337 if err: raise err
338
339 def observe_notification(self, notification):
340 err = NotificationProxyError(np_observe_notification(self._c_client, notification))
341 if err: raise err
342
343cdef extern from "libimobiledevice/sbservices.h":
344 cdef struct sbservices_client_int:
345 pass
346 ctypedef sbservices_client_int *sbservices_client_t
347 ctypedef int16_t sbservices_error_t
348 sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client)
349 sbservices_error_t sbservices_client_free(sbservices_client_t client)
350 sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state)
351 sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate)
352 sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize)
353
354cdef class SpringboardServicesError(BaseError):
355 pass
356
357cdef class SpringboardServices:
358 cdef sbservices_client_t _c_client
359
360 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
361 cdef iDevice dev = device
362 cdef LockdownClient lckd
363 if lockdown is None:
364 lckd = LockdownClient(dev)
365 else:
366 lckd = lockdown
367 port = lockdown.start_service("com.apple.springboardservices")
368 err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client)))
369 if err: raise err
370
371 def __dealloc__(self):
372 if self._c_client is not NULL:
373 err = SpringboardServicesError(sbservices_client_free(self._c_client))
374 if err: raise err