summaryrefslogtreecommitdiffstats
path: root/cython
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
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')
-rw-r--r--cython/Makefile.am14
-rw-r--r--cython/imobiledevice.pxd50
-rw-r--r--cython/imobiledevice.pyx203
-rw-r--r--cython/mobilebackup.pxi54
-rw-r--r--cython/mobilesync.pxi54
-rw-r--r--cython/notification_proxy.pxi52
-rw-r--r--cython/property_list_service.pxi15
-rw-r--r--cython/sbservices.pxi57
-rw-r--r--cython/stdint.pxi10
9 files changed, 311 insertions, 198 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am
index 3cada6c..f5f01ef 100644
--- a/cython/Makefile.am
+++ b/cython/Makefile.am
@@ -6,25 +6,27 @@ AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_L
6if HAVE_CYTHON 6if HAVE_CYTHON
7 7
8BUILT_SOURCES = imobiledevice.c 8BUILT_SOURCES = imobiledevice.c
9PXDINCLUDES = imobiledevice.pxd stdint.pxi $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd
10PXIINCLUDES = stdint.pxi mobilesync.pxi notification_proxy.pxi sbservices.pxi mobilebackup.pxi
9 11
10CLEANFILES = \ 12CLEANFILES = \
11 *.pyc \ 13 *.pyc \
12 *.pyo \ 14 *.pyo \
13 imobiledevice.so \
14 imobiledevice.c 15 imobiledevice.c
15 16
16EXTRA_DIST = \ 17EXTRA_DIST = imobiledevice.pyx imobiledevice.pxd $(PXIINCLUDES)
17 imobiledevice.pyx
18 18
19imobiledevicedir = $(pyexecdir) 19imobiledevicedir = $(pyexecdir)
20imobiledevice_LTLIBRARIES = imobiledevice.la 20imobiledevice_LTLIBRARIES = imobiledevice.la
21nodist_imobiledevice_la_SOURCES = imobiledevice.c #imobiledevice_private.c 21imobiledevice_la_SOURCES = imobiledevice.pyx
22imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) 22imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS)
23imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) 23imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS)
24imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la 24imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la
25 25
26imobiledevice.c: imobiledevice.pyx $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd 26imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES)
27 $(CYTHON) --line-directives -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $< 27
28.pyx.c:
29 $(CYTHON) -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $<
28 30
29# imobiledevice_private.c: $(IMOBILEDEVICE_PRIVATE_SOURCES) $(IMOBILEDEVICE_INCLUDES) $(PLIST_INCLUDES) 31# imobiledevice_private.c: $(IMOBILEDEVICE_PRIVATE_SOURCES) $(IMOBILEDEVICE_INCLUDES) $(PLIST_INCLUDES)
30# $(CYTHON) $(IMOBILEDEVICE_CPPFLAGS) -I$(top_srcdir)/src -o $@ $< 32# $(CYTHON) $(IMOBILEDEVICE_CPPFLAGS) -I$(top_srcdir)/src -o $@ $<
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd
new file mode 100644
index 0000000..bdebe33
--- /dev/null
+++ b/cython/imobiledevice.pxd
@@ -0,0 +1,50 @@
1cimport plist
2
3include "stdint.pxi"
4
5cdef extern from "pyerrors.h":
6 ctypedef class __builtin__.Exception [object PyBaseExceptionObject]:
7 pass
8
9cdef class BaseError(Exception):
10 cdef dict _lookup_table
11 cdef int16_t _c_errcode
12
13cdef class iDeviceError(BaseError): pass
14
15cdef extern from "libimobiledevice/libimobiledevice.h":
16 cdef struct idevice_int:
17 pass
18 ctypedef idevice_int* idevice_t
19 ctypedef int16_t idevice_error_t
20 cdef enum idevice_event_type:
21 IDEVICE_DEVICE_ADD = 1,
22 IDEVICE_DEVICE_REMOVE
23 ctypedef struct idevice_event_t:
24 idevice_event_type event
25 char *uuid
26 int conn_type
27 ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*"
28
29cdef class iDeviceEvent:
30 cdef const_idevice_event_t _c_event
31
32cdef class iDevice:
33 cdef idevice_t _c_dev
34
35cdef class LockdownError(BaseError): pass
36
37cdef extern from "libimobiledevice/lockdown.h":
38 cdef struct lockdownd_client_int:
39 pass
40 ctypedef lockdownd_client_int *lockdownd_client_t
41
42cdef class LockdownClient:
43 cdef lockdownd_client_t _c_client
44 cpdef int start_service(self, service)
45 cpdef goodbye(self)
46
47cpdef set_debug_level(int level)
48cpdef event_subscribe(object callback)
49cpdef event_unsubscribe()
50cpdef get_device_list()
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
diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi
new file mode 100644
index 0000000..2bbaebe
--- /dev/null
+++ b/cython/mobilebackup.pxi
@@ -0,0 +1,54 @@
1cdef extern from "libimobiledevice/mobilebackup.h":
2 cdef struct mobilebackup_client_int:
3 pass
4 ctypedef mobilebackup_client_int *mobilebackup_client_t
5
6 ctypedef int16_t mobilebackup_error_t
7 int16_t MOBILEBACKUP_E_SUCCESS
8 int16_t MOBILEBACKUP_E_INVALID_ARG
9 int16_t MOBILEBACKUP_E_PLIST_ERROR
10 int16_t MOBILEBACKUP_E_MUX_ERROR
11 int16_t MOBILEBACKUP_E_BAD_VERSION
12 int16_t MOBILEBACKUP_E_UNKNOWN_ERROR
13
14 mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client)
15 mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client)
16 mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist.plist_t *plist)
17 mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist.plist_t plist)
18
19cdef class MobileBackupError(BaseError):
20 def __init__(self, *args, **kwargs):
21 self._lookup_table = {
22 MOBILEBACKUP_E_SUCCESS: "Success",
23 MOBILEBACKUP_E_INVALID_ARG: "Invalid argument",
24 MOBILEBACKUP_E_PLIST_ERROR: "PList Error",
25 MOBILEBACKUP_E_MUX_ERROR: "MUX Error",
26 MOBILEBACKUP_E_BAD_VERSION: "Bad Version",
27 MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error"
28 }
29 BaseError.__init__(self, *args, **kwargs)
30
31cdef class MobileBackupClient(PropertyListService):
32 cdef mobilebackup_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.mobilebackup")
42 err = MobileBackupError(mobilebackup_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 = MobileBackupError(mobilebackup_client_free(self._c_client))
48 if err: raise err
49
50 cdef _send(self, plist.plist_t node):
51 return MobileBackupError(mobilebackup_send(self._c_client, node))
52
53 cdef _receive(self, plist.plist_t* node):
54 return MobileBackupError(mobilebackup_receive(self._c_client, node))
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 @@
1cdef 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
19cdef 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
31cdef 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))
diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi
new file mode 100644
index 0000000..acccf7d
--- /dev/null
+++ b/cython/notification_proxy.pxi
@@ -0,0 +1,52 @@
1cdef extern from *:
2 ctypedef char* const_char_ptr "const char*"
3
4cdef extern from "libimobiledevice/notification_proxy.h":
5 cdef struct np_client_int:
6 pass
7 ctypedef np_client_int *np_client_t
8 ctypedef int16_t np_error_t
9 ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata)
10 np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
11 np_error_t np_client_free(np_client_t client)
12 np_error_t np_post_notification(np_client_t client, char *notification)
13 np_error_t np_observe_notification(np_client_t client, char *notification)
14 np_error_t np_observe_notifications(np_client_t client, char **notification_spec)
15 np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata)
16
17cdef void np_notify_cb(const_char_ptr notification, void *py_callback):
18 (<object>py_callback)(notification)
19
20cdef class NotificationProxyError(BaseError):
21 pass
22
23cdef class NotificationProxy:
24 cdef np_client_t _c_client
25
26 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
27 cdef iDevice dev = device
28 cdef LockdownClient lckd
29 if lockdown is None:
30 lckd = LockdownClient(dev)
31 else:
32 lckd = lockdown
33 port = lckd.start_service("com.apple.mobile.notification_proxy")
34 err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client)))
35 if err: raise err
36
37 def __dealloc__(self):
38 if self._c_client is not NULL:
39 err = NotificationProxyError(np_client_free(self._c_client))
40 if err: raise err
41
42 cpdef set_notify_callback(self, object callback):
43 err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback))
44 if err: raise err
45
46 cpdef observe_notification(self, bytes notification):
47 err = NotificationProxyError(np_observe_notification(self._c_client, notification))
48 if err: raise err
49
50 cpdef post_notification(self, bytes notification):
51 err = NotificationProxyError(np_post_notification(self._c_client, notification))
52 if err: raise err
diff --git a/cython/property_list_service.pxi b/cython/property_list_service.pxi
new file mode 100644
index 0000000..9b3f694
--- /dev/null
+++ b/cython/property_list_service.pxi
@@ -0,0 +1,15 @@
1cdef class PropertyListService:
2 cpdef send(self, plist.Node node):
3 cdef plist.Node n = node
4 cdef BaseError err = self._send(n._c_node)
5 if err: raise err
6
7 cpdef plist.Node receive(self):
8 cdef plist.plist_t c_node = NULL
9 cdef BaseError err = self._receive(&c_node)
10 if err: raise err
11
12 return plist.plist_t_to_node(c_node)
13
14 cdef _send(self, plist.plist_t node): pass
15 cdef _receive(self, plist.plist_t* c_node): pass
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi
new file mode 100644
index 0000000..cb9de59
--- /dev/null
+++ b/cython/sbservices.pxi
@@ -0,0 +1,57 @@
1cdef extern from "libimobiledevice/sbservices.h":
2 cdef struct sbservices_client_int:
3 pass
4 ctypedef sbservices_client_int *sbservices_client_t
5 ctypedef int16_t sbservices_error_t
6 sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client)
7 sbservices_error_t sbservices_client_free(sbservices_client_t client)
8 sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state)
9 sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate)
10 sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize)
11
12cdef class SpringboardServicesError(BaseError):
13 pass
14
15cdef class SpringboardServices:
16 cdef sbservices_client_t _c_client
17
18 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
19 cdef iDevice dev = device
20 cdef LockdownClient lckd
21 if lockdown is None:
22 lckd = LockdownClient(dev)
23 else:
24 lckd = lockdown
25 port = lockdown.start_service("com.apple.springboardservices")
26 err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client)))
27 if err: raise err
28
29 def __dealloc__(self):
30 if self._c_client is not NULL:
31 err = SpringboardServicesError(sbservices_client_free(self._c_client))
32 if err: raise err
33
34 property icon_state:
35 def __get__(self):
36 cdef plist.plist_t c_node = NULL
37 cdef plist.Node node
38 cdef SpringboardServicesError err = \
39 SpringboardServicesError(sbservices_get_icon_state(self._c_client, &c_node))
40 if err: raise err
41 node = plist.plist_t_to_node(c_node)
42 return node
43 def __set__(self, plist.Node newstate not None):
44 cdef plist.Node node = newstate
45 cdef SpringboardServicesError err = \
46 SpringboardServicesError(sbservices_set_icon_state(self._c_client, node._c_node))
47 if err: raise err
48
49 cpdef bytes get_pngdata(self, bytes bundleId):
50 cdef bytes result
51 cdef char* pngdata = NULL
52 cdef uint64_t pngsize
53 cdef SpringboardServicesError err = \
54 SpringboardServicesError(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize))
55 if err: raise err
56 result = pngdata[:pngsize]
57 return result
diff --git a/cython/stdint.pxi b/cython/stdint.pxi
new file mode 100644
index 0000000..e21103f
--- /dev/null
+++ b/cython/stdint.pxi
@@ -0,0 +1,10 @@
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