From 89b57dc63bc2cb97bc2d3283de388f24f2debd3d Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Wed, 20 Feb 2013 13:29:37 +0200 Subject: [PATCH] client: Create monitor helper functions --- client/monitor.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ client/monitor.h | 3 ++ 2 files changed, 94 insertions(+) diff --git a/client/monitor.c b/client/monitor.c index 5e8b3923..296d00c3 100644 --- a/client/monitor.c +++ b/client/monitor.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,96 @@ int monitor_connman(DBusConnection *connection, char *interface, return 0; } +static void monitor_clear(DBusConnection *connection, char *interface) +{ + char *rule = g_strdup_printf("type='signal',interface='net.connman.%s'", + interface); + + dbus_bus_remove_match(connection, rule, NULL); +} + +static int monitor_add(DBusConnection *connection, char *interface) +{ + char *rule = g_strdup_printf("type='signal',interface='net.connman.%s'", + interface); + DBusError err; + + dbus_error_init(&err); + g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err); + if (dbus_error_is_set(&err)) { + fprintf(stderr, "Bus setup error:%s\n", err.message); + return -1; + } + dbus_bus_add_match(connection, rule, &err); + + if (dbus_error_is_set(&err)) { + fprintf(stderr, "Match Error: %s\n", err.message); + return -1; + } + return 0; +} + +int monitor_connman_service(DBusConnection *connection) +{ + int err; + + err = monitor_add(connection, "Service"); + if (err < 0) + return err; + + if (dbus_connection_add_filter(connection, + service_property_changed, + NULL, NULL) == FALSE) { + monitor_clear(connection, "Service"); + return -ENXIO; + } + + return 0; +} + +int monitor_connman_technology(DBusConnection *connection) +{ + int err; + + err = monitor_add(connection, "Technology"); + if (err < 0) + return err; + + if (dbus_connection_add_filter(connection, + tech_property_changed, + NULL, NULL) == FALSE) { + monitor_clear(connection, "Technology"); + return -ENXIO; + } + + return 0; +} + +int monitor_connman_manager(DBusConnection *connection) +{ + int err; + + err = monitor_add(connection, "Manager"); + if (err < 0) + return err; + + if (dbus_connection_add_filter(connection, manager_property_changed, + NULL, NULL) == FALSE) { + monitor_clear(connection, "Manager"); + return -ENXIO; + } + + if (dbus_connection_add_filter(connection, manager_services_changed, + NULL, NULL) == FALSE) { + dbus_connection_remove_filter(connection, + manager_property_changed, NULL); + monitor_clear(connection, "Manager"); + return -ENXIO; + } + + return 0; +} + DBusHandlerResult service_property_changed(DBusConnection *connection, DBusMessage *message, void *user_data) diff --git a/client/monitor.h b/client/monitor.h index db64aa13..a0607265 100644 --- a/client/monitor.h +++ b/client/monitor.h @@ -24,6 +24,9 @@ int monitor_connman(DBusConnection *connection, char *interface, char *signal_name); +int monitor_connman_service(DBusConnection *connection); +int monitor_connman_technology(DBusConnection *connection); +int monitor_connman_manager(DBusConnection *connection); DBusHandlerResult service_property_changed(DBusConnection *connection, DBusMessage *message, void *user_data); -- 2.34.1