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
30 static DBusMessage *get_properties(DBusConnection *conn,
31 DBusMessage *msg, void *data)
34 DBusMessageIter array, dict;
38 reply = dbus_message_new_method_return(msg);
42 dbus_message_iter_init_append(reply, &array);
44 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
45 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
46 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
47 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
49 dbus_message_iter_close_container(&array, &dict);
54 static DBusMessage *set_property(DBusConnection *conn,
55 DBusMessage *msg, void *data)
57 DBusMessageIter iter, value;
62 if (dbus_message_iter_init(msg, &iter) == FALSE)
63 return __connman_error_invalid_arguments(msg);
65 dbus_message_iter_get_basic(&iter, &name);
66 dbus_message_iter_next(&iter);
67 dbus_message_iter_recurse(&iter, &value);
69 if (__connman_security_check_privileges(msg) < 0)
70 return __connman_error_permission_denied(msg);
72 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
75 static GDBusMethodTable connection_methods[] = {
76 { "GetProperties", "", "a{sv}", get_properties },
77 { "SetProperty", "sv", "", set_property },
81 static GDBusSignalTable connection_signals[] = {
82 { "PropertyChanged", "sv" },
86 static DBusConnection *connection;
88 static void emit_connections_signal(void)
92 static int register_interface(struct connman_element *element)
94 DBG("element %p name %s", element, element->name);
96 if (g_dbus_register_interface(connection, element->path,
97 CONNMAN_CONNECTION_INTERFACE,
98 connection_methods, connection_signals,
99 NULL, element, NULL) == FALSE) {
100 connman_error("Failed to register %s connection", element->path);
104 emit_connections_signal();
109 static void unregister_interface(struct connman_element *element)
111 DBG("element %p name %s", element, element->name);
113 emit_connections_signal();
115 g_dbus_unregister_interface(connection, element->path,
116 CONNMAN_CONNECTION_INTERFACE);
119 static int connection_probe(struct connman_element *element)
121 DBG("element %p name %s", element, element->name);
123 return register_interface(element);
126 static void connection_remove(struct connman_element *element)
128 DBG("element %p name %s", element, element->name);
130 unregister_interface(element);
133 static struct connman_driver connection_driver = {
134 .name = "connection",
135 .type = CONNMAN_ELEMENT_TYPE_CONNECTION,
136 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
137 .probe = connection_probe,
138 .remove = connection_remove,
141 int __connman_connection_init(void)
145 connection = connman_dbus_get_connection();
147 return connman_driver_register(&connection_driver);
150 void __connman_connection_cleanup(void)
154 connman_driver_unregister(&connection_driver);
156 dbus_connection_unref(connection);