5 * Copyright (C) 2012-2013 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
38 static void print_service(char *path, DBusMessageIter *iter)
40 char *name = "", *str = NULL;
41 int autoconn = 0, favorite = 0, count = 0;
44 DBusMessageIter entry, val;
46 while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
48 dbus_message_iter_recurse(iter, &entry);
49 dbus_message_iter_get_basic(&entry, &property);
50 if (strcmp(property, "Name") == 0) {
51 dbus_message_iter_next(&entry);
52 dbus_message_iter_recurse(&entry, &val);
53 dbus_message_iter_get_basic(&val, &name);
55 } else if (strcmp(property, "State") == 0) {
56 dbus_message_iter_next(&entry);
57 dbus_message_iter_recurse(&entry, &val);
58 dbus_message_iter_get_basic(&val, &str);
61 if (strcmp(str, "online") == 0)
63 else if (strcmp(str, "ready") == 0)
65 else if (!strcmp(str, "association"))
67 else if (!strcmp(str, "configuration"))
69 else if (!strcmp(str, "disconnect"))
73 } else if (strcmp(property, "AutoConnect") == 0) {
74 dbus_message_iter_next(&entry);
75 dbus_message_iter_recurse(&entry, &val);
76 dbus_message_iter_get_basic(&val, &autoconn);
78 } else if (strcmp(property, "Favorite") == 0) {
79 dbus_message_iter_next(&entry);
80 dbus_message_iter_recurse(&entry, &val);
81 dbus_message_iter_get_basic(&val, &favorite);
85 dbus_message_iter_next(iter);
88 str = strrchr(path, '/');
95 fprintf(stdout, "%c%c%c %-20s %s", favorite != 0 ? '*' : ' ',
96 autoconn != 0 ? 'A' : ' ', state, name, str);
98 fprintf(stdout, "%-24s %s", "unchanged", str);
102 static void list_service_array(DBusMessageIter *iter)
104 DBusMessageIter array, dict;
107 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
109 dbus_message_iter_recurse(iter, &array);
110 if (dbus_message_iter_get_arg_type(&array)
111 != DBUS_TYPE_OBJECT_PATH)
114 dbus_message_iter_get_basic(&array, &path);
116 dbus_message_iter_next(&array);
117 if (dbus_message_iter_get_arg_type(&array)
118 == DBUS_TYPE_ARRAY) {
119 dbus_message_iter_recurse(&array, &dict);
120 print_service(path, &dict);
123 if (dbus_message_iter_has_next(iter))
124 fprintf(stdout, "\n");
126 dbus_message_iter_next(iter);
130 void __connmanctl_services_list(DBusMessageIter *iter)
132 DBusMessageIter array;
135 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
138 dbus_message_iter_recurse(iter, &array);
139 list_service_array(&array);
141 dbus_message_iter_next(iter);
142 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
145 fprintf(stdout, "\n}, {");
147 dbus_message_iter_recurse(iter, &array);
148 while (dbus_message_iter_get_arg_type(&array)
149 == DBUS_TYPE_OBJECT_PATH) {
150 dbus_message_iter_get_basic(&array, &path);
151 fprintf(stdout, "\n%-24s %s", "removed", path);
153 dbus_message_iter_next(&array);