diff options
Diffstat (limited to 'src/NotificationProxy.c')
| -rw-r--r-- | src/NotificationProxy.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 6fc048c..374420c 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c | |||
| @@ -25,18 +25,19 @@ | |||
| 25 | #include <arpa/inet.h> | 25 | #include <arpa/inet.h> |
| 26 | #include <plist/plist.h> | 26 | #include <plist/plist.h> |
| 27 | #include "NotificationProxy.h" | 27 | #include "NotificationProxy.h" |
| 28 | #include "iphone.h" | ||
| 28 | #include "utils.h" | 29 | #include "utils.h" |
| 29 | 30 | ||
| 30 | struct np_thread { | 31 | struct np_thread { |
| 31 | iphone_np_client_t client; | 32 | np_client_t client; |
| 32 | iphone_np_notify_cb_t cbfunc; | 33 | np_notify_cb_t cbfunc; |
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | /** Locks an NP client, done for thread safety stuff. | 36 | /** Locks an NP client, done for thread safety stuff. |
| 36 | * | 37 | * |
| 37 | * @param client The NP | 38 | * @param client The NP |
| 38 | */ | 39 | */ |
| 39 | static void np_lock(iphone_np_client_t client) | 40 | static void np_lock(np_client_t client) |
| 40 | { | 41 | { |
| 41 | log_debug_msg("NP: Locked\n"); | 42 | log_debug_msg("NP: Locked\n"); |
| 42 | g_mutex_lock(client->mutex); | 43 | g_mutex_lock(client->mutex); |
| @@ -46,7 +47,7 @@ static void np_lock(iphone_np_client_t client) | |||
| 46 | * | 47 | * |
| 47 | * @param client The NP | 48 | * @param client The NP |
| 48 | */ | 49 | */ |
| 49 | static void np_unlock(iphone_np_client_t client) | 50 | static void np_unlock(np_client_t client) |
| 50 | { | 51 | { |
| 51 | log_debug_msg("NP: Unlocked\n"); | 52 | log_debug_msg("NP: Unlocked\n"); |
| 52 | g_mutex_unlock(client->mutex); | 53 | g_mutex_unlock(client->mutex); |
| @@ -61,7 +62,7 @@ static void np_unlock(iphone_np_client_t client) | |||
| 61 | * | 62 | * |
| 62 | * @return IPHONE_E_SUCCESS or an error code. | 63 | * @return IPHONE_E_SUCCESS or an error code. |
| 63 | */ | 64 | */ |
| 64 | static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) | 65 | static iphone_error_t np_plist_send(np_client_t client, plist_t dict) |
| 65 | { | 66 | { |
| 66 | char *XML_content = NULL; | 67 | char *XML_content = NULL; |
| 67 | uint32_t length = 0; | 68 | uint32_t length = 0; |
| @@ -108,7 +109,7 @@ static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) | |||
| 108 | * | 109 | * |
| 109 | * @return A handle to the newly-connected client or NULL upon error. | 110 | * @return A handle to the newly-connected client or NULL upon error. |
| 110 | */ | 111 | */ |
| 111 | iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ) | 112 | iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ) |
| 112 | { | 113 | { |
| 113 | //makes sure thread environment is available | 114 | //makes sure thread environment is available |
| 114 | if (!g_thread_supported()) | 115 | if (!g_thread_supported()) |
| @@ -123,7 +124,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho | |||
| 123 | return IPHONE_E_UNKNOWN_ERROR; //ret; | 124 | return IPHONE_E_UNKNOWN_ERROR; //ret; |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); | 127 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); |
| 127 | client_loc->sfd = sfd; | 128 | client_loc->sfd = sfd; |
| 128 | 129 | ||
| 129 | client_loc->mutex = g_mutex_new(); | 130 | client_loc->mutex = g_mutex_new(); |
| @@ -138,7 +139,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho | |||
| 138 | * | 139 | * |
| 139 | * @param client The client to disconnect. | 140 | * @param client The client to disconnect. |
| 140 | */ | 141 | */ |
| 141 | iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) | 142 | iphone_error_t np_free_client ( np_client_t client ) |
| 142 | { | 143 | { |
| 143 | if (!client) | 144 | if (!client) |
| 144 | return IPHONE_E_INVALID_ARG; | 145 | return IPHONE_E_INVALID_ARG; |
| @@ -166,7 +167,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) | |||
| 166 | * @param client The client to send to | 167 | * @param client The client to send to |
| 167 | * @param notification The notification message to send | 168 | * @param notification The notification message to send |
| 168 | */ | 169 | */ |
| 169 | iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) | 170 | iphone_error_t np_post_notification( np_client_t client, const char *notification ) |
| 170 | { | 171 | { |
| 171 | if (!client || !notification) { | 172 | if (!client || !notification) { |
| 172 | return IPHONE_E_INVALID_ARG; | 173 | return IPHONE_E_INVALID_ARG; |
| @@ -202,7 +203,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha | |||
| 202 | * @param client The client to send to | 203 | * @param client The client to send to |
| 203 | * @param notification The notifications that should be observed. | 204 | * @param notification The notifications that should be observed. |
| 204 | */ | 205 | */ |
| 205 | iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification ) | 206 | iphone_error_t np_observe_notification( np_client_t client, const char *notification ) |
| 206 | { | 207 | { |
| 207 | if (!client || !notification) { | 208 | if (!client || !notification) { |
| 208 | return IPHONE_E_INVALID_ARG; | 209 | return IPHONE_E_INVALID_ARG; |
| @@ -245,7 +246,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const | |||
| 245 | * terminating NULL entry. However this parameter can be NULL; in this case, | 246 | * terminating NULL entry. However this parameter can be NULL; in this case, |
| 246 | * the default set of notifications will be used. | 247 | * the default set of notifications will be used. |
| 247 | */ | 248 | */ |
| 248 | iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec ) | 249 | iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec ) |
| 249 | { | 250 | { |
| 250 | int i = 0; | 251 | int i = 0; |
| 251 | iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; | 252 | iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; |
| @@ -260,7 +261,7 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const | |||
| 260 | } | 261 | } |
| 261 | 262 | ||
| 262 | while (notifications[i]) { | 263 | while (notifications[i]) { |
| 263 | res = iphone_np_observe_notification(client, notifications[i]); | 264 | res = np_observe_notification(client, notifications[i]); |
| 264 | if (res != IPHONE_E_SUCCESS) { | 265 | if (res != IPHONE_E_SUCCESS) { |
| 265 | break; | 266 | break; |
| 266 | } | 267 | } |
| @@ -281,10 +282,10 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const | |||
| 281 | * IPHONE_E_TIMEOUT if nothing has been received, | 282 | * IPHONE_E_TIMEOUT if nothing has been received, |
| 282 | * or an error value if an error occured. | 283 | * or an error value if an error occured. |
| 283 | * | 284 | * |
| 284 | * @note You probably want to check out iphone_np_set_notify_callback | 285 | * @note You probably want to check out np_set_notify_callback |
| 285 | * @see iphone_np_set_notify_callback | 286 | * @see np_set_notify_callback |
| 286 | */ | 287 | */ |
| 287 | iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification ) | 288 | static iphone_error_t np_get_notification( np_client_t client, char **notification ) |
| 288 | { | 289 | { |
| 289 | uint32_t bytes = 0; | 290 | uint32_t bytes = 0; |
| 290 | iphone_error_t res; | 291 | iphone_error_t res; |
| @@ -382,7 +383,7 @@ iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **not | |||
| 382 | /** | 383 | /** |
| 383 | * Internally used thread function. | 384 | * Internally used thread function. |
| 384 | */ | 385 | */ |
| 385 | gpointer iphone_np_notifier( gpointer arg ) | 386 | gpointer np_notifier( gpointer arg ) |
| 386 | { | 387 | { |
| 387 | char *notification = NULL; | 388 | char *notification = NULL; |
| 388 | struct np_thread *npt = (struct np_thread*)arg; | 389 | struct np_thread *npt = (struct np_thread*)arg; |
| @@ -391,7 +392,7 @@ gpointer iphone_np_notifier( gpointer arg ) | |||
| 391 | 392 | ||
| 392 | log_debug_msg("%s: starting callback.\n", __func__); | 393 | log_debug_msg("%s: starting callback.\n", __func__); |
| 393 | while (npt->client->sfd >= 0) { | 394 | while (npt->client->sfd >= 0) { |
| 394 | iphone_np_get_notification(npt->client, ¬ification); | 395 | np_get_notification(npt->client, ¬ification); |
| 395 | if (notification) { | 396 | if (notification) { |
| 396 | npt->cbfunc(notification); | 397 | npt->cbfunc(notification); |
| 397 | free(notification); | 398 | free(notification); |
| @@ -419,7 +420,7 @@ gpointer iphone_np_notifier( gpointer arg ) | |||
| 419 | * @return IPHONE_E_SUCCESS when the callback was successfully registered, | 420 | * @return IPHONE_E_SUCCESS when the callback was successfully registered, |
| 420 | * or an error value when an error occured. | 421 | * or an error value when an error occured. |
| 421 | */ | 422 | */ |
| 422 | iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ) | 423 | iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) |
| 423 | { | 424 | { |
| 424 | if (!client) { | 425 | if (!client) { |
| 425 | return IPHONE_E_INVALID_ARG; | 426 | return IPHONE_E_INVALID_ARG; |
| @@ -442,7 +443,7 @@ iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_ | |||
| 442 | npt->client = client; | 443 | npt->client = client; |
| 443 | npt->cbfunc = notify_cb; | 444 | npt->cbfunc = notify_cb; |
| 444 | 445 | ||
| 445 | client->notifier = g_thread_create(iphone_np_notifier, npt, TRUE, NULL); | 446 | client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); |
| 446 | if (client->notifier) { | 447 | if (client->notifier) { |
| 447 | res = IPHONE_E_SUCCESS; | 448 | res = IPHONE_E_SUCCESS; |
| 448 | } | 449 | } |
