From d4694679f918750e920a2238d891cd2fbb741a90 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Tue, 13 Jan 2009 18:57:52 +0100 Subject: Add parts of a python binding to libiphone that also include libplist (using SWIG). --- swig/iphone.i | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 swig/iphone.i (limited to 'swig/iphone.i') diff --git a/swig/iphone.i b/swig/iphone.i new file mode 100644 index 0000000..fb16208 --- /dev/null +++ b/swig/iphone.i @@ -0,0 +1,123 @@ + /* swig.i */ + %module(package="libiphone") iPhone + %{ + /* Includes the header in the wrapper code */ + #include + #include + + typedef struct { + iphone_device_t dev; + } iPhone; + + typedef struct { + iphone_device_t dev; + iphone_lckd_client_t client; + } Lockdownd; + + typedef struct { + iphone_msync_client_t client; + } MobileSync; +//typedef struct { +// plist_t node; +//} PListNode; + %} +/* Parse the header file to generate wrappers */ +%include "plist/swig/plist.i" + //(module="libplist.PList")override module name until package path gets fixed in swig (1.3.37) + +typedef struct { + iphone_device_t dev; +} iPhone; + +typedef struct { + iphone_device_t dev; + iphone_lckd_client_t client; +} Lockdownd; + +typedef struct { + iphone_msync_client_t client; +} MobileSync; + +%extend iPhone { // Attach these functions to struct iPhone + iPhone() { + iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); + if (IPHONE_E_SUCCESS == iphone_get_device ( &phone->dev )) + return phone; + free(phone); + return NULL; + } + + ~iPhone() { + iphone_free_device ( $self->dev ); + free($self); + } + + Lockdownd* GetLockdownClient() { + Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); + client->client = NULL; + if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { + client->dev = $self->dev; + return client; + } + free(client); + return NULL; + } +}; + +%extend Lockdownd { // Attach these functions to struct Lockdownd + Lockdownd(iPhone* phone) { + if (!phone) return NULL; + Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); + client->client = NULL; + if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &client->client)) { + client->dev = phone->dev; + return client; + } + else { + free(client); + return NULL; + } + } + + ~Lockdownd() { + iphone_lckd_free_client ( $self->client ); + free($self); + } + + MobileSync* GetMobileSyncClient() { + int port = 0; + if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( $self->client, "com.apple.mobilesync", &port )) { + MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); + client->client = NULL; + if (IPHONE_E_SUCCESS == iphone_msync_new_client ( $self->dev, 3432, port, &(client->client))) + return client; + } + return NULL; + } +}; + +%extend MobileSync { // Attach these functions to struct MobileSync + MobileSync(iPhone* phone, int src_port, int dst_port) { + if (!phone) return NULL; + MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); + client->client = NULL; + iphone_msync_new_client ( phone->dev, src_port, dst_port, &client->client); + return client; + } + + ~MobileSync() { + iphone_msync_free_client ( $self->client ); + free($self); + } + + void Send(PListNode* node) { + iphone_msync_send($self->client, node->node); + } + + PListNode* Receive() { + PListNode* node = NULL; + iphone_msync_recv($self->client, &(node->node)); + return node; + } +}; + -- cgit v1.1-32-gdbae From 47347ff723dd3c03b0006c150b02abaa2b9f4a76 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Tue, 13 Jan 2009 22:56:35 +0100 Subject: Fix some bugs in interface (Receive() still doesn't work). --- swig/iphone.i | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'swig/iphone.i') diff --git a/swig/iphone.i b/swig/iphone.i index fb16208..a0fe340 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -4,7 +4,7 @@ /* Includes the header in the wrapper code */ #include #include - +#include "../src/utils.h" typedef struct { iphone_device_t dev; } iPhone; @@ -17,13 +17,10 @@ typedef struct { iphone_msync_client_t client; } MobileSync; -//typedef struct { -// plist_t node; -//} PListNode; %} /* Parse the header file to generate wrappers */ +%include "stdint.i" %include "plist/swig/plist.i" - //(module="libplist.PList")override module name until package path gets fixed in swig (1.3.37) typedef struct { iphone_device_t dev; @@ -41,10 +38,9 @@ typedef struct { %extend iPhone { // Attach these functions to struct iPhone iPhone() { iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); - if (IPHONE_E_SUCCESS == iphone_get_device ( &phone->dev )) - return phone; - free(phone); - return NULL; + phone->dev = NULL; + iphone_set_debug_mask(DBGMASK_LOCKDOWND | DBGMASK_MOBILESYNC); + return phone; } ~iPhone() { @@ -52,9 +48,16 @@ typedef struct { free($self); } + int InitDevice() { + if (IPHONE_E_SUCCESS == iphone_get_device ( &($self->dev))) + return 1; + return 0; + } + Lockdownd* GetLockdownClient() { Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); client->client = NULL; + client->dev = NULL; if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { client->dev = $self->dev; return client; @@ -69,7 +72,7 @@ typedef struct { if (!phone) return NULL; Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); client->client = NULL; - if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &client->client)) { + if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { client->dev = phone->dev; return client; } @@ -101,7 +104,7 @@ typedef struct { if (!phone) return NULL; MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); client->client = NULL; - iphone_msync_new_client ( phone->dev, src_port, dst_port, &client->client); + iphone_msync_new_client ( phone->dev, src_port, dst_port, &(client->client)); return client; } @@ -115,7 +118,8 @@ typedef struct { } PListNode* Receive() { - PListNode* node = NULL; + PListNode* node = (PListNode*)malloc(sizeof(PListNode)); + node->node = NULL; iphone_msync_recv($self->client, &(node->node)); return node; } -- cgit v1.1-32-gdbae From 7f2e0f5f719a7092b45b0b7d538137a9b7d78567 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Thu, 15 Jan 2009 18:13:55 +0100 Subject: Rework SWIG interface to not duplicate constructor and destructor code. --- swig/iphone.i | 109 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 40 deletions(-) (limited to 'swig/iphone.i') diff --git a/swig/iphone.i b/swig/iphone.i index a0fe340..e970e89 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -10,13 +10,21 @@ } iPhone; typedef struct { - iphone_device_t dev; + iPhone* dev; iphone_lckd_client_t client; } Lockdownd; typedef struct { + Lockdownd* lckd; iphone_msync_client_t client; } MobileSync; + +//now declare funtions to handle creation and deletion of objects +void my_delete_iPhone(iPhone* dev); +Lockdownd* my_new_Lockdownd(iPhone* phone); +void my_delete_Lockdownd(Lockdownd* lckd); +MobileSync* my_new_MobileSync(Lockdownd* lckd); + %} /* Parse the header file to generate wrappers */ %include "stdint.i" @@ -27,14 +35,64 @@ typedef struct { } iPhone; typedef struct { - iphone_device_t dev; + iPhone* dev; iphone_lckd_client_t client; } Lockdownd; typedef struct { + Lockdownd* lckd; iphone_msync_client_t client; } MobileSync; +%inline %{ +//now define funtions to handle creation and deletion of objects + + +void my_delete_iPhone(iPhone* dev) { + if (dev) { + iphone_free_device ( dev->dev ); + free(dev); + } +} + +Lockdownd* my_new_Lockdownd(iPhone* phone) { + if (!phone) return NULL; + Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); + client->dev = phone; + client->client = NULL; + if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { + return client; + } + else { + free(client); + return NULL; + } +} + +void my_delete_Lockdownd(Lockdownd* lckd) { + if (lckd) { + my_delete_iPhone(lckd->dev); + iphone_lckd_free_client ( lckd->client ); + free(lckd); + } +} + +MobileSync* my_new_MobileSync(Lockdownd* lckd) { + if (!lckd || !lckd->dev) return NULL; + MobileSync* client = NULL; + int port = 0; + if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { + client = (MobileSync*) malloc(sizeof(MobileSync)); + client->lckd = lckd; + client->client = NULL; + iphone_msync_new_client ( lckd->dev->dev, 3432, port, &(client->client)); + } + return client; +} + +%} + + %extend iPhone { // Attach these functions to struct iPhone iPhone() { iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); @@ -44,8 +102,7 @@ typedef struct { } ~iPhone() { - iphone_free_device ( $self->dev ); - free($self); + my_delete_iPhone($self); } int InitDevice() { @@ -55,60 +112,32 @@ typedef struct { } Lockdownd* GetLockdownClient() { - Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); - client->client = NULL; - client->dev = NULL; - if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { - client->dev = $self->dev; - return client; - } - free(client); - return NULL; + return my_new_Lockdownd($self); } }; + %extend Lockdownd { // Attach these functions to struct Lockdownd Lockdownd(iPhone* phone) { - if (!phone) return NULL; - Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); - client->client = NULL; - if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { - client->dev = phone->dev; - return client; - } - else { - free(client); - return NULL; - } + return my_new_Lockdownd(phone); } ~Lockdownd() { - iphone_lckd_free_client ( $self->client ); - free($self); + my_delete_Lockdownd($self); } MobileSync* GetMobileSyncClient() { - int port = 0; - if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( $self->client, "com.apple.mobilesync", &port )) { - MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); - client->client = NULL; - if (IPHONE_E_SUCCESS == iphone_msync_new_client ( $self->dev, 3432, port, &(client->client))) - return client; - } - return NULL; + return my_new_MobileSync($self); } }; %extend MobileSync { // Attach these functions to struct MobileSync - MobileSync(iPhone* phone, int src_port, int dst_port) { - if (!phone) return NULL; - MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); - client->client = NULL; - iphone_msync_new_client ( phone->dev, src_port, dst_port, &(client->client)); - return client; + MobileSync(Lockdownd* lckd) { + return my_new_MobileSync(lckd); } ~MobileSync() { + my_delete_Lockdownd($self->lckd); iphone_msync_free_client ( $self->client ); free($self); } -- cgit v1.1-32-gdbae From 288929f45cb2641690879b52ec514097995cd41a Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Mon, 13 Apr 2009 10:06:42 +0200 Subject: Conform to python naling scheme. Add docstring directive. --- swig/iphone.i | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'swig/iphone.i') diff --git a/swig/iphone.i b/swig/iphone.i index e970e89..3ae0999 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -1,5 +1,6 @@ /* swig.i */ %module(package="libiphone") iPhone + %feature("autodoc", "1"); %{ /* Includes the header in the wrapper code */ #include @@ -105,13 +106,13 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { my_delete_iPhone($self); } - int InitDevice() { + int init_device() { if (IPHONE_E_SUCCESS == iphone_get_device ( &($self->dev))) return 1; return 0; } - Lockdownd* GetLockdownClient() { + Lockdownd* get_lockdown_client() { return my_new_Lockdownd($self); } }; @@ -126,7 +127,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { my_delete_Lockdownd($self); } - MobileSync* GetMobileSyncClient() { + MobileSync* get_mobile_sync_client() { return my_new_MobileSync($self); } }; @@ -142,11 +143,11 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { free($self); } - void Send(PListNode* node) { + void send(PListNode* node) { iphone_msync_send($self->client, node->node); } - PListNode* Receive() { + PListNode* receive() { PListNode* node = (PListNode*)malloc(sizeof(PListNode)); node->node = NULL; iphone_msync_recv($self->client, &(node->node)); -- cgit v1.1-32-gdbae