diff options
| -rw-r--r-- | src/NotificationProxy.c | 48 | ||||
| -rw-r--r-- | src/NotificationProxy.h | 3 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index b73b521..ef2063c 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | #include <plist/plist.h> | 27 | #include <plist/plist.h> |
| 28 | 28 | ||
| 29 | #include "NotificationProxy.h" | 29 | #include "NotificationProxy.h" |
| 30 | #include "iphone.h" | 30 | #include "property_list_service.h" |
| 31 | #include "utils.h" | 31 | #include "utils.h" |
| 32 | 32 | ||
| 33 | struct np_thread { | 33 | struct np_thread { |
| @@ -56,24 +56,25 @@ static void np_unlock(np_client_t client) | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * Convert an iphone_error_t value to an np_error_t value. | 59 | * Convert a property_list_service_error_t value to an np_error_t value. |
| 60 | * Used internally to get correct error codes when using plist helper | 60 | * Used internally to get correct error codes. |
| 61 | * functions. | ||
| 62 | * | 61 | * |
| 63 | * @param err An iphone_error_t error code | 62 | * @param err A property_list_service_error_t error code |
| 64 | * | 63 | * |
| 65 | * @return A matching np_error_t error code, | 64 | * @return A matching np_error_t error code, |
| 66 | * NP_E_UNKNOWN_ERROR otherwise. | 65 | * NP_E_UNKNOWN_ERROR otherwise. |
| 67 | */ | 66 | */ |
| 68 | static np_error_t iphone_to_np_error(iphone_error_t err) | 67 | static np_error_t np_error(property_list_service_error_t err) |
| 69 | { | 68 | { |
| 70 | switch (err) { | 69 | switch (err) { |
| 71 | case IPHONE_E_SUCCESS: | 70 | case PROPERTY_LIST_SERVICE_E_SUCCESS: |
| 72 | return NP_E_SUCCESS; | 71 | return NP_E_SUCCESS; |
| 73 | case IPHONE_E_INVALID_ARG: | 72 | case PROPERTY_LIST_SERVICE_E_INVALID_ARG: |
| 74 | return NP_E_INVALID_ARG; | 73 | return NP_E_INVALID_ARG; |
| 75 | case IPHONE_E_PLIST_ERROR: | 74 | case PROPERTY_LIST_SERVICE_E_PLIST_ERROR: |
| 76 | return NP_E_PLIST_ERROR; | 75 | return NP_E_PLIST_ERROR; |
| 76 | case PROPERTY_LIST_SERVICE_E_MUX_ERROR: | ||
| 77 | return NP_E_CONN_FAILED; | ||
| 77 | default: | 78 | default: |
| 78 | break; | 79 | break; |
| 79 | } | 80 | } |
| @@ -100,14 +101,13 @@ np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *clie | |||
| 100 | if (!device) | 101 | if (!device) |
| 101 | return NP_E_INVALID_ARG; | 102 | return NP_E_INVALID_ARG; |
| 102 | 103 | ||
| 103 | /* Attempt connection */ | 104 | property_list_service_client_t plistclient = NULL; |
| 104 | iphone_connection_t connection = NULL; | 105 | if (property_list_service_client_new(device, dst_port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { |
| 105 | if (iphone_device_connect(device, dst_port, &connection) != IPHONE_E_SUCCESS) { | ||
| 106 | return NP_E_CONN_FAILED; | 106 | return NP_E_CONN_FAILED; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); | 109 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); |
| 110 | client_loc->connection = connection; | 110 | client_loc->parent = plistclient; |
| 111 | 111 | ||
| 112 | client_loc->mutex = g_mutex_new(); | 112 | client_loc->mutex = g_mutex_new(); |
| 113 | 113 | ||
| @@ -128,8 +128,8 @@ np_error_t np_client_free(np_client_t client) | |||
| 128 | if (!client) | 128 | if (!client) |
| 129 | return NP_E_INVALID_ARG; | 129 | return NP_E_INVALID_ARG; |
| 130 | 130 | ||
| 131 | iphone_device_disconnect(client->connection); | 131 | property_list_service_client_free(client->parent); |
| 132 | client->connection = NULL; | 132 | client->parent = NULL; |
| 133 | if (client->notifier) { | 133 | if (client->notifier) { |
| 134 | log_debug_msg("joining np callback\n"); | 134 | log_debug_msg("joining np callback\n"); |
| 135 | g_thread_join(client->notifier); | 135 | g_thread_join(client->notifier); |
| @@ -160,13 +160,13 @@ np_error_t np_post_notification(np_client_t client, const char *notification) | |||
| 160 | plist_dict_insert_item(dict,"Command", plist_new_string("PostNotification")); | 160 | plist_dict_insert_item(dict,"Command", plist_new_string("PostNotification")); |
| 161 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); | 161 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); |
| 162 | 162 | ||
| 163 | np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 163 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 164 | plist_free(dict); | 164 | plist_free(dict); |
| 165 | 165 | ||
| 166 | dict = plist_new_dict(); | 166 | dict = plist_new_dict(); |
| 167 | plist_dict_insert_item(dict,"Command", plist_new_string("Shutdown")); | 167 | plist_dict_insert_item(dict,"Command", plist_new_string("Shutdown")); |
| 168 | 168 | ||
| 169 | res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 169 | res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 170 | plist_free(dict); | 170 | plist_free(dict); |
| 171 | 171 | ||
| 172 | if (res != NP_E_SUCCESS) { | 172 | if (res != NP_E_SUCCESS) { |
| @@ -196,7 +196,7 @@ np_error_t np_observe_notification( np_client_t client, const char *notification | |||
| 196 | plist_dict_insert_item(dict,"Command", plist_new_string("ObserveNotification")); | 196 | plist_dict_insert_item(dict,"Command", plist_new_string("ObserveNotification")); |
| 197 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); | 197 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); |
| 198 | 198 | ||
| 199 | np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 199 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 200 | if (res != NP_E_SUCCESS) { | 200 | if (res != NP_E_SUCCESS) { |
| 201 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); | 201 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); |
| 202 | } | 202 | } |
| @@ -259,12 +259,12 @@ static int np_get_notification(np_client_t client, char **notification) | |||
| 259 | int res = 0; | 259 | int res = 0; |
| 260 | plist_t dict = NULL; | 260 | plist_t dict = NULL; |
| 261 | 261 | ||
| 262 | if (!client || !client->connection || *notification) | 262 | if (!client || !client->parent || *notification) |
| 263 | return -1; | 263 | return -1; |
| 264 | 264 | ||
| 265 | np_lock(client); | 265 | np_lock(client); |
| 266 | 266 | ||
| 267 | iphone_device_receive_plist_with_timeout(client->connection, &dict, 500); | 267 | property_list_service_receive_plist_with_timeout(client->parent, &dict, 500); |
| 268 | if (!dict) { | 268 | if (!dict) { |
| 269 | log_debug_msg("NotificationProxy: no notification received!\n"); | 269 | log_debug_msg("NotificationProxy: no notification received!\n"); |
| 270 | res = 0; | 270 | res = 0; |
| @@ -322,7 +322,7 @@ gpointer np_notifier( gpointer arg ) | |||
| 322 | if (!npt) return NULL; | 322 | if (!npt) return NULL; |
| 323 | 323 | ||
| 324 | log_debug_msg("%s: starting callback.\n", __func__); | 324 | log_debug_msg("%s: starting callback.\n", __func__); |
| 325 | while (npt->client->connection) { | 325 | while (npt->client->parent) { |
| 326 | np_get_notification(npt->client, ¬ification); | 326 | np_get_notification(npt->client, ¬ification); |
| 327 | if (notification) { | 327 | if (notification) { |
| 328 | npt->cbfunc(notification); | 328 | npt->cbfunc(notification); |
| @@ -365,11 +365,11 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb | |||
| 365 | np_lock(client); | 365 | np_lock(client); |
| 366 | if (client->notifier) { | 366 | if (client->notifier) { |
| 367 | log_debug_msg("%s: callback already set, removing\n"); | 367 | log_debug_msg("%s: callback already set, removing\n"); |
| 368 | iphone_connection_t conn = client->connection; | 368 | property_list_service_client_t parent = client->parent; |
| 369 | client->connection = NULL; | 369 | client->parent = NULL; |
| 370 | g_thread_join(client->notifier); | 370 | g_thread_join(client->notifier); |
| 371 | client->notifier = NULL; | 371 | client->notifier = NULL; |
| 372 | client->connection = conn; | 372 | client->parent = parent; |
| 373 | } | 373 | } |
| 374 | 374 | ||
| 375 | if (notify_cb) { | 375 | if (notify_cb) { |
diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h index ea993c5..a2b3001 100644 --- a/src/NotificationProxy.h +++ b/src/NotificationProxy.h | |||
| @@ -24,9 +24,10 @@ | |||
| 24 | #include <glib.h> | 24 | #include <glib.h> |
| 25 | 25 | ||
| 26 | #include "libiphone/notification_proxy.h" | 26 | #include "libiphone/notification_proxy.h" |
| 27 | #include "property_list_service.h" | ||
| 27 | 28 | ||
| 28 | struct np_client_int { | 29 | struct np_client_int { |
| 29 | iphone_connection_t connection; | 30 | property_list_service_client_t parent; |
| 30 | GMutex *mutex; | 31 | GMutex *mutex; |
| 31 | GThread *notifier; | 32 | GThread *notifier; |
| 32 | }; | 33 | }; |
