Hi,
On Thu, 2012-08-23 at 11:31 -0700, Ceara Chewning 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 realtime verbose output
> from
> connman, and how it reacts to various input, e.g. setting ipv4 to dhcp.
> ---
> client/monitor.c | 180
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> client/monitor.h | 33 ++++++++++
> 2 files changed, 213 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..8c25bdd
> --- /dev/null
> +++ b/client/monitor.c
> @@ -0,0 +1,180 @@
> +/*
> + *
> + * 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.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);
> + fprintf(stdout, " { %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);
> + fprintf(stdout, "\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);
> + fprintf(stdout, " %s\n", value);
> + continue;
> + } else if (dbus_message_iter_get_arg_type(&array) ==
> + DBUS_TYPE_BOOLEAN) {
> + dbus_message_iter_get_basic(&array, &bvalue);
> + fprintf(stdout, " %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);
> + fprintf(stdout, " %s\n", value);
> + dbus_message_iter_next(&dict);
> + }
> + }
> + }
> +}
> +
> +DBusHandlerResult signal_filter(DBusConnection *connection,
> + DBusMessage *message, void *user_data)
> +{
Please provide different callback functions for different signals.
Technology signals in one (or two!), service in another, manager in a
third, etc. With that approach less testing is needed for the signal
type, since only one type of signals will be received by one function.
This of course has implications on the callbacks set up in patch 6/8.
> + 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);
> + } else {
> + printf("\n");
> + g_message("Path = %s, Interface = %s",
> + dbus_message_get_path(message),
> + dbus_message_get_interface(message));
> + }
> + if (dbus_message_is_signal(message, "net.connman.Technology",
> + "PropertyChanged"))
> + extract_signal_args(message);
> + if (dbus_message_is_signal(message, "net.connman.Manager",
> + "PropertyChanged"))
> + extract_signal_args(message);
> + if (dbus_message_is_signal(message, "net.connman.Manager",
> + "TechnologyAdded")) {
> + fprintf(stdout, "New technology added:\n");
> + extract_tech_signal(message);
> + }
> + if (dbus_message_is_signal(message, "net.connman.Manager",
> + "TechnologyRemoved")) {
> + fprintf(stdout, "Technology was removed:\n");
> + extract_tech_signal(message);
> + }
> + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> +}
> +
> diff --git a/client/monitor.h b/client/monitor.h
> new file mode 100644
> index 0000000..eec97ee
> --- /dev/null
> +++ b/client/monitor.h
> @@ -0,0 +1,33 @@
> +/*
> + *
> + * 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-glib.h>
> +#include <dbus/dbus.h>
> +
> +DBusHandlerResult signal_filter(DBusConnection *connection,
> + DBusMessage *message, void *user_data);
> +
> +#endif
> +
Cheers,
Patrik
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman