bluez glib编程 --- signal 信号的监听
监听添加新对象的信号
objectManager = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.bluez", "/", "org.freedesktop.DBus.ObjectManager", NULL, &error); PRINT_ERROR_LOG("ObjectManager"); g_signal_connect(objectManager, "g-signal", G_CALLBACK(objectManager_handler), NULL);
对象使用的是 /,接口使用的是标准接口 org.freedesktop.DBus.ObjectManager
监听属性改变的信号
properties1 = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.bluez", path, "org.freedesktop.DBus.Properties", NULL, &error); PRINT_WARN_LOG("Properties"); g_signal_connect(properties1, "g-signal::PropertiesChanged", G_CALLBACK(properties_handler), NULL);
如果使用的对象是 /org/bluez/hci0/dev_A4_C1_38_10_09_2C/service0021/char0022,则监听接口 org.bluez.GattCharacteristic1 的属性变化,此对象有三个接口:
interface_name: org.freedesktop.DBus.Introspectable
interface_name: org.bluez.GattCharacteristic1
interface_name: org.freedesktop.DBus.Properties
通过标准接口 org.freedesktop.DBus.Properties 监听接口 org.bluez.GattCharacteristic1 的属性变化
内存回收
g_dbus_proxy_new_sync 返回值所占内存的回收得等到信号 disconnect。