c - signal names generated on interface "org.freedesktop.NetworkManager.Device" of Network Manager in linux -
i new dbus , trying catch signal generated when network cable plugged in or plugged out.i trying sample code given @ "http://software.intel.com/en-us/articles/detecting-network-connectivity-using-d-bus"
what signal name shall use in dbus_message_is_signal() info.provide sample code can clear concept.
my code is:
enter code here #include<stdio.h> #include<dbus/dbus.h> #include <gdbus.h> #include<stdbool.h> #include<unistd.h> #include<stdlib.h> #include<dbus/dbus-glib-bindings.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> #define platform_service "org.freedesktop.networkmanager" #define platform_path "/org/freedesktop/networkmanager" #define platform_connection_if "org.freedesktop.networkmanager" main() { dbusmessage* msg; dbusconnection* conn; dbuserror err; printf("listening signals\n"); // initialise errors dbus_error_init(&err); //connect bus , check errors conn = dbus_bus_get(dbus_bus_system, &err); if (dbus_error_is_set(&err)) { fprintf(stderr, "connection error (%s)n", err.message); dbus_error_free(&err); } if (null == conn) { printf("error in connection\n"); exit(1); } dbus_bus_add_match(conn, "type='signal',interface='org.freedesktop.networkmanager'", &err); dbus_connection_flush(conn); if (dbus_error_is_set(&err)) { fprintf(stderr, "match error (%s)n", err.message); exit(1); } printf("match rule sent\n"); g_message("listening d-bus signals using connection filter"); // loop listening signals being emmitted while (true) { printf("in while \n"); // non blocking read of next available message dbus_connection_read_write(conn,0); msg = dbus_connection_pop_message(conn); // loop again if haven't read message if (null == msg) { sleep(1); continue; } if (dbus_message_is_signal(msg, platform_connection_if,"propertieschanged")) printf("received signal propertychanged \n"); if (dbus_message_is_signal(msg, platform_connection_if, "deviceremoved")) printf("received signal %s\n", "device changed"); // free message dbus_message_unref(msg); } }
i can property changed signal how other signals.
look @ networkmanager spec @ http://projects.gnome.org/networkmanager/developers/api/09/spec.html -- provides of details of interface.
signals can of interest "deviceadded" , "deviceremoved" discover when devices come , go (cable plugged , unplugged). can dive down org.freedesktop.networkmanager.device "propertieschanged" signal , grab "state" property, among others.
Comments
Post a Comment