Merge lp:~kvalo/indicator-network/libconnman-control-technology into lp:~indicator-applet-developers/indicator-network/indicator-network
- libconnman-control-technology
- Merge into indicator-network
Proposed by
Kalle Valo
Status: | Merged |
---|---|
Merged at revision: | 152 |
Proposed branch: | lp:~kvalo/indicator-network/libconnman-control-technology |
Merge into: | lp:~indicator-applet-developers/indicator-network/indicator-network |
Diff against target: |
534 lines (+361/-8) 5 files modified
src/libconnman/Connman-1.0.vapi (+15/-0) src/libconnman/connman-manager.c (+236/-8) src/libconnman/connman-manager.h (+26/-0) src/libconnman/connman.h (+1/-0) tests/libconnman-vala/libconnman-vala.vala (+83/-0) |
To merge this branch: | bzr merge lp:~kvalo/indicator-network/libconnman-control-technology |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mikkel Kamstrup Erlandsen (community) | Approve | ||
Review via email: mp+50750@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/libconnman/Connman-1.0.vapi' | |||
2 | --- src/libconnman/Connman-1.0.vapi 2011-02-21 15:25:04 +0000 | |||
3 | +++ src/libconnman/Connman-1.0.vapi 2011-02-22 14:03:59 +0000 | |||
4 | @@ -26,6 +26,8 @@ | |||
5 | 26 | [CCode (has_construct_function = false)] | 26 | [CCode (has_construct_function = false)] |
6 | 27 | public Manager (); | 27 | public Manager (); |
7 | 28 | public async void connect_service (Connman.ServiceType type, Connman.ServiceMode mode, Connman.ServiceSecurity security, [CCode (array_length = false)] uint8[] ssid, uint ssid_len, GLib.Cancellable? cancellable) throws GLib.Error; | 28 | public async void connect_service (Connman.ServiceType type, Connman.ServiceMode mode, Connman.ServiceSecurity security, [CCode (array_length = false)] uint8[] ssid, uint ssid_len, GLib.Cancellable? cancellable) throws GLib.Error; |
8 | 29 | public async void disable_technology (Connman.TechnologyType type, GLib.Cancellable? cancellable) throws GLib.Error; | ||
9 | 30 | public async void enable_technology (Connman.TechnologyType type, GLib.Cancellable? cancellable) throws GLib.Error; | ||
10 | 29 | public Connman.Service get_default_service (); | 31 | public Connman.Service get_default_service (); |
11 | 30 | [CCode (array_length = false, array_null_terminated = true)] | 32 | [CCode (array_length = false, array_null_terminated = true)] |
12 | 31 | public unowned Connman.Service[] get_services (); | 33 | public unowned Connman.Service[] get_services (); |
13 | @@ -34,8 +36,11 @@ | |||
14 | 34 | public Connman.TechnologyState get_cellular_state (); | 36 | public Connman.TechnologyState get_cellular_state (); |
15 | 35 | public Connman.TechnologyState get_ethernet_state (); | 37 | public Connman.TechnologyState get_ethernet_state (); |
16 | 36 | public Connman.TechnologyState get_wifi_state (); | 38 | public Connman.TechnologyState get_wifi_state (); |
17 | 39 | public bool get_offline_mode (); | ||
18 | 40 | public void set_offline_mode (bool mode); | ||
19 | 37 | public bool get_connected (); | 41 | public bool get_connected (); |
20 | 38 | public bool connected { get; } | 42 | public bool connected { get; } |
21 | 43 | public bool offline_mode { get; set; } | ||
22 | 39 | public Connman.Service default_service { get; } | 44 | public Connman.Service default_service { get; } |
23 | 40 | public signal void service_added (Connman.Service object); | 45 | public signal void service_added (Connman.Service object); |
24 | 41 | public signal void service_removed (string object); | 46 | public signal void service_removed (string object); |
25 | @@ -166,6 +171,14 @@ | |||
26 | 166 | ENABLED, | 171 | ENABLED, |
27 | 167 | CONNECTED | 172 | CONNECTED |
28 | 168 | } | 173 | } |
29 | 174 | [CCode (cprefix = "CONNMAN_TECHNOLOGY_TYPE_", cheader_filename = "connman-manager.h")] | ||
30 | 175 | public enum TechnologyType { | ||
31 | 176 | UNKNOWN, | ||
32 | 177 | ETHERNET, | ||
33 | 178 | WIFI, | ||
34 | 179 | BLUETOOTH, | ||
35 | 180 | CELLULAR | ||
36 | 181 | } | ||
37 | 169 | [CCode (cheader_filename = "connman-service.h")] | 182 | [CCode (cheader_filename = "connman-service.h")] |
38 | 170 | public const string MANAGER_PATH; | 183 | public const string MANAGER_PATH; |
39 | 171 | [CCode (cheader_filename = "connman-service.h")] | 184 | [CCode (cheader_filename = "connman-service.h")] |
40 | @@ -179,6 +192,8 @@ | |||
41 | 179 | [CCode (cheader_filename = "connman-service.h")] | 192 | [CCode (cheader_filename = "connman-service.h")] |
42 | 180 | public const string PROPERTY_NAME; | 193 | public const string PROPERTY_NAME; |
43 | 181 | [CCode (cheader_filename = "connman-service.h")] | 194 | [CCode (cheader_filename = "connman-service.h")] |
44 | 195 | public const string PROPERTY_OFFLINE_MODE; | ||
45 | 196 | [CCode (cheader_filename = "connman-service.h")] | ||
46 | 182 | public const string PROPERTY_PASSPHRASE; | 197 | public const string PROPERTY_PASSPHRASE; |
47 | 183 | [CCode (cheader_filename = "connman-service.h")] | 198 | [CCode (cheader_filename = "connman-service.h")] |
48 | 184 | public const string PROPERTY_SECURITY; | 199 | public const string PROPERTY_SECURITY; |
49 | 185 | 200 | ||
50 | === modified file 'src/libconnman/connman-manager.c' | |||
51 | --- src/libconnman/connman-manager.c 2011-02-21 16:00:36 +0000 | |||
52 | +++ src/libconnman/connman-manager.c 2011-02-22 14:03:59 +0000 | |||
53 | @@ -67,16 +67,10 @@ | |||
54 | 67 | ConnmanTechnologyState ethernet_state; | 67 | ConnmanTechnologyState ethernet_state; |
55 | 68 | ConnmanTechnologyState cellular_state; | 68 | ConnmanTechnologyState cellular_state; |
56 | 69 | ConnmanTechnologyState bluetooth_state; | 69 | ConnmanTechnologyState bluetooth_state; |
57 | 70 | |||
58 | 71 | gboolean offline_mode; | ||
59 | 70 | }; | 72 | }; |
60 | 71 | 73 | ||
61 | 72 | typedef enum { | ||
62 | 73 | CONNMAN_TECHNOLOGY_TYPE_UNKNOWN, | ||
63 | 74 | CONNMAN_TECHNOLOGY_TYPE_ETHERNET, | ||
64 | 75 | CONNMAN_TECHNOLOGY_TYPE_WIFI, | ||
65 | 76 | CONNMAN_TECHNOLOGY_TYPE_BLUETOOTH, | ||
66 | 77 | CONNMAN_TECHNOLOGY_TYPE_CELLULAR, | ||
67 | 78 | } ConnmanTechnologyType; | ||
68 | 79 | |||
69 | 80 | struct technology_type_string | 74 | struct technology_type_string |
70 | 81 | { | 75 | { |
71 | 82 | const gchar *str; | 76 | const gchar *str; |
72 | @@ -128,8 +122,145 @@ | |||
73 | 128 | PROP_ETHERNET_STATE, | 122 | PROP_ETHERNET_STATE, |
74 | 129 | PROP_CELLULAR_STATE, | 123 | PROP_CELLULAR_STATE, |
75 | 130 | PROP_BLUETOOTH_STATE, | 124 | PROP_BLUETOOTH_STATE, |
76 | 125 | PROP_OFFLINE_MODE, | ||
77 | 131 | }; | 126 | }; |
78 | 132 | 127 | ||
79 | 128 | static const gchar *technology_type2str(ConnmanTechnologyType type) | ||
80 | 129 | { | ||
81 | 130 | const struct technology_type_string *s; | ||
82 | 131 | guint i; | ||
83 | 132 | |||
84 | 133 | for (i = 0; i < G_N_ELEMENTS(technology_type_map); i++) { | ||
85 | 134 | s = &technology_type_map[i]; | ||
86 | 135 | if (s->type == type) | ||
87 | 136 | return s->str; | ||
88 | 137 | } | ||
89 | 138 | |||
90 | 139 | g_warning("%s(): unknown technology type %d", __func__, type); | ||
91 | 140 | |||
92 | 141 | return "unknown"; | ||
93 | 142 | } | ||
94 | 143 | |||
95 | 144 | static void enable_technology_cb(GObject *object, GAsyncResult *res, | ||
96 | 145 | gpointer user_data) | ||
97 | 146 | { | ||
98 | 147 | GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(user_data); | ||
99 | 148 | GDBusProxy *proxy = G_DBUS_PROXY(object); | ||
100 | 149 | GError *error = NULL; | ||
101 | 150 | |||
102 | 151 | g_dbus_proxy_call_finish(proxy, res, &error); | ||
103 | 152 | |||
104 | 153 | if (error != NULL) { | ||
105 | 154 | g_simple_async_result_set_from_error(simple, error); | ||
106 | 155 | g_error_free(error); | ||
107 | 156 | goto out; | ||
108 | 157 | } | ||
109 | 158 | |||
110 | 159 | out: | ||
111 | 160 | g_simple_async_result_complete(simple); | ||
112 | 161 | g_object_unref(simple); | ||
113 | 162 | } | ||
114 | 163 | |||
115 | 164 | void connman_manager_enable_technology(ConnmanManager *self, | ||
116 | 165 | ConnmanTechnologyType type, | ||
117 | 166 | GCancellable *cancellable, | ||
118 | 167 | GAsyncReadyCallback callback, | ||
119 | 168 | gpointer user_data) | ||
120 | 169 | { | ||
121 | 170 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
122 | 171 | GSimpleAsyncResult *simple; | ||
123 | 172 | GVariant *parameters; | ||
124 | 173 | const gchar *s; | ||
125 | 174 | |||
126 | 175 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
127 | 176 | g_return_if_fail(priv != NULL); | ||
128 | 177 | |||
129 | 178 | simple = g_simple_async_result_new(G_OBJECT(self), callback, | ||
130 | 179 | user_data, | ||
131 | 180 | connman_manager_enable_technology); | ||
132 | 181 | |||
133 | 182 | s = technology_type2str(type); | ||
134 | 183 | parameters = g_variant_new("(s)", s); | ||
135 | 184 | |||
136 | 185 | /* FIXME: cancel the call on dispose */ | ||
137 | 186 | g_dbus_proxy_call(priv->proxy, "EnableTechnology", parameters, | ||
138 | 187 | G_DBUS_CALL_FLAGS_NONE, CONNECT_TIMEOUT, cancellable, | ||
139 | 188 | enable_technology_cb, simple); | ||
140 | 189 | } | ||
141 | 190 | |||
142 | 191 | void connman_manager_enable_technology_finish(ConnmanManager *self, | ||
143 | 192 | GAsyncResult *res, | ||
144 | 193 | GError **error) | ||
145 | 194 | { | ||
146 | 195 | GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res); | ||
147 | 196 | |||
148 | 197 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
149 | 198 | g_return_if_fail(g_simple_async_result_get_source_tag(simple) == | ||
150 | 199 | connman_manager_enable_technology); | ||
151 | 200 | |||
152 | 201 | g_simple_async_result_propagate_error(simple, error); | ||
153 | 202 | } | ||
154 | 203 | |||
155 | 204 | static void disable_technology_cb(GObject *object, GAsyncResult *res, | ||
156 | 205 | gpointer user_data) | ||
157 | 206 | { | ||
158 | 207 | GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(user_data); | ||
159 | 208 | GDBusProxy *proxy = G_DBUS_PROXY(object); | ||
160 | 209 | GError *error = NULL; | ||
161 | 210 | |||
162 | 211 | g_dbus_proxy_call_finish(proxy, res, &error); | ||
163 | 212 | |||
164 | 213 | if (error != NULL) { | ||
165 | 214 | g_simple_async_result_set_from_error(simple, error); | ||
166 | 215 | g_error_free(error); | ||
167 | 216 | goto out; | ||
168 | 217 | } | ||
169 | 218 | |||
170 | 219 | out: | ||
171 | 220 | g_simple_async_result_complete(simple); | ||
172 | 221 | g_object_unref(simple); | ||
173 | 222 | } | ||
174 | 223 | |||
175 | 224 | void connman_manager_disable_technology(ConnmanManager *self, | ||
176 | 225 | ConnmanTechnologyType type, | ||
177 | 226 | GCancellable *cancellable, | ||
178 | 227 | GAsyncReadyCallback callback, | ||
179 | 228 | gpointer user_data) | ||
180 | 229 | { | ||
181 | 230 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
182 | 231 | GSimpleAsyncResult *simple; | ||
183 | 232 | GVariant *parameters; | ||
184 | 233 | const gchar *s; | ||
185 | 234 | |||
186 | 235 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
187 | 236 | g_return_if_fail(priv != NULL); | ||
188 | 237 | |||
189 | 238 | simple = g_simple_async_result_new(G_OBJECT(self), callback, | ||
190 | 239 | user_data, | ||
191 | 240 | connman_manager_disable_technology); | ||
192 | 241 | |||
193 | 242 | s = technology_type2str(type); | ||
194 | 243 | parameters = g_variant_new("(s)", s); | ||
195 | 244 | |||
196 | 245 | /* FIXME: cancel the call on dispose */ | ||
197 | 246 | g_dbus_proxy_call(priv->proxy, "DisableTechnology", parameters, | ||
198 | 247 | G_DBUS_CALL_FLAGS_NONE, CONNECT_TIMEOUT, cancellable, | ||
199 | 248 | disable_technology_cb, simple); | ||
200 | 249 | } | ||
201 | 250 | |||
202 | 251 | void connman_manager_disable_technology_finish(ConnmanManager *self, | ||
203 | 252 | GAsyncResult *res, | ||
204 | 253 | GError **error) | ||
205 | 254 | { | ||
206 | 255 | GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res); | ||
207 | 256 | |||
208 | 257 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
209 | 258 | g_return_if_fail(g_simple_async_result_get_source_tag(simple) == | ||
210 | 259 | connman_manager_disable_technology); | ||
211 | 260 | |||
212 | 261 | g_simple_async_result_propagate_error(simple, error); | ||
213 | 262 | } | ||
214 | 263 | |||
215 | 133 | static void connect_service_cb(GObject *object, GAsyncResult *res, | 264 | static void connect_service_cb(GObject *object, GAsyncResult *res, |
216 | 134 | gpointer user_data) | 265 | gpointer user_data) |
217 | 135 | { | 266 | { |
218 | @@ -370,6 +501,26 @@ | |||
219 | 370 | return priv->bluetooth_state; | 501 | return priv->bluetooth_state; |
220 | 371 | } | 502 | } |
221 | 372 | 503 | ||
222 | 504 | gboolean connman_manager_get_offline_mode(ConnmanManager *self) | ||
223 | 505 | { | ||
224 | 506 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
225 | 507 | |||
226 | 508 | g_return_val_if_fail(CONNMAN_IS_MANAGER(self), FALSE); | ||
227 | 509 | g_return_val_if_fail(priv != NULL, FALSE); | ||
228 | 510 | |||
229 | 511 | return priv->offline_mode; | ||
230 | 512 | } | ||
231 | 513 | |||
232 | 514 | void connman_manager_set_offline_mode(ConnmanManager *self, gboolean mode) | ||
233 | 515 | { | ||
234 | 516 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
235 | 517 | |||
236 | 518 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
237 | 519 | g_return_if_fail(priv != NULL); | ||
238 | 520 | |||
239 | 521 | g_object_set(self, "offline-mode", mode, NULL); | ||
240 | 522 | } | ||
241 | 523 | |||
242 | 373 | static void update_default_service(ConnmanManager *self) | 524 | static void update_default_service(ConnmanManager *self) |
243 | 374 | { | 525 | { |
244 | 375 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | 526 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); |
245 | @@ -987,6 +1138,22 @@ | |||
246 | 987 | g_variant_unref(variant); | 1138 | g_variant_unref(variant); |
247 | 988 | } | 1139 | } |
248 | 989 | 1140 | ||
249 | 1141 | static void offline_mode_updated(ConnmanManager *self, GVariant *value) | ||
250 | 1142 | { | ||
251 | 1143 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
252 | 1144 | gboolean mode; | ||
253 | 1145 | |||
254 | 1146 | mode = g_variant_get_boolean(value); | ||
255 | 1147 | |||
256 | 1148 | if (priv->offline_mode == mode) | ||
257 | 1149 | return; | ||
258 | 1150 | |||
259 | 1151 | priv->offline_mode = mode; | ||
260 | 1152 | g_object_notify(G_OBJECT(self), "offline-mode"); | ||
261 | 1153 | |||
262 | 1154 | g_variant_unref(value); | ||
263 | 1155 | } | ||
264 | 1156 | |||
265 | 990 | static void update_property(ConnmanManager *self, const gchar *property, | 1157 | static void update_property(ConnmanManager *self, const gchar *property, |
266 | 991 | GVariant *variant) | 1158 | GVariant *variant) |
267 | 992 | { | 1159 | { |
268 | @@ -994,6 +1161,8 @@ | |||
269 | 994 | update_services(self, variant); | 1161 | update_services(self, variant); |
270 | 995 | } else if (g_strcmp0(property, CONNMAN_PROPERTY_TECHNOLOGIES) == 0) { | 1162 | } else if (g_strcmp0(property, CONNMAN_PROPERTY_TECHNOLOGIES) == 0) { |
271 | 996 | technologies_updated(self, variant); | 1163 | technologies_updated(self, variant); |
272 | 1164 | } else if (g_strcmp0(property, CONNMAN_PROPERTY_OFFLINE_MODE) == 0) { | ||
273 | 1165 | offline_mode_updated(self, variant); | ||
274 | 997 | } else { | 1166 | } else { |
275 | 998 | /* unknown property */ | 1167 | /* unknown property */ |
276 | 999 | g_variant_unref(variant); | 1168 | g_variant_unref(variant); |
277 | @@ -1177,6 +1346,52 @@ | |||
278 | 1177 | NULL); | 1346 | NULL); |
279 | 1178 | } | 1347 | } |
280 | 1179 | 1348 | ||
281 | 1349 | static void set_dbus_property_cb(GObject *object, | ||
282 | 1350 | GAsyncResult *res, | ||
283 | 1351 | gpointer user_data) | ||
284 | 1352 | { | ||
285 | 1353 | ConnmanManager *self = CONNMAN_MANAGER(user_data); | ||
286 | 1354 | GDBusProxy *proxy = G_DBUS_PROXY(object); | ||
287 | 1355 | GError *error = NULL; | ||
288 | 1356 | |||
289 | 1357 | g_dbus_proxy_call_finish(proxy, res, &error); | ||
290 | 1358 | |||
291 | 1359 | if (error != NULL) { | ||
292 | 1360 | g_warning("ConnmanManager SetProperty() failed: %s", error->message); | ||
293 | 1361 | g_error_free(error); | ||
294 | 1362 | } | ||
295 | 1363 | |||
296 | 1364 | /* trick to avoid destroying self during async call */ | ||
297 | 1365 | g_object_unref(self); | ||
298 | 1366 | } | ||
299 | 1367 | |||
300 | 1368 | static void set_dbus_property(ConnmanManager *self, | ||
301 | 1369 | const gchar *property, | ||
302 | 1370 | GVariant *value) | ||
303 | 1371 | { | ||
304 | 1372 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
305 | 1373 | GVariant *parameters; | ||
306 | 1374 | |||
307 | 1375 | g_return_if_fail(CONNMAN_IS_MANAGER(self)); | ||
308 | 1376 | g_return_if_fail(priv != NULL); | ||
309 | 1377 | |||
310 | 1378 | parameters = g_variant_new("(sv)", property, value); | ||
311 | 1379 | |||
312 | 1380 | g_dbus_proxy_call(priv->proxy, "SetProperty", parameters, | ||
313 | 1381 | G_DBUS_CALL_FLAGS_NONE, -1, NULL, | ||
314 | 1382 | set_dbus_property_cb, g_object_ref(self)); | ||
315 | 1383 | } | ||
316 | 1384 | |||
317 | 1385 | static void update_offline_mode(ConnmanManager *self) | ||
318 | 1386 | { | ||
319 | 1387 | ConnmanManagerPrivate *priv = GET_PRIVATE(self); | ||
320 | 1388 | GVariant *value; | ||
321 | 1389 | |||
322 | 1390 | value = g_variant_new("b", priv->offline_mode); | ||
323 | 1391 | |||
324 | 1392 | set_dbus_property(self, "OfflineMode", value); | ||
325 | 1393 | } | ||
326 | 1394 | |||
327 | 1180 | static void set_property(GObject *object, guint property_id, | 1395 | static void set_property(GObject *object, guint property_id, |
328 | 1181 | const GValue *value, GParamSpec *pspec) | 1396 | const GValue *value, GParamSpec *pspec) |
329 | 1182 | { | 1397 | { |
330 | @@ -1204,6 +1419,10 @@ | |||
331 | 1204 | case PROP_BLUETOOTH_STATE: | 1419 | case PROP_BLUETOOTH_STATE: |
332 | 1205 | priv->bluetooth_state = g_value_get_uint(value); | 1420 | priv->bluetooth_state = g_value_get_uint(value); |
333 | 1206 | break; | 1421 | break; |
334 | 1422 | case PROP_OFFLINE_MODE: | ||
335 | 1423 | priv->offline_mode = g_value_get_boolean(value); | ||
336 | 1424 | update_offline_mode(self); | ||
337 | 1425 | break; | ||
338 | 1207 | default: | 1426 | default: |
339 | 1208 | /* We don't have any other property... */ | 1427 | /* We don't have any other property... */ |
340 | 1209 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); | 1428 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
341 | @@ -1236,6 +1455,9 @@ | |||
342 | 1236 | case PROP_BLUETOOTH_STATE: | 1455 | case PROP_BLUETOOTH_STATE: |
343 | 1237 | g_value_set_uint(value, priv->bluetooth_state); | 1456 | g_value_set_uint(value, priv->bluetooth_state); |
344 | 1238 | break; | 1457 | break; |
345 | 1458 | case PROP_OFFLINE_MODE: | ||
346 | 1459 | g_value_set_boolean(value, priv->offline_mode); | ||
347 | 1460 | break; | ||
348 | 1239 | default: | 1461 | default: |
349 | 1240 | /* We don't have any other property... */ | 1462 | /* We don't have any other property... */ |
350 | 1241 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); | 1463 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
351 | @@ -1366,6 +1588,12 @@ | |||
352 | 1366 | CONNMAN_TECHNOLOGY_STATE_UNKNOWN, | 1588 | CONNMAN_TECHNOLOGY_STATE_UNKNOWN, |
353 | 1367 | G_PARAM_READABLE); | 1589 | G_PARAM_READABLE); |
354 | 1368 | g_object_class_install_property(gobject_class, PROP_BLUETOOTH_STATE, pspec); | 1590 | g_object_class_install_property(gobject_class, PROP_BLUETOOTH_STATE, pspec); |
355 | 1591 | |||
356 | 1592 | pspec = g_param_spec_boolean("offline-mode", | ||
357 | 1593 | "ConnmanManager's offline mode property", | ||
358 | 1594 | "Set offline mode", FALSE, | ||
359 | 1595 | G_PARAM_READWRITE); | ||
360 | 1596 | g_object_class_install_property(gobject_class, PROP_OFFLINE_MODE, pspec); | ||
361 | 1369 | } | 1597 | } |
362 | 1370 | 1598 | ||
363 | 1371 | static void connman_manager_init(ConnmanManager *self) | 1599 | static void connman_manager_init(ConnmanManager *self) |
364 | 1372 | 1600 | ||
365 | === modified file 'src/libconnman/connman-manager.h' | |||
366 | --- src/libconnman/connman-manager.h 2011-02-21 15:25:04 +0000 | |||
367 | +++ src/libconnman/connman-manager.h 2011-02-22 14:03:59 +0000 | |||
368 | @@ -54,6 +54,14 @@ | |||
369 | 54 | } ConnmanManagerClass; | 54 | } ConnmanManagerClass; |
370 | 55 | 55 | ||
371 | 56 | typedef enum { | 56 | typedef enum { |
372 | 57 | CONNMAN_TECHNOLOGY_TYPE_UNKNOWN, | ||
373 | 58 | CONNMAN_TECHNOLOGY_TYPE_ETHERNET, | ||
374 | 59 | CONNMAN_TECHNOLOGY_TYPE_WIFI, | ||
375 | 60 | CONNMAN_TECHNOLOGY_TYPE_BLUETOOTH, | ||
376 | 61 | CONNMAN_TECHNOLOGY_TYPE_CELLULAR, | ||
377 | 62 | } ConnmanTechnologyType; | ||
378 | 63 | |||
379 | 64 | typedef enum { | ||
380 | 57 | CONNMAN_TECHNOLOGY_STATE_UNKNOWN, | 65 | CONNMAN_TECHNOLOGY_STATE_UNKNOWN, |
381 | 58 | CONNMAN_TECHNOLOGY_STATE_UNAVAILABLE, | 66 | CONNMAN_TECHNOLOGY_STATE_UNAVAILABLE, |
382 | 59 | CONNMAN_TECHNOLOGY_STATE_AVAILABLE, | 67 | CONNMAN_TECHNOLOGY_STATE_AVAILABLE, |
383 | @@ -64,6 +72,22 @@ | |||
384 | 64 | 72 | ||
385 | 65 | GType connman_manager_get_type(void); | 73 | GType connman_manager_get_type(void); |
386 | 66 | 74 | ||
387 | 75 | void connman_manager_enable_technology(ConnmanManager *self, | ||
388 | 76 | ConnmanTechnologyType type, | ||
389 | 77 | GCancellable *cancellable, | ||
390 | 78 | GAsyncReadyCallback callback, | ||
391 | 79 | gpointer user_data); | ||
392 | 80 | void connman_manager_enable_technology_finish(ConnmanManager *self, | ||
393 | 81 | GAsyncResult *res, | ||
394 | 82 | GError **error); | ||
395 | 83 | void connman_manager_disable_technology(ConnmanManager *self, | ||
396 | 84 | ConnmanTechnologyType type, | ||
397 | 85 | GCancellable *cancellable, | ||
398 | 86 | GAsyncReadyCallback callback, | ||
399 | 87 | gpointer user_data); | ||
400 | 88 | void connman_manager_disable_technology_finish(ConnmanManager *self, | ||
401 | 89 | GAsyncResult *res, | ||
402 | 90 | GError **error); | ||
403 | 67 | void connman_manager_connect_service(ConnmanManager *self, | 91 | void connman_manager_connect_service(ConnmanManager *self, |
404 | 68 | ConnmanServiceType type, | 92 | ConnmanServiceType type, |
405 | 69 | ConnmanServiceMode mode, | 93 | ConnmanServiceMode mode, |
406 | @@ -85,6 +109,8 @@ | |||
407 | 85 | ConnmanTechnologyState connman_manager_get_ethernet_state(ConnmanManager *self); | 109 | ConnmanTechnologyState connman_manager_get_ethernet_state(ConnmanManager *self); |
408 | 86 | ConnmanTechnologyState connman_manager_get_cellular_state(ConnmanManager *self); | 110 | ConnmanTechnologyState connman_manager_get_cellular_state(ConnmanManager *self); |
409 | 87 | ConnmanTechnologyState connman_manager_get_bluetooth_state(ConnmanManager *self); | 111 | ConnmanTechnologyState connman_manager_get_bluetooth_state(ConnmanManager *self); |
410 | 112 | gboolean connman_manager_get_offline_mode(ConnmanManager *self); | ||
411 | 113 | void connman_manager_set_offline_mode(ConnmanManager *self, gboolean mode); | ||
412 | 88 | ConnmanManager *connman_manager_new(void); | 114 | ConnmanManager *connman_manager_new(void); |
413 | 89 | 115 | ||
414 | 90 | #endif | 116 | #endif |
415 | 91 | 117 | ||
416 | === modified file 'src/libconnman/connman.h' | |||
417 | --- src/libconnman/connman.h 2011-02-21 15:25:04 +0000 | |||
418 | +++ src/libconnman/connman.h 2011-02-22 14:03:59 +0000 | |||
419 | @@ -75,6 +75,7 @@ | |||
420 | 75 | #define CONNMAN_PROPERTY_IPV4 "IPv4" | 75 | #define CONNMAN_PROPERTY_IPV4 "IPv4" |
421 | 76 | #define CONNMAN_PROPERTY_IPV4_CONFIGURATION "IPv4.Configuration" | 76 | #define CONNMAN_PROPERTY_IPV4_CONFIGURATION "IPv4.Configuration" |
422 | 77 | #define CONNMAN_PROPERTY_TECHNOLOGIES "Technologies" | 77 | #define CONNMAN_PROPERTY_TECHNOLOGIES "Technologies" |
423 | 78 | #define CONNMAN_PROPERTY_OFFLINE_MODE "OfflineMode" | ||
424 | 78 | 79 | ||
425 | 79 | #define CONNMAN_TECHNOLOGY_PROPERTY_STATE "State" | 80 | #define CONNMAN_TECHNOLOGY_PROPERTY_STATE "State" |
426 | 80 | #define CONNMAN_TECHNOLOGY_PROPERTY_TYPE "Type" | 81 | #define CONNMAN_TECHNOLOGY_PROPERTY_TYPE "Type" |
427 | 81 | 82 | ||
428 | === modified file 'tests/libconnman-vala/libconnman-vala.vala' | |||
429 | --- tests/libconnman-vala/libconnman-vala.vala 2011-02-21 16:01:54 +0000 | |||
430 | +++ tests/libconnman-vala/libconnman-vala.vala 2011-02-22 14:03:59 +0000 | |||
431 | @@ -260,6 +260,75 @@ | |||
432 | 260 | stdout.printf(" bluetooth %d\n", manager.get_bluetooth_state()); | 260 | stdout.printf(" bluetooth %d\n", manager.get_bluetooth_state()); |
433 | 261 | } | 261 | } |
434 | 262 | 262 | ||
435 | 263 | static Connman.TechnologyType str2tech(string s) | ||
436 | 264 | { | ||
437 | 265 | switch (s) { | ||
438 | 266 | case "wifi": | ||
439 | 267 | return Connman.TechnologyType.WIFI; | ||
440 | 268 | case "ethernet": | ||
441 | 269 | return Connman.TechnologyType.ETHERNET; | ||
442 | 270 | case "cellular": | ||
443 | 271 | return Connman.TechnologyType.CELLULAR; | ||
444 | 272 | case "bluetooth": | ||
445 | 273 | return Connman.TechnologyType.BLUETOOTH; | ||
446 | 274 | default: | ||
447 | 275 | stdout.printf("Unknown tech: %s\n", s); | ||
448 | 276 | return Connman.TechnologyType.UNKNOWN; | ||
449 | 277 | } | ||
450 | 278 | } | ||
451 | 279 | |||
452 | 280 | static void enable(string[] args) { | ||
453 | 281 | |||
454 | 282 | if (args.length != 1) { | ||
455 | 283 | stdout.printf("Invalid number of arguments for enable: %d\n", | ||
456 | 284 | args.length); | ||
457 | 285 | return; | ||
458 | 286 | } | ||
459 | 287 | |||
460 | 288 | var tech = str2tech(args[0]); | ||
461 | 289 | |||
462 | 290 | manager.enable_technology(tech, null); | ||
463 | 291 | } | ||
464 | 292 | |||
465 | 293 | static void disable(string[] args) { | ||
466 | 294 | |||
467 | 295 | if (args.length != 1) { | ||
468 | 296 | stdout.printf("Invalid number of arguments for enable: %d\n", | ||
469 | 297 | args.length); | ||
470 | 298 | return; | ||
471 | 299 | } | ||
472 | 300 | |||
473 | 301 | var tech = str2tech(args[0]); | ||
474 | 302 | |||
475 | 303 | manager.disable_technology(tech, null); | ||
476 | 304 | } | ||
477 | 305 | |||
478 | 306 | static void offline(string[] args) { | ||
479 | 307 | |||
480 | 308 | if (args.length != 1) { | ||
481 | 309 | stdout.printf("Invalid number of arguments for offline: %d\n", | ||
482 | 310 | args.length); | ||
483 | 311 | return; | ||
484 | 312 | } | ||
485 | 313 | |||
486 | 314 | var mode = args[0]; | ||
487 | 315 | bool value; | ||
488 | 316 | |||
489 | 317 | switch (mode) { | ||
490 | 318 | case "on": | ||
491 | 319 | value = true; | ||
492 | 320 | break; | ||
493 | 321 | case "off": | ||
494 | 322 | value = false; | ||
495 | 323 | break; | ||
496 | 324 | default: | ||
497 | 325 | stdout.printf("Unknown mode for offline: %s\n", mode); | ||
498 | 326 | return; | ||
499 | 327 | } | ||
500 | 328 | |||
501 | 329 | manager.offline_mode = value; | ||
502 | 330 | } | ||
503 | 331 | |||
504 | 263 | static bool cmd_handler() { | 332 | static bool cmd_handler() { |
505 | 264 | var line = cmd_queue.pop(); | 333 | var line = cmd_queue.pop(); |
506 | 265 | var tokens = line.split(" "); | 334 | var tokens = line.split(" "); |
507 | @@ -296,6 +365,15 @@ | |||
508 | 296 | case "tech": | 365 | case "tech": |
509 | 297 | tech(args); | 366 | tech(args); |
510 | 298 | break; | 367 | break; |
511 | 368 | case "enable": | ||
512 | 369 | enable(args); | ||
513 | 370 | break; | ||
514 | 371 | case "disable": | ||
515 | 372 | disable(args); | ||
516 | 373 | break; | ||
517 | 374 | case "offline": | ||
518 | 375 | offline(args); | ||
519 | 376 | break; | ||
520 | 299 | default: | 377 | default: |
521 | 300 | stdout.printf("Unknown command: %s\n", cmd); | 378 | stdout.printf("Unknown command: %s\n", cmd); |
522 | 301 | break; | 379 | break; |
523 | @@ -363,6 +441,11 @@ | |||
524 | 363 | manager.get_bluetooth_state()); | 441 | manager.get_bluetooth_state()); |
525 | 364 | }); | 442 | }); |
526 | 365 | 443 | ||
527 | 444 | manager.notify["offline-mode"].connect((s, p) => { | ||
528 | 445 | stdout.printf("offline-mode %s\n", | ||
529 | 446 | manager.offline_mode ? "on" : "off"); | ||
530 | 447 | }); | ||
531 | 448 | |||
532 | 366 | loop.run(); | 449 | loop.run(); |
533 | 367 | 450 | ||
534 | 368 | return 0; | 451 | return 0; |
Looks good