Remove obsolete file.
[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 #define PROFILE_DEFAULT_IDENT  "default"
32
33 static DBusConnection *connection = NULL;
34
35 const char *__connman_profile_active_ident(void)
36 {
37         DBG("");
38
39         return PROFILE_DEFAULT_IDENT;
40 }
41
42 const char *__connman_profile_active_path(void)
43 {
44         DBG("");
45
46         return "/profile/" PROFILE_DEFAULT_IDENT;
47 }
48
49 static void append_services(DBusMessageIter *entry)
50 {
51         DBusMessageIter value, iter;
52         const char *key = "Services";
53
54         dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
55
56         dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
57                 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
58                                                                 &value);
59
60         dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
61                                 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
62         __connman_service_list(&iter);
63         dbus_message_iter_close_container(&value, &iter);
64
65         dbus_message_iter_close_container(entry, &value);
66 }
67
68 void __connman_profile_changed(void)
69 {
70         const char *path = __connman_profile_active_path();
71         DBusMessage *signal;
72         DBusMessageIter entry;
73
74         signal = dbus_message_new_signal(path,
75                                 CONNMAN_PROFILE_INTERFACE, "PropertyChanged");
76         if (signal == NULL)
77                 return;
78
79         dbus_message_iter_init_append(signal, &entry);
80         append_services(&entry);
81         g_dbus_send_message(connection, signal);
82
83         signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
84                                 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
85         if (signal == NULL)
86                 return;
87
88         dbus_message_iter_init_append(signal, &entry);
89         append_services(&entry);
90         g_dbus_send_message(connection, signal);
91 }
92
93 int __connman_profile_add_device(struct connman_device *device)
94 {
95         struct connman_service *service;
96
97         DBG("device %p", device);
98
99         service = __connman_service_create_from_device(device);
100         if (service == NULL)
101                 return -EINVAL;
102
103         return 0;
104 }
105
106 int __connman_profile_remove_device(struct connman_device *device)
107 {
108         struct connman_service *service;
109
110         DBG("device %p", device);
111
112         service = __connman_service_lookup_from_device(device);
113         if (service == NULL)
114                 return -EINVAL;
115
116         __connman_service_put(service);
117
118         return 0;
119 }
120
121 int __connman_profile_add_network(struct connman_network *network)
122 {
123         struct connman_service *service;
124
125         DBG("network %p", network);
126
127         service = __connman_service_create_from_network(network);
128         if (service == NULL)
129                 return -EINVAL;
130
131         return 0;
132 }
133
134 int __connman_profile_remove_network(struct connman_network *network)
135 {
136         struct connman_service *service;
137
138         DBG("network %p", network);
139
140         service = __connman_service_lookup_from_network(network);
141         if (service == NULL)
142                 return -EINVAL;
143
144         __connman_service_put(service);
145
146         return 0;
147 }
148
149 void __connman_profile_list(DBusMessageIter *iter)
150 {
151         const char *path = __connman_profile_active_path();
152
153         DBG("");
154
155         dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
156 }
157
158 static DBusMessage *get_properties(DBusConnection *conn,
159                                         DBusMessage *msg, void *data)
160 {
161         const char *name = "Default";
162         DBusMessage *reply;
163         DBusMessageIter array, dict, entry;
164
165         DBG("conn %p", conn);
166
167         reply = dbus_message_new_method_return(msg);
168         if (reply == NULL)
169                 return NULL;
170
171         dbus_message_iter_init_append(reply, &array);
172
173         dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
174                         DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
175                         DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
176                         DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
177
178         connman_dbus_dict_append_variant(&dict, "Name",
179                                                 DBUS_TYPE_STRING, &name);
180
181         dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
182                                                                 NULL, &entry);
183         append_services(&entry);
184         dbus_message_iter_close_container(&dict, &entry);
185
186         dbus_message_iter_close_container(&array, &dict);
187
188         return reply;
189 }
190
191 static GDBusMethodTable profile_methods[] = {
192         { "GetProperties", "", "a{sv}", get_properties },
193         { },
194 };
195
196 static GDBusSignalTable profile_signals[] = {
197         { "PropertyChanged", "sv" },
198         { },
199 };
200
201 int __connman_profile_init(DBusConnection *conn)
202 {
203         const char *path = __connman_profile_active_path();
204
205         DBG("conn %p", conn);
206
207         connection = dbus_connection_ref(conn);
208         if (connection == NULL)
209                 return -1;
210
211         g_dbus_register_interface(connection, path,
212                                         CONNMAN_PROFILE_INTERFACE,
213                                         profile_methods, profile_signals,
214                                                         NULL, NULL, NULL);
215
216         return 0;
217 }
218
219 void __connman_profile_cleanup(void)
220 {
221         const char *path = __connman_profile_active_path();
222
223         DBG("conn %p", connection);
224
225         g_dbus_unregister_interface(connection, path,
226                                                 CONNMAN_PROFILE_INTERFACE);
227
228         if (connection == NULL)
229                 return;
230
231         dbus_connection_unref(connection);
232 }