summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-07-06 19:46:35 +0200
committerGravatar Martin Szulecki2009-07-07 20:27:57 +0200
commita1e2fec59eb7d0d2a3adbd4691b3ea2ee1302921 (patch)
tree7ec5dd7331716a33bb72fb47e8fa0a765ac89ba7
parentabb74bcae219c25cffb7e30db6a34c69dcd92f0a (diff)
downloadlibimobiledevice-a1e2fec59eb7d0d2a3adbd4691b3ea2ee1302921.tar.gz
libimobiledevice-a1e2fec59eb7d0d2a3adbd4691b3ea2ee1302921.tar.bz2
API cleanup for NotificationProxy
Signed-off-by: Martin Szulecki <opensuse@sukimashita.com>
-rw-r--r--dev/main.c40
-rw-r--r--include/Makefile.am2
-rw-r--r--include/libiphone/libiphone.h33
-rw-r--r--include/libiphone/notification_proxy.h46
-rw-r--r--src/NotificationProxy.c39
-rw-r--r--src/NotificationProxy.h7
6 files changed, 80 insertions, 87 deletions
diff --git a/dev/main.c b/dev/main.c
index fe340ff..d39baa7 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -26,6 +26,7 @@
#include <libiphone/libiphone.h>
#include <libiphone/afc.h>
+#include <libiphone/notification_proxy.h>
#include "../src/utils.h"
void notifier(const char *notification)
@@ -38,16 +39,16 @@ void notifier(const char *notification)
void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification)
{
int nport = 0;
- iphone_np_client_t np;
+ np_client_t np;
iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport);
if (nport) {
printf("::::::::::::::: np was started ::::::::::::\n");
- iphone_np_new_client(phone, nport, &np);
+ np_new_client(phone, nport, &np);
if (np) {
printf("::::::::: PostNotification %s\n", notification);
- iphone_np_post_notification(np, notification);
- iphone_np_free_client(np);
+ np_post_notification(np, notification);
+ np_free_client(np);
}
} else {
printf("::::::::::::::: np was NOT started ::::::::::::\n");
@@ -61,7 +62,7 @@ int main(int argc, char *argv[])
iphone_lckd_client_t control = NULL;
iphone_device_t phone = NULL;
uint64_t lockfile = 0;
- iphone_np_client_t gnp = NULL;
+ np_client_t gnp = NULL;
if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
iphone_set_debug(1);
@@ -104,7 +105,7 @@ int main(int argc, char *argv[])
iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp);
if (npp) {
printf("Notification Proxy started.\n");
- iphone_np_new_client(phone, npp, &gnp);
+ np_new_client(phone, npp, &gnp);
} else {
printf("ERROR: Notification proxy could not be started.\n");
}
@@ -115,8 +116,8 @@ int main(int argc, char *argv[])
NP_SYNC_RESUME_REQUEST,
NULL
};
- iphone_np_observe_notifications(gnp, nspec);
- iphone_np_set_notify_callback(gnp, notifier);
+ np_observe_notifications(gnp, nspec);
+ np_set_notify_callback(gnp, notifier);
}
perform_notification(phone, control, NP_SYNC_WILL_START);
@@ -219,28 +220,7 @@ int main(int argc, char *argv[])
if (gnp && lockfile) {
char *noti;
- /*
- noti = NULL;
- iphone_np_get_notification(gnp, &noti);
- if (noti) {
- printf("------> received notification '%s'\n", noti);
- free(noti);
- }*/
-
printf("XXX sleeping\n");
- /*for (i = 0; i < 5; i++) {
- noti = NULL;
- printf("--- getting notification\n");
- iphone_np_get_notification(gnp, &noti);
- if (noti) {
- printf("------> received notification '%s'\n", noti);
- free(noti);
- } else {
- printf("---- no notification\n");
- }
- sleep(1);
- }
- */
sleep(5);
//perform_notification(phone, control, NP_SYNC_DID_FINISH);
@@ -253,7 +233,7 @@ int main(int argc, char *argv[])
}
if (gnp) {
- iphone_np_free_client(gnp);
+ np_free_client(gnp);
gnp = NULL;
}
diff --git a/include/Makefile.am b/include/Makefile.am
index 4c17261..d8ae1e4 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1 @@
-nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h
+nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h
index 3f5d86c..456f000 100644
--- a/include/libiphone/libiphone.h
+++ b/include/libiphone/libiphone.h
@@ -63,9 +63,6 @@ typedef struct iphone_lckd_client_int *iphone_lckd_client_t;
struct iphone_msync_client_int;
typedef struct iphone_msync_client_int *iphone_msync_client_t;
-struct iphone_np_client_int;
-typedef struct iphone_np_client_int *iphone_np_client_t;
-
//debug related functions
#define DBGMASK_ALL 0xFFFF
#define DBGMASK_NONE 0x0000
@@ -102,36 +99,6 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client);
iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist);
iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist);
-// NotificationProxy related
-// notifications for use with post_notification (client --> device)
-#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart"
-#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart"
-#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish"
-
-// notifications for use with observe_notification (device --> client)
-#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest"
-#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest"
-#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest"
-#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed"
-#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed"
-#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation"
-#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed"
-#define NP_APP_INSTALLED "com.apple.mobile.application_installed"
-#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled"
-
-iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client );
-iphone_error_t iphone_np_free_client ( iphone_np_client_t client );
-
-iphone_error_t iphone_np_post_notification ( iphone_np_client_t client, const char *notification );
-
-iphone_error_t iphone_np_observe_notification ( iphone_np_client_t client, const char *notification );
-iphone_error_t iphone_np_observe_notifications ( iphone_np_client_t client, const char **notification_spec );
-iphone_error_t iphone_np_get_notification ( iphone_np_client_t client, char **notification );
-
-typedef void (*iphone_np_notify_cb_t) ( const char *notification );
-
-iphone_error_t iphone_np_set_notify_callback ( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb );
-
#ifdef __cplusplus
}
#endif
diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h
new file mode 100644
index 0000000..9412b4f
--- /dev/null
+++ b/include/libiphone/notification_proxy.h
@@ -0,0 +1,46 @@
+#ifndef NOTIFICATION_PROXY_H
+#define NOTIFICATION_PROXY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libiphone/libiphone.h>
+
+struct np_client_int;
+typedef struct np_client_int *np_client_t;
+
+// NotificationProxy related
+// notifications for use with post_notification (client --> device)
+#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart"
+#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart"
+#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish"
+
+// notifications for use with observe_notification (device --> client)
+#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest"
+#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest"
+#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest"
+#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed"
+#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed"
+#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation"
+#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed"
+#define NP_APP_INSTALLED "com.apple.mobile.application_installed"
+#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled"
+
+iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client );
+iphone_error_t np_free_client ( np_client_t client );
+
+iphone_error_t np_post_notification ( np_client_t client, const char *notification );
+
+iphone_error_t np_observe_notification ( np_client_t client, const char *notification );
+iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec );
+
+typedef void (*np_notify_cb_t) ( const char *notification );
+
+iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
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 @@
#include <arpa/inet.h>
#include <plist/plist.h>
#include "NotificationProxy.h"
+#include "iphone.h"
#include "utils.h"
struct np_thread {
- iphone_np_client_t client;
- iphone_np_notify_cb_t cbfunc;
+ np_client_t client;
+ np_notify_cb_t cbfunc;
};
/** Locks an NP client, done for thread safety stuff.
*
* @param client The NP
*/
-static void np_lock(iphone_np_client_t client)
+static void np_lock(np_client_t client)
{
log_debug_msg("NP: Locked\n");
g_mutex_lock(client->mutex);
@@ -46,7 +47,7 @@ static void np_lock(iphone_np_client_t client)
*
* @param client The NP
*/
-static void np_unlock(iphone_np_client_t client)
+static void np_unlock(np_client_t client)
{
log_debug_msg("NP: Unlocked\n");
g_mutex_unlock(client->mutex);
@@ -61,7 +62,7 @@ static void np_unlock(iphone_np_client_t client)
*
* @return IPHONE_E_SUCCESS or an error code.
*/
-static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict)
+static iphone_error_t np_plist_send(np_client_t client, plist_t dict)
{
char *XML_content = NULL;
uint32_t length = 0;
@@ -108,7 +109,7 @@ static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict)
*
* @return A handle to the newly-connected client or NULL upon error.
*/
-iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client )
+iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client )
{
//makes sure thread environment is available
if (!g_thread_supported())
@@ -123,7 +124,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho
return IPHONE_E_UNKNOWN_ERROR; //ret;
}
- iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int));
+ np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int));
client_loc->sfd = sfd;
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
*
* @param client The client to disconnect.
*/
-iphone_error_t iphone_np_free_client ( iphone_np_client_t client )
+iphone_error_t np_free_client ( np_client_t client )
{
if (!client)
return IPHONE_E_INVALID_ARG;
@@ -166,7 +167,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client )
* @param client The client to send to
* @param notification The notification message to send
*/
-iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification )
+iphone_error_t np_post_notification( np_client_t client, const char *notification )
{
if (!client || !notification) {
return IPHONE_E_INVALID_ARG;
@@ -202,7 +203,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
* @param client The client to send to
* @param notification The notifications that should be observed.
*/
-iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification )
+iphone_error_t np_observe_notification( np_client_t client, const char *notification )
{
if (!client || !notification) {
return IPHONE_E_INVALID_ARG;
@@ -245,7 +246,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const
* terminating NULL entry. However this parameter can be NULL; in this case,
* the default set of notifications will be used.
*/
-iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec )
+iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec )
{
int i = 0;
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
}
while (notifications[i]) {
- res = iphone_np_observe_notification(client, notifications[i]);
+ res = np_observe_notification(client, notifications[i]);
if (res != IPHONE_E_SUCCESS) {
break;
}
@@ -281,10 +282,10 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const
* IPHONE_E_TIMEOUT if nothing has been received,
* or an error value if an error occured.
*
- * @note You probably want to check out iphone_np_set_notify_callback
- * @see iphone_np_set_notify_callback
+ * @note You probably want to check out np_set_notify_callback
+ * @see np_set_notify_callback
*/
-iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification )
+static iphone_error_t np_get_notification( np_client_t client, char **notification )
{
uint32_t bytes = 0;
iphone_error_t res;
@@ -382,7 +383,7 @@ iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **not
/**
* Internally used thread function.
*/
-gpointer iphone_np_notifier( gpointer arg )
+gpointer np_notifier( gpointer arg )
{
char *notification = NULL;
struct np_thread *npt = (struct np_thread*)arg;
@@ -391,7 +392,7 @@ gpointer iphone_np_notifier( gpointer arg )
log_debug_msg("%s: starting callback.\n", __func__);
while (npt->client->sfd >= 0) {
- iphone_np_get_notification(npt->client, &notification);
+ np_get_notification(npt->client, &notification);
if (notification) {
npt->cbfunc(notification);
free(notification);
@@ -419,7 +420,7 @@ gpointer iphone_np_notifier( gpointer arg )
* @return IPHONE_E_SUCCESS when the callback was successfully registered,
* or an error value when an error occured.
*/
-iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb )
+iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb )
{
if (!client) {
return IPHONE_E_INVALID_ARG;
@@ -442,7 +443,7 @@ iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_
npt->client = client;
npt->cbfunc = notify_cb;
- client->notifier = g_thread_create(iphone_np_notifier, npt, TRUE, NULL);
+ client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL);
if (client->notifier) {
res = IPHONE_E_SUCCESS;
}
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 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libiphone/libiphone.h"
-#include "iphone.h"
+#include "libiphone/notification_proxy.h"
#include <glib.h>
-struct iphone_np_client_int {
+struct np_client_int {
int sfd;
GMutex *mutex;
GThread *notifier;
@@ -42,4 +41,4 @@ static const char *np_default_notifications[10] = {
NULL
};
-gpointer iphone_np_notifier( gpointer arg );
+gpointer np_notifier( gpointer arg );