5 * Copyright (C) 2012 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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "technology.h"
38 void extract_properties(DBusMessageIter *dict)
40 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
41 DBusMessageIter entry, value;
42 const char *key, *sdata;
45 dbus_message_iter_recurse(dict, &entry);
46 dbus_message_iter_get_basic(&entry, &key);
47 printf(" [%s] = ", key);
49 dbus_message_iter_next(&entry);
51 dbus_message_iter_recurse(&entry, &value);
53 if (dbus_message_iter_get_arg_type(&value) ==
55 dbus_message_iter_get_basic(&value, &bdata);
56 printf("%s\n", bdata ? "True" : "False");
57 } else if (dbus_message_iter_get_arg_type(&value) ==
59 dbus_message_iter_get_basic(&value, &sdata);
60 printf("%s\n", sdata);
62 dbus_message_iter_next(dict);
66 void match_tech_name(DBusMessage *message, char *tech_name,
67 struct tech_data *tech)
69 DBusMessageIter iter, array;
71 dbus_message_iter_init(message, &iter);
72 dbus_message_iter_recurse(&iter, &array);
73 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
74 DBusMessageIter entry;
78 dbus_message_iter_recurse(&array, &entry);
79 dbus_message_iter_get_basic(&entry, &path);
80 tech->path = g_strdup(path);
81 name = strrchr(path, '/') + 1;
82 tech->name = g_strdup(name);
83 if (g_strcmp0(tech_name, tech->name) == 0) {
86 dbus_message_iter_next(&array);
91 void extract_tech(DBusMessage *message)
93 DBusMessageIter iter, array;
95 dbus_message_iter_init(message, &iter);
96 dbus_message_iter_recurse(&iter, &array);
97 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
98 DBusMessageIter entry, dict;
102 dbus_message_iter_recurse(&array, &entry);
103 dbus_message_iter_get_basic(&entry, &path);
105 printf("{ %s }\n", path);
107 dbus_message_iter_next(&entry);
109 dbus_message_iter_recurse(&entry, &dict);
110 extract_properties(&dict);
112 dbus_message_iter_next(&array);
116 int scan_technology(DBusConnection *connection, DBusMessage *message,
119 DBusMessage *message_send;
120 struct tech_data technology;
123 match_tech_name(message, tech, &technology);
124 if (g_strcmp0(tech, technology.name) != 0) {
128 message_send = dbus_message_new_method_call("net.connman",
130 "net.connman.Technology",
132 if (message_send == NULL)
135 dbus_error_init(&err);
136 dbus_connection_send_with_reply_and_block(connection, message_send, -1,
139 if (dbus_error_is_set(&err)) {
140 printf("Error '%s' %s\n", technology.path, err.message);
141 dbus_error_free(&err);
145 dbus_message_unref(message_send);
146 g_free(technology.name);
147 g_free(technology.path);
152 int set_technology(DBusConnection *connection, DBusMessage *message, char *key,
153 char *tech, dbus_bool_t value)
155 DBusMessage *message_send;
156 DBusMessageIter iter;
157 struct tech_data technology;
160 match_tech_name(message, tech, &technology);
161 if (g_strcmp0(tech, technology.name) != 0) {
165 message_send = dbus_message_new_method_call("net.connman",
167 "net.connman.Technology",
169 if (message_send == NULL)
172 dbus_message_iter_init_append(message_send, &iter);
173 dbus_property_append_basic(&iter, (const char *) key,
174 DBUS_TYPE_BOOLEAN, &value);
176 dbus_error_init(&err);
177 dbus_connection_send_with_reply_and_block(connection, message_send,
179 if (dbus_error_is_set(&err) == TRUE) {
180 printf("Error '%s' %s\n", technology.path, err.message);
181 dbus_error_free(&err);
184 g_free(technology.name);
185 g_free(technology.path);