Hi Tudor,

I noticed that if connmand is killed when I have "cmn monitor" running, the monitor dumps core as there is a dbus message != NULL check that fails.


On 08/29/2012 03:08 AM, Tudor Marcu wrote:
The client is able to be run as a monitor to connman. When cmn is started with
the monitor option, it will wait for any signals from connman and display them
in the terminal. It is useful if one wants to have some realtime verbose output
of connman, and how it reacts to various input, e.g setting ipv4 to use dhcp.
---
  client/monitor.c |  214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  client/monitor.h |   40 ++++++++++
  2 files changed, 254 insertions(+)
  create mode 100644 client/monitor.c
  create mode 100644 client/monitor.h

diff --git a/client/monitor.c b/client/monitor.c
new file mode 100644
index 0000000..2cb5f76
--- /dev/null
+++ b/client/monitor.c
@@ -0,0 +1,214 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "client/monitor.h"
+#include "client/services.h"
+#include "client/technology.h"
+#include "client/data_manager.h"
+#include "connman.h"
+
+static const char *get_service_name(DBusMessage *message, char *dbus_path)
+{
+       DBusMessageIter iter, array;
+
+       dbus_message_iter_init(message, &iter);
+       dbus_message_iter_recurse(&iter, &array);
+
+       while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+               DBusMessageIter entry, dict;
+               struct service_data service;
+               char *path;
+
+               dbus_message_iter_recurse(&array, &entry);
+               dbus_message_iter_get_basic(&entry, &path);
+
+               if (strncmp(path, dbus_path, strlen(path)) == 0) {
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_recurse(&entry, &dict);
+                       extract_service_name(&dict, &service);
+                       return service.name;
+               } else {
+                       dbus_message_iter_next(&array);
+               }
+       }
+       return NULL;
+}
+
+static void extract_tech_signal(DBusMessage *message)
+{
+       DBusMessageIter iter, dict;
+       char *path;
+
+       dbus_message_iter_init(message, &iter);
+
+       if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_OBJECT_PATH) {
+               dbus_message_iter_get_basic(&iter, &path);
+               printf(" { %s }\n", path);
+       }
+       dbus_message_iter_next(&iter);
+
+       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INVALID) {
+               dbus_message_iter_recurse(&iter, &dict);
+               extract_properties(&dict);
+       }
+}
+
+static void extract_signal_args(DBusMessage *message)
+{
+       DBusMessageIter iter, array, dict;
+       char *string, *value;
+       uint16_t key_int;
+       dbus_bool_t bvalue;
+
+       value = NULL;
+       key_int = 0;
+
+       dbus_message_iter_init(message, &iter);
+
+       while (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INVALID) {
+               if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
+                       dbus_message_iter_get_basic(&iter, &string);
+                       printf("\n[%s] was set to the values:\n",
+                       string);
+               }
+               dbus_message_iter_next(&iter);
+               if (dbus_message_iter_get_arg_type(&iter) !=
+                                                       DBUS_TYPE_INVALID) {
+                       dbus_message_iter_recurse(&iter, &array);
+                       if (dbus_message_iter_get_arg_type(&array) ==
+                                                       DBUS_TYPE_STRING) {
+                               dbus_message_iter_get_basic(&array, &value);
+                               printf("    %s\n", value);
+                               continue;
+                       } else if (dbus_message_iter_get_arg_type(&array) ==
+                                                       DBUS_TYPE_BOOLEAN) {
+                               dbus_message_iter_get_basic(&array, &bvalue);
+                               printf("    %s\n", bvalue == TRUE ?
+                                                       "True" : "False");
+                               continue;
+                       } else if (dbus_message_iter_get_arg_type(&array) !=
+                                                       DBUS_TYPE_INVALID)
+                               dbus_message_iter_recurse(&array, &dict);
+
+                       if (dbus_message_iter_get_arg_type(&dict) ==
+                                               DBUS_TYPE_DICT_ENTRY) {
+                               iterate_dict(&dict, value, key_int);
+                       } else
+                               while (dbus_message_iter_get_arg_type(&dict) ==
+                                               DBUS_TYPE_STRING) {
+                                       dbus_message_iter_get_basic(&dict,
+                                                                   &value);
+                                       printf("    %s\n", value);
+                                       dbus_message_iter_next(&dict);
+                               }
+               }
+       }
+}
+
+DBusHandlerResult service_property_changed(DBusConnection *connection,
+                                               DBusMessage *message,
+                                               void *user_data)
+{
+       DBusMessage *service_message;
+       struct service_data service;
+
+       if (dbus_message_is_signal(message, "net.connman.Service",
+                                           "PropertyChanged")) {
+               service_message = get_message(connection, "GetServices");
+               service.name = get_service_name(service_message,
+                               (char *) dbus_message_get_path(message));
+               printf("\n");
+               g_message("Path = %s, Interface = %s\nService = %s",
+                               dbus_message_get_path(message),
+                               dbus_message_get_interface(message),
+                               service.name);
+               extract_signal_args(message);
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+DBusHandlerResult tech_property_changed(DBusConnection *connection,
+                                       DBusMessage *message, void *user_data)
+{
+       if (dbus_message_is_signal(message, "net.connman.Technology",
+                                           "PropertyChanged")) {
+               printf("\n");
+               g_message("Path = %s, Interface = %s",
+                               dbus_message_get_path(message),
+                               dbus_message_get_interface(message));
+               extract_signal_args(message);
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+DBusHandlerResult tech_added_removed(DBusConnection *connection,
+                                       DBusMessage *message, void *user_data)
+{
+       if (dbus_message_is_signal(message, "net.connman.Manager",
+                                           "TechnologyAdded")) {
+               printf("\n");
+               g_message("Path = %s, Interface = %s",
+                               dbus_message_get_path(message),
+                               dbus_message_get_interface(message));
+               printf("New technology added:\n");
+               extract_tech_signal(message);
+       } else if (dbus_message_is_signal(message, "net.connman.Manager",
+                                                  "TechnologyRemoved")) {
+               printf("\n");
+               g_message("Path = %s, Interface = %s",
+                               dbus_message_get_path(message),
+                               dbus_message_get_interface(message));
+               printf("Technology was removed:\n");
+               extract_tech_signal(message);
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+DBusHandlerResult manager_property_changed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       if (dbus_message_is_signal(message, "net.connman.Manager",
+                                           "PropertyChanged")) {
+               printf("\n");
+               g_message("Path = %s, Interface = %s",
+                               dbus_message_get_path(message),
+                               dbus_message_get_interface(message));
+               extract_signal_args(message);
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
diff --git a/client/monitor.h b/client/monitor.h
new file mode 100644
index 0000000..37fbcde
--- /dev/null
+++ b/client/monitor.h
@@ -0,0 +1,40 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CLIENT_MONITOR_H
+#define __CLIENT_MONITOR_H
+
+#include <dbus/dbus.h>
+
+DBusHandlerResult service_property_changed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data);
+
+DBusHandlerResult tech_property_changed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data);
+
+DBusHandlerResult tech_added_removed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data);
+
+DBusHandlerResult manager_property_changed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data);
+#endif
+


Cheers,
Jukka

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to