summaryrefslogtreecommitdiffstats
path: root/cython
diff options
context:
space:
mode:
authorGravatar Bryan Forbes2010-03-18 20:50:26 -0500
committerGravatar Martin Szulecki2012-03-20 23:25:54 +0100
commit7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95 (patch)
tree4268abec171becef6befdfc5bd0a1ffc46d1962a /cython
parent68c63cc1382326e7f0cb4e6bd863427f9069ca05 (diff)
downloadlibimobiledevice-7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95.tar.gz
libimobiledevice-7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95.tar.bz2
Added afc.pxi.
More errors handled. Changed error codes to enums in cython defs.
Diffstat (limited to 'cython')
-rw-r--r--cython/Makefile.am15
-rw-r--r--cython/afc.pxi165
-rw-r--r--cython/imobiledevice.pxd1
-rw-r--r--cython/imobiledevice.pyx60
-rw-r--r--cython/mobilebackup.pxi14
-rw-r--r--cython/mobilesync.pxi14
-rw-r--r--cython/notification_proxy.pxi50
-rw-r--r--cython/property_list_client.pxi2
-rw-r--r--cython/sbservices.pxi47
-rw-r--r--cython/stdint.pxi2
10 files changed, 283 insertions, 87 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am
index 1a71fbe..c0ebff6 100644
--- a/cython/Makefile.am
+++ b/cython/Makefile.am
@@ -7,13 +7,14 @@ 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 \
- property_list_client.pxi
+PXIINCLUDES = \
+ stdint.pxi \
+ mobilesync.pxi \
+ notification_proxy.pxi \
+ sbservices.pxi \
+ mobilebackup.pxi \
+ property_list_client.pxi \
+ afc.pxi
CLEANFILES = \
*.pyc \
diff --git a/cython/afc.pxi b/cython/afc.pxi
new file mode 100644
index 0000000..51251c8
--- /dev/null
+++ b/cython/afc.pxi
@@ -0,0 +1,165 @@
+cdef extern from "libimobiledevice/afc.h":
+ cdef struct afc_client_int:
+ pass
+ ctypedef afc_client_int *afc_client_t
+ ctypedef enum afc_error_t:
+ AFC_E_SUCCESS = 0
+ AFC_E_UNKNOWN_ERROR = 1
+ AFC_E_OP_HEADER_INVALID = 2
+ AFC_E_NO_RESOURCES = 3
+ AFC_E_READ_ERROR = 4
+ AFC_E_WRITE_ERROR = 5
+ AFC_E_UNKNOWN_PACKET_TYPE = 6
+ AFC_E_INVALID_ARGUMENT = 7
+ AFC_E_OBJECT_NOT_FOUND = 8
+ AFC_E_OBJECT_IS_DIR = 9
+ AFC_E_PERM_DENIED = 10
+ AFC_E_SERVICE_NOT_CONNECTED = 11
+ AFC_E_OP_TIMEOUT = 12
+ AFC_E_TOO_MUCH_DATA = 13
+ AFC_E_END_OF_DATA = 14
+ AFC_E_OP_NOT_SUPPORTED = 15
+ AFC_E_OBJECT_EXISTS = 16
+ AFC_E_OBJECT_BUSY = 17
+ AFC_E_NO_SPACE_LEFT = 18
+ AFC_E_OP_WOULD_BLOCK = 19
+ AFC_E_IO_ERROR = 20
+ AFC_E_OP_INTERRUPTED = 21
+ AFC_E_OP_IN_PROGRESS = 22
+ AFC_E_INTERNAL_ERROR = 23
+ AFC_E_MUX_ERROR = 30
+ AFC_E_NO_MEM = 31
+ AFC_E_NOT_ENOUGH_DATA = 32
+ AFC_E_DIR_NOT_EMPTY = 33
+ ctypedef enum afc_file_mode_t:
+ AFC_FOPEN_RDONLY = 0x00000001
+ AFC_FOPEN_RW = 0x00000002
+ AFC_FOPEN_WRONLY = 0x00000003
+ AFC_FOPEN_WR = 0x00000004
+ AFC_FOPEN_APPEND = 0x00000005
+ AFC_FOPEN_RDAPPEND = 0x00000006
+ ctypedef enum afc_link_type_t:
+ AFC_HARDLINK = 1
+ AFC_SYMLINK = 2
+ ctypedef enum afc_lock_op_t:
+ AFC_LOCK_SH = 1 | 4
+ AFC_LOCK_EX = 2 | 4
+ AFC_LOCK_UN = 8 | 4
+
+ afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t *client)
+ afc_error_t afc_client_free(afc_client_t client)
+ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
+ afc_error_t afc_read_directory(afc_client_t client, char *dir, char ***list)
+ afc_error_t afc_get_file_info(afc_client_t client, char *filename, char ***infolist)
+ afc_error_t afc_file_open(afc_client_t client, char *filename, afc_file_mode_t file_mode, uint64_t *handle)
+ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
+ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation)
+ afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read)
+ afc_error_t afc_file_write(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_written)
+ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence)
+ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)
+ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize)
+ afc_error_t afc_remove_path(afc_client_t client, char *path)
+ afc_error_t afc_rename_path(afc_client_t client, char *f, char *to)
+ afc_error_t afc_make_directory(afc_client_t client, char *dir)
+ afc_error_t afc_truncate(afc_client_t client, char *path, uint64_t newsize)
+ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, char *target, char *linkname)
+ afc_error_t afc_set_file_time(afc_client_t client, char *path, uint64_t mtime)
+
+cdef extern from *:
+ void free(void *ptr)
+
+cdef class AfcError(BaseError):
+ def __init__(self, *args, **kwargs):
+ self._lookup_table = {
+ AFC_E_SUCCESS: "Success",
+ AFC_E_UNKNOWN_ERROR: "Unknown error",
+ AFC_E_OP_HEADER_INVALID: "OP header invalid",
+ AFC_E_NO_RESOURCES: "No resources",
+ AFC_E_READ_ERROR: "Read error",
+ AFC_E_WRITE_ERROR: "Write error",
+ AFC_E_UNKNOWN_PACKET_TYPE: "Unknown packet type",
+ AFC_E_INVALID_ARGUMENT: "Invalid argument",
+ AFC_E_OBJECT_NOT_FOUND: "Object not found",
+ AFC_E_OBJECT_IS_DIR: "Object is directory",
+ AFC_E_PERM_DENIED: "Permission denied",
+ AFC_E_SERVICE_NOT_CONNECTED: "Service not connected",
+ AFC_E_OP_TIMEOUT: "OP timeout",
+ AFC_E_TOO_MUCH_DATA: "Too much data",
+ AFC_E_END_OF_DATA: "End of data",
+ AFC_E_OP_NOT_SUPPORTED: "OP not supported",
+ AFC_E_OBJECT_EXISTS: "Object exists",
+ AFC_E_OBJECT_BUSY: "Object busy",
+ AFC_E_NO_SPACE_LEFT: "No space left",
+ AFC_E_OP_WOULD_BLOCK: "OP would block",
+ AFC_E_IO_ERROR: "IO error",
+ AFC_E_OP_INTERRUPTED: "OP interrupted",
+ AFC_E_OP_IN_PROGRESS: "OP in progress",
+ AFC_E_INTERNAL_ERROR: "Internal error",
+ AFC_E_MUX_ERROR: "MUX error",
+ AFC_E_NO_MEM: "No memory",
+ AFC_E_NOT_ENOUGH_DATA: "Not enough data",
+ AFC_E_DIR_NOT_EMPTY: "Directory not empty"
+ }
+ BaseError.__init__(self, *args, **kwargs)
+
+cdef class AfcClient(Base):
+ cdef afc_client_t _c_client
+
+ def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
+ cdef:
+ iDevice dev = device
+ LockdownClient lckd
+ afc_error_t err
+ if lockdown is None:
+ lckd = LockdownClient(dev)
+ else:
+ lckd = lockdown
+ port = lckd.start_service("com.apple.afc")
+ err = afc_client_new(dev._c_dev, port, &(self._c_client))
+ self.handle_error(err)
+
+ def __dealloc__(self):
+ cdef afc_error_t err
+ if self._c_client is not NULL:
+ err = afc_client_free(self._c_client)
+ self.handle_error(err)
+
+ cdef inline BaseError _error(self, int16_t ret):
+ return AfcError(ret)
+
+ cpdef list get_device_info(self):
+ cdef:
+ afc_error_t err
+ char** infos
+ bytes info
+ int i = 0
+ list result = []
+ err = afc_get_device_info(self._c_client, &infos)
+ self.handle_error(err)
+ while infos[i]:
+ info = infos[i]
+ result.append(info)
+ free(infos[i])
+ i = i + 1
+ free(infos)
+
+ return result
+
+ cpdef list read_directory(self, bytes directory):
+ cdef:
+ afc_error_t err
+ char** dir_list
+ bytes f
+ int i = 0
+ list result = []
+ err = afc_read_directory(self._c_client, directory, &dir_list)
+ self.handle_error(err)
+ while dir_list[i]:
+ f = dir_list[i]
+ result.append(f)
+ free(dir_list[i])
+ i = i + 1
+ free(dir_list)
+
+ return result
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd
index 0557d37..8a7d6b2 100644
--- a/cython/imobiledevice.pxd
+++ b/cython/imobiledevice.pxd
@@ -20,7 +20,6 @@ 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
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx
index c6a96dd..ecf94e1 100644
--- a/cython/imobiledevice.pyx
+++ b/cython/imobiledevice.pyx
@@ -30,13 +30,14 @@ cdef class Base:
cdef inline BaseError _error(self, int16_t ret): pass
cdef extern from "libimobiledevice/libimobiledevice.h":
- int16_t IDEVICE_E_SUCCESS
- int16_t IDEVICE_E_INVALID_ARG
- int16_t IDEVICE_E_UNKNOWN_ERROR
- int16_t IDEVICE_E_NO_DEVICE
- int16_t IDEVICE_E_NOT_ENOUGH_DATA
- int16_t IDEVICE_E_BAD_HEADER
- int16_t IDEVICE_E_SSL_ERROR
+ ctypedef enum idevice_error_t:
+ IDEVICE_E_SUCCESS = 0
+ IDEVICE_E_INVALID_ARG = -1
+ IDEVICE_E_UNKNOWN_ERROR = -2
+ IDEVICE_E_NO_DEVICE = -3
+ IDEVICE_E_NOT_ENOUGH_DATA = -4
+ IDEVICE_E_BAD_HEADER = -5
+ IDEVICE_E_SSL_ERROR = -6
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()
@@ -49,7 +50,7 @@ cdef extern from "libimobiledevice/libimobiledevice.h":
idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)
cdef class iDeviceError(BaseError):
- def __cinit__(self, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
self._lookup_table = {
IDEVICE_E_SUCCESS: 'Success',
IDEVICE_E_INVALID_ARG: 'Invalid argument',
@@ -133,27 +134,27 @@ cdef extern from "libimobiledevice/lockdown.h":
cdef struct lockdownd_client_int:
pass
ctypedef lockdownd_client_int *lockdownd_client_t
- ctypedef int16_t lockdownd_error_t
- int16_t LOCKDOWN_E_SUCCESS
- int16_t LOCKDOWN_E_INVALID_ARG
- int16_t LOCKDOWN_E_INVALID_CONF
- int16_t LOCKDOWN_E_PLIST_ERROR
- int16_t LOCKDOWN_E_PAIRING_FAILED
- int16_t LOCKDOWN_E_SSL_ERROR
- int16_t LOCKDOWN_E_DICT_ERROR
- int16_t LOCKDOWN_E_START_SERVICE_FAILED
- int16_t LOCKDOWN_E_NOT_ENOUGH_DATA
- int16_t LOCKDOWN_E_SET_VALUE_PROHIBITED
- int16_t LOCKDOWN_E_GET_VALUE_PROHIBITED
- int16_t LOCKDOWN_E_REMOVE_VALUE_PROHIBITED
- int16_t LOCKDOWN_E_MUX_ERROR
- int16_t LOCKDOWN_E_ACTIVATION_FAILED
- int16_t LOCKDOWN_E_PASSWORD_PROTECTED
- int16_t LOCKDOWN_E_NO_RUNNING_SESSION
- int16_t LOCKDOWN_E_INVALID_HOST_ID
- int16_t LOCKDOWN_E_INVALID_SERVICE
- int16_t LOCKDOWN_E_INVALID_ACTIVATION_RECORD
- int16_t LOCKDOWN_E_UNKNOWN_ERROR
+ ctypedef enum lockdownd_error_t:
+ LOCKDOWN_E_SUCCESS = 0
+ LOCKDOWN_E_INVALID_ARG = -1
+ LOCKDOWN_E_INVALID_CONF = -2
+ LOCKDOWN_E_PLIST_ERROR = -3
+ LOCKDOWN_E_PAIRING_FAILED = -4
+ LOCKDOWN_E_SSL_ERROR = -5
+ LOCKDOWN_E_DICT_ERROR = -6
+ LOCKDOWN_E_START_SERVICE_FAILED = -7
+ LOCKDOWN_E_NOT_ENOUGH_DATA = -8
+ LOCKDOWN_E_SET_VALUE_PROHIBITED = -9
+ LOCKDOWN_E_GET_VALUE_PROHIBITED = -10
+ LOCKDOWN_E_REMOVE_VALUE_PROHIBITED = -11
+ LOCKDOWN_E_MUX_ERROR = -12
+ LOCKDOWN_E_ACTIVATION_FAILED = -13
+ LOCKDOWN_E_PASSWORD_PROTECTED = -14
+ LOCKDOWN_E_NO_RUNNING_SESSION = -15
+ LOCKDOWN_E_INVALID_HOST_ID = -16
+ LOCKDOWN_E_INVALID_SERVICE = -17
+ LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -18
+ LOCKDOWN_E_UNKNOWN_ERROR = -256
lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, char *label)
lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
@@ -217,3 +218,4 @@ include "mobilesync.pxi"
include "notification_proxy.pxi"
include "sbservices.pxi"
include "mobilebackup.pxi"
+include "afc.pxi"
diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi
index f6b13a9..53a4b6f 100644
--- a/cython/mobilebackup.pxi
+++ b/cython/mobilebackup.pxi
@@ -3,13 +3,13 @@ cdef extern from "libimobiledevice/mobilebackup.h":
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
+ ctypedef enum mobilebackup_error_t:
+ MOBILEBACKUP_E_SUCCESS = 0
+ MOBILEBACKUP_E_INVALID_ARG = -1
+ MOBILEBACKUP_E_PLIST_ERROR = -2
+ MOBILEBACKUP_E_MUX_ERROR = -3
+ MOBILEBACKUP_E_BAD_VERSION = -4
+ MOBILEBACKUP_E_UNKNOWN_ERROR = -256
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)
diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi
index abd56b4..87539d2 100644
--- a/cython/mobilesync.pxi
+++ b/cython/mobilesync.pxi
@@ -3,13 +3,13 @@ cdef extern from "libimobiledevice/mobilesync.h":
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
+ ctypedef enum mobilesync_error_t:
+ MOBILESYNC_E_SUCCESS = 0
+ MOBILESYNC_E_INVALID_ARG = -1
+ MOBILESYNC_E_PLIST_ERROR = -2
+ MOBILESYNC_E_MUX_ERROR = -3
+ MOBILESYNC_E_BAD_VERSION = -4
+ MOBILESYNC_E_UNKNOWN_ERROR = -256
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)
diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi
index acccf7d..2ca484a 100644
--- a/cython/notification_proxy.pxi
+++ b/cython/notification_proxy.pxi
@@ -5,7 +5,12 @@ 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 enum np_error_t:
+ NP_E_SUCCESS = 0
+ NP_E_INVALID_ARG = -1
+ NP_E_PLIST_ERROR = -2
+ NP_E_CONN_FAILED = -3
+ NP_E_UNKNOWN_ERROR = -256
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)
@@ -18,35 +23,46 @@ cdef void np_notify_cb(const_char_ptr notification, void *py_callback):
(<object>py_callback)(notification)
cdef class NotificationProxyError(BaseError):
- pass
+ def __init__(self, *args, **kwargs):
+ self._lookup_table = {
+ NP_E_SUCCESS: "Success",
+ NP_E_INVALID_ARG: "Invalid argument",
+ NP_E_PLIST_ERROR: "PList Error",
+ NP_E_CONN_FAILED: "Connection Failed",
+ NP_E_UNKNOWN_ERROR: "Unknown Error"
+ }
+ BaseError.__init__(self, *args, **kwargs)
-cdef class NotificationProxy:
+cdef class NotificationProxy(Base):
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
+ cdef:
+ iDevice dev = device
+ LockdownClient lckd
+ np_error_t err
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
+ err = np_client_new(dev._c_dev, port, &self._c_client)
+ self.handle_error(err)
def __dealloc__(self):
+ cdef np_error_t err
if self._c_client is not NULL:
- err = NotificationProxyError(np_client_free(self._c_client))
- if err: raise err
-
+ err = np_client_free(self._c_client)
+ self.handle_error(err)
+
+ cdef inline BaseError _error(self, int16_t ret):
+ return NotificationProxyError(ret)
+
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
-
+ self.handle_error(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback))
+
cpdef observe_notification(self, bytes notification):
- err = NotificationProxyError(np_observe_notification(self._c_client, notification))
- if err: raise err
+ self.handle_error(np_observe_notification(self._c_client, notification))
cpdef post_notification(self, bytes notification):
- err = NotificationProxyError(np_post_notification(self._c_client, notification))
- if err: raise err
+ self.handle_error(np_post_notification(self._c_client, notification))
diff --git a/cython/property_list_client.pxi b/cython/property_list_client.pxi
index 2689658..874f2b5 100644
--- a/cython/property_list_client.pxi
+++ b/cython/property_list_client.pxi
@@ -3,7 +3,7 @@ cdef class PropertyListClient(Base):
cdef plist.Node n = node
self.handle_error(self._send(n._c_node))
- cpdef plist.Node receive(self):
+ cpdef object receive(self):
cdef plist.plist_t c_node = NULL
self.handle_error(self._receive(&c_node))
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi
index cb9de59..384c92b 100644
--- a/cython/sbservices.pxi
+++ b/cython/sbservices.pxi
@@ -2,7 +2,12 @@ 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
+ ctypedef enum sbservices_error_t:
+ SBSERVICES_E_SUCCESS = 0
+ SBSERVICES_E_INVALID_ARG = -1
+ SBSERVICES_E_PLIST_ERROR = -2
+ SBSERVICES_E_CONN_FAILED = -3
+ SBSERVICES_E_UNKNOWN_ERROR = -256
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)
@@ -10,7 +15,15 @@ cdef extern from "libimobiledevice/sbservices.h":
sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize)
cdef class SpringboardServicesError(BaseError):
- pass
+ def __init__(self, *args, **kwargs):
+ self._lookup_table = {
+ SBSERVICES_E_SUCCESS: "Success",
+ SBSERVICES_E_INVALID_ARG: "Invalid argument",
+ SBSERVICES_E_PLIST_ERROR: "PList Error",
+ SBSERVICES_E_CONN_FAILED: "Connection Failed",
+ SBSERVICES_E_UNKNOWN_ERROR: "Unknown Error"
+ }
+ BaseError.__init__(self, *args, **kwargs)
cdef class SpringboardServices:
cdef sbservices_client_t _c_client
@@ -23,35 +36,33 @@ cdef class SpringboardServices:
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
+ self.handle_error(sbservices_client_new(dev._c_dev, port, &(self._c_client)))
def __dealloc__(self):
if self._c_client is not NULL:
err = SpringboardServicesError(sbservices_client_free(self._c_client))
if err: raise err
+ cdef inline BaseError _error(self, int16_t ret):
+ return SpringboardServicesError(ret)
+
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
+ cdef:
+ plist.plist_t c_node = NULL
+ plist.Node node
+ self.handle_error(sbservices_get_icon_state(self._c_client, &c_node))
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
+ self.handle_error(sbservices_set_icon_state(self._c_client, node._c_node))
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
+ cdef:
+ bytes result
+ char* pngdata = NULL
+ uint64_t pngsize
+ self.handle_error(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize))
result = pngdata[:pngsize]
return result
diff --git a/cython/stdint.pxi b/cython/stdint.pxi
index e21103f..2617dec 100644
--- a/cython/stdint.pxi
+++ b/cython/stdint.pxi
@@ -5,6 +5,8 @@ cdef extern from *:
ctypedef unsigned int uint32_t
ctypedef int int32_t
IF UNAME_MACHINE == 'x86_64':
+ ctypedef long int int64_t
ctypedef unsigned long int uint64_t
ELSE:
+ ctypedef long long int int64_t
ctypedef unsigned long long int uint64_t