forked from jkcoxson/idevice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_device.cpp
More file actions
120 lines (99 loc) · 2.84 KB
/
Copy pathcore_device.cpp
File metadata and controls
120 lines (99 loc) · 2.84 KB
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
// Jackson Coxson
#include <idevice++/core_device_proxy.hpp>
namespace IdeviceFFI {
// ---- Factories ----
Result<CoreDeviceProxy, FfiError> CoreDeviceProxy::connect(Provider &provider) {
CoreDeviceProxyHandle *out = nullptr;
FfiError e(::core_device_proxy_connect(provider.raw(), &out));
if (e) {
return Err(e);
}
return Ok(CoreDeviceProxy::adopt(out));
}
Result<CoreDeviceProxy, FfiError>
CoreDeviceProxy::from_socket(Idevice &&socket) {
CoreDeviceProxyHandle *out = nullptr;
// Rust consumes the socket regardless of result → release BEFORE call
IdeviceHandle *raw = socket.release();
FfiError e(::core_device_proxy_new(raw, &out));
if (e) {
return Err(e);
}
return Ok(CoreDeviceProxy::adopt(out));
}
// ---- IO ----
Result<void, FfiError> CoreDeviceProxy::send(const uint8_t *data, size_t len) {
FfiError e(::core_device_proxy_send(handle_.get(), data, len));
if (e) {
return Err(e);
}
return Ok();
}
Result<void, FfiError> CoreDeviceProxy::recv(std::vector<uint8_t> &out) {
if (out.empty())
out.resize(4096); // a reasonable default; caller can pre-size
size_t actual = 0;
FfiError e(
::core_device_proxy_recv(handle_.get(), out.data(), &actual, out.size()));
if (e) {
return Err(e);
}
out.resize(actual);
return Ok();
}
// ---- Handshake ----
Result<CoreClientParams, FfiError>
CoreDeviceProxy::get_client_parameters() const {
uint16_t mtu = 0;
char *addr_c = nullptr;
char *mask_c = nullptr;
FfiError e(::core_device_proxy_get_client_parameters(handle_.get(), &mtu,
&addr_c, &mask_c));
if (e) {
return Err(e);
}
CoreClientParams params;
params.mtu = mtu;
if (addr_c) {
params.address = addr_c;
::idevice_string_free(addr_c);
}
if (mask_c) {
params.netmask = mask_c;
::idevice_string_free(mask_c);
}
return Ok(std::move(params));
}
Result<std::string, FfiError> CoreDeviceProxy::get_server_address() const {
char *addr_c = nullptr;
FfiError e(::core_device_proxy_get_server_address(handle_.get(), &addr_c));
if (e) {
return Err(e);
}
std::string s;
if (addr_c) {
s = addr_c;
::idevice_string_free(addr_c);
}
return Ok(s);
}
Result<uint16_t, FfiError> CoreDeviceProxy::get_server_rsd_port() const {
uint16_t port = 0;
FfiError e(::core_device_proxy_get_server_rsd_port(handle_.get(), &port));
if (e) {
return Err(e);
}
return Ok(port);
}
// ---- Adapter creation (consumes *this) ----
Result<Adapter, FfiError> CoreDeviceProxy::create_tcp_adapter() && {
AdapterHandle *out = nullptr;
// Rust consumes the proxy regardless of result → release BEFORE call
CoreDeviceProxyHandle *raw = this->release();
FfiError e(::core_device_proxy_create_tcp_adapter(raw, &out));
if (e) {
return Err(e);
}
return Ok(Adapter::adopt(out));
}
} // namespace IdeviceFFI