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_set_carrier(struct connman_device *device,
115 connman_bool_t carrier)
117 struct connman_service *service;
119 DBG("device %p carrier %d", device, carrier);
121 service = __connman_service_lookup_from_device(device);
125 return __connman_service_set_carrier(service, carrier);
128 int __connman_profile_add_network(struct connman_network *network)
130 struct connman_service *service;
132 DBG("network %p", network);
134 service = __connman_service_create_from_network(network);
141 int __connman_profile_remove_network(struct connman_network *network)
143 struct connman_service *service;
145 DBG("network %p", network);
147 service = __connman_service_lookup_from_network(network);
151 connman_service_put(service);
156 void __connman_profile_list(DBusMessageIter *iter)
158 const char *path = __connman_profile_active();
162 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
165 static DBusMessage *get_properties(DBusConnection *conn,
166 DBusMessage *msg, void *data)
168 const char *name = "Default";
170 DBusMessageIter array, dict, entry;
172 DBG("conn %p", conn);
174 reply = dbus_message_new_method_return(msg);
178 dbus_message_iter_init_append(reply, &array);
180 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
181 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
182 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
183 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
185 connman_dbus_dict_append_variant(&dict, "Name",
186 DBUS_TYPE_STRING, &name);
188 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
190 append_services(&entry);
191 dbus_message_iter_close_container(&dict, &entry);
193 dbus_message_iter_close_container(&array, &dict);
198 static GDBusMethodTable profile_methods[] = {
199 { "GetProperties", "", "a{sv}", get_properties },
203 static GDBusSignalTable profile_signals[] = {
204 { "PropertyChanged", "sv" },
208 int __connman_profile_init(DBusConnection *conn)
210 DBG("conn %p", conn);
212 connection = dbus_connection_ref(conn);
213 if (connection == NULL)
216 g_dbus_register_interface(connection, PROFILE_DEFAULT,
217 CONNMAN_PROFILE_INTERFACE,
218 profile_methods, profile_signals,
224 void __connman_profile_cleanup(void)
226 DBG("conn %p", connection);
228 g_dbus_unregister_interface(connection, PROFILE_DEFAULT,
229 CONNMAN_PROFILE_INTERFACE);
231 if (connection == NULL)
234 dbus_connection_unref(connection);