5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
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.
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.
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
31 #define PROFILE_DEFAULT_IDENT "default"
33 static DBusConnection *connection = NULL;
35 const char *__connman_profile_active_ident(void)
39 return PROFILE_DEFAULT_IDENT;
42 const char *__connman_profile_active_path(void)
46 return "/profile/" PROFILE_DEFAULT_IDENT;
49 static void append_services(DBusMessageIter *entry)
51 DBusMessageIter value, iter;
52 const char *key = "Services";
54 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
56 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
57 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
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);
65 dbus_message_iter_close_container(entry, &value);
68 void __connman_profile_changed(void)
70 const char *path = __connman_profile_active_path();
72 DBusMessageIter entry;
74 signal = dbus_message_new_signal(path,
75 CONNMAN_PROFILE_INTERFACE, "PropertyChanged");
79 dbus_message_iter_init_append(signal, &entry);
80 append_services(&entry);
81 g_dbus_send_message(connection, signal);
83 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
84 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
88 dbus_message_iter_init_append(signal, &entry);
89 append_services(&entry);
90 g_dbus_send_message(connection, signal);
93 int __connman_profile_add_device(struct connman_device *device)
95 struct connman_service *service;
97 DBG("device %p", device);
99 service = __connman_service_create_from_device(device);
106 int __connman_profile_remove_device(struct connman_device *device)
108 struct connman_service *service;
110 DBG("device %p", device);
112 service = __connman_service_lookup_from_device(device);
116 __connman_service_put(service);
121 int __connman_profile_add_network(struct connman_network *network)
123 struct connman_service *service;
125 DBG("network %p", network);
127 service = __connman_service_create_from_network(network);
134 int __connman_profile_remove_network(struct connman_network *network)
136 struct connman_service *service;
138 DBG("network %p", network);
140 service = __connman_service_lookup_from_network(network);
144 __connman_service_put(service);
149 void __connman_profile_list(DBusMessageIter *iter)
151 const char *path = __connman_profile_active_path();
155 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
158 static DBusMessage *get_properties(DBusConnection *conn,
159 DBusMessage *msg, void *data)
161 const char *name = "Default";
163 DBusMessageIter array, dict, entry;
165 DBG("conn %p", conn);
167 reply = dbus_message_new_method_return(msg);
171 dbus_message_iter_init_append(reply, &array);
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);
178 connman_dbus_dict_append_variant(&dict, "Name",
179 DBUS_TYPE_STRING, &name);
181 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
183 append_services(&entry);
184 dbus_message_iter_close_container(&dict, &entry);
186 dbus_message_iter_close_container(&array, &dict);
191 static GDBusMethodTable profile_methods[] = {
192 { "GetProperties", "", "a{sv}", get_properties },
196 static GDBusSignalTable profile_signals[] = {
197 { "PropertyChanged", "sv" },
201 int __connman_profile_init(DBusConnection *conn)
203 const char *path = __connman_profile_active_path();
205 DBG("conn %p", conn);
207 connection = dbus_connection_ref(conn);
208 if (connection == NULL)
211 g_dbus_register_interface(connection, path,
212 CONNMAN_PROFILE_INTERFACE,
213 profile_methods, profile_signals,
219 void __connman_profile_cleanup(void)
221 const char *path = __connman_profile_active_path();
223 DBG("conn %p", connection);
225 g_dbus_unregister_interface(connection, path,
226 CONNMAN_PROFILE_INTERFACE);
228 if (connection == NULL)
231 dbus_connection_unref(connection);