Merge lp:~kvalo/indicator-network/libconnman-connect-dialog into lp:~indicator-applet-developers/indicator-network/indicator-network

Proposed by Kalle Valo on 2010-11-19
Status: Merged
Merged at revision: 104
Proposed branch: lp:~kvalo/indicator-network/libconnman-connect-dialog
Merge into: lp:~indicator-applet-developers/indicator-network/indicator-network
Diff against target: 1351 lines (+467/-456)
10 files modified
src/agent/Makefile.am (+4/-4)
src/agent/connect-error-dialog.c (+0/-5)
src/agent/passphrase-dialog.c (+0/-1)
src/agent/pin-dialog.c (+0/-1)
src/agent/wireless-connect-dialog.c (+139/-424)
src/common/connman-manager.c (+141/-9)
src/common/connman-manager.h (+13/-0)
src/common/connman-service.c (+97/-7)
src/common/connman-service.h (+17/-0)
tests/libconnman-tool.c (+56/-5)
To merge this branch: bzr merge lp:~kvalo/indicator-network/libconnman-connect-dialog
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) 2010-11-19 Approve on 2010-11-19
Review via email: mp+41275@code.launchpad.net
To post a comment you must log in.

 * connman_manager_connect_service() should add a GCancellable argument to like other GIO async calls use.

 * connman-service.h exports non-namespaced symbols str2*(). Either define them in a .c file or namespace them with connman_service_*()

review: Needs Fixing
115. By Kalle Valo on 2010-11-19

connman-manager: added cancellable to connect_service()

116. By Kalle Valo on 2010-11-19

connman-service: add proper namespace prefix to str2* functions

Kalle Valo (kvalo) wrote :

Mikkel Kamstrup Erlandsen <email address hidden> writes:

> Review: Needs Fixing
>
> * connman_manager_connect_service() should add a
> GCancellable argument to like other GIO async calls use.

Fixed.

> * connman-service.h exports non-namespaced symbols str2*(). Either
> define them in a .c file or namespace them with connman_service_*()

Fixed.

Thank you for the review. I now pushed the fixex to the branch.

--
Kalle Valo

ok, i'm happy now :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/agent/Makefile.am'
2--- src/agent/Makefile.am 2010-11-10 11:18:21 +0000
3+++ src/agent/Makefile.am 2010-11-19 12:16:09 +0000
4@@ -19,12 +19,12 @@
5
6 indicator_network_agent_CFLAGS = \
7 $(GTK_CFLAGS) \
8- $(DBUSGLIB_CFLAGS) \
9- $(GIO_CFLAGS)
10+ $(GIO_CFLAGS) \
11+ $(CONNMAN_CFLAGS)
12
13 indicator_network_agent_LDADD = \
14 $(GTK_LIBS) \
15- $(DBUSGLIB_LIBS) \
16 $(GIO_LIBS) \
17 $(top_builddir)/src/common/libmarshal.la \
18- $(top_builddir)/src/common/liblog.la
19+ $(top_builddir)/src/common/liblog.la \
20+ $(CONNMAN_LIBS)
21
22=== modified file 'src/agent/connect-error-dialog.c'
23--- src/agent/connect-error-dialog.c 2010-09-23 07:24:58 +0000
24+++ src/agent/connect-error-dialog.c 2010-11-19 12:16:09 +0000
25@@ -27,14 +27,9 @@
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <glib/gi18n.h>
29-#include <dbus/dbus-glib.h>
30 #include <gtk/gtk.h>
31 #include <locale.h>
32
33-#include "ofono.h"
34-#include "ofono-manager-client.h"
35-#include "ofono-simmanager-client.h"
36-#include "ofono-modem-client.h"
37 #include "marshal.h"
38
39 G_DEFINE_TYPE(ConnectErrorDialog, connect_error_dialog, GTK_TYPE_DIALOG);
40
41=== modified file 'src/agent/passphrase-dialog.c'
42--- src/agent/passphrase-dialog.c 2010-11-17 13:54:50 +0000
43+++ src/agent/passphrase-dialog.c 2010-11-19 12:16:09 +0000
44@@ -27,7 +27,6 @@
45 #include <glib.h>
46 #include <glib-object.h>
47 #include <glib/gi18n.h>
48-#include <dbus/dbus-glib.h>
49 #include <gtk/gtk.h>
50 #include <locale.h>
51
52
53=== modified file 'src/agent/pin-dialog.c'
54--- src/agent/pin-dialog.c 2010-11-04 10:22:03 +0000
55+++ src/agent/pin-dialog.c 2010-11-19 12:16:09 +0000
56@@ -27,7 +27,6 @@
57 #include <glib.h>
58 #include <glib-object.h>
59 #include <glib/gi18n.h>
60-#include <dbus/dbus-glib.h>
61 #include <gtk/gtk.h>
62 #include <locale.h>
63
64
65=== modified file 'src/agent/wireless-connect-dialog.c'
66--- src/agent/wireless-connect-dialog.c 2010-11-17 13:54:50 +0000
67+++ src/agent/wireless-connect-dialog.c 2010-11-19 12:16:09 +0000
68@@ -27,13 +27,12 @@
69 #include <glib.h>
70 #include <glib-object.h>
71 #include <glib/gi18n.h>
72-#include <dbus/dbus-glib.h>
73 #include <gtk/gtk.h>
74 #include <locale.h>
75+#include <string.h>
76
77-#include "connman.h"
78-#include "connman-manager-client.h"
79-#include "connman-service-client.h"
80+#include "connman-manager.h"
81+#include "connman-service.h"
82
83 G_DEFINE_TYPE(WirelessConnectDialog, wireless_connect_dialog, GTK_TYPE_DIALOG);
84
85@@ -41,17 +40,15 @@
86
87 struct _WirelessConnectDialogPriv
88 {
89- DBusGConnection *system_bus;
90- DBusGProxy *connman_manager;
91- DBusGProxy *service_proxy;
92+ ConnmanManager *manager;
93+
94 GtkWidget *network_combo;
95 GtkWidget *count_label;
96 GtkWidget *security_combo;
97+
98 guint service_count;
99 GtkListStore *store;
100- DBusGProxyCall *services_call;
101- DBusGProxyCall *connect_call;
102- DBusGProxyCall *connect_service;
103+
104 gboolean service_selected;
105 gboolean connecting;
106 };
107@@ -62,40 +59,24 @@
108 WirelessConnectDialogPriv))
109
110 enum {
111- COLUMN_PATH,
112+ COLUMN_SERVICE,
113 COLUMN_NAME,
114- COLUMN_SECURITY,
115 N_COLUMNS,
116 };
117
118 static void wireless_connect_dialog_init(WirelessConnectDialog *self)
119 {
120 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
121- GError *error = NULL;
122-
123- priv->system_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
124-
125- if (error) {
126- g_critical("Unable to connect to the dbus system bus: %s",
127- error->message);
128- g_error_free(error);
129- return;
130- }
131-
132- if (priv->system_bus == NULL) {
133- g_critical("%s(): failed to get system bus", __func__);
134- return;
135- }
136-
137- priv->connman_manager = NULL;
138- priv->service_proxy = NULL;
139+
140+ priv->manager = connman_manager_new();
141+
142 priv->network_combo = NULL;
143+ priv->count_label = NULL;
144 priv->security_combo = NULL;
145- priv->count_label = NULL;
146+
147 priv->service_count = 0;
148 priv->store = NULL;
149- priv->services_call = NULL;
150- priv->connect_call = NULL;
151+
152 priv->service_selected = FALSE;
153 priv->connecting = FALSE;
154
155@@ -107,30 +88,14 @@
156 WirelessConnectDialog *self = WIRELESS_CONNECT_DIALOG(object);
157 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
158
159- if (priv->service_proxy != NULL && priv->connect_call != NULL) {
160- dbus_g_proxy_cancel_call(priv->service_proxy, priv->connect_call);
161- priv->connect_call = NULL;
162- }
163-
164- if (priv->connman_manager != NULL && priv->services_call != NULL) {
165- dbus_g_proxy_cancel_call(priv->connman_manager, priv->services_call);
166- priv->services_call = NULL;
167- }
168-
169- if (priv->connman_manager != NULL && priv->connect_service != NULL) {
170- dbus_g_proxy_cancel_call(priv->connman_manager, priv->connect_service);
171- priv->connect_service = NULL;
172- }
173-
174- if (priv->connman_manager != NULL) {
175- g_object_unref(priv->connman_manager);
176- priv->connman_manager = NULL;
177- }
178-
179- if (priv->service_proxy != NULL) {
180- g_object_unref(priv->service_proxy);
181- priv->service_proxy = NULL;
182- }
183+ if (priv->manager != NULL) {
184+ g_object_unref(priv->manager);
185+ priv->manager = NULL;
186+ }
187+
188+ /* all the gtkwidgets are destroyed at the same time as this dialog */
189+
190+ /* FIXME: what about priv->store? */
191
192 G_OBJECT_CLASS(wireless_connect_dialog_parent_class)->dispose(object);
193 }
194@@ -152,180 +117,47 @@
195 g_assert(klass != NULL);
196 }
197
198-static void connect_service_cb(DBusGProxy *proxy, char *path,
199- GError *error, gpointer user_data)
200-{
201- WirelessConnectDialog *self;
202- WirelessConnectDialogPriv *priv;
203-
204- g_debug("%s", __func__);
205-
206- g_return_if_fail(user_data != NULL);
207-
208- self = WIRELESS_CONNECT_DIALOG(user_data);
209-
210- g_return_if_fail(self != NULL);
211- g_return_if_fail(IS_WIRELESS_CONNECT_DIALOG(self));
212-
213- priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
214-
215- g_return_if_fail(priv != NULL);
216-
217- priv->connect_service = NULL;
218- priv->connecting = FALSE;
219-
220- if (error) {
221- /* FIXME: show warning to the user that the connection failed */
222- g_warning("ConnectService() failed: %s",error->message);
223- g_error_free(error);
224- }
225-
226- g_free(path);
227-}
228-
229-static void connect_service(WirelessConnectDialog *self, const gchar *name,
230- const gchar *security)
231-{
232- WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
233- GHashTable *properties;
234- DBusGProxyCall *call;
235- GValue *value;
236-
237- g_debug("%s %s %s", __func__, name, security);
238-
239- g_return_if_fail(priv != NULL);
240- g_return_if_fail(priv->system_bus != NULL);
241- g_return_if_fail(priv->connman_manager != NULL);
242-
243- if (priv->connecting) {
244- g_debug("%s(): already connecting", __func__);
245- return;
246- }
247-
248- if (name == NULL || strlen(name) == 0) {
249- g_warning("%s(): invalid name", __func__);
250- return;
251- }
252-
253- if (security == NULL || strlen(security) == 0) {
254- g_warning("%s(): invalid security", __func__);
255- return;
256- }
257-
258- properties = g_hash_table_new_full(g_str_hash, g_str_equal,
259- g_free, g_free);
260-
261- value = g_malloc0(sizeof(*value));
262- g_value_init(value, G_TYPE_STRING);
263- g_value_set_string(value, CONNMAN_TECHNOLOGY_WIFI);
264- g_hash_table_insert(properties, g_strdup("Type"), value);
265-
266- value = g_malloc0(sizeof(*value));
267- g_value_init(value, G_TYPE_STRING);
268- g_value_set_string(value, "managed");
269- g_hash_table_insert(properties, g_strdup("Mode"), value);
270-
271- value = g_malloc0(sizeof(*value));
272- g_value_init(value, G_TYPE_STRING);
273- g_value_set_string(value, name);
274- g_hash_table_insert(properties, g_strdup("SSID"), value);
275-
276- value = g_malloc0(sizeof(*value));
277- g_value_init(value, G_TYPE_STRING);
278- g_value_set_string(value, security);
279- g_hash_table_insert(properties, g_strdup("Security"), value);
280-
281- /* FIXME: how to ask passphrase? */
282- /* g_hash_table_insert(properties, "Passphrase", value); */
283-
284- call = org_moblin_connman_Manager_connect_service_async(priv->connman_manager,
285- properties,
286- connect_service_cb,
287- self);
288- priv->connect_service = call;
289-
290- g_hash_table_destroy(properties);
291-}
292-
293-static void connect_cb(DBusGProxy *proxy, GError *error, gpointer user_data)
294-{
295- WirelessConnectDialog *self;
296- WirelessConnectDialogPriv *priv;
297-
298- self = WIRELESS_CONNECT_DIALOG(user_data);
299- g_return_if_fail(self != NULL);
300- g_return_if_fail(IS_WIRELESS_CONNECT_DIALOG(self));
301-
302- priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
303- g_return_if_fail(priv != NULL);
304-
305- priv->connect_call = NULL;
306-
307- if (priv->service_proxy != NULL) {
308- g_object_unref(priv->service_proxy);
309- priv->service_proxy = NULL;
310- }
311-
312- if (error) {
313- /* FIXME: show warning to the user that the connection failed */
314- g_warning("failed to connect service: %s",error->message);
315- g_error_free(error);
316- return;
317- }
318-}
319-
320-static void connect(WirelessConnectDialog *self, const gchar *path)
321-{
322- WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
323- GError *error = NULL;
324- DBusGProxy *proxy;
325-
326- g_return_if_fail(priv != NULL);
327- g_return_if_fail(priv->system_bus != NULL);
328-
329- if (priv->connecting) {
330- g_debug("%s(): already connecting", __func__);
331- return;
332- }
333-
334- if (path == NULL || strlen(path) == 0) {
335- g_warning("%s(): invalid path", __func__);
336- return;
337- }
338-
339- proxy = dbus_g_proxy_new_for_name_owner(priv->system_bus,
340- CONNMAN_SERVICE_NAME,
341- path,
342- CONNMAN_SERVICE_INTERFACE,
343- &error);
344-
345- if (error != NULL) {
346- g_warning("failed to create dbus proxy for service %s: %s", path,
347- error->message);
348- g_error_free(error);
349- return;
350- }
351-
352- if (proxy == NULL) {
353- g_warning("failed to create dbus proxy for service %s", path);
354- return;
355- }
356-
357- priv->service_proxy = proxy;
358- priv->connecting = TRUE;
359-
360- priv->connect_call = org_moblin_connman_Service_connect_async(proxy,
361- connect_cb,
362- self);
363+static void connect_service_cb(GObject *object, GAsyncResult *res,
364+ gpointer user_data)
365+{
366+ ConnmanManager *manager = CONNMAN_MANAGER(object);
367+ GError *error = NULL;
368+
369+ connman_manager_connect_service_finish(manager, res, &error);
370+
371+ if (error != NULL) {
372+ g_print("connect service failed: %s\n", error->message);
373+ g_error_free(error);
374+ return;
375+ }
376+}
377+
378+static void connect_cb(GObject *object, GAsyncResult *res,
379+ gpointer user_data)
380+{
381+ ConnmanService *service = CONNMAN_SERVICE(object);
382+ GError *error = NULL;
383+
384+ connman_service_connect_finish(service, res, &error);
385+
386+ if (error != NULL) {
387+ g_print("connect failed: %s\n", error->message);
388+ g_error_free(error);
389+ return;
390+ }
391 }
392
393 static void responded(GtkDialog *dialog, gint response_id, gpointer user_data)
394 {
395 WirelessConnectDialog *self = WIRELESS_CONNECT_DIALOG(user_data);
396 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
397+ ConnmanServiceSecurity security;
398+ ConnmanService *service;
399+ gchar *name;
400 GtkTreeIter iter;
401 gboolean result;
402- gchar *path, *name, *security;
403+
404+ g_return_if_fail(priv != NULL);
405
406 gtk_widget_hide_all(GTK_WIDGET(self));
407
408@@ -334,8 +166,6 @@
409
410 /* connect to the service */
411
412- g_debug("%s(): %d", __func__, priv->service_selected);
413-
414 if (priv->service_selected) {
415 result = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->network_combo),
416 &iter);
417@@ -343,51 +173,37 @@
418 return;
419
420 gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
421- COLUMN_PATH, &path, -1);
422- connect(self, path);
423-
424- g_free(path);
425- path = NULL;
426+ COLUMN_SERVICE, &service, -1);
427+
428+ g_return_if_fail(CONNMAN_IS_SERVICE(service));
429+
430+ connman_service_connect(service, connect_cb, dialog);
431 } else {
432 name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(priv->network_combo));
433- security = gtk_combo_box_get_active_text(GTK_COMBO_BOX(priv->security_combo));
434- connect_service(self, name, security);
435+ security = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->security_combo));
436+ connman_manager_connect_service(priv->manager,
437+ CONNMAN_SERVICE_TYPE_WIFI,
438+ CONNMAN_SERVICE_MODE_MANAGED,
439+ security,
440+ (guint8 *) name,
441+ strlen(name),
442+ NULL,
443+ connect_service_cb,
444+ self);
445
446 g_free(name);
447- g_free(security);
448 name = NULL;
449- security = NULL;
450 }
451 }
452
453-static int get_security_index(WirelessConnectDialog *self,
454- const gchar *security)
455-{
456- if (g_strcmp0(security, CONNMAN_SECURITY_NONE) == 0)
457- return 0;
458- else if (g_strcmp0(security, CONNMAN_SECURITY_WEP) == 0)
459- return 1;
460- else if (g_strcmp0(security, CONNMAN_SECURITY_PSK) == 0)
461- return 2;
462- else if (g_strcmp0(security, CONNMAN_SECURITY_WPA) == 0)
463- return 2;
464- else if (g_strcmp0(security, CONNMAN_SECURITY_RSN) == 0)
465- return 2;
466-
467- g_debug("unsupported security type: %s", security);
468- return -1;
469-}
470-
471-
472 static void network_changed(GtkComboBox *combo, gpointer user_data)
473 {
474 WirelessConnectDialog *self = WIRELESS_CONNECT_DIALOG(user_data);
475 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
476+ ConnmanServiceSecurity security;
477+ ConnmanService *service;
478 GtkTreeIter iter;
479 gboolean result;
480- gchar *security;
481-
482- g_debug("%s()", __func__);
483
484 result = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->network_combo),
485 &iter);
486@@ -397,23 +213,21 @@
487 return;
488
489 gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
490- COLUMN_SECURITY, &security, -1);
491-
492- gtk_combo_box_set_active(GTK_COMBO_BOX(priv->security_combo),
493- get_security_index(self, security));
494-
495- g_free(security);
496+ COLUMN_SERVICE, &service, -1);
497+
498+ security = connman_service_get_security(service);
499+
500+ gtk_combo_box_set_active(GTK_COMBO_BOX(priv->security_combo), security);
501 }
502
503 static void security_changed(GtkComboBox *combo, gpointer user_data)
504 {
505 WirelessConnectDialog *self = WIRELESS_CONNECT_DIALOG(user_data);
506 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
507+ ConnmanServiceSecurity active, security;
508+ ConnmanService *service;
509 GtkTreeIter iter;
510 gboolean result;
511- gchar *security;
512-
513- g_debug("%s()", __func__);
514
515 result = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(priv->network_combo),
516 &iter);
517@@ -423,15 +237,17 @@
518 }
519
520 gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
521- COLUMN_SECURITY, &security, -1);
522-
523- if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->security_combo)) !=
524- get_security_index(self, security))
525+ COLUMN_SERVICE, &service, -1);
526+
527+ g_return_if_fail(CONNMAN_IS_SERVICE(service));
528+
529+ active = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->security_combo));
530+ security = connman_service_get_security(service);
531+
532+ if (active != security)
533 priv->service_selected = FALSE;
534 else
535 priv->service_selected = TRUE;
536-
537- g_free(security);
538 }
539
540 static void update_count_label(WirelessConnectDialog *self)
541@@ -439,160 +255,31 @@
542 WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
543 gchar buf[200];
544
545+ /* FIXME: use g_strdup_printf()? */
546 g_snprintf(buf, sizeof(buf), _("%d networks detected"), priv->service_count);
547+
548 gtk_label_set_text(GTK_LABEL(priv->count_label), buf);
549 }
550
551-static void iterate_array(gpointer data, gpointer user_data)
552-{
553- WirelessConnectDialog *self = WIRELESS_CONNECT_DIALOG(user_data);
554- WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
555- GValueArray *val_array = data;
556- GHashTable *properties;
557- const gchar *path, *name, *type, *security;
558- GtkTreeIter iter;
559- GValue *value;
560-
561- g_return_if_fail(val_array != NULL);
562-
563- if (val_array->n_values != 2)
564- return;
565-
566- /* object path */
567- value = g_value_array_get_nth(val_array, 0);
568- g_return_if_fail(G_IS_VALUE(value));
569- g_return_if_fail(G_VALUE_TYPE(value) == DBUS_TYPE_G_OBJECT_PATH);
570- g_return_if_fail(G_VALUE_HOLDS_BOXED(value));
571-
572- path = g_value_get_boxed(value);
573- if (!path)
574- return;
575-
576- /* properties */
577- value = g_value_array_get_nth(val_array, 1);
578- g_return_if_fail(G_IS_VALUE(value));
579- g_return_if_fail(G_VALUE_HOLDS_BOXED(value));
580-
581- properties = g_value_get_boxed(value);
582-
583- value = g_hash_table_lookup(properties, CONNMAN_PROPERTY_TYPE);
584- if (value == NULL)
585- return;
586-
587- type = g_value_get_string(value);
588-
589- /* add only wifi services, drop others */
590- if (g_strcmp0(type, CONNMAN_TECHNOLOGY_WIFI) != 0)
591- return;
592-
593- value = g_hash_table_lookup(properties, CONNMAN_PROPERTY_NAME);
594- if (value == NULL)
595- return;
596-
597- name = g_value_get_string(value);
598-
599- value = g_hash_table_lookup(properties, CONNMAN_PROPERTY_SECURITY);
600- if (value == NULL)
601- return;
602-
603- security = g_value_get_string(value);
604-
605- gtk_list_store_append(priv->store, &iter);
606- gtk_list_store_set(priv->store, &iter, COLUMN_PATH, path,
607- COLUMN_NAME, name, COLUMN_SECURITY, security, -1);
608-
609- priv->service_count++;
610-}
611-
612-static void get_services_cb(DBusGProxy *proxy, GPtrArray *array, GError *error,
613- gpointer user_data)
614-{
615- WirelessConnectDialog *self;
616- WirelessConnectDialogPriv *priv;
617-
618- g_return_if_fail(user_data != NULL);
619- self = WIRELESS_CONNECT_DIALOG(user_data);
620-
621- g_return_if_fail(self != NULL);
622- g_return_if_fail(IS_WIRELESS_CONNECT_DIALOG(self));
623-
624- priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
625- g_return_if_fail(priv != NULL);
626-
627- priv->services_call = NULL;
628-
629- if (error) {
630- g_warning("%s(): failed to get properties from ofono manager: %s",
631- __func__, error->message);
632- g_error_free(error);
633- return;
634- }
635-
636- gtk_list_store_clear(priv->store);
637- priv->service_count = 0;
638-
639- g_ptr_array_foreach(array, iterate_array, self);
640- g_ptr_array_free(array, TRUE);
641-
642- update_count_label(self);
643-}
644-
645-static gboolean get_connman_manager(WirelessConnectDialog *self)
646-{
647- WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
648-
649- if (priv->connman_manager != NULL)
650- return TRUE;
651-
652- /* FIXME: handle connman missing or crashing */
653- priv->connman_manager = dbus_g_proxy_new_for_name(priv->system_bus,
654- CONNMAN_SERVICE_NAME,
655- CONNMAN_MANAGER_PATH,
656- CONNMAN_MANAGER_INTERFACE);
657- if (priv->connman_manager == NULL)
658- return FALSE;
659-
660- return TRUE;
661-}
662-
663-static void get_services(WirelessConnectDialog *self)
664-{
665- WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
666- DBusGProxyCall *call;
667-
668- if (priv->connman_manager == NULL)
669- if (get_connman_manager(self) == FALSE)
670- return;
671-
672- if (priv->services_call != NULL)
673- /* call already in progress */
674- return;
675-
676- call = org_moblin_connman_Manager_get_services_async(priv->connman_manager,
677- get_services_cb,
678- self);
679-
680- priv->services_call = call;
681-}
682-
683 void wireless_connect_dialog_show(WirelessConnectDialog *self)
684 {
685- WirelessConnectDialogPriv *priv;
686+ WirelessConnectDialogPriv *priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
687+ ConnmanService **services, *service;
688+ GtkTreeIter iter;
689 GtkWidget *entry;
690
691- g_return_if_fail(self != NULL);
692 g_return_if_fail(IS_WIRELESS_CONNECT_DIALOG(self));
693-
694- priv = WIRELESS_CONNECT_DIALOG_GET_PRIVATE(self);
695-
696- if (gtk_widget_get_visible(GTK_WIDGET(self)))
697- return;
698-
699- /*
700- * Delibretely updating services only when dialog is set to the visible
701- * until we have solved service update usability issues.
702- */
703- get_services(self);
704+ g_return_if_fail(priv != NULL);
705+
706+ if (gtk_widget_get_visible(GTK_WIDGET(self))) {
707+ g_warning("Already showing wireless connect dialog, canceling request");
708+ return;
709+ }
710+
711+ if (!connman_manager_is_connected(priv->manager)) {
712+ g_warning("Not connected to connman, not showing wireless connect dialog");
713+ return;
714+ }
715
716 priv->service_selected = FALSE;
717
718@@ -607,6 +294,30 @@
719
720 gtk_entry_set_text(GTK_ENTRY(entry), "");
721
722+ gtk_list_store_clear(priv->store);
723+
724+
725+ services = connman_manager_get_services(priv->manager);
726+ priv->service_count = 0;
727+
728+ if (services == NULL)
729+ goto out;
730+
731+ for (;*services != NULL; services++) {
732+ service = *services;
733+ g_object_ref(service);
734+
735+ gtk_list_store_append(priv->store, &iter);
736+ gtk_list_store_set(priv->store, &iter,
737+ COLUMN_SERVICE, service,
738+ COLUMN_NAME, connman_service_get_name(service),
739+ -1);
740+ priv->service_count++;
741+ }
742+
743+ out:
744+ update_count_label(self);
745+
746 gtk_widget_show_all(GTK_WIDGET(self));
747 }
748
749@@ -639,7 +350,7 @@
750 gtk_size_group_add_widget(group, label);
751 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
752
753- priv->store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
754+ priv->store = gtk_list_store_new(N_COLUMNS, CONNMAN_TYPE_SERVICE,
755 G_TYPE_STRING);
756 priv->network_combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(priv->store),
757 COLUMN_NAME);
758@@ -666,13 +377,17 @@
759 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
760
761 priv->security_combo = gtk_combo_box_new_text();
762- gtk_combo_box_append_text(GTK_COMBO_BOX(priv->security_combo),
763- CONNMAN_SECURITY_NONE);
764- gtk_combo_box_append_text(GTK_COMBO_BOX(priv->security_combo),
765- CONNMAN_SECURITY_WEP);
766- gtk_combo_box_append_text(GTK_COMBO_BOX(priv->security_combo),
767- CONNMAN_SECURITY_PSK);
768- gtk_combo_box_set_active(GTK_COMBO_BOX(priv->security_combo), 0);
769+ gtk_combo_box_insert_text(GTK_COMBO_BOX(priv->security_combo),
770+ CONNMAN_SERVICE_SECURITY_NONE,
771+ _("None"));
772+ gtk_combo_box_insert_text(GTK_COMBO_BOX(priv->security_combo),
773+ CONNMAN_SERVICE_SECURITY_WEP,
774+ _("WEP"));
775+ gtk_combo_box_insert_text(GTK_COMBO_BOX(priv->security_combo),
776+ CONNMAN_SERVICE_SECURITY_PSK,
777+ _("WPA-PSK"));
778+ gtk_combo_box_set_active(GTK_COMBO_BOX(priv->security_combo),
779+ CONNMAN_SERVICE_SECURITY_NONE);
780 g_signal_connect(G_OBJECT(priv->security_combo), "changed",
781 G_CALLBACK(security_changed), self);
782 gtk_box_pack_start(GTK_BOX(hbox), priv->security_combo, TRUE, TRUE, 5);
783
784=== modified file 'src/common/connman-manager.c'
785--- src/common/connman-manager.c 2010-11-18 08:24:56 +0000
786+++ src/common/connman-manager.c 2010-11-19 12:16:09 +0000
787@@ -20,6 +20,8 @@
788
789 #include "connman-manager.h"
790
791+#include <string.h>
792+
793 #include "connman-manager-xml.h"
794 #include "connman.h"
795 #include "marshal.h"
796@@ -46,6 +48,9 @@
797 gboolean initialised;
798
799 guint watch_id;
800+
801+ /* used only by get_services() */
802+ ConnmanService **array;
803 };
804
805 enum {
806@@ -64,6 +69,98 @@
807 PROP_CONNECTED,
808 };
809
810+static void connect_service_cb(GObject *object, GAsyncResult *res,
811+ gpointer user_data)
812+{
813+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(user_data);
814+ GDBusProxy *proxy = G_DBUS_PROXY(object);
815+ GError *error = NULL;
816+
817+ g_dbus_proxy_call_finish(proxy, res, &error);
818+
819+ if (error != NULL) {
820+ g_simple_async_result_set_from_error(simple, error);
821+ g_error_free(error);
822+ goto out;
823+ }
824+
825+ out:
826+ g_simple_async_result_complete(simple);
827+ g_object_unref(simple);
828+}
829+
830+void connman_manager_connect_service(ConnmanManager *self,
831+ ConnmanServiceType type,
832+ ConnmanServiceMode mode,
833+ ConnmanServiceSecurity security,
834+ guint8 *ssid,
835+ guint ssid_len,
836+ GCancellable *cancellable,
837+ GAsyncReadyCallback callback,
838+ gpointer user_data)
839+{
840+ ConnmanManagerPrivate *priv = GET_PRIVATE(self);
841+ gchar ssid_buf[ssid_len + 1];
842+ GSimpleAsyncResult *simple;
843+ GVariantBuilder *builder;
844+ GVariant *parameters;
845+
846+ g_return_if_fail(CONNMAN_IS_MANAGER(self));
847+ g_return_if_fail(priv != NULL);
848+
849+ simple = g_simple_async_result_new(G_OBJECT(self), callback,
850+ user_data,
851+ connman_manager_connect_service);
852+
853+ /*
854+ * FIXME: ssid can contain any character possible, including null, but
855+ * for now null terminate the buffer with null and send it as a string to
856+ * connman. But this needs to be properly fixed at some point.
857+ */
858+ memcpy(ssid_buf, ssid, ssid_len);
859+ ssid_buf[ssid_len] = '\0';
860+
861+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
862+ g_variant_builder_add(builder, "{sv}", "Type",
863+ g_variant_new_string(connman_service_type2str(type)));
864+ g_variant_builder_add(builder, "{sv}", "Mode",
865+ g_variant_new_string(connman_service_mode2str(mode)));
866+ g_variant_builder_add(builder, "{sv}", "Security",
867+ g_variant_new_string(connman_service_security2str(security)));
868+ g_variant_builder_add(builder, "{sv}", "SSID",
869+ g_variant_new_string(ssid_buf));
870+
871+ parameters = g_variant_new("(a{sv})", builder);
872+
873+ /* FIXME: cancel the call on dispose */
874+ g_dbus_proxy_call(priv->proxy, "ConnectService", parameters,
875+ G_DBUS_CALL_FLAGS_NONE, CONNECT_TIMEOUT, cancellable,
876+ connect_service_cb, simple);
877+}
878+
879+void connman_manager_connect_service_finish(ConnmanManager *self,
880+ GAsyncResult *res,
881+ GError **error)
882+{
883+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(res);
884+
885+ g_return_if_fail(CONNMAN_IS_MANAGER(self));
886+ g_return_if_fail(g_simple_async_result_get_source_tag(simple) ==
887+ connman_manager_connect_service);
888+
889+ g_simple_async_result_propagate_error(simple, error);
890+}
891+
892+gboolean connman_manager_is_connected(ConnmanManager *self)
893+{
894+ ConnmanManagerPrivate *priv = GET_PRIVATE(self);
895+
896+ g_return_val_if_fail(CONNMAN_IS_MANAGER(self), FALSE);
897+ g_return_val_if_fail(priv != NULL, FALSE);
898+
899+ return priv->connected;
900+}
901+
902 static void iterate_create_list(gpointer key, gpointer value,
903 gpointer user_data)
904 {
905@@ -80,7 +177,7 @@
906 ConnmanService **connman_manager_get_services(ConnmanManager *self)
907 {
908 ConnmanManagerPrivate *priv = GET_PRIVATE(self);
909- ConnmanService *service, **array;
910+ ConnmanService *service;
911 GList *l;
912 gint i;
913
914@@ -97,10 +194,12 @@
915
916 g_hash_table_foreach(priv->services, iterate_create_list, &l);
917
918+ g_free(priv->array);
919+
920 /* allocate space for the pointers and the null termination */
921- array = g_malloc((sizeof(ConnmanService *) * g_list_length(l)) + 1);
922+ priv->array = g_malloc((sizeof(ConnmanService *) * g_list_length(l)) + 1);
923
924- if (array == NULL)
925+ if (priv->array == NULL)
926 return NULL;
927
928 for (i = 0; l != NULL; l = l->next) {
929@@ -113,15 +212,35 @@
930 if (!connman_service_is_ready(service))
931 continue;
932
933- array[i++] = service;
934+ priv->array[i++] = service;
935 }
936
937- array[i] = NULL;
938+ priv->array[i] = NULL;
939
940 g_list_free(l);
941 l = NULL;
942
943- return array;
944+ return priv->array;
945+}
946+
947+static void iterate_service_ready(gpointer key, gpointer value,
948+ gpointer user_data)
949+{
950+ gboolean *not_ready = user_data;
951+ ConnmanService *service = value;
952+
953+ if (!connman_service_is_ready(service))
954+ *not_ready = TRUE;
955+}
956+
957+static gboolean all_services_ready(ConnmanManager *self)
958+{
959+ ConnmanManagerPrivate *priv = GET_PRIVATE(self);
960+ gboolean not_ready = FALSE;
961+
962+ g_hash_table_foreach(priv->services, iterate_service_ready, &not_ready);
963+
964+ return !not_ready;
965 }
966
967 static void service_ready(ConnmanService *service, GParamSpec *pspec,
968@@ -135,11 +254,17 @@
969
970 /*
971 * Send service added signals only after we are connected. The client
972- * needs to get all the services when it has received the connected
973+ * needs to call get_services() when it has received the connected
974 * signal.
975 */
976- if (!priv->connected)
977+ if (!priv->connected) {
978+ if (all_services_ready(self)) {
979+ priv->connected = TRUE;
980+ g_object_notify(G_OBJECT(self), "connected");
981+ }
982+
983 return;
984+ }
985
986 g_signal_emit(self, signals[SERVICE_ADDED_SIGNAL], 0, service);
987 }
988@@ -297,7 +422,8 @@
989 if (!priv->initialised)
990 priv->initialised = TRUE;
991
992- if (!priv->connected) {
993+ if (!priv->connected && g_hash_table_size(priv->services) == 0) {
994+ /* no services so we can change to connected immediately */
995 priv->connected = TRUE;
996 g_object_notify(G_OBJECT(self), "connected");
997 }
998@@ -458,6 +584,12 @@
999
1000 static void connman_manager_finalize(GObject *object)
1001 {
1002+ ConnmanManager *self = CONNMAN_MANAGER(object);
1003+ ConnmanManagerPrivate *priv = GET_PRIVATE(self);
1004+
1005+ g_free(priv->array);
1006+ priv->array = NULL;
1007+
1008 G_OBJECT_CLASS(connman_manager_parent_class)->finalize(object);
1009 }
1010
1011
1012=== modified file 'src/common/connman-manager.h'
1013--- src/common/connman-manager.h 2010-11-17 14:42:58 +0000
1014+++ src/common/connman-manager.h 2010-11-19 12:16:09 +0000
1015@@ -55,6 +55,19 @@
1016
1017 GType connman_manager_get_type(void);
1018
1019+void connman_manager_connect_service(ConnmanManager *self,
1020+ ConnmanServiceType type,
1021+ ConnmanServiceMode mode,
1022+ ConnmanServiceSecurity security,
1023+ guint8 *ssid,
1024+ guint ssid_len,
1025+ GCancellable *cancellable,
1026+ GAsyncReadyCallback callback,
1027+ gpointer user_data);
1028+void connman_manager_connect_service_finish(ConnmanManager *self,
1029+ GAsyncResult *res,
1030+ GError **error);
1031+gboolean connman_manager_is_connected(ConnmanManager *self);
1032 ConnmanService **connman_manager_get_services(ConnmanManager *self);
1033 ConnmanManager *connman_manager_new(void);
1034
1035
1036=== modified file 'src/common/connman-service.c'
1037--- src/common/connman-service.c 2010-11-18 10:53:50 +0000
1038+++ src/common/connman-service.c 2010-11-19 12:16:09 +0000
1039@@ -68,7 +68,6 @@
1040 };
1041
1042 #define SERVICE_NAME_UNKNOWN _("<unnamed>")
1043-#define CONNECT_TIMEOUT 120000
1044 #define DISCONNECT_TIMEOUT 10000
1045
1046 struct service_state_string
1047@@ -116,6 +115,17 @@
1048 { "cellular", CONNMAN_SERVICE_TYPE_CELLULAR },
1049 };
1050
1051+struct service_mode_string
1052+{
1053+ const gchar *str;
1054+ ConnmanServiceMode mode;
1055+};
1056+
1057+static const struct service_mode_string service_mode_map[] = {
1058+ { "managed", CONNMAN_SERVICE_MODE_MANAGED },
1059+ { "adhoc", CONNMAN_SERVICE_MODE_ADHOC },
1060+};
1061+
1062 static void connect_cb(GObject *object, GAsyncResult *res,
1063 gpointer user_data)
1064 {
1065@@ -289,7 +299,7 @@
1066 return priv->ready;
1067 }
1068
1069-static ConnmanServiceState str2state(const gchar *state)
1070+ConnmanServiceState connman_service_str2state(const gchar *state)
1071 {
1072 const struct service_state_string *s;
1073 guint i;
1074@@ -305,7 +315,23 @@
1075 return CONNMAN_SERVICE_STATE_IDLE;
1076 }
1077
1078-static ConnmanServiceType str2type(const gchar *type)
1079+const gchar *connman_service_state2str(ConnmanServiceState state)
1080+{
1081+ const struct service_state_string *s;
1082+ guint i;
1083+
1084+ for (i = 0; i < G_N_ELEMENTS(service_state_map); i++) {
1085+ s = &service_state_map[i];
1086+ if (s->state == state)
1087+ return s->str;
1088+ }
1089+
1090+ g_warning("%s(): unknown state %d", __func__, state);
1091+
1092+ return "unknown";
1093+}
1094+
1095+ConnmanServiceType connman_service_str2type(const gchar *type)
1096 {
1097 const struct service_type_string *s;
1098 guint i;
1099@@ -321,7 +347,23 @@
1100 return CONNMAN_SERVICE_TYPE_ETHERNET;
1101 }
1102
1103-static ConnmanServiceSecurity str2security(const gchar *security)
1104+const gchar *connman_service_type2str(ConnmanServiceType type)
1105+{
1106+ const struct service_type_string *s;
1107+ guint i;
1108+
1109+ for (i = 0; i < G_N_ELEMENTS(service_type_map); i++) {
1110+ s = &service_type_map[i];
1111+ if (s->type == type)
1112+ return s->str;
1113+ }
1114+
1115+ g_warning("%s(): unknown type %d", __func__, type);
1116+
1117+ return "unknown";
1118+}
1119+
1120+ConnmanServiceSecurity connman_service_str2security(const gchar *security)
1121 {
1122 const struct service_security_string *s;
1123 guint i;
1124@@ -337,13 +379,61 @@
1125 return CONNMAN_SERVICE_SECURITY_NONE;
1126 }
1127
1128+const gchar *connman_service_security2str(ConnmanServiceSecurity security)
1129+{
1130+ const struct service_security_string *s;
1131+ guint i;
1132+
1133+ for (i = 0; i < G_N_ELEMENTS(service_security_map); i++) {
1134+ s = &service_security_map[i];
1135+ if (s->security == security)
1136+ return s->str;
1137+ }
1138+
1139+ g_warning("%s(): unknown security %d", __func__, security);
1140+
1141+ return "unknown";
1142+}
1143+
1144+ConnmanServiceMode connman_service_str2mode(const gchar *mode)
1145+{
1146+ const struct service_mode_string *s;
1147+ guint i;
1148+
1149+ for (i = 0; i < G_N_ELEMENTS(service_mode_map); i++) {
1150+ s = &service_mode_map[i];
1151+ if (g_strcmp0(s->str, mode) == 0)
1152+ return s->mode;
1153+ }
1154+
1155+ g_warning("unknown service mode %s", mode);
1156+
1157+ return CONNMAN_SERVICE_MODE_MANAGED;
1158+}
1159+
1160+const gchar *connman_service_mode2str(ConnmanServiceMode mode)
1161+{
1162+ const struct service_mode_string *s;
1163+ guint i;
1164+
1165+ for (i = 0; i < G_N_ELEMENTS(service_mode_map); i++) {
1166+ s = &service_mode_map[i];
1167+ if (s->mode == mode)
1168+ return s->str;
1169+ }
1170+
1171+ g_warning("%s(): unknown mode %d", __func__, mode);
1172+
1173+ return "unknown";
1174+}
1175+
1176 static void update_state(ConnmanService *self, GVariant *variant)
1177 {
1178 ConnmanServicePrivate *priv = GET_PRIVATE(self);
1179 const gchar *s;
1180
1181 s = g_variant_get_string(variant, NULL);
1182- priv->state = str2state(s);
1183+ priv->state = connman_service_str2state(s);
1184
1185 g_object_notify(G_OBJECT(self), "state");
1186
1187@@ -380,7 +470,7 @@
1188 const gchar *s;
1189
1190 s = g_variant_get_string(variant, NULL);
1191- priv->type = str2type(s);
1192+ priv->type = connman_service_str2type(s);
1193
1194 g_object_notify(G_OBJECT(self), "type");
1195
1196@@ -393,7 +483,7 @@
1197 const gchar *s;
1198
1199 s = g_variant_get_string(variant, NULL);
1200- priv->security = str2security(s);
1201+ priv->security = connman_service_str2security(s);
1202
1203 g_object_notify(G_OBJECT(self), "security");
1204
1205
1206=== modified file 'src/common/connman-service.h'
1207--- src/common/connman-service.h 2010-11-18 10:53:50 +0000
1208+++ src/common/connman-service.h 2010-11-19 12:16:09 +0000
1209@@ -79,6 +79,13 @@
1210 CONNMAN_SERVICE_TYPE_CELLULAR,
1211 } ConnmanServiceType;
1212
1213+typedef enum {
1214+ CONNMAN_SERVICE_MODE_MANAGED,
1215+ CONNMAN_SERVICE_MODE_ADHOC,
1216+} ConnmanServiceMode;
1217+
1218+#define CONNECT_TIMEOUT 120000
1219+
1220 GType connman_service_get_type(void);
1221
1222 ConnmanServiceState connman_service_get_state(ConnmanService *self);
1223@@ -107,4 +114,14 @@
1224 gboolean connman_service_is_ready(ConnmanService *self);
1225 ConnmanService *connman_service_new(const gchar *path);
1226
1227+/* helper functions */
1228+ConnmanServiceState connman_service_str2state(const gchar *state);
1229+const gchar *connman_service_state2str(ConnmanServiceState state);
1230+ConnmanServiceType connman_service_str2type(const gchar *type);
1231+const gchar *connman_service_type2str(ConnmanServiceType type);
1232+ConnmanServiceSecurity connman_service_str2security(const gchar *security);
1233+const gchar *connman_service_security2str(ConnmanServiceSecurity security);
1234+ConnmanServiceMode connman_service_str2mode(const gchar *mode);
1235+const gchar *connman_service_mode2str(ConnmanServiceMode mode);
1236+
1237 #endif
1238
1239=== modified file 'tests/libconnman-tool.c'
1240--- tests/libconnman-tool.c 2010-11-18 10:55:19 +0000
1241+++ tests/libconnman-tool.c 2010-11-19 12:16:09 +0000
1242@@ -19,16 +19,40 @@
1243 */
1244
1245 #include <glib.h>
1246+#include <string.h>
1247
1248 #include "connman-manager.h"
1249 #include "connman-service.h"
1250
1251+#define HIDDEN_SSID "hiddenssid"
1252+
1253 static GMainLoop *loop;
1254 static ConnmanManager *connman;
1255
1256+static enum {
1257+ TEST_LIST_SERVICES,
1258+ TEST_CONNECT_SERVICE,
1259+} test;
1260+
1261 static void usage(const gchar *name)
1262 {
1263- g_print("%s: list-services\n", name);
1264+ g_print("%s: list-services|connect-service\n", name);
1265+}
1266+
1267+static void connect_hidden_ssid_cb(GObject *object, GAsyncResult *res,
1268+ gpointer user_data)
1269+{
1270+ GError *error = NULL;
1271+
1272+ connman_manager_connect_service_finish(connman, res, &error);
1273+
1274+ if (error != NULL) {
1275+ g_print("connect hidden ssid failed: %s\n", error->message);
1276+ g_error_free(error);
1277+ return;
1278+ }
1279+
1280+ g_print("hidden ssid connected\n");
1281 }
1282
1283 static void disconnect_cb(GObject *object, GAsyncResult *res,
1284@@ -151,6 +175,7 @@
1285 {
1286 ConnmanService **services;
1287 gboolean connected;
1288+ guint count;
1289
1290 g_object_get(proxy, "connected", &connected, NULL);
1291
1292@@ -159,6 +184,18 @@
1293 if (!connected)
1294 return;
1295
1296+ if (test == TEST_CONNECT_SERVICE) {
1297+ connman_manager_connect_service(connman, CONNMAN_SERVICE_TYPE_WIFI,
1298+ CONNMAN_SERVICE_MODE_MANAGED,
1299+ CONNMAN_SERVICE_SECURITY_NONE,
1300+ (guint8 *) HIDDEN_SSID,
1301+ strlen(HIDDEN_SSID),
1302+ NULL,
1303+ connect_hidden_ssid_cb,
1304+ NULL);
1305+ return;
1306+ }
1307+
1308 services = connman_manager_get_services(connman);
1309
1310 if (services == NULL) {
1311@@ -166,10 +203,15 @@
1312 return;
1313 }
1314
1315+ count = 0;
1316+
1317 while (*services != NULL) {
1318 new_service(*services);
1319 services++;
1320+ count++;
1321 }
1322+
1323+ g_print("%d services received\n", count);
1324 }
1325
1326 static void service_added(ConnmanManager *proxy, ConnmanService *service,
1327@@ -200,12 +242,21 @@
1328 loop = g_main_loop_new(NULL, FALSE);
1329
1330 connman = connman_manager_new();
1331+
1332+ if (g_strcmp0(argv[1], "list-services") == 0)
1333+ test = TEST_LIST_SERVICES;
1334+ else if (g_strcmp0(argv[1], "connect-service") == 0)
1335+ test = TEST_CONNECT_SERVICE;
1336+
1337 g_signal_connect(connman, "notify::connected", G_CALLBACK(connected_cb),
1338 NULL);
1339- g_signal_connect(connman, "service-added", G_CALLBACK(service_added),
1340- NULL);
1341- g_signal_connect(connman, "service-removed", G_CALLBACK(service_removed),
1342- NULL);
1343+
1344+ if (test == TEST_LIST_SERVICES) {
1345+ g_signal_connect(connman, "service-added", G_CALLBACK(service_added),
1346+ NULL);
1347+ g_signal_connect(connman, "service-removed", G_CALLBACK(service_removed),
1348+ NULL);
1349+ }
1350
1351 g_main_loop_run(loop);
1352

Subscribers

People subscribed via source and target branches