6 * Copyright (C) 2017 Samsung Electronics Co., Ltd.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
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
31 #include "dbus_helpers.h"
33 static void print_mesh_peer(char *path, DBusMessageIter *iter)
38 DBusMessageIter entry, val;
39 int count = 0, favorite = 0;
41 while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
42 dbus_message_iter_recurse(iter, &entry);
43 dbus_message_iter_get_basic(&entry, &property);
45 if (strcmp(property, "Name") == 0) {
46 dbus_message_iter_next(&entry);
47 dbus_message_iter_recurse(&entry, &val);
48 dbus_message_iter_get_basic(&val, &name);
49 } else if (strcmp(property, "State") == 0) {
50 dbus_message_iter_next(&entry);
51 dbus_message_iter_recurse(&entry, &val);
52 dbus_message_iter_get_basic(&val, &str);
55 if (strcmp(str, "online") == 0)
57 else if (strcmp(str, "ready") == 0)
59 else if (!strcmp(str, "association"))
61 else if (!strcmp(str, "configuration"))
63 else if (!strcmp(str, "disconnect"))
66 } else if (strcmp(property, "Favorite") == 0) {
67 dbus_message_iter_next(&entry);
68 dbus_message_iter_recurse(&entry, &val);
69 dbus_message_iter_get_basic(&val, &favorite);
72 dbus_message_iter_next(iter);
76 str = strrchr(path, '/');
83 fprintf(stdout, "%c%c %-20s %s", favorite != 0 ? 'A' : ' ',
86 fprintf(stdout, "%s %s", "unchanged", str);
89 static void list_mesh_peer_array(DBusMessageIter *iter)
91 DBusMessageIter array, dict;
94 while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
95 dbus_message_iter_recurse(iter, &array);
96 if (dbus_message_iter_get_arg_type(&array)
97 != DBUS_TYPE_OBJECT_PATH)
100 dbus_message_iter_get_basic(&array, &path);
102 dbus_message_iter_next(&array);
103 if (dbus_message_iter_get_arg_type(&array)
104 == DBUS_TYPE_ARRAY) {
105 dbus_message_iter_recurse(&array, &dict);
106 print_mesh_peer(path, &dict);
109 if (dbus_message_iter_has_next(iter))
110 fprintf(stdout, "\n");
112 dbus_message_iter_next(iter);
116 void __connmanctl_mesh_peers_list(DBusMessageIter *iter)
118 DBusMessageIter array;
121 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
124 dbus_message_iter_recurse(iter, &array);
125 list_mesh_peer_array(&array);
127 dbus_message_iter_next(iter);
128 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
131 fprintf(stdout, "\n}, {");
133 dbus_message_iter_recurse(iter, &array);
134 while (dbus_message_iter_get_arg_type(&array)
135 == DBUS_TYPE_OBJECT_PATH) {
136 dbus_message_iter_get_basic(&array, &path);
137 fprintf(stdout, "\n%s %s", "removed", path);
139 dbus_message_iter_next(&array);
144 void __connmanctl_mesh_connected_peers_list(DBusMessageIter *iter)
146 DBusMessageIter array;
148 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
151 dbus_message_iter_recurse(iter, &array);
152 __connmanctl_dbus_print(&array, " ", " = ", "\n");
153 fprintf(stdout, "\n");
156 void __connmanctl_mesh_disconnected_peers_list(DBusMessageIter *iter)
158 DBusMessageIter array;
160 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
163 dbus_message_iter_recurse(iter, &array);
164 __connmanctl_dbus_print(&array, " ", " = ", "\n");
165 fprintf(stdout, "\n");