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 @@ +INCLUDES = -I$(top_srcdir)/include  $(libplist_CFLAGS) + +BUILT_SOURCES = $(srcdir)/iphone_wrap.c +SWIG_SOURCES = iphone.i + +swigincludedir =$(includedir)/libiphone/swig +swiginclude_HEADERS = $(SWIG_SOURCES) + +pkgpython_PYTHON = iPhone.py __init__.py +pkgpyexec_LTLIBRARIES = _iPhone.la +_iPhone_la_SOURCES = $(srcdir)/iphone_wrap.c $(SWIG_SOURCES) +_iPhone_la_CFLAGS = $(PYTHON_CPPFLAGS) -I$(top_srcdir)/src +_iPhone_la_LDFLAGS = -module $(PYTHON_LDFLAGS) +_iPhone_la_LIBADD = ../src/libiphone.la + +$(srcdir)/iphone_wrap.c : $(SWIG_SOURCES) +	$(SWIG) $(SWIG_PYTHON_OPT) $(INCLUDES) -I$(top_srcdir)/src -o $@ $< + 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 @@ + /* swig.i */ + %module(package="libiphone") iPhone + %{ + /* Includes the header in the wrapper code */ + #include <libiphone/libiphone.h> + #include <plist/plist.h> + + typedef struct { +	iphone_device_t dev; + } iPhone; + + typedef struct { +	iphone_device_t dev; +	iphone_lckd_client_t client; + } Lockdownd; + + typedef struct { +	iphone_msync_client_t client; + } MobileSync; +//typedef struct { +//	plist_t node; +//} PListNode; + %} +/* Parse the header file to generate wrappers */ +%include "plist/swig/plist.i" + //(module="libplist.PList")override module name until package path gets fixed in swig (1.3.37) + +typedef struct { +	iphone_device_t dev; +} iPhone; + +typedef struct { +	iphone_device_t dev; +	iphone_lckd_client_t client; +} Lockdownd; + +typedef struct { +	iphone_msync_client_t client; +} MobileSync; + +%extend iPhone {             // Attach these functions to struct iPhone +	iPhone() { +		iPhone* phone = (iPhone*) malloc(sizeof(iPhone)); +		if (IPHONE_E_SUCCESS == iphone_get_device ( &phone->dev )) +			return phone; +		free(phone); +		return NULL; +	} + +	~iPhone() { +		iphone_free_device ( $self->dev ); +		free($self); +	} + +	Lockdownd* GetLockdownClient() { +		Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); +		client->client = NULL; +		if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( $self->dev , &(client->client)) ) { +			client->dev = $self->dev; +			return client; +		} +		free(client); +		return NULL; +	} +}; + +%extend Lockdownd {             // Attach these functions to struct Lockdownd +	Lockdownd(iPhone* phone) { +		if (!phone) return NULL; +		Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); +		client->client = NULL; +		if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &client->client)) { +			client->dev = phone->dev; +			return client; +		} +		else { +			free(client); +			return NULL; +		} +	} + +	~Lockdownd() { +		iphone_lckd_free_client ( $self->client ); +		free($self); +	} + +	MobileSync* GetMobileSyncClient() { +		int port = 0; +		if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( $self->client, "com.apple.mobilesync", &port )) { +			MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); +			client->client = NULL; +			if (IPHONE_E_SUCCESS == iphone_msync_new_client ( $self->dev, 3432, port, &(client->client))) +				return client; +		} +		return NULL; +	} +}; + +%extend MobileSync {             // Attach these functions to struct MobileSync +	MobileSync(iPhone* phone, int src_port, int dst_port) { +		if (!phone) return NULL; +		MobileSync* client = (MobileSync*) malloc(sizeof(MobileSync)); +		client->client = NULL; +		iphone_msync_new_client ( phone->dev, src_port, dst_port, &client->client); +		return client; +	} + +	~MobileSync() { +		iphone_msync_free_client ( $self->client ); +		free($self); +	} + +	void Send(PListNode* node) { +		iphone_msync_send($self->client, node->node); +	} + +	PListNode* Receive() { +		PListNode* node = NULL; +		iphone_msync_recv($self->client, &(node->node)); +		return node; +	} +}; + | 
