diff options
author | Petre Eftime <[email protected]> | 2016-10-31 15:58:36 +0200 |
---|---|---|
committer | petreeftime <[email protected]> | 2016-10-31 21:44:29 +0100 |
commit | 52a0b0660e84560822768aa78061f8eb3cab4889 (patch) | |
tree | f990166710e4127017b9e775bfb6cfc4b71c8bcd /src | |
parent | 2c3706fc16bf22c28ea3051703e98fc27b73f365 (diff) |
Add notifications for manufacturer data, service data and services resolved
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/BluetoothDevice.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/BluetoothDevice.cpp b/src/BluetoothDevice.cpp index a0832a43..9f3500a3 100644 --- a/src/BluetoothDevice.cpp +++ b/src/BluetoothDevice.cpp @@ -81,6 +81,59 @@ void BluetoothNotificationHandler::on_properties_changed_device(GDBusProxy *prox connected_callback(new_value); continue; } + auto mfg_callback = c->mfg_callback; + if (mfg_callback != nullptr && g_ascii_strncasecmp(key, "manufacturerdata", 16) == 0) { + std::map<uint16_t, std::vector<uint8_t>> new_value; + + GVariantIter *iter; + g_variant_get (value, "a{qv}", &iter); + + GVariant *array; + uint16_t key; + uint8_t val; + + while (g_variant_iter_loop(iter, "{qv}", &key, &array)) { + GVariantIter it_array; + g_variant_iter_init(&it_array, array); + while(g_variant_iter_loop(&it_array, "y", &val)) { + new_value[key].push_back(val); + } + } + + g_variant_iter_free(iter); + mfg_callback(new_value); + continue; + } + auto service_callback = c->service_callback; + if (service_callback != nullptr && g_ascii_strncasecmp(key, "servicedata", 11) == 0) { + std::map<std::string, std::vector<uint8_t>> new_value; + + GVariantIter *iter; + g_variant_get (value, "a{sv}", &iter); + + GVariant *array; + const char* key; + uint8_t val; + + while (g_variant_iter_loop(iter, "{sv}", &key, &array)) { + GVariantIter it_array; + g_variant_iter_init(&it_array, array); + while(g_variant_iter_loop(&it_array, "y", &val)) { + new_value[key].push_back(val); + } + } + + g_variant_iter_free(iter); + service_callback(new_value); + continue; + } + auto services_resolved_callback = c->services_resolved_callback; + if (services_resolved_callback != nullptr && g_ascii_strncasecmp(key, "servicesresolved", 16) == 0) { + bool new_value; + g_variant_get(value, "b", &new_value); + services_resolved_callback(new_value); + continue; + } } g_variant_iter_free (iter); } @@ -475,6 +528,19 @@ std::map<uint16_t, std::vector<uint8_t>> BluetoothDevice::get_manufacturer_data( return m_data; } +void BluetoothDevice::enable_manufacturer_data_notifications( + std::function<void(BluetoothDevice &, std::map<uint16_t, std::vector<uint8_t>> &, void *)> callback, + void *userdata) { + mfg_callback = std::bind(callback, std::ref(*this), std::placeholders::_1, userdata); +} +void BluetoothDevice::enable_manufacturer_data_notifications( + std::function<void(std::map<uint16_t, std::vector<uint8_t>> &)> callback) { + mfg_callback = callback; +} +void BluetoothDevice::disable_manufacturer_data_notifications() { + mfg_callback = nullptr; +} + std::map<std::string, std::vector<uint8_t>> BluetoothDevice::get_service_data() { std::map<std::string, std::vector<uint8_t>> m_data; @@ -505,6 +571,19 @@ std::map<std::string, std::vector<uint8_t>> BluetoothDevice::get_service_data() return m_data; } +void BluetoothDevice::enable_service_data_notifications( + std::function<void(BluetoothDevice &, std::map<std::string, std::vector<uint8_t>> &, void *)> callback, + void *userdata) { + service_callback = std::bind(callback, std::ref(*this), std::placeholders::_1, userdata); +} +void BluetoothDevice::enable_service_data_notifications( + std::function<void(std::map<std::string, std::vector<uint8_t>> &)> callback) { + service_callback = callback; +} +void BluetoothDevice::disable_service_data_notifications() { + service_callback = nullptr; +} + int16_t BluetoothDevice::get_tx_power () { return device1_get_tx_power (object); @@ -515,3 +594,16 @@ bool BluetoothDevice::get_services_resolved () return device1_get_services_resolved (object); } +void BluetoothDevice::enable_services_resolved_notifications( + std::function<void(BluetoothDevice &, bool, void *)> callback, + void *userdata) { + services_resolved_callback = std::bind(callback, std::ref(*this), std::placeholders::_1, userdata); +} +void BluetoothDevice::enable_services_resolved_notifications( + std::function<void(bool)> callback) { + services_resolved_callback = callback; +} +void BluetoothDevice::disable_services_resolved_notifications() { + services_resolved_callback = nullptr; +} + |