summaryrefslogtreecommitdiffstats
path: root/cython/sbservices.pxi
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/sbservices.pxi
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/sbservices.pxi')
-rw-r--r--cython/sbservices.pxi47
1 files changed, 29 insertions, 18 deletions
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