diff options
| author | 2019-06-16 03:38:50 +0200 | |
|---|---|---|
| committer | 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 | |||
| 186 | return res; | 186 | return res; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification ) | 189 | static np_error_t internal_np_observe_notification(np_client_t client, const char *notification) |
| 190 | { | 190 | { |
| 191 | if (!client || !notification) { | ||
| 192 | return NP_E_INVALID_ARG; | ||
| 193 | } | ||
| 194 | np_lock(client); | ||
| 195 | |||
| 196 | plist_t dict = plist_new_dict(); | 191 | plist_t dict = plist_new_dict(); |
| 197 | plist_dict_set_item(dict,"Command", plist_new_string("ObserveNotification")); | 192 | plist_dict_set_item(dict,"Command", plist_new_string("ObserveNotification")); |
| 198 | plist_dict_set_item(dict,"Name", plist_new_string(notification)); | 193 | 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 | |||
| 203 | } | 198 | } |
| 204 | plist_free(dict); | 199 | plist_free(dict); |
| 205 | 200 | ||
| 201 | return res; | ||
| 202 | } | ||
| 203 | |||
| 204 | LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification ) | ||
| 205 | { | ||
| 206 | if (!client || !notification) { | ||
| 207 | return NP_E_INVALID_ARG; | ||
| 208 | } | ||
| 209 | np_lock(client); | ||
| 210 | np_error_t res = internal_np_observe_notification(client, notification); | ||
| 206 | np_unlock(client); | 211 | np_unlock(client); |
| 207 | return res; | 212 | return res; |
| 208 | } | 213 | } |
| @@ -221,13 +226,15 @@ LIBIMOBILEDEVICE_API np_error_t np_observe_notifications(np_client_t client, con | |||
| 221 | return NP_E_INVALID_ARG; | 226 | return NP_E_INVALID_ARG; |
| 222 | } | 227 | } |
| 223 | 228 | ||
| 229 | np_lock(client); | ||
| 224 | while (notifications[i]) { | 230 | while (notifications[i]) { |
| 225 | res = np_observe_notification(client, notifications[i]); | 231 | res = internal_np_observe_notification(client, notifications[i]); |
| 226 | if (res != NP_E_SUCCESS) { | 232 | if (res != NP_E_SUCCESS) { |
| 227 | break; | 233 | break; |
| 228 | } | 234 | } |
| 229 | i++; | 235 | i++; |
| 230 | } | 236 | } |
| 237 | np_unlock(client); | ||
| 231 | 238 | ||
| 232 | return res; | 239 | return res; |
| 233 | } | 240 | } |
