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 "/profile/default"
33 static DBusConnection *connection = NULL;
35 const char *__connman_profile_active(void)
39 return PROFILE_DEFAULT;
42 static void append_services(DBusMessageIter *entry)
44 DBusMessageIter value, iter;
45 const char *key = "Services";
47 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
49 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
50 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
53 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
54 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
55 __connman_service_list(&iter);
56 dbus_message_iter_close_container(&value, &iter);
58 dbus_message_iter_close_container(entry, &value);
61 void __connman_profile_changed(void)
63 const char *path = __connman_profile_active();
65 DBusMessageIter entry;
67 signal = dbus_message_new_signal(path,
68 CONNMAN_PROFILE_INTERFACE, "PropertyChanged");
72 dbus_message_iter_init_append(signal, &entry);
73 append_services(&entry);
74 g_dbus_send_message(connection, signal);
76 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
77 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
81 dbus_message_iter_init_append(signal, &entry);
82 append_services(&entry);
83 g_dbus_send_message(connection, signal);
86 int __connman_profile_add_device(struct connman_device *device)
88 struct connman_service *service;
90 DBG("device %p", device);
92 service = __connman_service_create_from_device(device);
99 int __connman_profile_remove_device(struct connman_device *device)
101 struct connman_service *service;
103 DBG("device %p", device);
105 service = __connman_service_lookup_from_device(device);
109 connman_service_put(service);
114 int __connman_profile_add_network(struct connman_network *network)
116 struct connman_service *service;
118 DBG("network %p", network);
120 service = __connman_service_create_from_network(network);
127 int __connman_profile_remove_network(struct connman_network *network)
129 struct connman_service *service;
131 DBG("network %p", network);
133 service = __connman_service_lookup_from_network(network);
137 connman_service_put(service);
142 void __connman_profile_list(DBusMessageIter *iter)
144 const char *path = __connman_profile_active();
148 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
151 static DBusMessage *get_properties(DBusConnection *conn,
152 DBusMessage *msg, void *data)
154 const char *name = "Default";
156 DBusMessageIter array, dict, entry;
158 DBG("conn %p", conn);
160 reply = dbus_message_new_method_return(msg);
164 dbus_message_iter_init_append(reply, &array);
166 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
167 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
168 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
169 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
171 connman_dbus_dict_append_variant(&dict, "Name",
172 DBUS_TYPE_STRING, &name);
174 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
176 append_services(&entry);
177 dbus_message_iter_close_container(&dict, &entry);
179 dbus_message_iter_close_container(&array, &dict);
184 static GDBusMethodTable profile_methods[] = {
185 { "GetProperties", "", "a{sv}", get_properties },
189 static GDBusSignalTable profile_signals[] = {
190 { "PropertyChanged", "sv" },
194 int __connman_profile_init(DBusConnection *conn)
196 DBG("conn %p", conn);
198 connection = dbus_connection_ref(conn);
199 if (connection == NULL)
202 g_dbus_register_interface(connection, PROFILE_DEFAULT,
203 CONNMAN_PROFILE_INTERFACE,
204 profile_methods, profile_signals,
210 void __connman_profile_cleanup(void)
212 DBG("conn %p", connection);
214 g_dbus_unregister_interface(connection, PROFILE_DEFAULT,
215 CONNMAN_PROFILE_INTERFACE);
217 if (connection == NULL)
220 dbus_connection_unref(connection);