tethering: Add async tethering_enabled callback
authorSamuel Ortiz <sameo@linux.intel.com>
Wed, 10 Nov 2010 17:15:15 +0000 (18:15 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 10 Nov 2010 17:15:15 +0000 (18:15 +0100)
Makefile.am
include/tethering.h [new file with mode: 0644]
plugins/bluetooth.c
src/tethering.c

index badab1c..651eede 100644 (file)
@@ -8,7 +8,7 @@ include_HEADERS = include/types.h include/log.h include/plugin.h \
                        include/storage.h include/service.h \
                        include/resolver.h include/ipconfig.h \
                        include/device.h include/network.h include/inet.h \
-                       include/ondemand.h
+                       include/ondemand.h include/tethering.h
 
 nodist_include_HEADERS = include/version.h
 
diff --git a/include/tethering.h b/include/tethering.h
new file mode 100644 (file)
index 0000000..63f4f68
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CONNMAN_TETHERING_H
+#define __CONNMAN_TETHERING_H
+
+void connman_tethering_enabled(void);
+void connman_tethering_disabled(void);
+
+#endif
index 9a73e96..984a647 100644 (file)
@@ -36,6 +36,7 @@
 #include <connman/technology.h>
 #include <connman/device.h>
 #include <connman/inet.h>
+#include <connman/tethering.h>
 #include <connman/dbus.h>
 #include <connman/log.h>
 
@@ -968,8 +969,35 @@ static void server_register_reply(DBusPendingCall *call, void *user_data)
        dbus_message_unref(reply);
        dbus_pending_call_unref(call);
 
+       connman_tethering_enabled();
 }
 
+static void server_unregister_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusError error;
+       DBusMessage *reply;
+
+       DBG("");
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, reply) == TRUE) {
+               connman_error("%s", error.message);
+               dbus_error_free(&error);
+               dbus_message_unref(reply);
+               dbus_pending_call_unref(call);
+               return;
+       }
+
+       dbus_message_unref(reply);
+       dbus_pending_call_unref(call);
+
+       connman_tethering_disabled();
+}
+
+
 static void server_register(const char *path, const char *uuid,
                                const char *bridge, connman_bool_t enabled)
 {
@@ -1008,8 +1036,12 @@ static void server_register(const char *path, const char *uuid,
                return;
        }
 
-       dbus_pending_call_set_notify(call, server_register_reply,
-                                       g_strdup(path), g_free);
+       if (enabled == TRUE)
+               dbus_pending_call_set_notify(call, server_register_reply,
+                                               NULL, NULL);
+       else
+               dbus_pending_call_set_notify(call, server_unregister_reply,
+                                               NULL, NULL);
 
        dbus_message_unref(message);
 }
@@ -1021,6 +1053,8 @@ static void enable_nap(gpointer key, gpointer value,
        const char *bridge = user_data;
        const char *path;
 
+       DBG("");
+
        path = connman_device_get_string(device, "Path");
 
        server_register(path, "nap", bridge, TRUE);
@@ -1033,6 +1067,8 @@ static void disable_nap(gpointer key, gpointer value,
        const char *bridge = user_data;
        const char *path;
 
+       DBG("");
+
        path = connman_device_get_string(device, "Path");
 
        server_register(path, "nap", bridge, FALSE);
index 864f22c..208a39f 100644 (file)
 
 #include "connman.h"
 
+#include <connman/tethering.h>
+
 #define BRIDGE_NAME "tether"
 
 static connman_bool_t tethering_status = FALSE;
+gint tethering_enabled;
 
 connman_bool_t __connman_tethering_get_status(void)
 {
@@ -79,6 +82,32 @@ static int remove_bridge(const char *name)
        return 0;
 }
 
+void connman_tethering_enabled(void)
+{
+       if (tethering_status == FALSE)
+               return;
+
+       DBG("enabled %d", tethering_enabled + 1);
+
+       if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) {
+               /* TODO Start DHCP server and DNS proxy on the bridge */
+               DBG("tethering started");
+       }
+}
+
+void connman_tethering_disabled(void)
+{
+       if (tethering_status == FALSE)
+               return;
+
+       DBG("enabled %d", tethering_enabled - 1);
+
+       if (g_atomic_int_dec_and_test(&tethering_enabled) == 0) {
+               /* TODO Stop DHCP server and DNS proxy on the bridge */
+               DBG("tethering stopped");
+       }
+}
+
 int __connman_tethering_set_status(connman_bool_t status)
 {
        if (status == tethering_status)
@@ -106,6 +135,8 @@ int __connman_tethering_init(void)
 {
        DBG("");
 
+       tethering_enabled = 0;
+
        return 0;
 }