From a51d364ba254346c4b6722945caf4e6eb90d05df Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 18 Apr 2011 11:33:19 -0700 Subject: [PATCH] clock: Add D-Bus interface skeleton --- include/dbus.h | 1 + src/clock.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/include/dbus.h b/include/dbus.h index 0d89456..58f4055 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -39,6 +39,7 @@ extern "C" { #define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" #define CONNMAN_MANAGER_PATH "/" +#define CONNMAN_CLOCK_INTERFACE CONNMAN_SERVICE ".Clock" #define CONNMAN_TASK_INTERFACE CONNMAN_SERVICE ".Task" #define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" #define CONNMAN_PROVIDER_INTERFACE CONNMAN_SERVICE ".Provider" diff --git a/src/clock.c b/src/clock.c index 3a59f31..99aff3c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -23,16 +23,90 @@ #include #endif +#include + #include "connman.h" +static DBusMessage *get_properties(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + DBusMessageIter array, dict; + + DBG("conn %p", conn); + + reply = dbus_message_new_method_return(msg); + if (reply == NULL) + return NULL; + + dbus_message_iter_init_append(reply, &array); + + connman_dbus_dict_open(&array, &dict); + + connman_dbus_dict_close(&array, &dict); + + return reply; +} + +static DBusMessage *set_property(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessageIter iter, value; + const char *name; + int type; + + DBG("conn %p", conn); + + if (dbus_message_iter_init(msg, &iter) == FALSE) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_get_basic(&iter, &name); + dbus_message_iter_next(&iter); + dbus_message_iter_recurse(&iter, &value); + + type = dbus_message_iter_get_arg_type(&value); + + return __connman_error_invalid_property(msg); +} + +static GDBusMethodTable clock_methods[] = { + { "GetProperties", "", "a{sv}", get_properties }, + { "SetProperty", "sv", "", set_property }, + { }, +}; + +static GDBusSignalTable clock_signals[] = { + { "PropertyChanged", "sv" }, + { }, +}; + +static DBusConnection *connection = NULL; + int __connman_clock_init(void) { DBG(""); + connection = connman_dbus_get_connection(); + if (connection == NULL) + return -1; + + g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH, + CONNMAN_CLOCK_INTERFACE, + clock_methods, clock_signals, + NULL, NULL, NULL); + return 0; } void __connman_clock_cleanup(void) { DBG(""); + + if (connection == NULL) + return; + + g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH, + CONNMAN_CLOCK_INTERFACE); + + dbus_connection_unref(connection); } -- 2.7.4