summaryrefslogtreecommitdiffstats
path: root/cython/notification_proxy.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/notification_proxy.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/notification_proxy.pxi')
-rw-r--r--cython/notification_proxy.pxi50
1 files changed, 33 insertions, 17 deletions
diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi
index acccf7d..2ca484a 100644
--- a/cython/notification_proxy.pxi
+++ b/cython/notification_proxy.pxi
@@ -5,7 +5,12 @@ cdef extern from "libimobiledevice/notification_proxy.h":
5 cdef struct np_client_int: 5 cdef struct np_client_int:
6 pass 6 pass
7 ctypedef np_client_int *np_client_t 7 ctypedef np_client_int *np_client_t
8 ctypedef int16_t np_error_t 8 ctypedef enum np_error_t:
9 NP_E_SUCCESS = 0
10 NP_E_INVALID_ARG = -1
11 NP_E_PLIST_ERROR = -2
12 NP_E_CONN_FAILED = -3
13 NP_E_UNKNOWN_ERROR = -256
9 ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) 14 ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata)
10 np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) 15 np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
11 np_error_t np_client_free(np_client_t client) 16 np_error_t np_client_free(np_client_t client)
@@ -18,35 +23,46 @@ cdef void np_notify_cb(const_char_ptr notification, void *py_callback):
18 (<object>py_callback)(notification) 23 (<object>py_callback)(notification)
19 24
20cdef class NotificationProxyError(BaseError): 25cdef class NotificationProxyError(BaseError):
21 pass 26 def __init__(self, *args, **kwargs):
27 self._lookup_table = {
28 NP_E_SUCCESS: "Success",
29 NP_E_INVALID_ARG: "Invalid argument",
30 NP_E_PLIST_ERROR: "PList Error",
31 NP_E_CONN_FAILED: "Connection Failed",
32 NP_E_UNKNOWN_ERROR: "Unknown Error"
33 }
34 BaseError.__init__(self, *args, **kwargs)
22 35
23cdef class NotificationProxy: 36cdef class NotificationProxy(Base):
24 cdef np_client_t _c_client 37 cdef np_client_t _c_client
25 38
26 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): 39 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
27 cdef iDevice dev = device 40 cdef:
28 cdef LockdownClient lckd 41 iDevice dev = device
42 LockdownClient lckd
43 np_error_t err
29 if lockdown is None: 44 if lockdown is None:
30 lckd = LockdownClient(dev) 45 lckd = LockdownClient(dev)
31 else: 46 else:
32 lckd = lockdown 47 lckd = lockdown
33 port = lckd.start_service("com.apple.mobile.notification_proxy") 48 port = lckd.start_service("com.apple.mobile.notification_proxy")
34 err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) 49 err = np_client_new(dev._c_dev, port, &self._c_client)
35 if err: raise err 50 self.handle_error(err)
36 51
37 def __dealloc__(self): 52 def __dealloc__(self):
53 cdef np_error_t err
38 if self._c_client is not NULL: 54 if self._c_client is not NULL:
39 err = NotificationProxyError(np_client_free(self._c_client)) 55 err = np_client_free(self._c_client)
40 if err: raise err 56 self.handle_error(err)
41 57
58 cdef inline BaseError _error(self, int16_t ret):
59 return NotificationProxyError(ret)
60
42 cpdef set_notify_callback(self, object callback): 61 cpdef set_notify_callback(self, object callback):
43 err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) 62 self.handle_error(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback))
44 if err: raise err 63
45
46 cpdef observe_notification(self, bytes notification): 64 cpdef observe_notification(self, bytes notification):
47 err = NotificationProxyError(np_observe_notification(self._c_client, notification)) 65 self.handle_error(np_observe_notification(self._c_client, notification))
48 if err: raise err
49 66
50 cpdef post_notification(self, bytes notification): 67 cpdef post_notification(self, bytes notification):
51 err = NotificationProxyError(np_post_notification(self._c_client, notification)) 68 self.handle_error(np_post_notification(self._c_client, notification))
52 if err: raise err