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)
67 } else if (strcmp(property, "AutoConnect") == 0) {
68 dbus_message_iter_next(&entry);
69 dbus_message_iter_recurse(&entry, &val);
70 dbus_message_iter_get_basic(&val, &autoconn);
72 } else if (strcmp(property, "Favorite") == 0) {
73 dbus_message_iter_next(&entry);
74 dbus_message_iter_recurse(&entry, &val);
75 dbus_message_iter_get_basic(&val, &favorite);
79 dbus_message_iter_next(iter);
82 str = strrchr(path, '/');
92 fprintf(stdout, "%c%c%c %-20s %s", favorite != 0 ? '*' : ' ',
93 autoconn != 0 ? 'A' : ' ', state, name, str);
95 fprintf(stdout, "%-24s %s", "unchanged", str);
99 static void list_service_array(DBusMessageIter *iter)
101 DBusMessageIter array, dict;
104 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
106 dbus_message_iter_recurse(iter, &array);
107 if (dbus_message_iter_get_arg_type(&array)
108 != DBUS_TYPE_OBJECT_PATH)
111 dbus_message_iter_get_basic(&array, &path);
113 dbus_message_iter_next(&array);
114 if (dbus_message_iter_get_arg_type(&array)
115 == DBUS_TYPE_ARRAY) {
116 dbus_message_iter_recurse(&array, &dict);
117 print_service(path, &dict);
120 if (dbus_message_iter_has_next(iter) == TRUE)
121 fprintf(stdout, "\n");
123 dbus_message_iter_next(iter);
127 void __connmanctl_services_list(DBusMessageIter *iter)
129 DBusMessageIter array;
132 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
135 dbus_message_iter_recurse(iter, &array);
136 list_service_array(&array);
138 dbus_message_iter_next(iter);
139 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
142 fprintf(stdout, "\n}, {");
144 dbus_message_iter_recurse(iter, &array);
145 while (dbus_message_iter_get_arg_type(&array)
146 == DBUS_TYPE_OBJECT_PATH) {
147 dbus_message_iter_get_basic(&array, &path);
148 fprintf(stdout, "\n%-24s %s", "removed", path);
150 dbus_message_iter_next(&array);