The new main.c compiles with the previously added services, technology,
data_manager, interactive, and monitor files to create the CLI called cmn. This
is the program a user would run to use connman from the command line. It
is able to view properties of services and technologies, and set/enable
connman's properties.
The updated Makefile compiles all of the above source client files.
---
 Makefile.am   |   17 +-
 client/main.c |  622 +++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 464 insertions(+), 175 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index ca0cf0b..fee2e7a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -123,7 +123,7 @@ AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
 
 INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus
 
-EXTRA_DIST = src/genbuiltin src/connman-dbus.conf src/connman-polkit.conf \
+EXTRA_DIST = src/genbuiltin src/connman-dbusls.conf src/connman-polkit.conf \
                                                plugins/connman-nmcompat.conf
 
 
@@ -134,10 +134,19 @@ script_LTLIBRARIES =
 include Makefile.plugins
 
 if CLIENT
-noinst_PROGRAMS += client/cm
+noinst_PROGRAMS += client/cmn
 
-client_cm_SOURCES = client/main.c
-client_cm_LDADD = @DBUS_LIBS@
+man_MANS = doc/cmn.1
+
+client_cmn_SOURCES =  $(gdbus_sources) src/log.c include/log.h src/dbus.c \
+                       include/dbus.h client/data_manager.c \
+                       client/data_manager.h client/services.c \
+                       client/services.h client/technology.c \
+                       client/technology.h client/interactive.c \
+                       client/interactive.h client/monitor.c \
+                       client/monitor.h client/main.c
+
+client_cmn_LDADD = @DBUS_LIBS@ @GLIB_LIBS@ -ldbus-glib-1 -lreadline -ldl
 endif
 
 if WISPR
diff --git a/client/main.c b/client/main.c
index 4a88d6e..45808c6 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2,7 +2,8 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  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
@@ -19,226 +20,505 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <stdio.h>
-#include <errno.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
 #include <string.h>
 
-#include <dbus/dbus.h>
-
-#define CONNMAN_SERVICE                        "net.connman"
-
-#define CONNMAN_MANAGER_INTERFACE      CONNMAN_SERVICE ".Manager"
-#define CONNMAN_MANAGER_PATH           "/"
+#include <glib.h>
 
-struct service_data {
-       const char *path;
-       const char *name;
-       dbus_bool_t favorite;
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "client/data_manager.h"
+#include "client/services.h"
+#include "client/technology.h"
+#include "client/interactive.h"
+#include "client/monitor.h"
+
+#define MANDATORY_ARGS 4
+
+static char *ipv4[] = {
+       "Method",
+       "Address",
+       "Netmask",
+       "Gateway",
+       NULL
 };
 
-static DBusMessage *get_services(DBusConnection *connection)
-{
-       DBusMessage *message, *reply;
-       DBusError error;
-
-       message = dbus_message_new_method_call(CONNMAN_SERVICE,
-                                               CONNMAN_MANAGER_PATH,
-                                               CONNMAN_MANAGER_INTERFACE,
-                                                       "GetServices");
-       if (message == NULL)
-               return NULL;
-
-       dbus_error_init(&error);
-
-       reply = dbus_connection_send_with_reply_and_block(connection,
-                                                       message, -1, &error);
-       if (reply == NULL) {
-               if (dbus_error_is_set(&error) == TRUE) {
-                       fprintf(stderr, "%s\n", error.message);
-                       dbus_error_free(&error);
-               } else
-                       fprintf(stderr, "Failed to get properties\n");
-               dbus_message_unref(message);
-               return NULL;
-       }
+static char *ipv6[] = {
+       "Method",
+       "Address",
+       "PrefixLength",
+       "Gateway",
+       "Privacy",
+       NULL
+};
 
-       dbus_message_unref(message);
+static char *proxy_simple[] = {
+       "Method",
+       "URL",
+       NULL
+};
 
-       return reply;
-}
+static GMainLoop *main_loop;
 
-static DBusMessage *lookup_service(DBusConnection *connection,
-                                                       const char *pattern)
+static void show_help(void)
 {
-       DBusMessage *message, *reply;
-       DBusError error;
-
-       message = dbus_message_new_method_call(CONNMAN_SERVICE,
-                                               CONNMAN_MANAGER_PATH,
-                                               CONNMAN_MANAGER_INTERFACE,
-                                                       "LookupService");
-       if (message == NULL)
-               return NULL;
-
-       dbus_message_append_args(message, DBUS_TYPE_STRING, &pattern,
-                                                       DBUS_TYPE_INVALID);
-
-       dbus_error_init(&error);
-
-       reply = dbus_connection_send_with_reply_and_block(connection,
-                                                       message, -1, &error);
-       if (reply == NULL) {
-               if (dbus_error_is_set(&error) == TRUE) {
-                       fprintf(stderr, "%s\n", error.message);
-                       dbus_error_free(&error);
-               } else
-                       fprintf(stderr, "Failed to get properties\n");
-               dbus_message_unref(message);
-               return NULL;
-       }
-
-       dbus_message_unref(message);
-
-       return reply;
+       printf("Usage: cmn <command> [args]\n"
+       "  enable                             Enables given technology\n"
+       "        <technology>\n"
+       "        offlinemode                  Enables OfflineMode\n"
+       "  disable                            Disables given technology\n"
+       "        <technology>\n"
+       "        offlinemode                  Disables OfflineMode\n"
+       "  state                              Shows if the system is online or 
offline\n"
+       "  services                           Display list of all services\n"
+       "        --properties <service name>  Show properties of service\n"
+       "  tech                               Current technology on the 
system\n"
+       "  scan <technology>                  Scans for new services on the 
given technology\n"
+       "  connect <service>                  Connect to a given service\n"
+       "  disconnect <service>               Disconnect from service\n"
+       "  config <service> [arg]             Set certain config options\n"
+       "        --autoconnect=y/n            Set autoconnect to service\n"
+       "        --nameservers <names>        Set manual name servers\n"
+       "        --timeservers <names>        Set manual time servers\n"
+       "        --domains <domains>          Set manual domains\n"
+       "        --ipv4                       Set ipv4 configuration\n"
+       "          [METHOD|DHCP|AUTO|MANUAL] [IP] [NETMASK] [GATEWAY]\n"
+       "        --ipv6                       Set ipv6 configuration\n"
+       "          [METHOD|AUTO|MANUAL|OFF] [IP] [PREFIXLENGTH] [GATEWAY]\n"
+       "          [PRIVACY|DISABLED|ENABLED|PREFERED]\n"
+       "        --proxy                      Set proxy configuration\n"
+       "          [METHOD|URL|SERVERS|EXCLUDES]\n"
+       "          if METHOD = manual, enter 'servers' then the list of 
servers\n"
+       "                         then enter 'excludes' then the list of 
excludes\n"
+       "  monitor                            Monitor signals from all Connman 
interfaces\n"
+       "        --services                   Monitor signals from the Service 
interface\n"
+       "        --tech                       Monitor signals from the 
Technology interface\n"
+       "        --manager                    Monitor signals from the Manager 
interface\n"
+       "  help, --help, (no arguments)       Show this dialogue\n"
+       "  interactive                        Drop into the interactive 
shell\n");
 }
 
-static void extract_properties(DBusMessageIter *dict,
-                                       struct service_data *service)
+static int monitor_connman(DBusConnection *connection, char *interface,
+                               char *signal_name)
 {
-       while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
-               DBusMessageIter entry, value;
-               const char *key;
-
-               dbus_message_iter_recurse(dict, &entry);
-               dbus_message_iter_get_basic(&entry, &key);
+       char *rule = g_strdup_printf("type='signal',interface='net.connman.%s',"
+                                       "member='%s'", interface, signal_name);
+       DBusError err;
 
-               dbus_message_iter_next(&entry);
+       dbus_error_init(&err);
+       dbus_connection_setup_with_g_main(connection, NULL);
+       dbus_bus_add_match(connection, rule, &err);
 
-               dbus_message_iter_recurse(&entry, &value);
-
-               //type = dbus_message_iter_get_arg_type(&value);
-               //dbus_message_iter_get_basic(&value, &val);
-
-               if (strcmp(key, "Name") == 0)
-                       dbus_message_iter_get_basic(&value, &service->name);
-               else if (strcmp(key, "Favorite") == 0)
-                       dbus_message_iter_get_basic(&value, &service->favorite);
-
-               dbus_message_iter_next(dict);
+       if (dbus_error_is_set(&err)) {
+               fprintf(stderr, "Match Error: %s\n", err.message);
+               return -1;
        }
+       return 0;
 }
 
-static void extract_services(DBusMessage *message)
+static void store_proxy_input(DBusConnection *connection, DBusMessage *message,
+                               char *name, int num_args, char *argv[])
 {
-       DBusMessageIter iter, array;
+       int i, j, k;
 
-       dbus_message_iter_init(message, &iter);
-       dbus_message_iter_recurse(&iter, &array);
+       gchar **servers = g_try_malloc(0);
+       gchar **excludes = g_try_malloc(0);
 
-       while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
-               DBusMessageIter entry, dict;
-               struct service_data service;
-               const char *path;
-
-               dbus_message_iter_recurse(&array, &entry);
-               dbus_message_iter_get_basic(&entry, &path);
-
-               service.path = strrchr(path, '/') + 1;
-
-               dbus_message_iter_next(&entry);
+       for (i = 0; strcmp(argv[i+6], "excludes"); i++) {
+               servers = g_try_realloc(servers, (i + 1) * sizeof(char *));
+               if (servers == NULL) {
+                       fprintf(stderr, "Could not allocate memory for list\n");
+                       exit(EXIT_FAILURE);
+               }
+               servers[i] = g_strdup(argv[i+6]);
+               /* In case the user doesn't enter "excludes" */
+               if (i + 7 == num_args) {
+                       i++;
+                       j = 0;
+                       goto free_servers;
+               }
+       }
+       for (j = 0; j + (i + 7) != num_args; j++) {
+               excludes = g_try_realloc(excludes, (j + 1) * sizeof(char *));
+               if (excludes == NULL) {
+                       fprintf(stderr, "Could not allocate memory for list\n");
+                       exit(EXIT_FAILURE);
+               }
+               excludes[j] = g_strdup(argv[j + (i + 7)]);
+       }
 
-               dbus_message_iter_recurse(&entry, &dict);
-               extract_properties(&dict, &service);
+free_servers:
+       set_proxy_manual(connection, message, name, servers, excludes, i, j);
 
-               printf("%c %-20s { %-50s }\n",
-                               service.favorite == TRUE ? '*' : ' ',
-                                               service.name, service.path);
+       for (k = 0; k < j - 1; k++)
+               g_free(excludes[k]);
+       g_free(excludes);
 
-               dbus_message_iter_next(&array);
-       }
+       for (k = 0; k < i - 1; k++)
+               g_free(servers[k]);
+       g_free(servers);
 }
 
-static int cmd_list_services(DBusConnection *connection)
+static void service_switch(int argc, char *argv[], int c, DBusConnection *conn,
+                       struct service_data *service)
 {
+       const char *name;
        DBusMessage *message;
 
-       message = get_services(connection);
-       if (message == NULL)
-               return -1;
-
-       extract_services(message);
+       message = get_message(conn, "GetServices");
 
-       dbus_message_unref(message);
-
-       return 0;
+       switch (c) {
+       case 'p':
+               if (argc > 3) {
+                       printf("Properties for %s:\n", argv[3]);
+                       name = find_service(conn, message, argv[3], service);
+                       if (name == NULL)
+                               break;
+                       list_properties(conn, "GetServices", (char *) name);
+               }
+               break;
+       default:
+               fprintf(stderr, "Command not recognized, please check help\n");
+               exit(EXIT_FAILURE);
+               break;
+       }
 }
 
-static int cmd_show_service(DBusConnection *connection, const char *pattern)
+static void config_switch(int argc, char *argv[], int c, DBusConnection *conn)
 {
        DBusMessage *message;
-       const char *path;
-
-       message = lookup_service(connection, pattern);
-       if (message == NULL)
-               return -1;
-
-       dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
-                                                       DBUS_TYPE_INVALID);
-
-       printf("Service: %s\n", path);
-
-       dbus_message_unref(message);
-
-       return 0;
+       int num_args = argc - MANDATORY_ARGS;
+
+       message = get_message(conn, "GetServices");
+
+       switch (c) {
+       case 'a':
+               if (*optarg == 'y' || *optarg == 'n' || *optarg == '1' ||
+                                       *optarg == '0' || *optarg == 't' ||
+                                                       *optarg == 'f'){
+                       dbus_bool_t val;
+                       if (*optarg == 'y' || *optarg == '1' ||
+                                                       *optarg == 't')
+                               val = TRUE;
+                       else if (*optarg == 'n' || *optarg == '0' ||
+                                                       *optarg == 'f')
+                               val = FALSE;
+                       set_service_property(conn, message, argv[2],
+                                               "AutoConnect", NULL,
+                                               &val, 0);
+               }
+               break;
+       case 'i':
+               if (argc > 4)
+                       set_service_property(conn, message, argv[2],
+                                       "IPv4.Configuration", ipv4,
+                                       argv + MANDATORY_ARGS, num_args);
+               break;
+       case 'v':
+               if (argc > 4)
+                       set_service_property(conn, message, argv[2],
+                                       "IPv6.Configuration", ipv6,
+                                       argv + MANDATORY_ARGS, num_args);
+               break;
+       case 'n':
+               if (argc > 4)
+                       set_service_property(conn, message, argv[2],
+                               "Nameservers.Configuration", NULL,
+                               argv + MANDATORY_ARGS, num_args);
+               break;
+       case 't':
+               if (argc > 4)
+                       set_service_property(conn, message, argv[2],
+                                       "Timeservers.Configuration", NULL,
+                                       argv + MANDATORY_ARGS, num_args);
+               break;
+       case 'd':
+               if (argc > 4)
+                       set_service_property(conn, message, argv[2],
+                                       "Domains.Configuration", NULL,
+                                       argv + MANDATORY_ARGS, num_args);
+               break;
+       case 'x':
+               if (argc > 4) {
+                       if ((strcmp(argv[4], "direct") == 0 && argc < 6) ||
+                               (strcmp(argv[4], "auto") == 0 && argc < 7))
+                               set_service_property(conn, message, argv[2],
+                                       "Proxy.Configuration", proxy_simple,
+                                       argv + MANDATORY_ARGS, num_args);
+                       else if (strcmp(argv[4], "manual") == 0
+                                         && strcmp(argv[5], "servers") == 0
+                                         && argc > 6) {
+                               store_proxy_input(conn, message, argv[2],
+                                                       argc, argv);
+                       } else {
+                               fprintf(stderr, "Incorrect arguments\n");
+                       }
+               }
+               break;
+       default:
+               fprintf(stderr, "Command not recognized, please check help\n");
+               exit(EXIT_FAILURE);
+               break;
+       }
 }
 
-static void usage(const char *program)
+static void monitor_switch(int argc, char *argv[], int c, DBusConnection *conn)
 {
-       printf("ConnMan utility ver %s\n\n", VERSION);
-
-       printf("Usage:\n"
-               "\t%s <command> [options]\n\n", program);
+       switch (c) {
+       case 's':
+               printf("Now monitoring the service interface.\n");
+               monitor_connman(conn, "Service", "PropertyChanged");
+               dbus_connection_add_filter(conn, service_property_changed,
+                                                       NULL, NULL);
+               break;
+       case 'c':
+               printf("Now monitoring the technology interface.\n");
+               monitor_connman(conn, "Technology", "PropertyChanged");
+               dbus_connection_add_filter(conn, tech_property_changed,
+                                                       NULL, NULL);
+               break;
+       case 'm':
+               printf("Now monitoring the manager interface.\n");
+               monitor_connman(conn, "Manager", "PropertyChanged");
+               monitor_connman(conn, "Manager", "TechnologyAdded");
+               monitor_connman(conn, "Manager", "TechnologyRemoved");
+               dbus_connection_add_filter(conn, manager_property_changed,
+                                                       NULL, NULL);
+               dbus_connection_add_filter(conn, tech_added_removed,
+                                                       NULL, NULL);
+               break;
+       default:
+               fprintf(stderr, "Command not recognized, please check help\n");
+               exit(EXIT_FAILURE);
+               break;
+       }
+}
 
-       printf("Commands:\n"
-               "\thelp\n"
-               "\tlist\n"
-               "\tshow <service>\n"
-               "\n");
+static gboolean timeout_wait(gpointer data)
+{
+       static int i;
+       i++;
+       /* Set to whatever number of retries is wanted/needed */
+       if (i == 1) {
+               g_main_loop_quit(data);
+               return FALSE;
+       }
+       return TRUE;
 }
 
 int main(int argc, char *argv[])
 {
-       DBusConnection *conn;
+       int c;
+       int option_index = 0;
+       struct service_data service;
+       DBusConnection *connection;
+       DBusMessage *message;
+       DBusError err;
+
+       static struct option service_options[] = {
+               {"properties", required_argument, 0, 'p'},
+               {0, 0, 0, 0}
+       };
+
+       static struct option config_options[] = {
+               {"nameservers", required_argument, 0, 'n'},
+               {"timeservers", required_argument, 0, 't'},
+               {"domains", required_argument, 0, 'd'},
+               {"ipv6", required_argument, 0, 'v'},
+               {"proxy", required_argument, 0, 'x'},
+               {"autoconnect", required_argument, 0, 'a'},
+               {"ipv4", required_argument, 0, 'i'},
+               {0, 0, 0, 0}
+       };
+
+       static struct option monitor_options[] = {
+               {"services", no_argument, 0, 's'},
+               {"tech", no_argument, 0, 'c'},
+               {"manager", no_argument, 0, 'm'},
+               {0, 0, 0, 0}
+       };
+
+       g_type_init();
+       main_loop = g_main_loop_new(NULL, TRUE);
+
+       dbus_error_init(&err);
+       connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+       message = get_message(connection, "GetServices");
+
+       if (dbus_error_is_set(&err)) {
+               fprintf(stderr, "Connection Error: %s\n", err.message);
+               dbus_error_free(&err);
+       }
 
-       if (argc > 1 && strcmp(argv[1], "help") == 0) {
-               usage(argv[0]);
-               exit(0);
+       if (connection == NULL) {
+               fprintf(stderr, "Could not connect to system bus...exiting\n");
+               exit(EXIT_FAILURE);
        }
 
-       conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-       if (!conn) {
-               fprintf(stderr, "Can't get on system bus\n");
-               exit(1);
+       if (argc < 2) {
+               show_help();
+               g_main_loop_unref(main_loop);
+               exit(EXIT_SUCCESS);
        }
 
-       if (argc > 1) {
-               if (strcmp(argv[1], "list") == 0)
-                       cmd_list_services(conn);
-               else if (strcmp(argv[1], "show") == 0) {
-                       if (argc > 2)
-                               cmd_show_service(conn, argv[2]);
-                       else
-                               usage(argv[0]);
+       if (strcmp(argv[1], "monitor") != 0)
+               g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
+                                                              main_loop, NULL);
+
+       if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "help") == 0) {
+               show_help();
+               g_main_loop_unref(main_loop);
+               exit(EXIT_SUCCESS);
+       } else if (strcmp(argv[1], "interactive") == 0) {
+               if (argc != 2) {
+                       fprintf(stderr, "Interactive cannot accept an argument,"
+                                                               " see help\n");
+                       return -1;
                }
+               show_interactive(connection);
+       } else if (strcmp(argv[1], "state") == 0) {
+               if (argc != 2) {
+                       fprintf(stderr, "State cannot accept an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               list_properties(connection, "GetProperties", NULL);
+       } else if (strcmp(argv[1], "tech") == 0) {
+               if (argc != 2) {
+                       fprintf(stderr, "Tech cannot accept an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               printf("* All currently connected technology:\n");
+               list_properties(connection, "GetTechnologies", NULL);
+       } else if (strcmp(argv[1], "connect") == 0) {
+               if (argc != 3) {
+                       fprintf(stderr, "Connect requires an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               printf("Connecting to: %s\n", strip_service_path(argv[2]));
+               connect_service(connection, strip_service_path(argv[2]));
+       } else if (strcmp(argv[1], "disconnect") == 0) {
+               if (argc != 3) {
+                       fprintf(stderr, "Disconnect requires an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               printf("Disconnecting from: %s\n", strip_service_path(argv[2]));
+               disconnect_service(connection, strip_service_path(argv[2]));
+       } else if (strcmp(argv[1], "scan") == 0) {
+               if (argc != 3) {
+                       fprintf(stderr, "Scan requires an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               message = get_message(connection, "GetTechnologies");
+               scan_technology(connection, message, argv[2]);
+               dbus_message_unref(message);
+       } else if (strcmp(argv[1], "enable") == 0) {
+               if (argc != 3) {
+                       fprintf(stderr, "Enable requires an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               if (strcmp(argv[2], "offlinemode") == 0) {
+                       set_manager(connection, "OfflineMode", TRUE);
+                       printf("OfflineMode is now enabled\n");
+               } else {
+                       message = get_message(connection, "GetTechnologies");
+                       if (set_technology(connection, message, "Powered",
+                                                       argv[2], TRUE) == 0)
+                               printf("Enabled %s technology\n", argv[2]);
+                       dbus_message_unref(message);
+               }
+       } else if (strcmp(argv[1], "disable") == 0) {
+               if (argc != 3) {
+                       fprintf(stderr, "Disable requires an argument, "
+                                                               "see help\n");
+                       return -1;
+               }
+               if (strcmp(argv[2], "offlinemode") == 0) {
+                       set_manager(connection, "OfflineMode", FALSE);
+                       printf("OfflineMode is now disabled\n");
+               } else {
+                       message = get_message(connection, "GetTechnologies");
+                       if (set_technology(connection, message, "Powered",
+                                                       argv[2], FALSE) == 0)
+                               printf("Disabled %s technology\n", argv[2]);
+                       dbus_message_unref(message);
+               }
+       } else if (strcmp(argv[1], "services") == 0) {
+               if (argc > 4) {
+                       fprintf(stderr, "Too many arguments for services, "
+                                                               "see help\n");
+                       return -1;
+               }
+               if (argc < 3) {
+                       printf("List of all services:\n");
+                       list_properties(connection, "GetServices", NULL);
+               }
+               while ((c = getopt_long(argc, argv, "", service_options,
+                                               &option_index))) {
+                       if (c == -1)
+                               break;
+                       service_switch(argc, argv, c, connection, &service);
+               }
+       } else if (strcmp(argv[1], "config") == 0) {
+               if (argc < 4) {
+                       fprintf(stderr, "Config requires an option, "
+                                                               "see help\n");
+                       return -1;
+               }
+               while ((c = getopt_long(argc, argv, "", config_options,
+                                                       &option_index))) {
+                       if (c == -1)
+                               break;
+                       config_switch(argc, argv, c, connection);
+               }
+       } else if (strcmp(argv[1], "monitor") == 0) {
+               if (argc > 3) {
+                       fprintf(stderr, "Too many arguments for monitor, "
+                                                               "see help\n");
+                       return -1;
+               }
+               if (argc < 3) {
+                       printf("Now monitoring all interfaces.\n");
+                       monitor_connman(connection, "Service",
+                                                       "PropertyChanged");
+                       monitor_connman(connection, "Technology",
+                                                       "PropertyChanged");
+                       monitor_connman(connection, "Manager",
+                                                       "PropertyChanged");
+                       monitor_connman(connection, "Manager",
+                                                       "TechnologyAdded");
+                       monitor_connman(connection, "Manager",
+                                                       "TechnologyRemoved");
+                       dbus_connection_add_filter(connection,
+                                       service_property_changed, NULL, NULL);
+                       dbus_connection_add_filter(connection,
+                                       tech_property_changed, NULL, NULL);
+                       dbus_connection_add_filter(connection,
+                                       tech_added_removed, NULL, NULL);
+                       dbus_connection_add_filter(connection,
+                                       manager_property_changed, NULL, NULL);
+               } else
+                       while ((c = getopt_long(argc, argv, "", monitor_options,
+                                                       &option_index))) {
+                               if (c == -1)
+                                       break;
+                               monitor_switch(argc, argv, c, connection);
+                       }
        } else
-               usage(argv[0]);
-
-       dbus_connection_unref(conn);
+               fprintf(stderr, "%s is not a valid command, check help.\n",
+                                                               argv[1]);
 
+       g_main_loop_run(main_loop);
+       g_main_loop_unref(main_loop);
        return 0;
 }
+
-- 
1.7.9.5

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

Reply via email to