Add simple GetState method for really simple applications
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 19 Jul 2009 18:24:35 +0000 (20:24 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 19 Jul 2009 18:24:35 +0000 (20:24 +0200)
doc/manager-api.txt
src/manager.c

index 509817b..79761ce 100644 (file)
@@ -22,6 +22,13 @@ Methods              dict GetProperties()
                        Possible Errors: [service].Error.InvalidArguments
                                         [service].Error.InvalidProperty
 
+               string GetState()
+
+                       Return global connection state of a system. The
+                       same value is return via the State property.
+
+                       Possible Errors: [service].Error.InvalidArguments
+
                object AddProfile(string name)
 
                        Add a new profile with the specified name.
index 580fe52..814a063 100644 (file)
@@ -294,6 +294,26 @@ static DBusMessage *set_property(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static DBusMessage *get_state(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       const char *str;
+
+       DBG("conn %p", conn);
+
+       if (__connman_security_check_privilege(msg,
+                                       CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
+               return __connman_error_permission_denied(msg);
+
+       if (__connman_element_count(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION) > 0)
+               str = "online";
+       else
+               str = "offline";
+
+       return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &str,
+                                               DBUS_TYPE_INVALID);
+}
+
 static DBusMessage *add_profile(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -505,6 +525,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn,
 static GDBusMethodTable manager_methods[] = {
        { "GetProperties",     "",      "a{sv}", get_properties     },
        { "SetProperty",       "sv",    "",      set_property       },
+       { "GetState",          "",      "s",     get_state          },
        { "AddProfile",        "s",     "o",     add_profile        },
        { "RemoveProfile",     "o",     "",      remove_profile     },
        { "RequestScan",       "s",     "",      request_scan       },