From ddba0b5efbcab483e80be10130c5c797f9ac8d08 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 16 Jun 2019 03:38:50 +0200 Subject: notification_proxy: Make np_observe_notifications() atomic Otherwise the notification callback might fire before all notifications that should be observed have been registered. This way the callback will only be called after _all_ notifications have been registered. --- src/notification_proxy.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 3015ed9..cd8e64c 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c @@ -186,13 +186,8 @@ LIBIMOBILEDEVICE_API np_error_t np_post_notification(np_client_t client, const c return res; } -LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification ) +static np_error_t internal_np_observe_notification(np_client_t client, const char *notification) { - if (!client || !notification) { - return NP_E_INVALID_ARG; - } - np_lock(client); - plist_t dict = plist_new_dict(); plist_dict_set_item(dict,"Command", plist_new_string("ObserveNotification")); plist_dict_set_item(dict,"Name", plist_new_string(notification)); @@ -203,6 +198,16 @@ LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, con } plist_free(dict); + return res; +} + +LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification ) +{ + if (!client || !notification) { + return NP_E_INVALID_ARG; + } + np_lock(client); + np_error_t res = internal_np_observe_notification(client, notification); np_unlock(client); return res; } @@ -221,13 +226,15 @@ LIBIMOBILEDEVICE_API np_error_t np_observe_notifications(np_client_t client, con return NP_E_INVALID_ARG; } + np_lock(client); while (notifications[i]) { - res = np_observe_notification(client, notifications[i]); + res = internal_np_observe_notification(client, notifications[i]); if (res != NP_E_SUCCESS) { break; } i++; } + np_unlock(client); return res; } -- cgit v1.1-32-gdbae