summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-08-07 11:33:47 -0700
committerMarcel Holtmann <marcel@holtmann.org>2009-08-07 11:33:47 -0700
commit2a90839ba7f5985f78fb89b11bfe89fc0c0a45c5 (patch)
tree4f5bacafa6ba866c138fdef321651d9454f136c7
parent15a9b7abf662910638662ffe11cf880f91baee12 (diff)
downloadconnman-2a90839ba7f5985f78fb89b11bfe89fc0c0a45c5.tar.gz
connman-2a90839ba7f5985f78fb89b11bfe89fc0c0a45c5.tar.bz2
connman-2a90839ba7f5985f78fb89b11bfe89fc0c0a45c5.zip
Add first steps of generic task framework
-rw-r--r--include/dbus.h1
-rw-r--r--include/task.h5
-rw-r--r--src/connman.h3
-rw-r--r--src/main.c2
-rw-r--r--src/task.c114
5 files changed, 125 insertions, 0 deletions
diff --git a/include/dbus.h b/include/dbus.h
index 1a6833bc..0593a608 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -37,6 +37,7 @@ extern "C" {
#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager"
#define CONNMAN_MANAGER_PATH "/"
+#define CONNMAN_TASK_INTERFACE CONNMAN_SERVICE ".Task"
#define CONNMAN_PROFILE_INTERFACE CONNMAN_SERVICE ".Profile"
#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service"
#define CONNMAN_DEVICE_INTERFACE CONNMAN_SERVICE ".Device"
diff --git a/include/task.h b/include/task.h
index e31a4c37..dbeb3a76 100644
--- a/include/task.h
+++ b/include/task.h
@@ -32,6 +32,11 @@ extern "C" {
* @short_description: Functions for handling tasks
*/
+struct connman_task;
+
+struct connman_task *connman_task_create(void);
+void connman_task_destroy(struct connman_task *task);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/connman.h b/src/connman.h
index 39efb97a..bbe9e226 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -81,6 +81,9 @@ void __connman_plugin_cleanup(void);
#include <connman/task.h>
+int __connman_task_init(void);
+void __connman_task_cleanup(void);
+
#include <connman/security.h>
int __connman_security_check_privilege(DBusMessage *message,
diff --git a/src/main.c b/src/main.c
index ede37a0b..3e77472e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -207,6 +207,7 @@ int main(int argc, char *argv[])
__connman_resolver_init();
__connman_rtnl_init();
__connman_udev_init();
+ __connman_task_init();
__connman_plugin_init(option_plugin, option_noplugin);
@@ -231,6 +232,7 @@ int main(int argc, char *argv[])
__connman_plugin_cleanup();
+ __connman_task_cleanup();
__connman_udev_cleanup();
__connman_rtnl_cleanup();
__connman_resolver_cleanup();
diff --git a/src/task.c b/src/task.c
index 97a6592a..da94b3fb 100644
--- a/src/task.c
+++ b/src/task.c
@@ -23,4 +23,118 @@
#include <config.h>
#endif
+#include <glib.h>
+
#include "connman.h"
+
+struct connman_task {
+ char *path;
+ pid_t pid;
+};
+
+static GHashTable *task_hash = NULL;
+
+static volatile gint task_counter;
+
+static void free_task(gpointer data)
+{
+ struct connman_task *task = data;
+
+ DBG("task %p", task);
+
+ g_free(task->path);
+ g_free(task);
+}
+
+struct connman_task *connman_task_create(void)
+{
+ struct connman_task *task;
+ gint counter;
+
+ DBG("");
+
+ task = g_try_new0(struct connman_task, 1);
+ if (task == NULL)
+ return NULL;
+
+ counter = g_atomic_int_exchange_and_add(&task_counter, 1);
+
+ task->path = g_strdup_printf("/task/%d", counter);
+ task->pid = -1;
+
+ DBG("task %p", task);
+
+ g_hash_table_insert(task_hash, task->path, task);
+
+ return task;
+}
+
+void connman_task_destroy(struct connman_task *task)
+{
+ DBG("task %p", task);
+
+ g_hash_table_remove(task_hash, task->path);
+}
+
+static DBusHandlerResult task_filter(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct connman_task *task;
+ const char *path;
+
+ if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_has_interface(message,
+ CONNMAN_TASK_INTERFACE) == FALSE)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ path = dbus_message_get_path(message);
+ if (path == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ task = g_hash_table_lookup(task_hash, path);
+ if (task == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static const char *task_rule = "type=method_call"
+ ",interface=" CONNMAN_TASK_INTERFACE;
+
+static DBusConnection *connection;
+
+int __connman_task_init(void)
+{
+ DBG("");
+
+ connection = connman_dbus_get_connection();
+
+ dbus_connection_add_filter(connection, task_filter, NULL, NULL);
+
+ g_atomic_int_set(&task_counter, 0);
+
+ task_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, free_task);
+
+ dbus_bus_add_match(connection, task_rule, NULL);
+ dbus_connection_flush(connection);
+
+ return 0;
+}
+
+void __connman_task_cleanup(void)
+{
+ DBG("");
+
+ dbus_bus_remove_match(connection, task_rule, NULL);
+ dbus_connection_flush(connection);
+
+ g_hash_table_destroy(task_hash);
+ task_hash = NULL;
+
+ dbus_connection_remove_filter(connection, task_filter, NULL);
+
+ dbus_connection_unref(connection);
+}