clock: Add D-Bus interface skeleton
[framework/connectivity/connman.git] / src / clock.c
index 3a59f31..99aff3c 100644 (file)
 #include <config.h>
 #endif
 
+#include <gdbus.h>
+
 #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);
 }