diff options
Diffstat (limited to 'swig/iphone.i')
| -rw-r--r-- | swig/iphone.i | 123 |
1 files changed, 123 insertions, 0 deletions
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 @@ | |||
| 1 | /* swig.i */ | ||
| 2 | %module(package="libiphone") iPhone | ||
| 3 | %{ | ||
| 4 | /* Includes the header in the wrapper code */ | ||
| 5 | #include <libiphone/libiphone.h> | ||
| 6 | #include <plist/plist.h> | ||
| 7 | |||
| 8 | typedef struct { | ||
| 9 | iphone_device_t dev; | ||
| 10 | } iPhone; | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | iphone_device_t dev; | ||
| 14 | iphone_lckd_client_t client; | ||
| 15 | } Lockdownd; | ||
| 16 | |||
| 17 | typedef struct { | ||
| 18 | iphone_msync_client_t client; | ||
| 19 | } MobileSync; | ||
| 20 | //typedef struct { | ||
| 21 | // plist_t node; | ||
| 22 | //} PListNode; | ||
| 23 | %} | ||
| 24 | /* Parse the header file to generate wrappers */ | ||
| 25 | %include "plist/swig/plist.i" | ||
| 26 | //(module="libplist.PList")override module name until package path gets fixed in swig (1.3.37) | ||
| 27 | |||
| 28 | typedef struct { | ||
| 29 | iphone_device_t dev; | ||
| 30 | } iPhone; | ||
| 31 | |||
| 32 | typedef struct { | ||
| 33 | iphone_device_t dev; | ||
| 34 | iphone_lckd_client_t client; | ||
| 35 | } Lockdownd; | ||
| 36 | |||
| 37 | typedef struct { | ||
| 38 | iphone_msync_client_t client; | ||
| 39 | } MobileSync; | ||
| 40 | |||
| 41 | %extend iPhone { // Attach these functions to struct iPhone | ||
| 42 | iPhone() { | ||
| 43 | iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); | ||
| 44 | if (IPHONE_E_SUCCESS == iphone_get_device ( &phone->dev )) | ||
| 45 | return phone; | ||
| 46 | free(phone); | ||
| 47 | return NULL; | ||
| 48 | } | ||
| 49 | |||
| 50 | ~iPhone() { | ||
| 51 | iphone_free_device ( $self->dev ); | ||
| 52 | free($self); | ||
| 53 | } | ||
| 54 | |||
| 55 | Lockdownd* GetLockdownClient() { | ||
| 56 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
| 57 | client->client = NULL; | ||
| 58 | if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { | ||
| 59 | client->dev = $self->dev; | ||
| 60 | return client; | ||
| 61 | } | ||
| 62 | free(client); | ||
| 63 | return NULL; | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | %extend Lockdownd { // Attach these functions to struct Lockdownd | ||
| 68 | Lockdownd(iPhone* phone) { | ||
| 69 | if (!phone) return NULL; | ||
| 70 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
| 71 | client->client = NULL; | ||
| 72 | if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &client->client)) { | ||
| 73 | client->dev = phone->dev; | ||
| 74 | return client; | ||
| 75 | } | ||
| 76 | else { | ||
| 77 | free(client); | ||
| 78 | return NULL; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | ~Lockdownd() { | ||
| 83 | iphone_lckd_free_client ( $self->client ); | ||
| 84 | free($self); | ||
| 85 | } | ||
| 86 | |||
| 87 | MobileSync* GetMobileSyncClient() { | ||
| 88 | int port = 0; | ||
| 89 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( $self->client, "com.apple.mobilesync", &port )) { | ||
| 90 | MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 91 | client->client = NULL; | ||
| 92 | if (IPHONE_E_SUCCESS == iphone_msync_new_client ( $self->dev, 3432, port, &(client->client))) | ||
| 93 | return client; | ||
| 94 | } | ||
| 95 | return NULL; | ||
| 96 | } | ||
| 97 | }; | ||
| 98 | |||
| 99 | %extend MobileSync { // Attach these functions to struct MobileSync | ||
| 100 | MobileSync(iPhone* phone, int src_port, int dst_port) { | ||
| 101 | if (!phone) return NULL; | ||
| 102 | MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 103 | client->client = NULL; | ||
| 104 | iphone_msync_new_client ( phone->dev, src_port, dst_port, &client->client); | ||
| 105 | return client; | ||
| 106 | } | ||
| 107 | |||
| 108 | ~MobileSync() { | ||
| 109 | iphone_msync_free_client ( $self->client ); | ||
| 110 | free($self); | ||
| 111 | } | ||
| 112 | |||
| 113 | void Send(PListNode* node) { | ||
| 114 | iphone_msync_send($self->client, node->node); | ||
| 115 | } | ||
| 116 | |||
| 117 | PListNode* Receive() { | ||
| 118 | PListNode* node = NULL; | ||
| 119 | iphone_msync_recv($self->client, &(node->node)); | ||
| 120 | return node; | ||
| 121 | } | ||
| 122 | }; | ||
| 123 | |||
