summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-20 13:29:37 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-21 16:23:12 +0200
commit89b57dc63bc2cb97bc2d3283de388f24f2debd3d (patch)
treed997dd9386a95a562eb091b076856c1aa971c645
parent0344eecf90e964ea15df34cb03b4316ae7e5766a (diff)
downloadconnman-89b57dc63bc2cb97bc2d3283de388f24f2debd3d.tar.gz
connman-89b57dc63bc2cb97bc2d3283de388f24f2debd3d.tar.bz2
connman-89b57dc63bc2cb97bc2d3283de388f24f2debd3d.zip
client: Create monitor helper functions
-rw-r--r--client/monitor.c91
-rw-r--r--client/monitor.h3
2 files changed, 94 insertions, 0 deletions
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 <unistd.h>
#include <string.h>
#include <stdint.h>
+#include <errno.h>
#include <glib.h>
#include <gdbus.h>
@@ -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);