diff options
author | Bryan Forbes | 2010-03-17 01:12:52 -0500 |
---|---|---|
committer | Martin Szulecki | 2012-03-20 23:25:54 +0100 |
commit | cfe6244f8954efce4ef12b9b4338cc0d41a9ff40 (patch) | |
tree | 8b181941ea31e9f8a16930536b429178ce7d4afe /cython | |
parent | bc6886898d03d28dc30c90db18c2a5f90f20c746 (diff) | |
download | libimobiledevice-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.am | 14 | ||||
-rw-r--r-- | cython/imobiledevice.pxd | 50 | ||||
-rw-r--r-- | cython/imobiledevice.pyx | 203 | ||||
-rw-r--r-- | cython/mobilebackup.pxi | 54 | ||||
-rw-r--r-- | cython/mobilesync.pxi | 54 | ||||
-rw-r--r-- | cython/notification_proxy.pxi | 52 | ||||
-rw-r--r-- | cython/property_list_service.pxi | 15 | ||||
-rw-r--r-- | cython/sbservices.pxi | 57 | ||||
-rw-r--r-- | cython/stdint.pxi | 10 |
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 if HAVE_CYTHON BUILT_SOURCES = imobiledevice.c +PXDINCLUDES = imobiledevice.pxd stdint.pxi $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd +PXIINCLUDES = stdint.pxi mobilesync.pxi notification_proxy.pxi sbservices.pxi mobilebackup.pxi CLEANFILES = \ *.pyc \ *.pyo \ - imobiledevice.so \ imobiledevice.c -EXTRA_DIST = \ - imobiledevice.pyx +EXTRA_DIST = imobiledevice.pyx imobiledevice.pxd $(PXIINCLUDES) imobiledevicedir = $(pyexecdir) imobiledevice_LTLIBRARIES = imobiledevice.la -nodist_imobiledevice_la_SOURCES = imobiledevice.c #imobiledevice_private.c +imobiledevice_la_SOURCES = imobiledevice.pyx imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la -imobiledevice.c: imobiledevice.pyx $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd - $(CYTHON) --line-directives -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $< +imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES) + +.pyx.c: + $(CYTHON) -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $< # imobiledevice_private.c: $(IMOBILEDEVICE_PRIVATE_SOURCES) $(IMOBILEDEVICE_INCLUDES) $(PLIST_INCLUDES) # $(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 @@ +cimport plist + +include "stdint.pxi" + +cdef extern from "pyerrors.h": + ctypedef class __builtin__.Exception [object PyBaseExceptionObject]: + pass + +cdef class BaseError(Exception): + cdef dict _lookup_table + cdef int16_t _c_errcode + +cdef class iDeviceError(BaseError): pass + +cdef extern from "libimobiledevice/libimobiledevice.h": + cdef struct idevice_int: + pass + ctypedef idevice_int* idevice_t + ctypedef int16_t idevice_error_t + cdef enum idevice_event_type: + IDEVICE_DEVICE_ADD = 1, + IDEVICE_DEVICE_REMOVE + ctypedef struct idevice_event_t: + idevice_event_type event + char *uuid + int conn_type + ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*" + +cdef class iDeviceEvent: + cdef const_idevice_event_t _c_event + +cdef class iDevice: + cdef idevice_t _c_dev + +cdef class LockdownError(BaseError): pass + +cdef extern from "libimobiledevice/lockdown.h": + cdef struct lockdownd_client_int: + pass + ctypedef lockdownd_client_int *lockdownd_client_t + +cdef class LockdownClient: + cdef lockdownd_client_t _c_client + cpdef int start_service(self, service) + cpdef goodbye(self) + +cpdef set_debug_level(int level) +cpdef event_subscribe(object callback) +cpdef event_unsubscribe() +cpdef 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 @@ -cdef extern from *: - ctypedef unsigned char uint8_t - ctypedef short int int16_t - ctypedef unsigned short int uint16_t - ctypedef unsigned int uint32_t - ctypedef int int32_t -IF UNAME_MACHINE == 'x86_64': - ctypedef unsigned long int uint64_t -ELSE: - ctypedef unsigned long long int uint64_t - -cimport plist - -cdef extern from "pyerrors.h": - ctypedef class __builtin__.Exception [object PyBaseExceptionObject]: - pass - cdef class BaseError(Exception): - cdef dict _lookup_table - cdef int16_t _c_errcode - def __cinit__(self, int16_t errcode): self._c_errcode = errcode @@ -40,10 +20,6 @@ cdef class BaseError(Exception): return self.__str__() cdef extern from "libimobiledevice/libimobiledevice.h": - cdef struct idevice_int: - pass - ctypedef idevice_int* idevice_t - ctypedef int16_t idevice_error_t int16_t IDEVICE_E_SUCCESS int16_t IDEVICE_E_INVALID_ARG int16_t IDEVICE_E_UNKNOWN_ERROR @@ -51,14 +27,6 @@ cdef extern from "libimobiledevice/libimobiledevice.h": int16_t IDEVICE_E_NOT_ENOUGH_DATA int16_t IDEVICE_E_BAD_HEADER int16_t IDEVICE_E_SSL_ERROR - cdef enum idevice_event_type: - IDEVICE_DEVICE_ADD = 1, - IDEVICE_DEVICE_REMOVE - ctypedef struct idevice_event_t: - idevice_event_type event - char *uuid - int conn_type - ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*" ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) cdef extern idevice_error_t idevice_event_unsubscribe() @@ -83,26 +51,25 @@ cdef class iDeviceError(BaseError): } BaseError.__init__(self, *args, **kwargs) -def set_debug_level(level): +cpdef set_debug_level(int level): idevice_set_debug_level(level) -cdef class iDeviceEvent: - cdef const_idevice_event_t _c_event +cdef class iDeviceEvent: pass cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): cdef iDeviceEvent event = iDeviceEvent() event._c_event = c_event (<object>user_data)(event) -def event_subscribe(callback): +cpdef event_subscribe(object callback): cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) if err: raise err -def event_unsubscribe(): +cpdef event_unsubscribe(): cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) if err: raise err -def get_device_list(): +cpdef get_device_list(): cdef char** devices cdef int count cdef list result @@ -118,8 +85,6 @@ def get_device_list(): return result cdef class iDevice: - cdef idevice_t _c_dev - def __cinit__(self, uuid=None, *args, **kwargs): cdef char* c_uuid = NULL if uuid is not None: @@ -202,8 +167,6 @@ cdef class LockdownError(BaseError): BaseError.__init__(self, *args, **kwargs) cdef class LockdownClient: - cdef lockdownd_client_t _c_client - def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs): cdef iDevice dev = device err = LockdownError(lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label)) @@ -220,155 +183,11 @@ cdef class LockdownClient: if err: raise err return port - def goodbye(self): + cpdef goodbye(self): pass - - -cdef extern from "libimobiledevice/mobilesync.h": - cdef struct mobilesync_client_int: - pass - ctypedef mobilesync_client_int *mobilesync_client_t - - ctypedef int16_t mobilesync_error_t - int16_t MOBILESYNC_E_SUCCESS - int16_t MOBILESYNC_E_INVALID_ARG - int16_t MOBILESYNC_E_PLIST_ERROR - int16_t MOBILESYNC_E_MUX_ERROR - int16_t MOBILESYNC_E_BAD_VERSION - int16_t MOBILESYNC_E_UNKNOWN_ERROR - - mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) - mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) - mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) - mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) - -cdef class MobileSyncError(BaseError): - def __init__(self, *args, **kwargs): - self._lookup_table = { - MOBILESYNC_E_SUCCESS: "Success", - MOBILESYNC_E_INVALID_ARG: "Invalid argument", - MOBILESYNC_E_PLIST_ERROR: "PList Error", - MOBILESYNC_E_MUX_ERROR: "MUX Error", - MOBILESYNC_E_BAD_VERSION: "Bad Version", - MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" - } - BaseError.__init__(self, *args, **kwargs) - -cdef class MobileSyncClient: - cdef mobilesync_client_t _c_client - - def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): - cdef iDevice dev = device - cdef LockdownClient lckd - if lockdown is None: - lckd = LockdownClient(dev) - else: - lcdk = lockdown - port = lckd.start_service("com.apple.mobilesync") - err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) - if err: raise err - - def __dealloc__(self): - if self._c_client is not NULL: - err = MobileSyncError(mobilesync_client_free(self._c_client)) - if err: raise err - - cpdef send(self, object obj): - cdef plist.Node node - cdef plist.plist_t c_node - if isinstance(obj, plist.Node): - node = obj - c_node = node._c_node - else: - c_node = plist.native_to_plist_t(obj) - err = MobileSyncError(mobilesync_send(self._c_client, c_node)) - if err: raise err - - cpdef receive(self): - cdef plist.plist_t c_node = NULL - err = MobileSyncError(mobilesync_receive(self._c_client, &(c_node))) - if err: raise err - return plist.plist_t_to_node(c_node) - -cdef extern from *: - ctypedef char* const_char_ptr "const char*" - -cdef extern from "libimobiledevice/notification_proxy.h": - cdef struct np_client_int: - pass - ctypedef np_client_int *np_client_t - ctypedef int16_t np_error_t - ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) - np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) - np_error_t np_client_free(np_client_t client) - np_error_t np_post_notification(np_client_t client, char *notification) - np_error_t np_observe_notification(np_client_t client, char *notification) - np_error_t np_observe_notifications(np_client_t client, char **notification_spec) - np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata) - -cdef void np_notify_cb(const_char_ptr notification, void *py_callback): - (<object>py_callback)(notification) - -cdef class NotificationProxyError(BaseError): - pass - -cdef class NotificationProxy: - cdef np_client_t _c_client - - def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): - cdef iDevice dev = device - cdef LockdownClient lckd - if lockdown is None: - lckd = LockdownClient(dev) - else: - lckd = lockdown - port = lckd.start_service("com.apple.mobile.notification_proxy") - err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) - if err: raise err - - def __dealloc__(self): - if self._c_client is not NULL: - err = NotificationProxyError(np_client_free(self._c_client)) - if err: raise err - - def set_notify_callback(self, callback): - err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) - if err: raise err - - def observe_notification(self, notification): - err = NotificationProxyError(np_observe_notification(self._c_client, notification)) - if err: raise err - -cdef extern from "libimobiledevice/sbservices.h": - cdef struct sbservices_client_int: - pass - ctypedef sbservices_client_int *sbservices_client_t - ctypedef int16_t sbservices_error_t - sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) - sbservices_error_t sbservices_client_free(sbservices_client_t client) - sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state) - sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate) - sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) - -cdef class SpringboardServicesError(BaseError): - pass - -cdef class SpringboardServices: - cdef sbservices_client_t _c_client - - def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): - cdef iDevice dev = device - cdef LockdownClient lckd - if lockdown is None: - lckd = LockdownClient(dev) - else: - lckd = lockdown - port = lockdown.start_service("com.apple.springboardservices") - err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) - if err: raise err - - def __dealloc__(self): - if self._c_client is not NULL: - err = SpringboardServicesError(sbservices_client_free(self._c_client)) - if err: raise err +include "property_list_service.pxi" +include "mobilesync.pxi" +include "notification_proxy.pxi" +include "sbservices.pxi" +include "mobilebackup.pxi" 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 @@ +cdef extern from "libimobiledevice/mobilebackup.h": + cdef struct mobilebackup_client_int: + pass + ctypedef mobilebackup_client_int *mobilebackup_client_t + + ctypedef int16_t mobilebackup_error_t + int16_t MOBILEBACKUP_E_SUCCESS + int16_t MOBILEBACKUP_E_INVALID_ARG + int16_t MOBILEBACKUP_E_PLIST_ERROR + int16_t MOBILEBACKUP_E_MUX_ERROR + int16_t MOBILEBACKUP_E_BAD_VERSION + int16_t MOBILEBACKUP_E_UNKNOWN_ERROR + + mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client) + mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) + mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist.plist_t *plist) + mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist.plist_t plist) + +cdef class MobileBackupError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + MOBILEBACKUP_E_SUCCESS: "Success", + MOBILEBACKUP_E_INVALID_ARG: "Invalid argument", + MOBILEBACKUP_E_PLIST_ERROR: "PList Error", + MOBILEBACKUP_E_MUX_ERROR: "MUX Error", + MOBILEBACKUP_E_BAD_VERSION: "Bad Version", + MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class MobileBackupClient(PropertyListService): + cdef mobilebackup_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef iDevice dev = device + cdef LockdownClient lckd + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobilebackup") + err = MobileBackupError(mobilebackup_client_new(dev._c_dev, port, &self._c_client)) + if err: raise err + + def __dealloc__(self): + if self._c_client is not NULL: + err = MobileBackupError(mobilebackup_client_free(self._c_client)) + if err: raise err + + cdef _send(self, plist.plist_t node): + return MobileBackupError(mobilebackup_send(self._c_client, node)) + + cdef _receive(self, plist.plist_t* node): + 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 @@ +cdef extern from "libimobiledevice/mobilesync.h": + cdef struct mobilesync_client_int: + pass + ctypedef mobilesync_client_int *mobilesync_client_t + + ctypedef int16_t mobilesync_error_t + int16_t MOBILESYNC_E_SUCCESS + int16_t MOBILESYNC_E_INVALID_ARG + int16_t MOBILESYNC_E_PLIST_ERROR + int16_t MOBILESYNC_E_MUX_ERROR + int16_t MOBILESYNC_E_BAD_VERSION + int16_t MOBILESYNC_E_UNKNOWN_ERROR + + mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) + mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) + mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) + mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) + +cdef class MobileSyncError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + MOBILESYNC_E_SUCCESS: "Success", + MOBILESYNC_E_INVALID_ARG: "Invalid argument", + MOBILESYNC_E_PLIST_ERROR: "PList Error", + MOBILESYNC_E_MUX_ERROR: "MUX Error", + MOBILESYNC_E_BAD_VERSION: "Bad Version", + MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class MobileSyncClient(PropertyListService): + cdef mobilesync_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef iDevice dev = device + cdef LockdownClient lckd + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobilesync") + err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) + if err: raise err + + def __dealloc__(self): + if self._c_client is not NULL: + err = MobileSyncError(mobilesync_client_free(self._c_client)) + if err: raise err + + cdef _send(self, plist.plist_t node): + return MobileSyncError(mobilesync_send(self._c_client, node)) + + cdef _receive(self, plist.plist_t* node): + 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 @@ +cdef extern from *: + ctypedef char* const_char_ptr "const char*" + +cdef extern from "libimobiledevice/notification_proxy.h": + cdef struct np_client_int: + pass + ctypedef np_client_int *np_client_t + ctypedef int16_t np_error_t + ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) + np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) + np_error_t np_client_free(np_client_t client) + np_error_t np_post_notification(np_client_t client, char *notification) + np_error_t np_observe_notification(np_client_t client, char *notification) + np_error_t np_observe_notifications(np_client_t client, char **notification_spec) + np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata) + +cdef void np_notify_cb(const_char_ptr notification, void *py_callback): + (<object>py_callback)(notification) + +cdef class NotificationProxyError(BaseError): + pass + +cdef class NotificationProxy: + cdef np_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef iDevice dev = device + cdef LockdownClient lckd + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobile.notification_proxy") + err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) + if err: raise err + + def __dealloc__(self): + if self._c_client is not NULL: + err = NotificationProxyError(np_client_free(self._c_client)) + if err: raise err + + cpdef set_notify_callback(self, object callback): + err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) + if err: raise err + + cpdef observe_notification(self, bytes notification): + err = NotificationProxyError(np_observe_notification(self._c_client, notification)) + if err: raise err + + cpdef post_notification(self, bytes notification): + err = NotificationProxyError(np_post_notification(self._c_client, notification)) + 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 @@ +cdef class PropertyListService: + cpdef send(self, plist.Node node): + cdef plist.Node n = node + cdef BaseError err = self._send(n._c_node) + if err: raise err + + cpdef plist.Node receive(self): + cdef plist.plist_t c_node = NULL + cdef BaseError err = self._receive(&c_node) + if err: raise err + + return plist.plist_t_to_node(c_node) + + cdef _send(self, plist.plist_t node): pass + 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 @@ +cdef extern from "libimobiledevice/sbservices.h": + cdef struct sbservices_client_int: + pass + ctypedef sbservices_client_int *sbservices_client_t + ctypedef int16_t sbservices_error_t + sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) + sbservices_error_t sbservices_client_free(sbservices_client_t client) + sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state) + sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate) + sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) + +cdef class SpringboardServicesError(BaseError): + pass + +cdef class SpringboardServices: + cdef sbservices_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef iDevice dev = device + cdef LockdownClient lckd + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lockdown.start_service("com.apple.springboardservices") + err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) + if err: raise err + + def __dealloc__(self): + if self._c_client is not NULL: + err = SpringboardServicesError(sbservices_client_free(self._c_client)) + if err: raise err + + property icon_state: + def __get__(self): + cdef plist.plist_t c_node = NULL + cdef plist.Node node + cdef SpringboardServicesError err = \ + SpringboardServicesError(sbservices_get_icon_state(self._c_client, &c_node)) + if err: raise err + node = plist.plist_t_to_node(c_node) + return node + def __set__(self, plist.Node newstate not None): + cdef plist.Node node = newstate + cdef SpringboardServicesError err = \ + SpringboardServicesError(sbservices_set_icon_state(self._c_client, node._c_node)) + if err: raise err + + cpdef bytes get_pngdata(self, bytes bundleId): + cdef bytes result + cdef char* pngdata = NULL + cdef uint64_t pngsize + cdef SpringboardServicesError err = \ + SpringboardServicesError(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) + if err: raise err + result = pngdata[:pngsize] + 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 @@ +cdef extern from *: + ctypedef unsigned char uint8_t + ctypedef short int int16_t + ctypedef unsigned short int uint16_t + ctypedef unsigned int uint32_t + ctypedef int int32_t +IF UNAME_MACHINE == 'x86_64': + ctypedef unsigned long int uint64_t +ELSE: + ctypedef unsigned long long int uint64_t |