diff options
| author | 2009-01-15 18:13:55 +0100 | |
|---|---|---|
| committer | 2009-01-15 18:13:55 +0100 | |
| commit | 7f2e0f5f719a7092b45b0b7d538137a9b7d78567 (patch) | |
| tree | 809881979d1506b2d63fa67fa9f73cd2e504ecac /swig | |
| parent | 47347ff723dd3c03b0006c150b02abaa2b9f4a76 (diff) | |
| download | libimobiledevice-7f2e0f5f719a7092b45b0b7d538137a9b7d78567.tar.gz libimobiledevice-7f2e0f5f719a7092b45b0b7d538137a9b7d78567.tar.bz2 | |
Rework SWIG interface to not duplicate constructor and destructor code.
Diffstat (limited to 'swig')
| -rw-r--r-- | swig/iphone.i | 109 |
1 files changed, 69 insertions, 40 deletions
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 @@ | |||
| 10 | } iPhone; | 10 | } iPhone; |
| 11 | 11 | ||
| 12 | typedef struct { | 12 | typedef struct { |
| 13 | iphone_device_t dev; | 13 | iPhone* dev; |
| 14 | iphone_lckd_client_t client; | 14 | iphone_lckd_client_t client; |
| 15 | } Lockdownd; | 15 | } Lockdownd; |
| 16 | 16 | ||
| 17 | typedef struct { | 17 | typedef struct { |
| 18 | Lockdownd* lckd; | ||
| 18 | iphone_msync_client_t client; | 19 | iphone_msync_client_t client; |
| 19 | } MobileSync; | 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 | |||
| 20 | %} | 28 | %} |
| 21 | /* Parse the header file to generate wrappers */ | 29 | /* Parse the header file to generate wrappers */ |
| 22 | %include "stdint.i" | 30 | %include "stdint.i" |
| @@ -27,14 +35,64 @@ typedef struct { | |||
| 27 | } iPhone; | 35 | } iPhone; |
| 28 | 36 | ||
| 29 | typedef struct { | 37 | typedef struct { |
| 30 | iphone_device_t dev; | 38 | iPhone* dev; |
| 31 | iphone_lckd_client_t client; | 39 | iphone_lckd_client_t client; |
| 32 | } Lockdownd; | 40 | } Lockdownd; |
| 33 | 41 | ||
| 34 | typedef struct { | 42 | typedef struct { |
| 43 | Lockdownd* lckd; | ||
| 35 | iphone_msync_client_t client; | 44 | iphone_msync_client_t client; |
| 36 | } MobileSync; | 45 | } MobileSync; |
| 37 | 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 | |||
| 38 | %extend iPhone { // Attach these functions to struct iPhone | 96 | %extend iPhone { // Attach these functions to struct iPhone |
| 39 | iPhone() { | 97 | iPhone() { |
| 40 | iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); | 98 | iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); |
| @@ -44,8 +102,7 @@ typedef struct { | |||
| 44 | } | 102 | } |
| 45 | 103 | ||
| 46 | ~iPhone() { | 104 | ~iPhone() { |
| 47 | iphone_free_device ( $self->dev ); | 105 | my_delete_iPhone($self); |
| 48 | free($self); | ||
| 49 | } | 106 | } |
| 50 | 107 | ||
| 51 | int InitDevice() { | 108 | int InitDevice() { |
| @@ -55,60 +112,32 @@ typedef struct { | |||
| 55 | } | 112 | } |
| 56 | 113 | ||
| 57 | Lockdownd* GetLockdownClient() { | 114 | Lockdownd* GetLockdownClient() { |
| 58 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | 115 | return my_new_Lockdownd($self); |
| 59 | client->client = NULL; | ||
| 60 | client->dev = NULL; | ||
| 61 | if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { | ||
| 62 | client->dev = $self->dev; | ||
| 63 | return client; | ||
| 64 | } | ||
| 65 | free(client); | ||
| 66 | return NULL; | ||
| 67 | } | 116 | } |
| 68 | }; | 117 | }; |
| 69 | 118 | ||
| 119 | |||
| 70 | %extend Lockdownd { // Attach these functions to struct Lockdownd | 120 | %extend Lockdownd { // Attach these functions to struct Lockdownd |
| 71 | Lockdownd(iPhone* phone) { | 121 | Lockdownd(iPhone* phone) { |
| 72 | if (!phone) return NULL; | 122 | return my_new_Lockdownd(phone); |
| 73 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
| 74 | client->client = NULL; | ||
| 75 | if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { | ||
| 76 | client->dev = phone->dev; | ||
| 77 | return client; | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | free(client); | ||
| 81 | return NULL; | ||
| 82 | } | ||
| 83 | } | 123 | } |
| 84 | 124 | ||
| 85 | ~Lockdownd() { | 125 | ~Lockdownd() { |
| 86 | iphone_lckd_free_client ( $self->client ); | 126 | my_delete_Lockdownd($self); |
| 87 | free($self); | ||
| 88 | } | 127 | } |
| 89 | 128 | ||
| 90 | MobileSync* GetMobileSyncClient() { | 129 | MobileSync* GetMobileSyncClient() { |
| 91 | int port = 0; | 130 | return my_new_MobileSync($self); |
| 92 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( $self->client, "com.apple.mobilesync", &port )) { | ||
| 93 | MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 94 | client->client = NULL; | ||
| 95 | if (IPHONE_E_SUCCESS == iphone_msync_new_client ( $self->dev, 3432, port, &(client->client))) | ||
| 96 | return client; | ||
| 97 | } | ||
| 98 | return NULL; | ||
| 99 | } | 131 | } |
| 100 | }; | 132 | }; |
| 101 | 133 | ||
| 102 | %extend MobileSync { // Attach these functions to struct MobileSync | 134 | %extend MobileSync { // Attach these functions to struct MobileSync |
| 103 | MobileSync(iPhone* phone, int src_port, int dst_port) { | 135 | MobileSync(Lockdownd* lckd) { |
| 104 | if (!phone) return NULL; | 136 | return my_new_MobileSync(lckd); |
| 105 | MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 106 | client->client = NULL; | ||
| 107 | iphone_msync_new_client ( phone->dev, src_port, dst_port, &(client->client)); | ||
| 108 | return client; | ||
| 109 | } | 137 | } |
| 110 | 138 | ||
| 111 | ~MobileSync() { | 139 | ~MobileSync() { |
| 140 | my_delete_Lockdownd($self->lckd); | ||
| 112 | iphone_msync_free_client ( $self->client ); | 141 | iphone_msync_free_client ( $self->client ); |
| 113 | free($self); | 142 | free($self); |
| 114 | } | 143 | } |
