clock: Add D-Bus interface skeleton
[platform/upstream/connman.git] / src / clock.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <gdbus.h>
27
28 #include "connman.h"
29
30 static DBusMessage *get_properties(DBusConnection *conn,
31                                         DBusMessage *msg, void *data)
32 {
33         DBusMessage *reply;
34         DBusMessageIter array, dict;
35
36         DBG("conn %p", conn);
37
38         reply = dbus_message_new_method_return(msg);
39         if (reply == NULL)
40                 return NULL;
41
42         dbus_message_iter_init_append(reply, &array);
43
44         connman_dbus_dict_open(&array, &dict);
45
46         connman_dbus_dict_close(&array, &dict);
47
48         return reply;
49 }
50
51 static DBusMessage *set_property(DBusConnection *conn,
52                                         DBusMessage *msg, void *data)
53 {
54         DBusMessageIter iter, value;
55         const char *name;
56         int type;
57
58         DBG("conn %p", conn);
59
60         if (dbus_message_iter_init(msg, &iter) == FALSE)
61                 return __connman_error_invalid_arguments(msg);
62
63         dbus_message_iter_get_basic(&iter, &name);
64         dbus_message_iter_next(&iter);
65         dbus_message_iter_recurse(&iter, &value);
66
67         type = dbus_message_iter_get_arg_type(&value);
68
69         return __connman_error_invalid_property(msg);
70 }
71
72 static GDBusMethodTable clock_methods[] = {
73         { "GetProperties", "",   "a{sv}", get_properties },
74         { "SetProperty",   "sv", "",      set_property   },
75         { },
76 };
77
78 static GDBusSignalTable clock_signals[] = {
79         { "PropertyChanged", "sv" },
80         { },
81 };
82
83 static DBusConnection *connection = NULL;
84
85 int __connman_clock_init(void)
86 {
87         DBG("");
88
89         connection = connman_dbus_get_connection();
90         if (connection == NULL)
91                 return -1;
92
93         g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
94                                                 CONNMAN_CLOCK_INTERFACE,
95                                                 clock_methods, clock_signals,
96                                                 NULL, NULL, NULL);
97
98         return 0;
99 }
100
101 void __connman_clock_cleanup(void)
102 {
103         DBG("");
104
105         if (connection == NULL)
106                 return;
107
108         g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
109                                                 CONNMAN_CLOCK_INTERFACE);
110
111         dbus_connection_unref(connection);
112 }