>From 7148fe48a593bfcf72e927ee0e74cf80319896be Mon Sep 17 00:00:00 2001
From: Martin Xu <[email protected]>
Date: Mon, 6 Jul 2009 02:06:28 -0400
Subject: [PATCH 2/4] add function __connman_service_connect()
---
src/connman.h | 2 ++
src/service.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index 50e5d66..8cc9d4b 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -258,6 +258,8 @@ int __connman_service_indicate_error(struct connman_service
*service,
enum connman_service_error error);
int __connman_service_indicate_default(struct connman_service *service);
+int __connman_service_connect(struct connman_service *service);
+
#include <connman/notifier.h>
int __connman_notifier_init(void);
diff --git a/src/service.c b/src/service.c
index 71e57de..d2d57e7 100644
--- a/src/service.c
+++ b/src/service.c
@@ -461,6 +461,59 @@ static gboolean connect_timeout(gpointer user_data)
return FALSE;
}
+static int connect_service_err_handle(struct connman_service *service, int err)
+{
+ if (err != -EINPROGRESS) {
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_FAILURE);
+ return -err;
+ } else {
+ service->timeout = g_timeout_add_seconds(45,
+ connect_timeout, service);
+ return -EINPROGRESS;
+ }
+}
+
+int __connman_service_connect(struct connman_service *service)
+{
+ DBG("service %p", service);
+
+ if (service->pending != NULL)
+ return -EINPROGRESS;
+
+ if (service->state == CONNMAN_SERVICE_STATE_READY)
+ return -EALREADY;
+
+ if (service->network != NULL) {
+ int err;
+
+ if (service->hidden == TRUE)
+ return -EINVAL;
+
+ connman_network_set_string(service->network,
+ "WiFi.Passphrase", service->passphrase);
+
+ err = __connman_network_connect(service->network);
+ if (err < 0)
+ return connect_service_err_handle(service, err);
+
+ } else if (service->device != NULL) {
+ int err;
+ if (service->favorite == FALSE)
+ /*fix me, Not sure the errno is right*/
+ return -ENODEV;
+
+ err = __connman_device_connect(service->device);
+ if (err < 0)
+ return connect_service_err_handle(service, err);
+
+ } else
+ /*fix me, Not sure the errno is right*/
+ return -EPERM;
+
+ return 0;
+}
+
static DBusMessage *connect_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
--
1.6.1.3
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman