summaryrefslogtreecommitdiffstats
path: root/swig/iphone.i
blob: fb16208de8da5a44d301fb41160dffc0ea0b3d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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;
	}
};