diff options
| author | 2009-01-13 18:57:52 +0100 | |
|---|---|---|
| committer | 2009-01-13 18:57:52 +0100 | |
| commit | d4694679f918750e920a2238d891cd2fbb741a90 (patch) | |
| tree | ea52b9d253993b31ec71cbad35280d7c5eeab957 /swig | |
| parent | 564aebf941f2f0c5fb57d2f86091b37d6331b9d9 (diff) | |
| download | libimobiledevice-d4694679f918750e920a2238d891cd2fbb741a90.tar.gz libimobiledevice-d4694679f918750e920a2238d891cd2fbb741a90.tar.bz2 | |
Add parts of a python binding to libiphone that also include libplist (using SWIG).
Diffstat (limited to 'swig')
| -rw-r--r-- | swig/Makefile.am | 18 | ||||
| -rw-r--r-- | swig/__init__.py | 1 | ||||
| -rw-r--r-- | swig/iphone.i | 123 |
3 files changed, 142 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..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 | |||
