diff options
author | Nikias Bassen | 2019-06-16 03:38:50 +0200 |
---|---|---|
committer | Nikias Bassen | 2019-06-16 03:38:50 +0200 |
commit | ddba0b5efbcab483e80be10130c5c797f9ac8d08 (patch) | |
tree | c3bd2efe3e607e4c98233528937dcc139d08547d | |
parent | 7a0ab5f8f25b1c7f0c7313d7feda9c41c8058702 (diff) | |
download | libimobiledevice-ddba0b5efbcab483e80be10130c5c797f9ac8d08.tar.gz libimobiledevice-ddba0b5efbcab483e80be10130c5c797f9ac8d08.tar.bz2 |
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.
-rw-r--r-- | src/notification_proxy.c | 21 |
1 files 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; } |