diff options
Diffstat (limited to 'swig/iphone.i')
| -rw-r--r-- | swig/iphone.i | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/swig/iphone.i b/swig/iphone.i new file mode 100644 index 0000000..e970e89 --- /dev/null +++ b/swig/iphone.i | |||
| @@ -0,0 +1,156 @@ | |||
| 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 | #include "../src/utils.h" | ||
| 8 | typedef struct { | ||
| 9 | iphone_device_t dev; | ||
| 10 | } iPhone; | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | iPhone* dev; | ||
| 14 | iphone_lckd_client_t client; | ||
| 15 | } Lockdownd; | ||
| 16 | |||
| 17 | typedef struct { | ||
| 18 | Lockdownd* lckd; | ||
| 19 | iphone_msync_client_t client; | ||
| 20 | } MobileSync; | ||
| 21 | |||
| 22 | //now declare funtions to handle creation and deletion of objects | ||
| 23 | void my_delete_iPhone(iPhone* dev); | ||
| 24 | Lockdownd* my_new_Lockdownd(iPhone* phone); | ||
| 25 | void my_delete_Lockdownd(Lockdownd* lckd); | ||
| 26 | MobileSync* my_new_MobileSync(Lockdownd* lckd); | ||
| 27 | |||
| 28 | %} | ||
| 29 | /* Parse the header file to generate wrappers */ | ||
| 30 | %include "stdint.i" | ||
| 31 | %include "plist/swig/plist.i" | ||
| 32 | |||
| 33 | typedef struct { | ||
| 34 | iphone_device_t dev; | ||
| 35 | } iPhone; | ||
| 36 | |||
| 37 | typedef struct { | ||
| 38 | iPhone* dev; | ||
| 39 | iphone_lckd_client_t client; | ||
| 40 | } Lockdownd; | ||
| 41 | |||
| 42 | typedef struct { | ||
| 43 | Lockdownd* lckd; | ||
| 44 | iphone_msync_client_t client; | ||
| 45 | } MobileSync; | ||
| 46 | |||
| 47 | %inline %{ | ||
| 48 | //now define funtions to handle creation and deletion of objects | ||
| 49 | |||
| 50 | |||
| 51 | void my_delete_iPhone(iPhone* dev) { | ||
| 52 | if (dev) { | ||
| 53 | iphone_free_device ( dev->dev ); | ||
| 54 | free(dev); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | Lockdownd* my_new_Lockdownd(iPhone* phone) { | ||
| 59 | if (!phone) return NULL; | ||
| 60 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
| 61 | client->dev = phone; | ||
| 62 | client->client = NULL; | ||
| 63 | if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { | ||
| 64 | return client; | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | free(client); | ||
| 68 | return NULL; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | void my_delete_Lockdownd(Lockdownd* lckd) { | ||
| 73 | if (lckd) { | ||
| 74 | my_delete_iPhone(lckd->dev); | ||
| 75 | iphone_lckd_free_client ( lckd->client ); | ||
| 76 | free(lckd); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | MobileSync* my_new_MobileSync(Lockdownd* lckd) { | ||
| 81 | if (!lckd || !lckd->dev) return NULL; | ||
| 82 | MobileSync* client = NULL; | ||
| 83 | int port = 0; | ||
| 84 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { | ||
| 85 | client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 86 | client->lckd = lckd; | ||
| 87 | client->client = NULL; | ||
| 88 | iphone_msync_new_client ( lckd->dev->dev, 3432, port, &(client->client)); | ||
| 89 | } | ||
| 90 | return client; | ||
| 91 | } | ||
| 92 | |||
| 93 | %} | ||
| 94 | |||
| 95 | |||
| 96 | %extend iPhone { // Attach these functions to struct iPhone | ||
| 97 | iPhone() { | ||
| 98 | iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); | ||
| 99 | phone->dev = NULL; | ||
| 100 | iphone_set_debug_mask(DBGMASK_LOCKDOWND | DBGMASK_MOBILESYNC); | ||
| 101 | return phone; | ||
| 102 | } | ||
| 103 | |||
| 104 | ~iPhone() { | ||
| 105 | my_delete_iPhone($self); | ||
| 106 | } | ||
| 107 | |||
| 108 | int InitDevice() { | ||
| 109 | if (IPHONE_E_SUCCESS == iphone_get_device ( &($self->dev))) | ||
| 110 | return 1; | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | Lockdownd* GetLockdownClient() { | ||
| 115 | return my_new_Lockdownd($self); | ||
| 116 | } | ||
| 117 | }; | ||
| 118 | |||
| 119 | |||
| 120 | %extend Lockdownd { // Attach these functions to struct Lockdownd | ||
| 121 | Lockdownd(iPhone* phone) { | ||
| 122 | return my_new_Lockdownd(phone); | ||
| 123 | } | ||
| 124 | |||
| 125 | ~Lockdownd() { | ||
| 126 | my_delete_Lockdownd($self); | ||
| 127 | } | ||
| 128 | |||
| 129 | MobileSync* GetMobileSyncClient() { | ||
| 130 | return my_new_MobileSync($self); | ||
| 131 | } | ||
| 132 | }; | ||
| 133 | |||
| 134 | %extend MobileSync { // Attach these functions to struct MobileSync | ||
| 135 | MobileSync(Lockdownd* lckd) { | ||
| 136 | return my_new_MobileSync(lckd); | ||
| 137 | } | ||
| 138 | |||
| 139 | ~MobileSync() { | ||
| 140 | my_delete_Lockdownd($self->lckd); | ||
| 141 | iphone_msync_free_client ( $self->client ); | ||
| 142 | free($self); | ||
| 143 | } | ||
| 144 | |||
| 145 | void Send(PListNode* node) { | ||
| 146 | iphone_msync_send($self->client, node->node); | ||
| 147 | } | ||
| 148 | |||
| 149 | PListNode* Receive() { | ||
| 150 | PListNode* node = (PListNode*)malloc(sizeof(PListNode)); | ||
| 151 | node->node = NULL; | ||
| 152 | iphone_msync_recv($self->client, &(node->node)); | ||
| 153 | return node; | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | |||
