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
33 #include "client/technology.h"
34 #include "src/connman.h"
37 void extract_properties(DBusMessageIter *dict)
39 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
40 DBusMessageIter entry, value;
41 const char *key, *sdata;
44 dbus_message_iter_recurse(dict, &entry);
45 dbus_message_iter_get_basic(&entry, &key);
46 printf(" [%s] = ", key);
48 dbus_message_iter_next(&entry);
50 dbus_message_iter_recurse(&entry, &value);
52 if (dbus_message_iter_get_arg_type(&value) ==
54 dbus_message_iter_get_basic(&value, &bdata);
55 printf("%s\n", bdata ? "True" : "False");
56 } else if (dbus_message_iter_get_arg_type(&value) ==
58 dbus_message_iter_get_basic(&value, &sdata);
59 printf("%s\n", sdata);
61 dbus_message_iter_next(dict);
65 void match_tech_name(DBusMessage *message, char *tech_name,
66 struct tech_data *tech)
68 DBusMessageIter iter, array;
70 dbus_message_iter_init(message, &iter);
71 dbus_message_iter_recurse(&iter, &array);
72 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
73 DBusMessageIter entry;
77 dbus_message_iter_recurse(&array, &entry);
78 dbus_message_iter_get_basic(&entry, &path);
79 tech->path = g_strdup(path);
80 name = strrchr(path, '/') + 1;
81 tech->name = g_strdup(name);
82 if (g_strcmp0(tech_name, tech->name) == 0) {
83 printf(" %-20s { %s } exists\n", tech->name,
87 dbus_message_iter_next(&array);
92 void extract_tech(DBusMessage *message)
94 DBusMessageIter iter, array;
96 dbus_message_iter_init(message, &iter);
97 dbus_message_iter_recurse(&iter, &array);
98 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
99 DBusMessageIter entry, dict;
103 dbus_message_iter_recurse(&array, &entry);
104 dbus_message_iter_get_basic(&entry, &path);
106 printf("{ %s }\n", path);
108 dbus_message_iter_next(&entry);
110 dbus_message_iter_recurse(&entry, &dict);
111 extract_properties(&dict);
113 dbus_message_iter_next(&array);
117 int scan_technology(DBusConnection *connection, DBusMessage *message,
120 DBusMessage *message_send;
121 struct tech_data technology;
124 match_tech_name(message, tech, &technology);
125 if (g_strcmp0(tech, technology.name) != 0) {
126 fprintf(stderr, "%s does not exist on the system\n", tech);
127 fprintf(stderr, "Use the 'tech' command to find available "
128 "technologies on your system.\n");
132 message_send = dbus_message_new_method_call("net.connman",
134 "net.connman.Technology",
136 if (message_send == NULL)
139 dbus_error_init(&err);
140 dbus_connection_send_with_reply_and_block(connection, message_send, -1,
143 if (dbus_error_is_set(&err)) {
144 printf("Scan failed; error: '%s'\n", err.message);
148 dbus_message_unref(message_send);
149 printf("Scanned for new services on %s.\n", technology.name);
150 g_free(technology.name);
151 g_free(technology.path);
156 int set_technology(DBusConnection *connection, DBusMessage *message, char *key,
157 char *tech, dbus_bool_t value)
159 DBusMessage *message_send;
160 DBusMessageIter iter;
161 struct tech_data technology;
163 match_tech_name(message, tech, &technology);
164 if (g_strcmp0(tech, technology.name) != 0) {
165 fprintf(stderr, "%s does not exist on the system\n", tech);
166 fprintf(stderr, "Use the 'tech' command to find available "
167 "technologies on your system.\n");
171 message_send = dbus_message_new_method_call("net.connman",
173 "net.connman.Technology",
175 if (message_send == NULL)
178 dbus_message_iter_init_append(message_send, &iter);
179 dbus_property_append_basic(&iter, (const char *) key,
180 DBUS_TYPE_BOOLEAN, &value);
181 dbus_connection_send(connection, message_send, NULL);
182 dbus_connection_flush(connection);
183 dbus_message_unref(message_send);
184 g_free(technology.name);
185 g_free(technology.path);