diff options
author | Nikias Bassen | 2010-03-06 01:26:19 +0100 |
---|---|---|
committer | Matt Colyer | 2010-03-08 21:09:35 -0800 |
commit | 6ceabe1e0a3c107c4b98d38f59f044b8eb7731a0 (patch) | |
tree | 701a591e8cd3df615906dc42000e7fa5ea1fba66 | |
parent | 1d59d15f3b78f26fb231a9bf401ee40cd7b60463 (diff) | |
download | libimobiledevice-6ceabe1e0a3c107c4b98d38f59f044b8eb7731a0.tar.gz libimobiledevice-6ceabe1e0a3c107c4b98d38f59f044b8eb7731a0.tar.bz2 |
Add user data parameter to notification callback function
[#114 state:resolved]
-rw-r--r-- | dev/ideviceclient.c | 4 | ||||
-rw-r--r-- | include/libimobiledevice/notification_proxy.h | 4 | ||||
-rw-r--r-- | src/notification_proxy.c | 8 | ||||
-rw-r--r-- | tools/idevicebackup.c | 4 |
4 files changed, 12 insertions, 8 deletions
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c index 2ed93d2..d952594 100644 --- a/dev/ideviceclient.c +++ b/dev/ideviceclient.c @@ -30,7 +30,7 @@ #include <libimobiledevice/afc.h> #include <libimobiledevice/notification_proxy.h> -static void notifier(const char *notification) +static void notifier(const char *notification, void *userdata) { printf("---------------------------------------------------------\n"); printf("------> Notification received: %s\n", notification); @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) NULL }; np_observe_notifications(gnp, nspec); - np_set_notify_callback(gnp, notifier); + np_set_notify_callback(gnp, notifier, NULL); } perform_notification(phone, client, NP_SYNC_WILL_START); diff --git a/include/libimobiledevice/notification_proxy.h b/include/libimobiledevice/notification_proxy.h index adbb4cc..4f4c1fd 100644 --- a/include/libimobiledevice/notification_proxy.h +++ b/include/libimobiledevice/notification_proxy.h @@ -71,7 +71,7 @@ typedef int16_t np_error_t; struct np_client_int; typedef struct np_client_int *np_client_t; -typedef void (*np_notify_cb_t) (const char *notification); +typedef void (*np_notify_cb_t) (const char *notification, void *userdata); /* Interface */ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client); @@ -79,7 +79,7 @@ np_error_t np_client_free(np_client_t client); np_error_t np_post_notification(np_client_t client, const char *notification); np_error_t np_observe_notification(np_client_t client, const char *notification); np_error_t np_observe_notifications(np_client_t client, const char **notification_spec); -np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb); +np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata); #ifdef __cplusplus } diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 827468e..41647c8 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c @@ -33,6 +33,7 @@ struct np_thread { np_client_t client; np_notify_cb_t cbfunc; + void *userdata; }; /** @@ -333,7 +334,7 @@ gpointer np_notifier( gpointer arg ) while (npt->client->parent) { np_get_notification(npt->client, ¬ification); if (notification) { - npt->cbfunc(notification); + npt->cbfunc(notification, npt->userdata); free(notification); notification = NULL; } @@ -355,6 +356,8 @@ gpointer np_notifier( gpointer arg ) * @param client the NP client * @param notify_cb pointer to a callback function or NULL to de-register a * previously set callback function. + * @param userdata Pointer that will be passed to the callback function as + * userdata. If notify_cb is NULL, this parameter is ignored. * * @note Only one callback function can be registered at the same time; * any previously set callback function will be removed automatically. @@ -363,7 +366,7 @@ gpointer np_notifier( gpointer arg ) * NP_E_INVALID_ARG when client is NULL, or NP_E_UNKNOWN_ERROR when * the callback thread could no be created. */ -np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) +np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, void *userdata ) { if (!client) return NP_E_INVALID_ARG; @@ -385,6 +388,7 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb if (npt) { npt->client = client; npt->cbfunc = notify_cb; + npt->userdata = userdata; client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); if (client->notifier) { diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index d3b3ccc..1984833 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -59,7 +59,7 @@ enum device_link_file_status_t { DEVICE_LINK_FILE_STATUS_LAST_HUNK }; -static void notify_cb(const char *notification) +static void notify_cb(const char *notification, void *userdata) { if (!strcmp(notification, NP_SYNC_CANCEL_REQUEST)) { printf("User has aborted on-device\n"); @@ -543,7 +543,7 @@ int main(int argc, char *argv[]) ret = lockdownd_start_service(client, NP_SERVICE_NAME, &port); if ((ret == LOCKDOWN_E_SUCCESS) && port) { np_client_new(phone, port, &np); - np_set_notify_callback(np, notify_cb); + np_set_notify_callback(np, notify_cb, NULL); const char *noties[5] = { NP_SYNC_CANCEL_REQUEST, NP_SYNC_SUSPEND_REQUEST, |