summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-12 12:49:55 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-12 12:49:55 +0000
commited62b516d4db8930b0f768caf462c53bbaecaa4e (patch)
treec9b0bc93dca6f1d6ca2a04835b4c655822170342 /network
parented17ae18d87cba8f8564bebde2f0707883b73d58 (diff)
network: use global server/connection list for manager
Diffstat (limited to 'network')
-rw-r--r--network/manager.c74
1 files changed, 22 insertions, 52 deletions
diff --git a/network/manager.c b/network/manager.c
index 0195c960..b2b47aaa 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -47,15 +47,12 @@
#include "connection.h"
#include "common.h"
-struct manager {
- GSList *servers; /* Network registered servers paths */
- GSList *connections; /* Network registered connections paths */
-};
+static GSList *server_paths = NULL; /* Network registered servers paths */
+static GSList *connection_paths = NULL; /* Network registered connections paths */
struct pending_reply {
DBusConnection *conn;
DBusMessage *msg;
- struct manager *mgr;
char *addr;
char *path;
char *adapter_path;
@@ -219,8 +216,7 @@ static void pan_record_reply(DBusPendingCall *call, void *data)
goto fail;
}
- pr->mgr->connections = g_slist_append(pr->mgr->connections,
- g_strdup(pr->path));
+ connection_paths = g_slist_append(connection_paths, g_strdup(pr->path));
create_path(pr->conn, pr->msg, pr->path, "ConnectionCreated");
fail:
@@ -359,8 +355,7 @@ static void get_address_reply(DBusPendingCall *call, void *data)
goto fail;
}
- pr->mgr->servers = g_slist_append(pr->mgr->servers,
- g_strdup(pr->path));
+ server_paths = g_slist_append(server_paths, g_strdup(pr->path));
create_path(pr->conn, pr->msg, pr->path, "ServerCreated");
fail:
@@ -459,15 +454,12 @@ static int get_default_adapter(struct pending_reply *pr,
static DBusHandlerResult list_servers(DBusConnection *conn, DBusMessage *msg,
void *data)
{
- struct manager *mgr = data;
-
- return list_paths(conn, msg, mgr->servers);
+ return list_paths(conn, msg, server_paths);
}
static DBusHandlerResult create_server(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct manager *mgr = data;
struct pending_reply *pr;
DBusError derr;
const char *str;
@@ -489,13 +481,12 @@ static DBusHandlerResult create_server(DBusConnection *conn,
pr = g_new0(struct pending_reply, 1);
pr->conn = dbus_connection_ref(conn);;
pr->msg = dbus_message_ref(msg);
- pr->mgr = mgr;
pr->addr = NULL;
pr->id = id;
pr->path = g_new0(char, 32);
snprintf(pr->path, 32, NETWORK_PATH "/server/%s", bnep_name(id));
- if (g_slist_find_custom(mgr->servers, pr->path,
+ if (g_slist_find_custom(server_paths, pr->path,
(GCompareFunc) strcmp)) {
err_already_exists(conn, msg, "Server Already exists");
pending_reply_free(pr);
@@ -513,23 +504,18 @@ static DBusHandlerResult create_server(DBusConnection *conn,
static DBusHandlerResult remove_server(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct manager *mgr = data;
-
- return remove_path(conn, msg, &mgr->servers, "ServerRemoved");
+ return remove_path(conn, msg, &server_paths, "ServerRemoved");
}
static DBusHandlerResult list_connections(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct manager *mgr = data;
-
- return list_paths(conn, msg, mgr->connections);
+ return list_paths(conn, msg, connection_paths);
}
static DBusHandlerResult create_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct manager *mgr = data;
struct pending_reply *pr;
static int uid = 0;
DBusError derr;
@@ -554,7 +540,6 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
pr = g_new0(struct pending_reply, 1);
pr->conn = dbus_connection_ref(conn);
pr->msg = dbus_message_ref(msg);
- pr->mgr = mgr;
pr->addr = g_strdup(addr);
pr->id = id;
pr->path = g_new0(char, 48);
@@ -571,9 +556,7 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
static DBusHandlerResult remove_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct manager *mgr = data;
-
- return remove_path(conn, msg, &mgr->connections, "ConnectionRemoved");
+ return remove_path(conn, msg, &connection_paths, "ConnectionRemoved");
}
static DBusHandlerResult manager_message(DBusConnection *conn,
@@ -614,34 +597,25 @@ static DBusHandlerResult manager_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void manager_free(struct manager *mgr)
+static void manager_unregister(DBusConnection *conn, void *data)
{
- if (!mgr)
- return;
+ info("Unregistered manager path");
- if (mgr->servers) {
- g_slist_foreach(mgr->servers, (GFunc)g_free, NULL);
- g_slist_free(mgr->servers);
+ if (server_paths) {
+ g_slist_foreach(server_paths, (GFunc)g_free, NULL);
+ g_slist_free(server_paths);
+ server_paths = NULL;
}
- if (mgr->connections) {
- g_slist_foreach(mgr->connections, (GFunc)g_free, NULL);
- g_slist_free(mgr->connections);
+ if (connection_paths) {
+ g_slist_foreach(connection_paths, (GFunc)g_free, NULL);
+ g_slist_free(connection_paths);
+ connection_paths = NULL;
}
- g_free (mgr);
bnep_kill_all_connections();
}
-static void manager_unregister(DBusConnection *conn, void *data)
-{
- struct manager *mgr = data;
-
- info("Unregistered manager path");
-
- manager_free(mgr);
-}
-
/* Virtual table to handle manager object path hierarchy */
static const DBusObjectPathVTable manager_table = {
.message_function = manager_message,
@@ -650,8 +624,6 @@ static const DBusObjectPathVTable manager_table = {
int network_init(DBusConnection *conn)
{
- struct manager *mgr;
-
if (bridge_init() < 0) {
error("Can't init bridge module");
return -1;
@@ -669,14 +641,10 @@ int network_init(DBusConnection *conn)
connection = dbus_connection_ref(conn);
- /* FIXME: make manager global */
- mgr = g_new0(struct manager, 1);
-
/* Fallback to catch invalid network path */
if (dbus_connection_register_fallback(connection, NETWORK_PATH,
- &manager_table, mgr) == FALSE) {
+ &manager_table, NULL) == FALSE) {
error("D-Bus failed to register %s path", NETWORK_PATH);
- manager_free(mgr);
dbus_connection_unref(connection);
return -1;
@@ -684,6 +652,8 @@ int network_init(DBusConnection *conn)
info("Registered manager path:%s", NETWORK_PATH);
+ /* FIXME: Missing register stored servers */
+
return 0;
}