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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/**
* Object representing a [[https://github.com/luetzel/bluez/blob/master/doc/device-api.txt|device]].
*/
public class AstalBluetooth.Device : Object {
private IDevice proxy;
private Battery battery;
internal ObjectPath object_path { owned get; private set; }
internal Device(IDevice proxy) {
this.proxy = proxy;
this.object_path = (ObjectPath)proxy.g_object_path;
proxy.g_properties_changed.connect((props) => {
var map = (HashTable<string, Variant>)props;
foreach (var key in map.get_keys()) {
var prop = kebab_case(key);
if (get_class().find_property(prop) != null) {
notify_property(prop);
}
}
});
}
internal void set_battery(Battery battery) {
this.battery = battery;
notify_property("battery_percentage");
battery.notify["percentage"].connect((obj, pspec) => {
notify_property("battery_percentage");
});
}
/**
* List of 128-bit UUIDs that represents the available remote services.
*/
public string[] uuids { owned get { return proxy.uuids; } }
/**
* Indicates if the remote device is currently connected.
*/
public bool connected { get { return proxy.connected; } }
/**
* `true` if the device only supports the pre-2.1 pairing mechanism.
*/
public bool legacy_pairing { get { return proxy.legacy_pairing; } }
/**
* Indicates if the remote device is paired.
*/
public bool paired { get { return proxy.paired; } }
/**
* Received Signal Strength Indicator of the remote device (inquiry or advertising).
*/
public int16 rssi { get { return proxy.rssi; } }
/**
* The object path of the adapter the device belongs to.
*/
public ObjectPath adapter { owned get { return proxy.adapter; } }
/**
* The Bluetooth device address of the remote device.
*/
public string address { owned get { return proxy.address; } }
/**
* Proposed icon name.
*/
public string icon { owned get { return proxy.icon; } }
/**
* Remote Device ID information in modalias format used by the kernel and udev.
*/
public string modalias { owned get { return proxy.modalias; } }
/**
* The Bluetooth remote name.
*
* It is always better to use [[email protected]:alias].
*/
public string name { owned get { return proxy.name; } }
/**
* External appearance of device, as found on GAP service.
*/
public uint16 appearance { get { return proxy.appearance; } }
/**
* The Bluetooth class of device of the remote device.
*/
public uint32 class { get { return proxy.class; } }
/**
* Indicates if this device is currently trying to be connected.
*/
public bool connecting { get; private set; }
/**
* If set to `true` any incoming connections from the device will be immediately rejected.
*/
public bool blocked {
get { return proxy.blocked; }
set { proxy.blocked = value; }
}
/**
* Indicates if the remote is seen as trusted.
*/
public bool trusted {
get { return proxy.trusted; }
set { proxy.trusted = value; }
}
/**
* The percentage of battery left on the device if it has one, else -1.
*/
public double battery_percentage {
get {
if (battery != null) return battery.percentage * 0.01;
else return -1;
}
}
/**
* The name alias for the remote device.
*
* In case no alias is set, it will return the remote device [[email protected]:name].
*/
public string alias {
owned get { return proxy.alias; }
set { proxy.alias = value; }
}
/**
* This is a generic method to connect any profiles
* the remote device supports that can be connected to.
*
* Possible errors: `NotReady`, `Failed`, `InProgress`, `AlreadyConnected`.
*/
public async void connect_device() throws Error {
try {
connecting = true;
yield proxy.connect();
} finally {
connecting = false;
}
}
/**
* This method gracefully disconnects all connected profiles.
*
* Possible errors: `NotConnected`.
*/
public async void disconnect_device() throws Error {
yield proxy.disconnect();
}
/**
* This method connects a specific profile of this device.
* The UUID provided is the remote service UUID for the profile.
*
* Possible errors: `Failed`, `InProgress`, `InvalidArguments`, `NotAvailable`, `NotReady`.
*
* @param uuid the remote service UUID.
*/
public void connect_profile(string uuid) throws Error {
proxy.connect_profile(uuid);
}
/**
* This method disconnects a specific profile of this device.
*
* Possible errors: `Failed`, `InProgress`, `InvalidArguments`, `NotSupported`.
*
* @param uuid the remote service UUID.
*/
public void disconnect_profile(string uuid) throws Error {
proxy.disconnect_profile(uuid);
}
/**
* This method will connect to the remote device and initiate pairing.
*
* Possible errors: `InvalidArguments`, `Failed`, `AlreadyExists`,
* `AuthenticationCanceled`, `AuthenticationFailed`, `AuthenticationRejected`,
* `AuthenticationTimeout`, `ConnectionAttemptFailed`.
*/
public void pair() throws Error {
proxy.pair();
}
/**
* This method can be used to cancel a pairing operation
* initiated by [[email protected]].
*
* Possible errors: `DoesNotExist`, `Failed`.
*/
public void cancel_pairing() throws Error {
proxy.cancel_pairing();
}
}
|