Add support RTNL gateway change notifications
[connman] / src / profile.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  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 <glib.h>
27 #include <gdbus.h>
28
29 #include "connman.h"
30
31 void __connman_profile_list(DBusMessageIter *iter)
32 {
33         const char *path = "/profile/default";
34
35         DBG("");
36
37         dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
38 }
39
40 static void append_string(DBusMessageIter *dict, const char *key, void *val)
41 {
42         DBusMessageIter entry, value;
43
44         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
45                                                                 NULL, &entry);
46
47         dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
48
49         dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
50                                         DBUS_TYPE_STRING_AS_STRING, &value);
51         dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, val);
52         dbus_message_iter_close_container(&entry, &value);
53
54         dbus_message_iter_close_container(dict, &entry);
55 }
56
57 static DBusMessage *get_properties(DBusConnection *conn,
58                                         DBusMessage *msg, void *data)
59 {
60         const char *name = "Default";
61         DBusMessage *reply;
62         DBusMessageIter array, dict;
63
64         DBG("conn %p", conn);
65
66         reply = dbus_message_new_method_return(msg);
67         if (reply == NULL)
68                 return NULL;
69
70         dbus_message_iter_init_append(reply, &array);
71
72         dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
73                         DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
74                         DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
75                         DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
76
77         append_string(&dict, "Name", &name);
78
79         dbus_message_iter_close_container(&array, &dict);
80
81         return reply;
82 }
83
84 static GDBusMethodTable profile_methods[] = {
85         { "GetProperties", "", "a{sv}", get_properties },
86         { },
87 };
88
89 static DBusConnection *connection = NULL;
90
91 int __connman_profile_init(DBusConnection *conn)
92 {
93         DBG("conn %p", conn);
94
95         connection = dbus_connection_ref(conn);
96         if (connection == NULL)
97                 return -1;
98
99         g_dbus_register_interface(connection, "/profile/default",
100                                                 CONNMAN_PROFILE_INTERFACE,
101                                                 profile_methods,
102                                                 NULL, NULL, NULL, NULL);
103
104         return 0;
105 }
106
107 void __connman_profile_cleanup(void)
108 {
109         DBG("conn %p", connection);
110
111         g_dbus_unregister_interface(connection, "/profile/default",
112                                                 CONNMAN_PROFILE_INTERFACE);
113
114         if (connection == NULL)
115                 return;
116
117         dbus_connection_unref(connection);
118 }