summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/notification_proxy.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/notification_proxy.h')
-rw-r--r--include/libimobiledevice/notification_proxy.h150
1 files changed, 124 insertions, 26 deletions
diff --git a/include/libimobiledevice/notification_proxy.h b/include/libimobiledevice/notification_proxy.h
index 43c479d..f4f090b 100644
--- a/include/libimobiledevice/notification_proxy.h
+++ b/include/libimobiledevice/notification_proxy.h
@@ -3,7 +3,8 @@
3 * @brief Observe and post notifications. 3 * @brief Observe and post notifications.
4 * \internal 4 * \internal
5 * 5 *
6 * Copyright (c) 2009 Nikias Bassen All Rights Reserved. 6 * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved.
7 * Copyright (c) 2009-2010 Nikias Bassen All Rights Reserved.
7 * 8 *
8 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 10 * modify it under the terms of the GNU Lesser General Public
@@ -20,45 +21,49 @@
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 22 */
22 23
23#ifndef NOTIFICATION_PROXY_H 24#ifndef INOTIFICATION_PROXY_H
24#define NOTIFICATION_PROXY_H 25#define INOTIFICATION_PROXY_H
25 26
26#ifdef __cplusplus 27#ifdef __cplusplus
27extern "C" { 28extern "C" {
28#endif 29#endif
29 30
30#include <libimobiledevice/libimobiledevice.h> 31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
31 33
32/** @name Error Codes */ 34/** Service identifier passed to lockdownd_start_service() to start the notification proxy service */
33/*@{*/ 35#define NP_SERVICE_NAME "com.apple.mobile.notification_proxy"
34#define NP_E_SUCCESS 0
35#define NP_E_INVALID_ARG -1
36#define NP_E_PLIST_ERROR -2
37#define NP_E_CONN_FAILED -3
38 36
39#define NP_E_UNKNOWN_ERROR -256 37/** Error Codes */
40/*@}*/ 38typedef enum {
41 39 NP_E_SUCCESS = 0,
42/** Represents an error code. */ 40 NP_E_INVALID_ARG = -1,
43typedef int16_t np_error_t; 41 NP_E_PLIST_ERROR = -2,
42 NP_E_CONN_FAILED = -3,
43 NP_E_UNKNOWN_ERROR = -256
44} np_error_t;
44 45
45/** 46/**
46 * @name Notifications that can be send 47 * @name Notifications that can be sent
47 * 48 *
48 * For use with np_post_notification() (client --> device) 49 * For use with np_post_notification() (client --> device)
49 */ 50 */
51/**@{*/
52//! @cond
50#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" 53#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart"
51#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" 54#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart"
52#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" 55#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish"
53#define NP_SYNC_LOCK_REQUEST "com.apple.itunes-mobdev.syncLockRequest" 56#define NP_SYNC_LOCK_REQUEST "com.apple.itunes-mobdev.syncLockRequest"
54/*@}*/ 57//! @endcond
58/**@}*/
55 59
56/** 60/**
57 * @name Notifications that can be received 61 * @name Notifications that can be received
58 * 62 *
59 * For use with np_observe_notification() (device --> client) 63 * For use with np_observe_notification() (device --> client)
60 */ 64 */
61/*@{*/ 65/**@{*/
66//! @cond
62#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" 67#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest"
63#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" 68#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest"
64#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" 69#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest"
@@ -81,21 +86,114 @@ typedef int16_t np_error_t;
81#define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" 86#define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd"
82#define NP_LANGUAGE_CHANGED "com.apple.language.changed" 87#define NP_LANGUAGE_CHANGED "com.apple.language.changed"
83#define NP_ADDRESS_BOOK_PREF_CHANGED "com.apple.AddressBook.PreferenceChanged" 88#define NP_ADDRESS_BOOK_PREF_CHANGED "com.apple.AddressBook.PreferenceChanged"
84/*@}*/ 89//! @endcond
90/**@}*/
85 91
86typedef struct np_client_private np_client_private; 92typedef struct np_client_private np_client_private; /**< \private */
87typedef np_client_private *np_client_t; /**< The client handle. */ 93typedef np_client_private *np_client_t; /**< The client handle. */
88 94
89/** Reports which notification was received. */ 95/** Callback function that reports which notification was received. */
90typedef void (*np_notify_cb_t) (const char *notification, void *user_data); 96typedef void (*np_notify_cb_t) (const char *notification, void *user_data);
91 97
92/* Interface */ 98/* Interface */
93np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client); 99
94np_error_t np_client_free(np_client_t client); 100/**
95np_error_t np_post_notification(np_client_t client, const char *notification); 101 * Connects to the notification_proxy on the specified device.
96np_error_t np_observe_notification(np_client_t client, const char *notification); 102 *
97np_error_t np_observe_notifications(np_client_t client, const char **notification_spec); 103 * @param device The device to connect to.
98np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata); 104 * @param service The service descriptor returned by lockdownd_start_service.
105 * @param client Pointer that will be set to a newly allocated np_client_t
106 * upon successful return.
107 *
108 * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when device is NULL,
109 * or NP_E_CONN_FAILED when the connection to the device could not be
110 * established.
111 */
112LIBIMOBILEDEVICE_API np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client);
113
114/**
115 * Starts a new notification proxy service on the specified device and connects to it.
116 *
117 * @param device The device to connect to.
118 * @param client Pointer that will point to a newly allocated
119 * np_client_t upon successful return. Must be freed using
120 * np_client_free() after use.
121 * @param label The label to use for communication. Usually the program name.
122 * Pass NULL to disable sending the label in requests to lockdownd.
123 *
124 * @return NP_E_SUCCESS on success, or an NP_E_* error
125 * code otherwise.
126 */
127LIBIMOBILEDEVICE_API np_error_t np_client_start_service(idevice_t device, np_client_t* client, const char* label);
128
129/**
130 * Disconnects a notification_proxy client from the device and frees up the
131 * notification_proxy client data.
132 *
133 * @param client The notification_proxy client to disconnect and free.
134 *
135 * @return NP_E_SUCCESS on success, or NP_E_INVALID_ARG when client is NULL.
136 */
137LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client);
138
139
140/**
141 * Sends a notification to the device's notification_proxy.
142 *
143 * @param client The client to send to
144 * @param notification The notification message to send
145 *
146 * @return NP_E_SUCCESS on success, or an error returned by np_plist_send
147 */
148LIBIMOBILEDEVICE_API np_error_t np_post_notification(np_client_t client, const char *notification);
149
150/**
151 * Tells the device to send a notification on the specified event.
152 *
153 * @param client The client to send to
154 * @param notification The notifications that should be observed.
155 *
156 * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client or
157 * notification are NULL, or an error returned by np_plist_send.
158 */
159LIBIMOBILEDEVICE_API np_error_t np_observe_notification(np_client_t client, const char *notification);
160
161/**
162 * Tells the device to send a notification on specified events.
163 *
164 * @param client The client to send to
165 * @param notification_spec Specification of the notifications that should be
166 * observed. This is expected to be an array of const char* that MUST have a
167 * terminating NULL entry.
168 *
169 * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client is null,
170 * or an error returned by np_observe_notification.
171 */
172LIBIMOBILEDEVICE_API np_error_t np_observe_notifications(np_client_t client, const char **notification_spec);
173
174/**
175 * This function allows an application to define a callback function that will
176 * be called when a notification has been received.
177 * It will start a thread that polls for notifications and calls the callback
178 * function if a notification has been received.
179 * In case of an error condition when polling for notifications - e.g. device
180 * disconnect - the thread will call the callback function with an empty
181 * notification "" and terminate itself.
182 *
183 * @param client the NP client
184 * @param notify_cb pointer to a callback function or NULL to de-register a
185 * previously set callback function.
186 * @param user_data Pointer that will be passed to the callback function as
187 * user data. If notify_cb is NULL, this parameter is ignored.
188 *
189 * @note Only one callback function can be registered at the same time;
190 * any previously set callback function will be removed automatically.
191 *
192 * @return NP_E_SUCCESS when the callback was successfully registered,
193 * NP_E_INVALID_ARG when client is NULL, or NP_E_UNKNOWN_ERROR when
194 * the callback thread could no be created.
195 */
196LIBIMOBILEDEVICE_API np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *user_data);
99 197
100#ifdef __cplusplus 198#ifdef __cplusplus
101} 199}