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