diff options
| author | 2010-03-31 14:19:38 -0500 | |
|---|---|---|
| committer | 2012-03-20 23:25:55 +0100 | |
| commit | 23954a2b28e6f763a83524a85ead4716620ee7cc (patch) | |
| tree | 33a4a940c26d7b7a228400ffcf6abbc0435958ae /cython/screenshotr.pxi | |
| parent | 7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95 (diff) | |
| download | libimobiledevice-23954a2b28e6f763a83524a85ead4716620ee7cc.tar.gz libimobiledevice-23954a2b28e6f763a83524a85ead4716620ee7cc.tar.bz2 | |
Added all remaining classes from libimobiledevice.
Diffstat (limited to 'cython/screenshotr.pxi')
| -rw-r--r-- | cython/screenshotr.pxi | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/cython/screenshotr.pxi b/cython/screenshotr.pxi new file mode 100644 index 0000000..92d95b9 --- /dev/null +++ b/cython/screenshotr.pxi | |||
| @@ -0,0 +1,65 @@ | |||
| 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_BAD_VERSION = -4 | ||
| 12 | SCREENSHOTR_E_UNKNOWN_ERROR = -256 | ||
| 13 | |||
| 14 | screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, screenshotr_client_t * client) | ||
| 15 | screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) | ||
| 16 | screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) | ||
| 17 | |||
| 18 | cdef class ScreenshotrError(BaseError): | ||
| 19 | def __init__(self, *args, **kwargs): | ||
| 20 | self._lookup_table = { | ||
| 21 | SCREENSHOTR_E_SUCCESS: "Success", | ||
| 22 | SCREENSHOTR_E_INVALID_ARG: "Invalid argument", | ||
| 23 | SCREENSHOTR_E_PLIST_ERROR: "Property list error", | ||
| 24 | SCREENSHOTR_E_MUX_ERROR: "MUX error", | ||
| 25 | SCREENSHOTR_E_BAD_VERSION: "Bad version", | ||
| 26 | SCREENSHOTR_E_UNKNOWN_ERROR: "Unknown error" | ||
| 27 | } | ||
| 28 | BaseError.__init__(self, *args, **kwargs) | ||
| 29 | |||
| 30 | cdef class ScreenshotrClient(Base): | ||
| 31 | cdef screenshotr_client_t _c_client | ||
| 32 | |||
| 33 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 34 | cdef: | ||
| 35 | iDevice dev = device | ||
| 36 | LockdownClient lckd | ||
| 37 | screenshotr_error_t err | ||
| 38 | if lockdown is None: | ||
| 39 | lckd = LockdownClient(dev) | ||
| 40 | else: | ||
| 41 | lckd = lockdown | ||
| 42 | port = lckd.start_service("com.apple.mobile.screenshotr") | ||
| 43 | err = screenshotr_client_new(dev._c_dev, port, &self._c_client) | ||
| 44 | self.handle_error(err) | ||
| 45 | |||
| 46 | def __dealloc__(self): | ||
| 47 | cdef screenshotr_error_t err | ||
| 48 | if self._c_client is not NULL: | ||
| 49 | err = screenshotr_client_free(self._c_client) | ||
| 50 | self.handle_error(err) | ||
| 51 | |||
| 52 | cpdef bytes take_screenshot(self): | ||
| 53 | cdef: | ||
| 54 | char* c_data | ||
| 55 | uint64_t data_size | ||
| 56 | bytes result | ||
| 57 | screenshotr_error_t err | ||
| 58 | |||
| 59 | err = screenshotr_take_screenshot(self._c_client, &c_data, &data_size) | ||
| 60 | self.handle_error(err) | ||
| 61 | result = c_data[:data_size] | ||
| 62 | return result | ||
| 63 | |||
| 64 | cdef inline BaseError _error(self, int16_t ret): | ||
| 65 | return ScreenshotrError(ret) | ||
