diff options
Diffstat (limited to 'cython/sbservices.pxi')
-rw-r--r-- | cython/sbservices.pxi | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi new file mode 100644 index 0000000..8ff2595 --- /dev/null +++ b/cython/sbservices.pxi | |||
@@ -0,0 +1,80 @@ | |||
1 | cdef extern from "libimobiledevice/sbservices.h": | ||
2 | cdef struct sbservices_client_private: | ||
3 | pass | ||
4 | ctypedef sbservices_client_private *sbservices_client_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 | ||
11 | sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, sbservices_client_t *client) | ||
12 | sbservices_error_t sbservices_client_free(sbservices_client_t client) | ||
13 | sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state, char *format_version) | ||
14 | sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate) | ||
15 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) | ||
16 | |||
17 | cdef class SpringboardServicesError(BaseError): | ||
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: "Property list error", | ||
23 | SBSERVICES_E_CONN_FAILED: "Connection failed", | ||
24 | SBSERVICES_E_UNKNOWN_ERROR: "Unknown error" | ||
25 | } | ||
26 | BaseError.__init__(self, *args, **kwargs) | ||
27 | |||
28 | cdef class SpringboardServicesClient(PropertyListService): | ||
29 | __service_name__ = "com.apple.springboardservices" | ||
30 | cdef sbservices_client_t _c_client | ||
31 | cdef char* format_version | ||
32 | |||
33 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
34 | self.handle_error(sbservices_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
35 | self.format_version = "2" | ||
36 | |||
37 | def __dealloc__(self): | ||
38 | if self._c_client is not NULL: | ||
39 | err = sbservices_client_free(self._c_client) | ||
40 | self.handle_error(err) | ||
41 | |||
42 | cdef inline BaseError _error(self, int16_t ret): | ||
43 | return SpringboardServicesError(ret) | ||
44 | |||
45 | property format_version: | ||
46 | def __get__(self): | ||
47 | return <bytes>self.format_version | ||
48 | def __set__(self, char* newversion): | ||
49 | self.format_version = newversion | ||
50 | |||
51 | property icon_state: | ||
52 | def __get__(self): | ||
53 | cdef: | ||
54 | plist.plist_t c_node = NULL | ||
55 | sbservices_error_t err | ||
56 | err = sbservices_get_icon_state(self._c_client, &c_node, self.format_version) | ||
57 | try: | ||
58 | self.handle_error(err) | ||
59 | |||
60 | return plist.plist_t_to_node(c_node) | ||
61 | except BaseError, e: | ||
62 | if c_node != NULL: | ||
63 | plist.plist_free(c_node) | ||
64 | raise | ||
65 | def __set__(self, plist.Node newstate not None): | ||
66 | self.handle_error(sbservices_set_icon_state(self._c_client, newstate._c_node)) | ||
67 | |||
68 | cpdef bytes get_pngdata(self, bytes bundleId): | ||
69 | cdef: | ||
70 | char* pngdata = NULL | ||
71 | uint64_t pngsize | ||
72 | sbservices_error_t err | ||
73 | err = sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize) | ||
74 | try: | ||
75 | self.handle_error(err) | ||
76 | |||
77 | return pngdata[:pngsize] | ||
78 | except BaseError, e: | ||
79 | free(pngdata) | ||
80 | raise | ||