summaryrefslogtreecommitdiff
path: root/src/manager.c
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /src/manager.c
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-upstream/1.24.zip
connman-upstream/1.24.tar.gz
connman-upstream/1.24.tar.bz2
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'src/manager.c')
-rw-r--r--src/manager.c92
1 files changed, 41 insertions, 51 deletions
diff --git a/src/manager.c b/src/manager.c
index e56f2e1..b31ab4c 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 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
@@ -31,21 +31,21 @@
#include "connman.h"
-static connman_bool_t connman_state_idle;
-static DBusMessage *session_mode_pending = NULL;
+static bool connman_state_idle;
+static dbus_bool_t sessionmode;
static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
DBusMessageIter array, dict;
- connman_bool_t offlinemode, sessionmode;
+ dbus_bool_t offlinemode;
const char *str;
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
@@ -60,7 +60,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
connman_dbus_dict_append_basic(&dict, "OfflineMode",
DBUS_TYPE_BOOLEAN, &offlinemode);
- sessionmode = __connman_session_mode();
connman_dbus_dict_append_basic(&dict, "SessionMode",
DBUS_TYPE_BOOLEAN,
&sessionmode);
@@ -79,7 +78,7 @@ static DBusMessage *set_property(DBusConnection *conn,
DBG("conn %p", conn);
- if (dbus_message_iter_init(msg, &iter) == FALSE)
+ if (!dbus_message_iter_init(msg, &iter))
return __connman_error_invalid_arguments(msg);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
@@ -95,8 +94,8 @@ static DBusMessage *set_property(DBusConnection *conn,
type = dbus_message_iter_get_arg_type(&value);
- if (g_str_equal(name, "OfflineMode") == TRUE) {
- connman_bool_t offlinemode;
+ if (g_str_equal(name, "OfflineMode")) {
+ dbus_bool_t offlinemode;
if (type != DBUS_TYPE_BOOLEAN)
return __connman_error_invalid_arguments(msg);
@@ -104,24 +103,13 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&value, &offlinemode);
__connman_technology_set_offlinemode(offlinemode);
- } else if (g_str_equal(name, "SessionMode") == TRUE) {
- connman_bool_t sessionmode;
+ } else if (g_str_equal(name, "SessionMode")) {
if (type != DBUS_TYPE_BOOLEAN)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_get_basic(&value, &sessionmode);
- if (session_mode_pending != NULL)
- return __connman_error_in_progress(msg);
-
- __connman_session_set_mode(sessionmode);
-
- if (sessionmode == TRUE && connman_state_idle == FALSE) {
- session_mode_pending = dbus_message_ref(msg);
- return NULL;
- }
-
} else
return __connman_error_invalid_property(msg);
@@ -141,7 +129,7 @@ static DBusMessage *get_technologies(DBusConnection *conn,
DBG("");
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
__connman_dbus_append_objpath_dict_array(reply,
@@ -170,28 +158,15 @@ static DBusMessage *remove_provider(DBusConnection *conn,
static DBusConnection *connection = NULL;
-static void session_mode_notify(void)
-{
- DBusMessage *reply;
-
- reply = g_dbus_create_reply(session_mode_pending, DBUS_TYPE_INVALID);
- g_dbus_send_message(connection, reply);
-
- dbus_message_unref(session_mode_pending);
- session_mode_pending = NULL;
-}
-
-static void idle_state(connman_bool_t idle)
+static void idle_state(bool idle)
{
DBG("idle %d", idle);
connman_state_idle = idle;
- if (connman_state_idle == FALSE || session_mode_pending == NULL)
+ if (!connman_state_idle)
return;
-
- session_mode_notify();
}
static struct connman_notifier technology_notifier = {
@@ -211,7 +186,7 @@ static DBusMessage *get_services(DBusConnection *conn,
DBusMessage *reply;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
__connman_dbus_append_objpath_dict_array(reply,
@@ -220,6 +195,25 @@ static DBusMessage *get_services(DBusConnection *conn,
return reply;
}
+static void append_peer_structs(DBusMessageIter *iter, void *user_data)
+{
+ __connman_peer_list_struct(iter);
+}
+
+static DBusMessage *get_peers(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
+
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_peer_structs, NULL);
+ return reply;
+}
+
static DBusMessage *connect_provider(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -227,13 +221,6 @@ static DBusMessage *connect_provider(DBusConnection *conn,
DBG("conn %p", conn);
- if (__connman_session_mode() == TRUE) {
- connman_info("Session mode enabled: "
- "direct provider connect disabled");
-
- return __connman_error_failed(msg, EINVAL);
- }
-
err = __connman_provider_create_and_connect(msg);
if (err < 0)
return __connman_error_failed(msg, -err);
@@ -409,6 +396,9 @@ static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetServices",
NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
get_services) },
+ { GDBUS_METHOD("GetPeers",
+ NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
+ get_peers) },
{ GDBUS_DEPRECATED_ASYNC_METHOD("ConnectProvider",
GDBUS_ARGS({ "provider", "a{sv}" }),
GDBUS_ARGS({ "path", "o" }),
@@ -456,6 +446,9 @@ static const GDBusSignalTable manager_signals[] = {
{ GDBUS_SIGNAL("ServicesChanged",
GDBUS_ARGS({ "changed", "a(oa{sv})" },
{ "removed", "ao" })) },
+ { GDBUS_SIGNAL("PeersChanged",
+ GDBUS_ARGS({ "changed", "a(oa{sv})" },
+ { "removed", "ao" })) },
{ },
};
@@ -464,7 +457,7 @@ int __connman_manager_init(void)
DBG("");
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -1;
if (connman_notifier_register(&technology_notifier) < 0)
@@ -475,7 +468,7 @@ int __connman_manager_init(void)
manager_methods,
manager_signals, NULL, NULL, NULL);
- connman_state_idle = TRUE;
+ connman_state_idle = true;
return 0;
}
@@ -484,12 +477,9 @@ void __connman_manager_cleanup(void)
{
DBG("");
- if (connection == NULL)
+ if (!connection)
return;
- if (session_mode_pending != NULL)
- dbus_message_unref(session_mode_pending);
-
connman_notifier_unregister(&technology_notifier);
g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,