diff options
Diffstat (limited to 'cython/sbservices.pxi')
| -rw-r--r-- | cython/sbservices.pxi | 47 |
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": | |||
| 2 | cdef struct sbservices_client_int: | 2 | cdef struct sbservices_client_int: |
| 3 | pass | 3 | pass |
| 4 | ctypedef sbservices_client_int *sbservices_client_t | 4 | ctypedef sbservices_client_int *sbservices_client_t |
| 5 | ctypedef int16_t sbservices_error_t | 5 | ctypedef enum sbservices_error_t: |
| 6 | SBSERVICES_E_SUCCESS = 0 | ||
| 7 | SBSERVICES_E_INVALID_ARG = -1 | ||
| 8 | SBSERVICES_E_PLIST_ERROR = -2 | ||
| 9 | SBSERVICES_E_CONN_FAILED = -3 | ||
| 10 | SBSERVICES_E_UNKNOWN_ERROR = -256 | ||
| 6 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) | 11 | 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) | 12 | 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) | 13 | 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": | |||
| 10 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) | 15 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) |
| 11 | 16 | ||
| 12 | cdef class SpringboardServicesError(BaseError): | 17 | cdef class SpringboardServicesError(BaseError): |
| 13 | pass | 18 | def __init__(self, *args, **kwargs): |
| 19 | self._lookup_table = { | ||
| 20 | SBSERVICES_E_SUCCESS: "Success", | ||
| 21 | SBSERVICES_E_INVALID_ARG: "Invalid argument", | ||
| 22 | SBSERVICES_E_PLIST_ERROR: "PList Error", | ||
| 23 | SBSERVICES_E_CONN_FAILED: "Connection Failed", | ||
| 24 | SBSERVICES_E_UNKNOWN_ERROR: "Unknown Error" | ||
| 25 | } | ||
| 26 | BaseError.__init__(self, *args, **kwargs) | ||
| 14 | 27 | ||
| 15 | cdef class SpringboardServices: | 28 | cdef class SpringboardServices: |
| 16 | cdef sbservices_client_t _c_client | 29 | cdef sbservices_client_t _c_client |
| @@ -23,35 +36,33 @@ cdef class SpringboardServices: | |||
| 23 | else: | 36 | else: |
| 24 | lckd = lockdown | 37 | lckd = lockdown |
| 25 | port = lockdown.start_service("com.apple.springboardservices") | 38 | port = lockdown.start_service("com.apple.springboardservices") |
| 26 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) | 39 | self.handle_error(sbservices_client_new(dev._c_dev, port, &(self._c_client))) |
| 27 | if err: raise err | ||
| 28 | 40 | ||
| 29 | def __dealloc__(self): | 41 | def __dealloc__(self): |
| 30 | if self._c_client is not NULL: | 42 | if self._c_client is not NULL: |
| 31 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) | 43 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) |
| 32 | if err: raise err | 44 | if err: raise err |
| 33 | 45 | ||
| 46 | cdef inline BaseError _error(self, int16_t ret): | ||
| 47 | return SpringboardServicesError(ret) | ||
| 48 | |||
| 34 | property icon_state: | 49 | property icon_state: |
| 35 | def __get__(self): | 50 | def __get__(self): |
| 36 | cdef plist.plist_t c_node = NULL | 51 | cdef: |
| 37 | cdef plist.Node node | 52 | plist.plist_t c_node = NULL |
| 38 | cdef SpringboardServicesError err = \ | 53 | plist.Node node |
| 39 | SpringboardServicesError(sbservices_get_icon_state(self._c_client, &c_node)) | 54 | self.handle_error(sbservices_get_icon_state(self._c_client, &c_node)) |
| 40 | if err: raise err | ||
| 41 | node = plist.plist_t_to_node(c_node) | 55 | node = plist.plist_t_to_node(c_node) |
| 42 | return node | 56 | return node |
| 43 | def __set__(self, plist.Node newstate not None): | 57 | def __set__(self, plist.Node newstate not None): |
| 44 | cdef plist.Node node = newstate | 58 | cdef plist.Node node = newstate |
| 45 | cdef SpringboardServicesError err = \ | 59 | self.handle_error(sbservices_set_icon_state(self._c_client, node._c_node)) |
| 46 | SpringboardServicesError(sbservices_set_icon_state(self._c_client, node._c_node)) | ||
| 47 | if err: raise err | ||
| 48 | 60 | ||
| 49 | cpdef bytes get_pngdata(self, bytes bundleId): | 61 | cpdef bytes get_pngdata(self, bytes bundleId): |
| 50 | cdef bytes result | 62 | cdef: |
| 51 | cdef char* pngdata = NULL | 63 | bytes result |
| 52 | cdef uint64_t pngsize | 64 | char* pngdata = NULL |
| 53 | cdef SpringboardServicesError err = \ | 65 | uint64_t pngsize |
| 54 | SpringboardServicesError(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) | 66 | self.handle_error(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) |
| 55 | if err: raise err | ||
| 56 | result = pngdata[:pngsize] | 67 | result = pngdata[:pngsize] |
| 57 | return result | 68 | return result |
