diff options
Diffstat (limited to 'cython/screenshotr.pxi')
-rw-r--r-- | cython/screenshotr.pxi | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cython/screenshotr.pxi b/cython/screenshotr.pxi new file mode 100644 index 0000000..a1e82e2 --- /dev/null +++ b/cython/screenshotr.pxi | |||
@@ -0,0 +1,66 @@ | |||
1 | cdef extern from "libimobiledevice/screenshotr.h": | ||
2 | cdef struct screenshotr_client_private: | ||
3 | pass | ||
4 | ctypedef screenshotr_client_private *screenshotr_client_t | ||
5 | |||
6 | ctypedef enum screenshotr_error_t: | ||
7 | SCREENSHOTR_E_SUCCESS = 0 | ||
8 | SCREENSHOTR_E_INVALID_ARG = -1 | ||
9 | SCREENSHOTR_E_PLIST_ERROR = -2 | ||
10 | SCREENSHOTR_E_MUX_ERROR = -3 | ||
11 | SCREENSHOTR_E_SSL_ERROR = -4 | ||
12 | SCREENSHOTR_E_RECEIVE_TIMEOUT = 5 | ||
13 | SCREENSHOTR_E_BAD_VERSION = -6 | ||
14 | SCREENSHOTR_E_UNKNOWN_ERROR = -256 | ||
15 | |||
16 | screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, screenshotr_client_t * client) | ||
17 | screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) | ||
18 | screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) | ||
19 | |||
20 | cdef class ScreenshotrError(BaseError): | ||
21 | def __init__(self, *args, **kwargs): | ||
22 | self._lookup_table = { | ||
23 | SCREENSHOTR_E_SUCCESS: "Success", | ||
24 | SCREENSHOTR_E_INVALID_ARG: "Invalid argument", | ||
25 | SCREENSHOTR_E_PLIST_ERROR: "Property list error", | ||
26 | SCREENSHOTR_E_MUX_ERROR: "MUX error", | ||
27 | SCREENSHOTR_E_SSL_ERROR: "SSL error", | ||
28 | SCREENSHOTR_E_RECEIVE_TIMEOUT: "Receive timeout", | ||
29 | SCREENSHOTR_E_BAD_VERSION: "Bad version", | ||
30 | SCREENSHOTR_E_UNKNOWN_ERROR: "Unknown error" | ||
31 | } | ||
32 | BaseError.__init__(self, *args, **kwargs) | ||
33 | |||
34 | cdef class ScreenshotrClient(DeviceLinkService): | ||
35 | __service_name__ = "com.apple.mobile.screenshotr" | ||
36 | cdef screenshotr_client_t _c_client | ||
37 | |||
38 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
39 | self.handle_error(screenshotr_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
40 | |||
41 | def __dealloc__(self): | ||
42 | cdef screenshotr_error_t err | ||
43 | if self._c_client is not NULL: | ||
44 | err = screenshotr_client_free(self._c_client) | ||
45 | self.handle_error(err) | ||
46 | |||
47 | cpdef bytes take_screenshot(self): | ||
48 | cdef: | ||
49 | char* c_data = NULL | ||
50 | uint64_t data_size | ||
51 | bytes result | ||
52 | screenshotr_error_t err | ||
53 | |||
54 | err = screenshotr_take_screenshot(self._c_client, &c_data, &data_size) | ||
55 | try: | ||
56 | self.handle_error(err) | ||
57 | |||
58 | result = c_data[:data_size] | ||
59 | return result | ||
60 | except Exception, e: | ||
61 | if c_data != NULL: | ||
62 | free(c_data) | ||
63 | raise | ||
64 | |||
65 | cdef inline BaseError _error(self, int16_t ret): | ||
66 | return ScreenshotrError(ret) | ||