diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-04-07 04:01:28 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-04-07 04:01:28 +0200 |
commit | 56b36256ff076ccc319b0d591c96fef98e3ce893 (patch) | |
tree | d52d65e0f2d4e56614c568ebb37fe2b2426561e8 /src | |
parent | 425dafdb4b29c2dc415bb6e299cd575103481b04 (diff) | |
download | connman-56b36256ff076ccc319b0d591c96fef98e3ce893.tar.gz connman-56b36256ff076ccc319b0d591c96fef98e3ce893.tar.bz2 connman-56b36256ff076ccc319b0d591c96fef98e3ce893.zip |
Implement master state and fix Network Manager compat methods
Diffstat (limited to 'src')
-rw-r--r-- | src/connman.h | 3 | ||||
-rw-r--r-- | src/iface.c | 19 | ||||
-rw-r--r-- | src/manager.c | 93 |
3 files changed, 41 insertions, 74 deletions
diff --git a/src/connman.h b/src/connman.h index c989fcb4..90a70d9a 100644 --- a/src/connman.h +++ b/src/connman.h @@ -21,6 +21,8 @@ #include <stdio.h> +#include <glib.h> + #include <dbus/dbus.h> #define CONNMAN_SERVICE "org.freedesktop.connman" @@ -66,6 +68,7 @@ void __connman_iface_cleanup(void); struct connman_iface *__connman_iface_find(int index); void __connman_iface_list(DBusMessageIter *iter); +gboolean __connman_iface_is_connected(void); int __connman_iface_create_identifier(struct connman_iface *iface); int __connman_iface_init_via_inet(struct connman_iface *iface); diff --git a/src/iface.c b/src/iface.c index dc24dd26..a29c9019 100644 --- a/src/iface.c +++ b/src/iface.c @@ -97,6 +97,25 @@ void __connman_iface_list(DBusMessageIter *iter) } } +gboolean __connman_iface_is_connected(void) +{ + GSList *list; + gboolean connected = FALSE; + + DBG(""); + + for (list = interfaces; list; list = list->next) { + struct connman_iface *iface = list->data; + + if (iface->state == CONNMAN_IFACE_STATE_READY) { + connected = TRUE; + break; + } + } + + return connected; +} + static void append_entry(DBusMessageIter *dict, const char *key, int type, void *val) { diff --git a/src/manager.c b/src/manager.c index 11c25572..3b2430a3 100644 --- a/src/manager.c +++ b/src/manager.c @@ -27,8 +27,6 @@ #include "connman.h" -static const char *master_state = "unknown"; - static DBusMessage *list_interfaces(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -57,6 +55,7 @@ static DBusMessage *get_state(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; + const char *state; DBG("conn %p", conn); @@ -64,7 +63,12 @@ static DBusMessage *get_state(DBusConnection *conn, if (reply == NULL) return NULL; - dbus_message_append_args(reply, DBUS_TYPE_STRING, &master_state, + if (__connman_iface_is_connected() == TRUE) + state = "online"; + else + state = "offline"; + + dbus_message_append_args(reply, DBUS_TYPE_STRING, &state, DBUS_TYPE_INVALID); return reply; @@ -133,67 +137,7 @@ static GDBusSignalTable manager_signals[] = { { }, }; -static DBusMessage *activate_device(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *path; - - DBG("conn %p", conn); - - dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID); - - DBG("device %s", path); - - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - return reply; -} - -static DBusMessage *set_wireless(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - dbus_bool_t enabled; - - DBG("conn %p", conn); - - dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &enabled, - DBUS_TYPE_INVALID); - - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - return reply; -} - -static DBusMessage *get_wireless(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - dbus_bool_t enabled = TRUE; - - DBG("conn %p", conn); - - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &enabled, - DBUS_TYPE_INVALID); - - return reply; -} - -static DBusMessage *do_sleep(DBusConnection *conn, +static DBusMessage *nm_sleep(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; @@ -209,7 +153,7 @@ static DBusMessage *do_sleep(DBusConnection *conn, return reply; } -static DBusMessage *do_wake(DBusConnection *conn, +static DBusMessage *nm_wake(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; @@ -233,11 +177,11 @@ enum { NM_STATE_DISCONNECTED }; -static DBusMessage *do_state(DBusConnection *conn, +static DBusMessage *nm_state(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - dbus_uint32_t state = NM_STATE_DISCONNECTED; + dbus_uint32_t state; DBG("conn %p", conn); @@ -245,6 +189,11 @@ static DBusMessage *do_state(DBusConnection *conn, if (reply == NULL) return NULL; + if (__connman_iface_is_connected() == TRUE) + state = NM_STATE_CONNECTED; + else + state = NM_STATE_DISCONNECTED; + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); @@ -252,13 +201,9 @@ static DBusMessage *do_state(DBusConnection *conn, } static GDBusMethodTable nm_methods[] = { - { "getDevices", "", "ao", list_interfaces }, - { "setActiveDevice", "o", "", activate_device }, - { "setWirelessEnabled", "b", "", set_wireless }, - { "getWirelessEnabled", "", "b", get_wireless }, - { "sleep", "", "", do_sleep }, - { "wake", "", "", do_wake }, - { "state", "", "u", do_state }, + { "sleep", "", "", nm_sleep }, + { "wake", "", "", nm_wake }, + { "state", "", "u", nm_state }, { }, }; |