5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 static GHashTable *task_hash = NULL;
37 static volatile gint task_counter;
39 static void free_task(gpointer data)
41 struct connman_task *task = data;
49 struct connman_task *connman_task_create(void)
51 struct connman_task *task;
56 task = g_try_new0(struct connman_task, 1);
60 counter = g_atomic_int_exchange_and_add(&task_counter, 1);
62 task->path = g_strdup_printf("/task/%d", counter);
67 g_hash_table_insert(task_hash, task->path, task);
72 void connman_task_destroy(struct connman_task *task)
76 g_hash_table_remove(task_hash, task->path);
79 static DBusHandlerResult task_filter(DBusConnection *connection,
80 DBusMessage *message, void *user_data)
82 struct connman_task *task;
85 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
86 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
88 if (dbus_message_has_interface(message,
89 CONNMAN_TASK_INTERFACE) == FALSE)
90 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
92 path = dbus_message_get_path(message);
94 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
96 task = g_hash_table_lookup(task_hash, path);
98 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
100 return DBUS_HANDLER_RESULT_HANDLED;
103 static const char *task_rule = "type=method_call"
104 ",interface=" CONNMAN_TASK_INTERFACE;
106 static DBusConnection *connection;
108 int __connman_task_init(void)
112 connection = connman_dbus_get_connection();
114 dbus_connection_add_filter(connection, task_filter, NULL, NULL);
116 g_atomic_int_set(&task_counter, 0);
118 task_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
121 dbus_bus_add_match(connection, task_rule, NULL);
122 dbus_connection_flush(connection);
127 void __connman_task_cleanup(void)
131 dbus_bus_remove_match(connection, task_rule, NULL);
132 dbus_connection_flush(connection);
134 g_hash_table_destroy(task_hash);
137 dbus_connection_remove_filter(connection, task_filter, NULL);
139 dbus_connection_unref(connection);