Fix parsing of network dictionary
[connman] / src / profile.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  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 int __connman_profile_add_device(struct connman_device *device)
32 {
33         DBG("device %p", device);
34
35         return 0;
36 }
37
38 int __connman_profile_remove_device(struct connman_device *device)
39 {
40         DBG("device %p", device);
41
42         return 0;
43 }
44
45 int __connman_profile_add_network(struct connman_network *network)
46 {
47         DBG("network %p", network);
48
49         return 0;
50 }
51
52 int __connman_profile_remove_network(struct connman_network *network)
53 {
54         DBG("network %p", network);
55
56         return 0;
57 }
58
59 const char *__connman_profile_active(void)
60 {
61         DBG("");
62
63         return "/profile/default";
64 }
65
66 void __connman_profile_list(DBusMessageIter *iter)
67 {
68         const char *path = __connman_profile_active();
69
70         DBG("");
71
72         dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
73 }
74
75 void __connman_profile_list_services(DBusMessageIter *iter)
76 {
77         DBG("");
78 }
79
80 static DBusMessage *get_properties(DBusConnection *conn,
81                                         DBusMessage *msg, void *data)
82 {
83         const char *name = "Default";
84         DBusMessage *reply;
85         DBusMessageIter array, dict;
86
87         DBG("conn %p", conn);
88
89         reply = dbus_message_new_method_return(msg);
90         if (reply == NULL)
91                 return NULL;
92
93         dbus_message_iter_init_append(reply, &array);
94
95         dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
96                         DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
97                         DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
98                         DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
99
100         connman_dbus_dict_append_variant(&dict, "Name",
101                                                 DBUS_TYPE_STRING, &name);
102
103         dbus_message_iter_close_container(&array, &dict);
104
105         return reply;
106 }
107
108 static GDBusMethodTable profile_methods[] = {
109         { "GetProperties", "", "a{sv}", get_properties },
110         { },
111 };
112
113 static DBusConnection *connection = NULL;
114
115 int __connman_profile_init(DBusConnection *conn)
116 {
117         DBG("conn %p", conn);
118
119         connection = dbus_connection_ref(conn);
120         if (connection == NULL)
121                 return -1;
122
123         g_dbus_register_interface(connection, "/profile/default",
124                                                 CONNMAN_PROFILE_INTERFACE,
125                                                 profile_methods,
126                                                 NULL, NULL, NULL, NULL);
127
128         return 0;
129 }
130
131 void __connman_profile_cleanup(void)
132 {
133         DBG("conn %p", connection);
134
135         g_dbus_unregister_interface(connection, "/profile/default",
136                                                 CONNMAN_PROFILE_INTERFACE);
137
138         if (connection == NULL)
139                 return;
140
141         dbus_connection_unref(connection);
142 }