5 * Copyright (C) 2007-2008 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 version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <dbus/dbus.h>
33 #define CONNMAN_SERVICE "org.moblin.connman"
35 #define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager"
36 #define CONNMAN_MANAGER_PATH "/"
38 static const char *extract_state(DBusMessage *message)
40 DBusMessageIter array, dict;
42 dbus_message_iter_init(message, &array);
43 dbus_message_iter_recurse(&array, &dict);
45 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
46 DBusMessageIter entry, value;
49 dbus_message_iter_recurse(&dict, &entry);
50 dbus_message_iter_get_basic(&entry, &key);
52 dbus_message_iter_next(&entry);
54 dbus_message_iter_recurse(&entry, &value);
56 //type = dbus_message_iter_get_arg_type(&value);
57 //dbus_message_iter_get_basic(&value, &val);
59 if (strcmp(key, "State") == 0) {
61 dbus_message_iter_get_basic(&value, &val);
65 dbus_message_iter_next(&dict);
71 static int cmd_status(DBusConnection *connection)
73 DBusMessage *message, *reply;
77 message = dbus_message_new_method_call(CONNMAN_SERVICE,
79 CONNMAN_MANAGER_INTERFACE,
84 dbus_error_init(&error);
86 reply = dbus_connection_send_with_reply_and_block(connection,
89 if (dbus_error_is_set(&error) == TRUE) {
90 fprintf(stderr, "%s\n", error.message);
91 dbus_error_free(&error);
93 fprintf(stderr, "Failed to get properties\n");
94 dbus_message_unref(message);
98 dbus_message_unref(message);
100 dbus_error_init(&error);
102 state = extract_state(reply);
104 dbus_message_unref(reply);
109 printf("System is %s\n", state);
114 int main(int argc, char *argv[])
116 DBusConnection *conn;
118 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
120 fprintf(stderr, "Can't get on system bus\n");
126 dbus_connection_unref(conn);