5 * Copyright (C) 2014 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
32 static void print_peer(char *path, DBusMessageIter *iter)
34 char *name = "", *state = "";
36 DBusMessageIter entry, val;
39 while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
40 dbus_message_iter_recurse(iter, &entry);
41 dbus_message_iter_get_basic(&entry, &property);
43 if (strcmp(property, "Name") == 0) {
44 dbus_message_iter_next(&entry);
45 dbus_message_iter_recurse(&entry, &val);
46 dbus_message_iter_get_basic(&val, &name);
47 } else if (strcmp(property, "State") == 0) {
48 dbus_message_iter_next(&entry);
49 dbus_message_iter_recurse(&entry, &val);
50 dbus_message_iter_get_basic(&val, &state);
53 dbus_message_iter_next(iter);
57 str = strrchr(path, '/');
64 fprintf(stdout, "%s %s %s", name, state, str);
66 fprintf(stdout, "%s %s", "unchanged", str);
69 static void list_peer_array(DBusMessageIter *iter)
71 DBusMessageIter array, dict;
74 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
75 dbus_message_iter_recurse(iter, &array);
76 if (dbus_message_iter_get_arg_type(&array)
77 != DBUS_TYPE_OBJECT_PATH)
80 dbus_message_iter_get_basic(&array, &path);
82 dbus_message_iter_next(&array);
83 if (dbus_message_iter_get_arg_type(&array)
85 dbus_message_iter_recurse(&array, &dict);
86 print_peer(path, &dict);
89 if (dbus_message_iter_has_next(iter))
90 fprintf(stdout, "\n");
92 dbus_message_iter_next(iter);
96 void __connmanctl_peers_list(DBusMessageIter *iter)
98 DBusMessageIter array;
101 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
104 dbus_message_iter_recurse(iter, &array);
105 list_peer_array(&array);
107 dbus_message_iter_next(iter);
108 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
111 fprintf(stdout, "\n}, {");
113 dbus_message_iter_recurse(iter, &array);
114 while (dbus_message_iter_get_arg_type(&array)
115 == DBUS_TYPE_OBJECT_PATH) {
116 dbus_message_iter_get_basic(&array, &path);
117 fprintf(stdout, "\n%s %s", "removed", path);
119 dbus_message_iter_next(&array);