summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-07-06 19:46:35 +0200
committerGravatar Matt Colyer2009-07-18 10:39:42 -0700
commitab8e29dafc0577203e6867329b1d3ff9095a4fb2 (patch)
treeb8b19f763cc83b0a0449b16ec4ddc626ce66a136 /src
parent4105af17e9f2df5405afa6a74a02a304ed6bacff (diff)
downloadlibimobiledevice-ab8e29dafc0577203e6867329b1d3ff9095a4fb2.tar.gz
libimobiledevice-ab8e29dafc0577203e6867329b1d3ff9095a4fb2.tar.bz2
API cleanup for NotificationProxy
Diffstat (limited to 'src')
-rw-r--r--src/NotificationProxy.c39
-rw-r--r--src/NotificationProxy.h7
2 files changed, 23 insertions, 23 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
30struct np_thread { 31struct 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 */
39static void np_lock(iphone_np_client_t client) 40static 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 */
49static void np_unlock(iphone_np_client_t client) 50static 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 */
64static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) 65static 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 */
111iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ) 112iphone_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 */
141iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) 142iphone_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 */
169iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) 170iphone_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 */
205iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification ) 206iphone_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 */
248iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec ) 249iphone_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 */
287iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification ) 288static 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 */
385gpointer iphone_np_notifier( gpointer arg ) 386gpointer 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, &notification); 395 np_get_notification(npt->client, &notification);
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 */
422iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ) 423iphone_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 }
diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h
index afae98a..a10cde4 100644
--- a/src/NotificationProxy.h
+++ b/src/NotificationProxy.h
@@ -18,12 +18,11 @@
18 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21#include "libiphone/libiphone.h" 21#include "libiphone/notification_proxy.h"
22#include "iphone.h"
23 22
24#include <glib.h> 23#include <glib.h>
25 24
26struct iphone_np_client_int { 25struct np_client_int {
27 int sfd; 26 int sfd;
28 GMutex *mutex; 27 GMutex *mutex;
29 GThread *notifier; 28 GThread *notifier;
@@ -42,4 +41,4 @@ static const char *np_default_notifications[10] = {
42 NULL 41 NULL
43}; 42};
44 43
45gpointer iphone_np_notifier( gpointer arg ); 44gpointer np_notifier( gpointer arg );