From e0a888a51fe95f7ff016510b21cd49ae261f0b40 Mon Sep 17 00:00:00 2001 From: lasan Date: Thu, 19 Mar 2026 20:23:24 +0530 Subject: [PATCH] migrated to sdbus-cpp v2 --- .../platform/implementation/linux/avahi.cc | 4 +- .../platform/implementation/linux/avahi.h | 2 +- .../implementation/linux/ble_gatt_client.cc | 28 +++++------ .../implementation/linux/ble_gatt_client.h | 2 +- .../implementation/linux/ble_gatt_server.cc | 4 +- .../implementation/linux/ble_gatt_server.h | 3 +- .../implementation/linux/ble_v2_medium.cc | 18 ++++---- .../linux/bluetooth_bluez_profile.cc | 18 ++++---- .../linux/bluetooth_bluez_profile.h | 4 +- .../linux/bluetooth_classic_device.cc | 17 +++---- .../linux/bluetooth_classic_device.h | 14 ++++-- .../linux/bluetooth_classic_medium.cc | 2 +- .../implementation/linux/bluetooth_devices.cc | 30 ++++++------ .../implementation/linux/bluetooth_pairing.cc | 8 ++-- .../implementation/linux/bluetooth_pairing.h | 2 +- .../platform/implementation/linux/bluez.cc | 22 ++++----- .../linux/bluez_advertisement_monitor.cc | 2 +- .../bluez_advertisement_monitor_manager.h | 4 +- .../implementation/linux/bluez_device.h | 9 ++-- .../linux/bluez_gatt_characteristic_client.cc | 11 +++-- .../linux/bluez_gatt_characteristic_client.h | 12 ++--- .../linux/bluez_gatt_characteristic_server.cc | 22 ++++----- .../linux/bluez_gatt_service_server.cc | 2 +- .../linux/bluez_gatt_service_server.h | 4 +- .../linux/bluez_le_advertisement.cc | 2 +- .../linux/bluez_le_advertisement.h | 6 +-- .../implementation/linux/network_manager.cc | 28 +++++------ .../network_manager_active_connection.cc | 2 +- .../platform/implementation/linux/platform.cc | 8 ++-- .../implementation/linux/wifi_hotspot.cc | 46 ++++++++++--------- .../linux/wifi_lan_server_socket.cc | 2 +- .../implementation/linux/wifi_medium.cc | 40 ++++++++-------- .../implementation/linux/wifi_medium.h | 6 +-- 33 files changed, 198 insertions(+), 186 deletions(-) diff --git a/internal/platform/implementation/linux/avahi.cc b/internal/platform/implementation/linux/avahi.cc index 022610c3..fa8db0dc 100644 --- a/internal/platform/implementation/linux/avahi.cc +++ b/internal/platform/implementation/linux/avahi.cc @@ -26,8 +26,8 @@ void Server::onResolveServiceReply(const int32_t& interface, const std::string& host, const int32_t& aprotocol, const std::string& address, const uint16_t& port, const std::vector>& txt, const uint32_t& flags, - const sdbus::Error* error) { - if (error != nullptr && error->isValid()) { + std::optional error) { + if (error.has_value()) { LOG(ERROR) << __func__ << ": ResolveService failed with error '" << error->getName() << "' message '" << error->getMessage() << "'"; diff --git a/internal/platform/implementation/linux/avahi.h b/internal/platform/implementation/linux/avahi.h index 7c8f87aa..d99ac0a9 100644 --- a/internal/platform/implementation/linux/avahi.h +++ b/internal/platform/implementation/linux/avahi.h @@ -67,7 +67,7 @@ class Server final const std::string& host, const int32_t& aprotocol, const std::string& address, const uint16_t& port, const std::vector>& txt, const uint32_t& flags, - const sdbus::Error* error) override; + std::optional error) override; }; class EntryGroup final diff --git a/internal/platform/implementation/linux/ble_gatt_client.cc b/internal/platform/implementation/linux/ble_gatt_client.cc index 9dbd7ff5..74047ab2 100644 --- a/internal/platform/implementation/linux/ble_gatt_client.cc +++ b/internal/platform/implementation/linux/ble_gatt_client.cc @@ -120,10 +120,10 @@ bool GattClient::WriteCharacteristic( try { chr->WriteValue( value_bytes, - {{"type", - type == api::ble::GattClient::WriteType::kWithResponse - ? "request" - : "command"}}); + {{sdbus::PropertyName("type"), + sdbus::Variant(type == api::ble::GattClient::WriteType::kWithResponse + ? "request" + : "command")}}); return true; } catch (const sdbus::Error &e) { DBUS_LOG_METHOD_CALL_ERROR(chr, "WriteValue", e); @@ -199,7 +199,7 @@ void BluezGattDiscovery::Shutdown() { bool BluezGattDiscovery::InitializeKnownServices() { std::map>> + std::map>> objects; try { objects = GetManagedObjects(); @@ -213,16 +213,16 @@ bool BluezGattDiscovery::InitializeKnownServices() { auto chr_it = std::find_if( objects.cbegin(), objects.cend(), [](std::pair>> + std::map>> object) { return object.second.count( - org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME) == 1; + sdbus::InterfaceName(org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME)) == 1; }); for (; chr_it != objects.cend(); ++chr_it) { const auto& [path, ifaces] = *chr_it; - auto iface_it = ifaces.find(org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME); + auto iface_it = ifaces.find(sdbus::InterfaceName(org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME)); if (iface_it == ifaces.end()) { // Not a GattCharacteristic1 object (or interfaces map incomplete) -> skip continue; @@ -343,10 +343,11 @@ BluezGattDiscovery::GetSubscribedCharacteristic( std::optional> BluezGattDiscovery::characteristicProperties( const sdbus::ObjectPath &char_path, - const std::map &properties) { + const std::map &properties) { mutex_.AssertHeld(); - const std::string &chr_uuid_str = properties.at("UUID"); + const std::string &chr_uuid_str = + properties.at(sdbus::PropertyName("UUID")).get(); auto chr_uuid = UuidFromString(chr_uuid_str); if (!chr_uuid.has_value()) { LOG(ERROR) << ": Couldn't parse UUID '" << chr_uuid_str @@ -354,7 +355,8 @@ BluezGattDiscovery::characteristicProperties( return std::nullopt; } - const sdbus::ObjectPath &service_path = properties.at("Service"); + const sdbus::ObjectPath &service_path = + properties.at(sdbus::PropertyName("Service")).get(); if (cached_services_.count(service_path) == 0) { cached_services_.emplace( service_path, std::make_unique(system_bus_, service_path)); @@ -403,11 +405,11 @@ void BluezGattDiscovery::onInterfacesAdded( std::map> &interfacesAndProperties) { if (interfacesAndProperties.count( - org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME) == 0) + sdbus::InterfaceName(org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME)) == 0) return; const auto &properties = interfacesAndProperties.at( - org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME); + sdbus::InterfaceName(org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME)); absl::MutexLock lock(&mutex_); auto maybe_props = characteristicProperties(objectPath, properties); diff --git a/internal/platform/implementation/linux/ble_gatt_client.h b/internal/platform/implementation/linux/ble_gatt_client.h index 7ae7eb45..108b4769 100644 --- a/internal/platform/implementation/linux/ble_gatt_client.h +++ b/internal/platform/implementation/linux/ble_gatt_client.h @@ -78,7 +78,7 @@ class BluezGattDiscovery final : public bluez::BluezObjectManager { std::optional> characteristicProperties( const sdbus::ObjectPath &char_path, - const std::map &properties) + const std::map &properties) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_); void Shutdown() ABSL_LOCKS_EXCLUDED(mutex_); diff --git a/internal/platform/implementation/linux/ble_gatt_server.cc b/internal/platform/implementation/linux/ble_gatt_server.cc index 24afa9ac..cc761c22 100644 --- a/internal/platform/implementation/linux/ble_gatt_server.cc +++ b/internal/platform/implementation/linux/ble_gatt_server.cc @@ -45,7 +45,7 @@ GattServer::CreateCharacteristic( system_bus_, count, service_uuid, server_cb_, devices_); try { service->emitInterfacesAddedSignal( - {org::bluez::GattService1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::GattService1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error& e) { LOG(ERROR) << __func__ @@ -144,7 +144,7 @@ void GattServer::Stop() { LOG(INFO) << __func__ << ": Unregistering service " << service->getObject().getObjectPath(); try { - manager.UnregisterApplication("/"); + manager.UnregisterApplication(sdbus::ObjectPath("/")); } catch (const sdbus::Error& e) { DBUS_LOG_METHOD_CALL_ERROR(&manager, "UnregisterApplication", e); } diff --git a/internal/platform/implementation/linux/ble_gatt_server.h b/internal/platform/implementation/linux/ble_gatt_server.h index b387781b..1343a4be 100644 --- a/internal/platform/implementation/linux/ble_gatt_server.h +++ b/internal/platform/implementation/linux/ble_gatt_server.h @@ -65,7 +65,8 @@ class GattServer : public api::ble::GattServer { devices_(std::move(devices)), adapter_(adapter), local_peripheral_(adapter_), - gatt_service_root_object_manager(std::make_unique(system_bus_, "/com/google/nearby/medium/ble/gatt")), + gatt_service_root_object_manager(std::make_unique(system_bus_, + sdbus::ObjectPath("/com/google/nearby/medium/ble/gatt"))), gatt_manager_(std::make_unique(system_bus_, adapter_.GetObjectPath())), server_cb_(std::make_shared( std::move(server_cb))) {} diff --git a/internal/platform/implementation/linux/ble_v2_medium.cc b/internal/platform/implementation/linux/ble_v2_medium.cc index d008bcea..8a96debe 100644 --- a/internal/platform/implementation/linux/ble_v2_medium.cc +++ b/internal/platform/implementation/linux/ble_v2_medium.cc @@ -72,7 +72,7 @@ BleV2Medium::BleV2Medium(BluetoothAdapter &adapter) observers_(std::make_shared>()), devices_(std::make_unique( system_bus_, adapter_.GetObjectPath(), *observers_)), - root_object_manager_(std::make_unique(*system_bus_, "/com/google/nearby/medium/ble/advertisement/monitor")), + root_object_manager_(std::make_unique(*system_bus_, sdbus::ObjectPath("/com/google/nearby/medium/ble/advertisement/monitor"))), adv_monitor_manager_( bluez::AdvertisementMonitorManager:: DiscoverAdvertisementMonitorManager(*system_bus_, adapter_)), @@ -268,7 +268,7 @@ bool BleV2Medium::StartScanning(const Uuid &service_uuid, try { // why is this emitted? monitor->emitInterfacesAddedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); // adv_monitor_manager_ -> RegisterMonitor(monitor -> getObject().getObjectPath()); LOG(INFO)<< __func__ << ": Registered advertisement monitor with path " << monitor -> getObject().getObjectPath(); @@ -289,7 +289,7 @@ bool BleV2Medium::StartScanning(const Uuid &service_uuid, device_watcher = nullptr; try { monitor->emitInterfacesRemovedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -338,7 +338,7 @@ bool BleV2Medium::StopScanning() { LOG(INFO) << __func__ << ": Removing advertising monitor " << adv_monitor->getObject().getObjectPath(); adv_monitor->emitInterfacesRemovedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); } active_adv_monitors_.erase(monitor_it); cur_monitored_service_uuid_ = std::nullopt; @@ -366,7 +366,7 @@ bool BleV2Medium::StopScanning() { std::move(callback)); try { monitor->emitInterfacesAddedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -384,7 +384,7 @@ bool BleV2Medium::StopScanning() { << adapter_.GetObjectPath(); try { monitor->emitInterfacesRemovedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -412,7 +412,7 @@ bool BleV2Medium::StopScanning() { auto &[monitor, watcher] = active_adv_monitors_[service_uuid]; try { monitor->emitInterfacesRemovedSignal( - {org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::AdvertisementMonitor1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -497,8 +497,8 @@ bool BleV2Medium::IsExtendedAdvertisementsAvailable() { bool BleV2Medium::StartLEDiscovery() { std::map filter; - filter["Transport"] = "auto"; - filter["DuplicateData"] = true; + filter["Transport"] = sdbus::Variant("auto"); + filter["DuplicateData"] = sdbus::Variant(true); auto &adapter = adapter_.GetBluezAdapterObject(); try { diff --git a/internal/platform/implementation/linux/bluetooth_bluez_profile.cc b/internal/platform/implementation/linux/bluetooth_bluez_profile.cc index 18cdd266..b1ef90d7 100644 --- a/internal/platform/implementation/linux/bluetooth_bluez_profile.cc +++ b/internal/platform/implementation/linux/bluetooth_bluez_profile.cc @@ -58,7 +58,7 @@ void Profile::NewConnection( LOG(ERROR) << __func__ << ": NewConnection called on released object " << getObject().getObjectPath(); - throw sdbus::Error("org.bluez.Error.Rejected", + throw sdbus::Error(sdbus::Error::Name("org.bluez.Error.Rejected"), "NewConnection called on released object"); } @@ -95,7 +95,7 @@ void Profile::RequestDisconnection( << ": RequestDisconnection called with a device object " "we don't know about: " << device_object_path; - throw sdbus::Error("org.bluez.Error.Rejected", "Unknown object"); + throw sdbus::Error(sdbus::Error::Name("org.bluez.Error.Rejected"), "Unknown object"); } auto mac_addr = device -> GetMacAddress(); @@ -128,17 +128,17 @@ bool ProfileManager::Register(std::optional name, try { std::map options; if (name.has_value()) { - options["Name"] = std::string(*name); + options["Name"] = sdbus::Variant(std::string(*name)); } - options["RequireAuthorization"] = false; - options["RequireAuthentication"] = false; - options["Channel"] = static_cast(0); - options["PSM"] = static_cast(0); + options["RequireAuthorization"] = sdbus::Variant(false); + options["RequireAuthentication"] = sdbus::Variant(false); + options["Channel"] = sdbus::Variant(static_cast(0)); + options["PSM"] = sdbus::Variant(static_cast(0)); RegisterProfile(profile->getObject().getObjectPath(), std::string(service_uuid), options); } catch (const sdbus::Error &e) { - BLUEZ_LOG_METHOD_CALL_ERROR(&getProxy(), "RegisterProfile", e); + BLUEZ_LOG_METHOD_CALL_ERROR(this, "RegisterProfile", e); return false; } @@ -167,7 +167,7 @@ void ProfileManager::Unregister(absl::string_view service_uuid) { try { UnregisterProfile(profile_object_path); } catch (const sdbus::Error &e) { - BLUEZ_LOG_METHOD_CALL_ERROR(&getProxy(), "UnregisterProfile", e); + BLUEZ_LOG_METHOD_CALL_ERROR(this, "UnregisterProfile", e); } registered_services_.erase(std::string(service_uuid)); diff --git a/internal/platform/implementation/linux/bluetooth_bluez_profile.h b/internal/platform/implementation/linux/bluetooth_bluez_profile.h index d0613eb8..983c7eee 100644 --- a/internal/platform/implementation/linux/bluetooth_bluez_profile.h +++ b/internal/platform/implementation/linux/bluetooth_bluez_profile.h @@ -72,10 +72,10 @@ class Profile final explicit FDProperties(const std::map &fd_props) : version(std::nullopt), features(std::nullopt) { if (fd_props.count("Version") == 1) { - version = fd_props.at("Version"); + version = fd_props.at("Version").get(); } if (fd_props.count("Features") == 1) { - features = fd_props.at("Features"); + features = fd_props.at("Features").get(); } } diff --git a/internal/platform/implementation/linux/bluetooth_classic_device.cc b/internal/platform/implementation/linux/bluetooth_classic_device.cc index cfd7e8f5..f21c20c6 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_device.cc +++ b/internal/platform/implementation/linux/bluetooth_classic_device.cc @@ -151,7 +151,8 @@ bool BluetoothDevice::ConnectToProfile(absl::string_view service_uuid) { std::shared_ptr device, ObserverList &observers) : BluetoothDevice(device), - ProxyInterfaces(*system_bus, bluez::SERVICE_DEST, + ProxyInterfaces(*system_bus, + sdbus::ServiceName(bluez::SERVICE_DEST), device->getProxy().getObjectPath()), system_bus_(std::move(system_bus)), observers_(observers) { @@ -159,9 +160,9 @@ bool BluetoothDevice::ConnectToProfile(absl::string_view service_uuid) { } void MonitoredBluetoothDevice::onPropertiesChanged( - const std::string &interfaceName, - const std::map &changedProperties, - const std::vector &invalidatedProperties) { + const sdbus::InterfaceName &interfaceName, + const std::map &changedProperties, + const std::vector &invalidatedProperties) { if (interfaceName != bluez::DEVICE_INTERFACE) { return; } @@ -172,7 +173,7 @@ void MonitoredBluetoothDevice::onPropertiesChanged( if (it->first == bluez::DEVICE_PROP_ADDRESS) { LOG(INFO) << __func__ << ": " << getProxy().getObjectPath() << ": Notifying observers about address change"; - std::string address = it->second; + std::string address = it->second.get(); for (const auto &observer : observers_.GetObservers()) { observer->DeviceAddressChanged(*this, address); } @@ -181,17 +182,17 @@ void MonitoredBluetoothDevice::onPropertiesChanged( LOG(INFO) << __func__ << ": " << getProxy().getObjectPath() << "Notifying observers about paired status change."; for (const auto &observer : observers_.GetObservers()) { - observer->DevicePairedChanged(*this, it->second); + observer->DevicePairedChanged(*this, it->second.get()); } } else if (it->first == bluez::DEVICE_PROP_CONNECTED) { LOG(INFO) << __func__ << ": " << getProxy().getObjectPath() << "Notifying observers about connected status change"; for (const auto &observer : observers_.GetObservers()) { - observer->DeviceConnectedStateChanged(*this, it->second); + observer->DeviceConnectedStateChanged(*this, it->second.get()); } } else if ( it -> first == "ServicesResolved"){ - LOG(INFO) << ": ServicesResolved :" << std::string(it->second); + LOG(INFO) << ": ServicesResolved :" << it->second.get(); }else if (it->first == bluez::DEVICE_NAME) { auto callback = GetDiscoveryCallback(); if (callback != nullptr && callback->device_name_changed_cb != nullptr) diff --git a/internal/platform/implementation/linux/bluetooth_classic_device.h b/internal/platform/implementation/linux/bluetooth_classic_device.h index 99841b8a..0412db95 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_device.h +++ b/internal/platform/implementation/linux/bluetooth_classic_device.h @@ -108,7 +108,8 @@ class BluetoothDevice : public api::BluetoothDevice { } } - void SetPairReplyCallback(absl::AnyInvocable cb) { + void SetPairReplyCallback( + absl::AnyInvocable)> cb) { auto device = device_; if (device) device->SetPairReplyCallback(std::move(cb)); } @@ -137,7 +138,10 @@ class MonitoredBluetoothDevice final public: using sdbus::ProxyInterfaces::registerProxy; using sdbus::ProxyInterfaces::unregisterProxy; - using sdbus::ProxyInterfaces::getObjectPath; + + sdbus::ObjectPath getObjectPath() const { + return getProxy().getObjectPath(); + } MonitoredBluetoothDevice(const MonitoredBluetoothDevice &) = delete; MonitoredBluetoothDevice(MonitoredBluetoothDevice &&) = delete; @@ -159,9 +163,9 @@ class MonitoredBluetoothDevice final protected: void onPropertiesChanged( - const std::string &interfaceName, - const std::map &changedProperties, - const std::vector &invalidatedProperties) override; + const sdbus::InterfaceName &interfaceName, + const std::map &changedProperties, + const std::vector &invalidatedProperties) override; private: std::shared_ptr system_bus_; diff --git a/internal/platform/implementation/linux/bluetooth_classic_medium.cc b/internal/platform/implementation/linux/bluetooth_classic_medium.cc index a205efc5..0d3d23f7 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_medium.cc +++ b/internal/platform/implementation/linux/bluetooth_classic_medium.cc @@ -58,7 +58,7 @@ bool BluetoothClassicMedium::StartDiscovery( observers_); std::map filter; - filter["Transport"] = "auto"; + filter["Transport"] = sdbus::Variant("auto"); auto &adapter = adapter_.GetBluezAdapterObject(); try { diff --git a/internal/platform/implementation/linux/bluetooth_devices.cc b/internal/platform/implementation/linux/bluetooth_devices.cc index 012abce5..ee0740f3 100644 --- a/internal/platform/implementation/linux/bluetooth_devices.cc +++ b/internal/platform/implementation/linux/bluetooth_devices.cc @@ -93,7 +93,7 @@ std::shared_ptr BluetoothDevices::get_device_by_address( const MacAddress &addr) { auto device_object_path = bluez::device_object_path(adapter_object_path_, addr.ToString()); - return get_device_by_path(device_object_path); + return get_device_by_path(sdbus::ObjectPath(device_object_path)); } void BluetoothDevices::remove_device_by_path( @@ -152,7 +152,7 @@ void DeviceWatcher::onInterfacesAdded( return; } - if (interfacesAndProperties.count(org::bluez::Device1_proxy::INTERFACE_NAME) == + if (interfacesAndProperties.count(sdbus::InterfaceName(org::bluez::Device1_proxy::INTERFACE_NAME)) == 0) return; @@ -181,16 +181,16 @@ void DeviceWatcher::onInterfacesRemoved( auto removed_device_it = std::find(interfaces.begin(), interfaces.end(), org::bluez::Device1_proxy::INTERFACE_NAME); if (removed_device_it != interfaces.end()) { - auto device = devices_->get_device_by_path(object); + auto device = devices_->get_device_by_path(objectPath); if (device == nullptr) { LOG(WARNING) << __func__ << ": received InterfacesRemoved for a device " "we don't know about: " - << object; + << objectPath; return; } - LOG(INFO) << __func__ << ": Device " << object + LOG(INFO) << __func__ << ": Device " << objectPath << " has been removed"; if (discovery_cb_ != nullptr && discovery_cb_->device_lost_cb != nullptr) { discovery_cb_->device_lost_cb(*device); @@ -200,16 +200,16 @@ void DeviceWatcher::onInterfacesRemoved( for (const auto &observer : observers_->GetObservers()) { observer->DeviceRemoved(*device); } - devices_->remove_device_by_path(object); + devices_->remove_device_by_path(objectPath); } else { - devices_->mark_peripheral_lost(object); + devices_->mark_peripheral_lost(objectPath); } } } void DeviceWatcher::notifyExistingDevices() { std::map>> + std::map>> objects; try { objects = GetManagedObjects(); @@ -222,15 +222,15 @@ void DeviceWatcher::notifyExistingDevices() { for (const auto& [device_path, interfaces] : objects) { if (device_path.find(absl::Substitute("$0/dev_", adapter_object_path_)) == 0 && - interfaces.count(org::bluez::Device1_proxy::INTERFACE_NAME) == 1) { + interfaces.count(sdbus::InterfaceName(org::bluez::Device1_proxy::INTERFACE_NAME)) == 1) { // Don't remove bonded, paired, connected, or trusted devices bool should_skip = false; - auto device_interface_it = interfaces.find(org::bluez::Device1_proxy::INTERFACE_NAME); + auto device_interface_it = interfaces.find(sdbus::InterfaceName(org::bluez::Device1_proxy::INTERFACE_NAME)); if (device_interface_it != interfaces.end()) { const auto& properties = device_interface_it->second; - auto check_bool_property = [&properties](const std::string& prop_name) -> bool { + auto check_bool_property = [&properties](const sdbus::PropertyName& prop_name) -> bool { auto it = properties.find(prop_name); if (it != properties.end()) { try { @@ -242,10 +242,10 @@ void DeviceWatcher::notifyExistingDevices() { return false; }; - if (check_bool_property("Bonded") || - check_bool_property("Paired") || - check_bool_property("Connected") || - check_bool_property("Trusted")) { + if (check_bool_property(sdbus::PropertyName("Bonded")) || + check_bool_property(sdbus::PropertyName("Paired")) || + check_bool_property(sdbus::PropertyName("Connected")) || + check_bool_property(sdbus::PropertyName("Trusted"))) { should_skip = true; LOG(INFO) << __func__ << ": Skipping device " << device_path << " (bonded/paired/connected/trusted)"; diff --git a/internal/platform/implementation/linux/bluetooth_pairing.cc b/internal/platform/implementation/linux/bluetooth_pairing.cc index afaf623a..024568ab 100644 --- a/internal/platform/implementation/linux/bluetooth_pairing.cc +++ b/internal/platform/implementation/linux/bluetooth_pairing.cc @@ -26,8 +26,8 @@ namespace nearby { namespace linux { -void BluetoothPairing::pairing_reply_handler(const sdbus::Error *error) { - if (error != nullptr && error->isValid()) { +void BluetoothPairing::pairing_reply_handler(std::optional error) { + if (error.has_value() && error->isValid()) { const auto &name = error->getName(); api::BluetoothPairingCallback::PairingError err = api::BluetoothPairingCallback::PairingError::kAuthFailed; @@ -78,8 +78,8 @@ bool BluetoothPairing::InitiatePairing( bool BluetoothPairing::FinishPairing( std::optional pin_code) { - device_->SetPairReplyCallback([this](const sdbus::Error *error) { - this->pairing_reply_handler(error); + device_->SetPairReplyCallback([this](std::optional error) { + this->pairing_reply_handler(std::move(error)); }); auto call = device_->Pair(); diff --git a/internal/platform/implementation/linux/bluetooth_pairing.h b/internal/platform/implementation/linux/bluetooth_pairing.h index 0f7cc51d..ecc46de0 100644 --- a/internal/platform/implementation/linux/bluetooth_pairing.h +++ b/internal/platform/implementation/linux/bluetooth_pairing.h @@ -41,7 +41,7 @@ class BluetoothPairing final : public api::BluetoothPairing { bool IsPaired() override; private: - void pairing_reply_handler(const sdbus::Error *e); + void pairing_reply_handler(std::optional e); sdbus::PendingAsyncCall pair_async_call_; diff --git a/internal/platform/implementation/linux/bluez.cc b/internal/platform/implementation/linux/bluez.cc index bf5ce3c4..37d4b18a 100644 --- a/internal/platform/implementation/linux/bluez.cc +++ b/internal/platform/implementation/linux/bluez.cc @@ -30,39 +30,39 @@ std::string device_object_path(const sdbus::ObjectPath &adapter_object_path, } sdbus::ObjectPath profile_object_path(absl::string_view service_uuid) { - return absl::Substitute( + return sdbus::ObjectPath(absl::Substitute( "/com/google/nearby/medium/bluetooth_classic/profiles/$0", - absl::StrReplaceAll(service_uuid, {{"-", "_"}})); + absl::StrReplaceAll(service_uuid, {{"-", "_"}}))); } sdbus::ObjectPath gatt_profile_object_path(absl::string_view service_uuid) { - return absl::Substitute( + return sdbus::ObjectPath(absl::Substitute( "$0/profile_$1", NEARBY_BLE_GATT_PROFILE_PATH_ROOT, - absl::StrReplaceAll(service_uuid, {{"-", "_"}})); + absl::StrReplaceAll(service_uuid, {{"-", "_"}}))); } sdbus::ObjectPath adapter_object_path(absl::string_view name) { - return absl::Substitute("/org/bluez/$0", name); + return sdbus::ObjectPath(absl::Substitute("/org/bluez/$0", name)); } sdbus::ObjectPath gatt_service_path(size_t num) { - return absl::Substitute("$0/service$1", NEARBY_BLE_GATT_PATH_ROOT, num); + return sdbus::ObjectPath(absl::Substitute("$0/service$1", NEARBY_BLE_GATT_PATH_ROOT, num)); } sdbus::ObjectPath gatt_characteristic_path( const sdbus::ObjectPath &service_path, size_t num) { - return absl::Substitute("$0/char$1", service_path, num); + return sdbus::ObjectPath(absl::Substitute("$0/char$1", service_path, num)); } sdbus::ObjectPath ble_advertisement_path(size_t num) { - return absl::Substitute("/com/google/nearby/medium/ble/advertisement/$0", - num); + return sdbus::ObjectPath(absl::Substitute("/com/google/nearby/medium/ble/advertisement/$0", + num)); } sdbus::ObjectPath advertisement_monitor_path(absl::string_view uuid) { - return absl::Substitute( + return sdbus::ObjectPath(absl::Substitute( "/com/google/nearby/medium/ble/advertisement/monitor/$0", - absl::StrReplaceAll(uuid, {{"-", "_"}})); + absl::StrReplaceAll(uuid, {{"-", "_"}}))); } int16_t TxPowerLevelDbm(api::ble::TxPowerLevel level) { diff --git a/internal/platform/implementation/linux/bluez_advertisement_monitor.cc b/internal/platform/implementation/linux/bluez_advertisement_monitor.cc index 521061d5..084a8187 100644 --- a/internal/platform/implementation/linux/bluez_advertisement_monitor.cc +++ b/internal/platform/implementation/linux/bluez_advertisement_monitor.cc @@ -56,7 +56,7 @@ void AdvertisementMonitor::DeviceFound(const sdbus::ObjectPath &device) { continue; } - std::vector bytes = data; + std::vector bytes = data.get>(); adv_data.service_data.emplace(*uuid, std::string(bytes.begin(), bytes.end())); } diff --git a/internal/platform/implementation/linux/bluez_advertisement_monitor_manager.h b/internal/platform/implementation/linux/bluez_advertisement_monitor_manager.h index 1cc55319..5c285fbb 100644 --- a/internal/platform/implementation/linux/bluez_advertisement_monitor_manager.h +++ b/internal/platform/implementation/linux/bluez_advertisement_monitor_manager.h @@ -56,7 +56,7 @@ class AdvertisementMonitorManager final const ::nearby::linux::BluetoothAdapter &adapter) { bluez::BluezObjectManager manager(system_bus); std::map>> + std::map>> objects; try { objects = manager.GetManagedObjects(); @@ -71,7 +71,7 @@ class AdvertisementMonitorManager final } if (objects[adapter.GetObjectPath()].count( - org::bluez::AdvertisementMonitorManager1_proxy::INTERFACE_NAME) == + sdbus::InterfaceName(org::bluez::AdvertisementMonitorManager1_proxy::INTERFACE_NAME)) == 0) { LOG(ERROR) << __func__ << ": Adapter " << adapter.GetObjectPath() diff --git a/internal/platform/implementation/linux/bluez_device.h b/internal/platform/implementation/linux/bluez_device.h index 215cf445..dc509857 100644 --- a/internal/platform/implementation/linux/bluez_device.h +++ b/internal/platform/implementation/linux/bluez_device.h @@ -35,7 +35,8 @@ class Device : public sdbus::ProxyInterfaces { } ~Device() { unregisterProxy(); } - void SetPairReplyCallback(absl::AnyInvocable cb) + void SetPairReplyCallback( + absl::AnyInvocable)> cb) ABSL_LOCKS_EXCLUDED(pair_callback_lock_) { absl::MutexLock l(&pair_callback_lock_); on_pair_reply_cb_ = std::move(cb); @@ -47,16 +48,16 @@ class Device : public sdbus::ProxyInterfaces { } protected: - void onPairReply(const sdbus::Error *error) override + void onPairReply(std::optional error) override ABSL_LOCKS_EXCLUDED(pair_callback_lock_) { absl::ReaderMutexLock l(&pair_callback_lock_); - if (on_pair_reply_cb_ != nullptr) on_pair_reply_cb_(error); + if (on_pair_reply_cb_ != nullptr) on_pair_reply_cb_(std::move(error)); }; private: std::shared_ptr system_bus; absl::Mutex pair_callback_lock_; - absl::AnyInvocable on_pair_reply_cb_ + absl::AnyInvocable)> on_pair_reply_cb_ ABSL_GUARDED_BY(pair_callback_lock_) = nullptr; }; } // namespace bluez diff --git a/internal/platform/implementation/linux/bluez_gatt_characteristic_client.cc b/internal/platform/implementation/linux/bluez_gatt_characteristic_client.cc index 19e4b7c5..08936da0 100644 --- a/internal/platform/implementation/linux/bluez_gatt_characteristic_client.cc +++ b/internal/platform/implementation/linux/bluez_gatt_characteristic_client.cc @@ -22,14 +22,15 @@ namespace nearby { namespace linux { namespace bluez { void SubscribedGattCharacteristicClient::onPropertiesChanged( - const std::string& interfaceName, - const std::map& changedProperties, - const std::vector& invalidatedProperties) { + const sdbus::InterfaceName& interfaceName, + const std::map& changedProperties, + const std::vector& invalidatedProperties) { if (interfaceName != org::bluez::GattCharacteristic1_proxy::INTERFACE_NAME) return; - if (changedProperties.count("Value") == 1) { - std::vector value_bytes = changedProperties.at("Value"); + if (changedProperties.count(sdbus::PropertyName("Value")) == 1) { + std::vector value_bytes = changedProperties.at(sdbus::PropertyName("Value")) + .get>(); if (notify_callback_ != nullptr) { auto value = std::string(value_bytes.cbegin(), value_bytes.cend()); notify_callback_(value); diff --git a/internal/platform/implementation/linux/bluez_gatt_characteristic_client.h b/internal/platform/implementation/linux/bluez_gatt_characteristic_client.h index 1da6a434..3c7cdadb 100644 --- a/internal/platform/implementation/linux/bluez_gatt_characteristic_client.h +++ b/internal/platform/implementation/linux/bluez_gatt_characteristic_client.h @@ -41,9 +41,9 @@ class GattCharacteristicClient protected: void onPropertiesChanged( - const std::string& interfaceName, - const std::map& changedProperties, - const std::vector& invalidatedProperties) override {} + const sdbus::InterfaceName& interfaceName, + const std::map& changedProperties, + const std::vector& invalidatedProperties) override {} std::shared_ptr system_bus_; }; @@ -58,9 +58,9 @@ class SubscribedGattCharacteristicClient : public GattCharacteristicClient { protected: void onPropertiesChanged( - const std::string& interfaceName, - const std::map& changedProperties, - const std::vector& invalidatedProperties) override; + const sdbus::InterfaceName& interfaceName, + const std::map& changedProperties, + const std::vector& invalidatedProperties) override; private: absl::AnyInvocable notify_callback_; diff --git a/internal/platform/implementation/linux/bluez_gatt_characteristic_server.cc b/internal/platform/implementation/linux/bluez_gatt_characteristic_server.cc index dde5a09f..af7a8364 100644 --- a/internal/platform/implementation/linux/bluez_gatt_characteristic_server.cc +++ b/internal/platform/implementation/linux/bluez_gatt_characteristic_server.cc @@ -57,8 +57,8 @@ absl::Status GattCharacteristicServer::NotifyChanged( } try { - emitPropertiesChangedSignal(GattCharacteristic1_adaptor::INTERFACE_NAME, - {"Value"}); + emitPropertiesChangedSignal(sdbus::InterfaceName(GattCharacteristic1_adaptor::INTERFACE_NAME), + {sdbus::PropertyName("Value")}); return absl::OkStatus(); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -84,13 +84,13 @@ void GattCharacteristicServer::ReadValue( } } - uint16_t offset = options["offset"]; - sdbus::ObjectPath device_path = options["device"]; + uint16_t offset = options["offset"].get(); + sdbus::ObjectPath device_path = options["device"].get(); auto device = devices_->get_device_by_path(device_path); if (device == nullptr) { result.returnError( - sdbus::Error("org.bluez.Error.NotAuthorized", "device does not exist")); + sdbus::Error(sdbus::Error::Name("org.bluez.Error.NotAuthorized"), "device does not exist")); return; } auto characteristic = characteristic_; @@ -132,16 +132,16 @@ void GattCharacteristicServer::ReadValue( void GattCharacteristicServer::WriteValue( sdbus::Result<> &&result, std::vector value, std::map options) { - uint16_t offset = options["offset"]; - sdbus::ObjectPath device_path = options["device"]; + uint16_t offset = options["offset"].get(); + sdbus::ObjectPath device_path = options["device"].get(); auto device = devices_->get_device_by_path(device_path); if (device == nullptr) { result.returnError( - sdbus::Error("org.bluez.Error.NotAuthorized", "device does not exist")); + sdbus::Error(sdbus::Error::Name("org.bluez.Error.NotAuthorized"), "device does not exist")); return; } - std::string type = options["type"]; + std::string type = options["type"].get(); std::string data(value.begin(), value.end()); auto characteristic = characteristic_; @@ -183,7 +183,7 @@ void GattCharacteristicServer::StartNotify() { notifying_ = true; } } else { - throw(sdbus::Error("org.bluez.Error.NotSupported")); + throw(sdbus::Error(sdbus::Error::Name("org.bluez.Error.NotSupported"))); } } @@ -198,7 +198,7 @@ void GattCharacteristicServer::StopNotify() { notifying_ = false; } } else { - throw(sdbus::Error("org.bluez.Error.Failed")); + throw(sdbus::Error(sdbus::Error::Name("org.bluez.Error.Failed"))); } } diff --git a/internal/platform/implementation/linux/bluez_gatt_service_server.cc b/internal/platform/implementation/linux/bluez_gatt_service_server.cc index c6b43137..a3742329 100644 --- a/internal/platform/implementation/linux/bluez_gatt_service_server.cc +++ b/internal/platform/implementation/linux/bluez_gatt_service_server.cc @@ -36,7 +36,7 @@ bool GattServiceServer::AddCharacteristic( server_cb_, devices_); try { chr->emitInterfacesAddedSignal( - {org::bluez::GattCharacteristic1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::GattCharacteristic1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ diff --git a/internal/platform/implementation/linux/bluez_gatt_service_server.h b/internal/platform/implementation/linux/bluez_gatt_service_server.h index dd197284..968bee6b 100644 --- a/internal/platform/implementation/linux/bluez_gatt_service_server.h +++ b/internal/platform/implementation/linux/bluez_gatt_service_server.h @@ -66,7 +66,7 @@ class GattServiceServer final << characteristic->getObject().getObjectPath(); try { characteristic->emitInterfacesRemovedSignal( - {org::bluez::GattCharacteristic1_adaptor::INTERFACE_NAME}); + {sdbus::InterfaceName(org::bluez::GattCharacteristic1_adaptor::INTERFACE_NAME)}); } catch (const sdbus::Error &e) { LOG(ERROR) << __func__ @@ -90,7 +90,7 @@ class GattServiceServer final // Properties std::string UUID() override { return uuid_; } bool Primary() override { return primary_; } - sdbus::ObjectPath Device() override { return "/"; } + sdbus::ObjectPath Device() override { return sdbus::ObjectPath("/"); } std::vector Includes() override { return {}; } absl::Mutex characterstics_mutex_; diff --git a/internal/platform/implementation/linux/bluez_le_advertisement.cc b/internal/platform/implementation/linux/bluez_le_advertisement.cc index 3de5727a..c58b55ca 100644 --- a/internal/platform/implementation/linux/bluez_le_advertisement.cc +++ b/internal/platform/implementation/linux/bluez_le_advertisement.cc @@ -51,7 +51,7 @@ LEAdvertisement::LEAdvertisement( } // LOG(INFO)<< __func__ << ": " << uuid_string; // LOG(INFO)<< __func__ << ": " << BytesToHexString(data_bytes); - service_data_.insert({uuid_string, std::move(data_bytes)}); + service_data_.insert({uuid_string, std::move(sdbus::Variant(data_bytes))}); // service_data_.insert({"0000FE2C-0000-1000-8000-00805F9B34FB", std::move(data_bytes)}); } diff --git a/internal/platform/implementation/linux/bluez_le_advertisement.h b/internal/platform/implementation/linux/bluez_le_advertisement.h index 8de0a8ce..9bef2572 100644 --- a/internal/platform/implementation/linux/bluez_le_advertisement.h +++ b/internal/platform/implementation/linux/bluez_le_advertisement.h @@ -73,9 +73,9 @@ class LEAdvertisement final std::map ServiceData() override { return service_data_; } - std::map ScanResponseServiceData() override { - return {}; - } + //std::map ScanResponseServiceData() override { + // return {}; + //} std::vector Includes() override { return {}; } diff --git a/internal/platform/implementation/linux/network_manager.cc b/internal/platform/implementation/linux/network_manager.cc index 5c046fa5..913b5969 100644 --- a/internal/platform/implementation/linux/network_manager.cc +++ b/internal/platform/implementation/linux/network_manager.cc @@ -26,7 +26,7 @@ ObjectManager::GetActiveConnectionForAccessPoint( const sdbus::ObjectPath &access_point, const sdbus::ObjectPath &device_path) { std::map>> + std::map>> objects; try { objects = GetManagedObjects(); @@ -38,13 +38,13 @@ ObjectManager::GetActiveConnectionForAccessPoint( for (auto &[object_path, interfaces] : objects) { if (object_path.find("/org/freedesktop/NetworkManager/ActiveConnection/") == 0) { - if (interfaces.count(org::freedesktop::NetworkManager::Connection:: - Active_proxy::INTERFACE_NAME) == 1) { - auto props = interfaces[org::freedesktop::NetworkManager::Connection:: - Active_proxy::INTERFACE_NAME]; - sdbus::ObjectPath specific_object = props["SpecificObject"]; + if (interfaces.count(sdbus::InterfaceName(org::freedesktop::NetworkManager::Connection:: + Active_proxy::INTERFACE_NAME)) == 1) { + auto props = interfaces[sdbus::InterfaceName(org::freedesktop::NetworkManager::Connection:: + Active_proxy::INTERFACE_NAME)]; + sdbus::ObjectPath specific_object = props[sdbus::PropertyName("SpecificObject")].get(); if (specific_object == access_point) { - std::vector devices = props["Devices"]; + std::vector devices = props[sdbus::PropertyName("Devices")].get>(); for (auto &path : devices) { if (path == device_path) { return std::make_unique( @@ -61,7 +61,7 @@ ObjectManager::GetActiveConnectionForAccessPoint( std::unique_ptr ObjectManager::GetIp4Config( const sdbus::ObjectPath &active_connection) { std::map>> + std::map>> objects; try { objects = GetManagedObjects(); @@ -73,13 +73,13 @@ std::unique_ptr ObjectManager::GetIp4Config( for (auto &[object_path, interfaces] : objects) { if (object_path.find("/org/freedesktop/NetworkManager/ActiveConnection/", 0) == 0) { - if (interfaces.count(org::freedesktop::NetworkManager::Connection:: - Active_proxy::INTERFACE_NAME) == 1) { - auto props = interfaces[org::freedesktop::NetworkManager::Connection:: - Active_proxy::INTERFACE_NAME]; - sdbus::ObjectPath specific_object = props["SpecificObject"]; + if (interfaces.count(sdbus::InterfaceName(org::freedesktop::NetworkManager::Connection:: + Active_proxy::INTERFACE_NAME)) == 1) { + auto props = interfaces[sdbus::InterfaceName(org::freedesktop::NetworkManager::Connection:: + Active_proxy::INTERFACE_NAME)]; + sdbus::ObjectPath specific_object = props[sdbus::PropertyName("SpecificObject")].get(); if (specific_object == active_connection) { - sdbus::ObjectPath ip4config = props["Ip4Config"]; + sdbus::ObjectPath ip4config = sdbus::ObjectPath(props[sdbus::MemberName("Ip4Config")]); return std::make_unique(system_bus_, ip4config); } } diff --git a/internal/platform/implementation/linux/network_manager_active_connection.cc b/internal/platform/implementation/linux/network_manager_active_connection.cc index 4f2fdfc5..c44d7897 100644 --- a/internal/platform/implementation/linux/network_manager_active_connection.cc +++ b/internal/platform/implementation/linux/network_manager_active_connection.cc @@ -96,7 +96,7 @@ std::vector ActiveConnection::GetIP4Addresses() { std::vector ip4addresses; for (auto &data : address_data) { if (data.count("address") == 1) { - ip4addresses.push_back(data["address"]); + ip4addresses.push_back(data["address"].get()); } } return ip4addresses; diff --git a/internal/platform/implementation/linux/platform.cc b/internal/platform/implementation/linux/platform.cc index 43792de0..c0e34d6a 100644 --- a/internal/platform/implementation/linux/platform.cc +++ b/internal/platform/implementation/linux/platform.cc @@ -224,7 +224,7 @@ ImplementationPlatform::CreateBluetoothAdapter() { try { auto interfaces = manager.GetManagedObjects(); for (auto &[object, properties] : interfaces) { - if (properties.count(org::bluez::Adapter1_proxy::INTERFACE_NAME) == 1) { + if (properties.count(sdbus::InterfaceName(org::bluez::Adapter1_proxy::INTERFACE_NAME)) == 1) { LOG(INFO) << __func__ << ": found bluetooth adapter " << object; return std::make_unique(system_bus, object); } @@ -273,7 +273,7 @@ static std::unique_ptr createWifiMedium( auto manager = linux::networkmanager::ObjectManager(nm->GetConnection()); std::map>> + std::map>> objects; try { objects = manager.GetManagedObjects(); @@ -285,8 +285,8 @@ static std::unique_ptr createWifiMedium( for (auto &device_path : device_paths) { if (objects.count(device_path) == 1) { auto device = objects[device_path]; - if (device.count(org::freedesktop::NetworkManager::Device:: - Wireless_proxy::INTERFACE_NAME) == 1) { + if (device.count(sdbus::InterfaceName(org::freedesktop::NetworkManager::Device:: + Wireless_proxy::INTERFACE_NAME)) == 1) { LOG(INFO) << __func__ << ": Found a wireless device at :" << device_path; return std::make_unique(nm, diff --git a/internal/platform/implementation/linux/wifi_hotspot.cc b/internal/platform/implementation/linux/wifi_hotspot.cc index 2d47b97e..86293058 100644 --- a/internal/platform/implementation/linux/wifi_hotspot.cc +++ b/internal/platform/implementation/linux/wifi_hotspot.cc @@ -192,40 +192,42 @@ bool NetworkManagerWifiHotspotMedium::StartWifiHotspot( connection_settings{ { "connection", - {{"uuid", *connection_id}, - {"id", "Google Nearby Hotspot"}, - {"type", "802-11-wireless"}, - {"zone", "Public"}}, + {{"uuid", sdbus::Variant(*connection_id)}, + {"id", sdbus::Variant("Google Nearby Hotspot")}, + {"type", sdbus::Variant("802-11-wireless")}, + {"zone", sdbus::Variant("Public")}}, }, {"802-11-wireless", - {{"assigned-mac-address", "random"}, - {"ap-isolation", networkmanager::constants::kNMTernaryFalse}, - {"mode", "ap"}, - {"band", selected_band}, - {"channel", selected_channel}, - {"ssid", std::vector(ssid.begin(), ssid.end())}, - {"security", "802-11-wireless-security"}}}, + {{"assigned-mac-address", sdbus::Variant("random")}, + {"ap-isolation", sdbus::Variant(networkmanager::constants::kNMTernaryFalse)}, + {"mode", sdbus::Variant("ap")}, + {"band", sdbus::Variant(selected_band)}, + {"channel", sdbus::Variant(selected_channel)}, + {"ssid", sdbus::Variant(std::vector(ssid.begin(), ssid.end()))}, + {"security", sdbus::Variant("802-11-wireless-security")}}}, {"802-11-wireless-security", - {{"pmf", - networkmanager::constants::setting::kWirelessSecurityPMFDisable}, - {"key-mgmt", "wpa-psk"}, - {"psk", password}}}, - {"ipv4", {{"method", "shared"}}}, + {{"pmf", sdbus::Variant(networkmanager::constants::setting::kWirelessSecurityPMFDisable)}, + {"key-mgmt", sdbus::Variant("wpa-psk")}, + {"psk", sdbus::Variant(password)}}}, + {"ipv4", {{"method", sdbus::Variant("shared")}}}, {"ipv6", { - {"addr-gen-mode", networkmanager::constants::setting:: - kIP6ConfigAddrGenModeStablePrivacy}, - {"method", "shared"}, + {"addr-gen-mode", + sdbus::Variant(networkmanager::constants::setting::kIP6ConfigAddrGenModeStablePrivacy)}, + {"method", sdbus::Variant("shared")}, }}}; if (include_channel_width) { connection_settings["802-11-wireless"]["channel-width"] = - fallback_channel_width; + sdbus::Variant(fallback_channel_width); } try { auto [path, active_path, result] = network_manager_->AddAndActivateConnection2( - connection_settings, wireless_device_->getProxy().getObjectPath(), "/", - {{"persist", "volatile"}, {"bind-activation", "dbus-client"}}); + connection_settings, + wireless_device_->getProxy().getObjectPath(), + sdbus::ObjectPath("/"), + {{"persist", sdbus::Variant("volatile")}, + {"bind-activation", sdbus::Variant("dbus-client")}}); active_conn = std::make_unique( system_bus_, active_path); break; diff --git a/internal/platform/implementation/linux/wifi_lan_server_socket.cc b/internal/platform/implementation/linux/wifi_lan_server_socket.cc index 4c10eff3..8e00985d 100644 --- a/internal/platform/implementation/linux/wifi_lan_server_socket.cc +++ b/internal/platform/implementation/linux/wifi_lan_server_socket.cc @@ -63,7 +63,7 @@ std::string WifiLanServerSocket::GetIPAddress() const { } if (address_data.size() > 0) { - std::string ip_address = address_data[0]["address"]; + std::string ip_address = address_data[0]["address"].get(); struct in_addr addr {}; if (inet_aton(ip_address.c_str(), &addr) == 0) { LOG(ERROR) << __func__ diff --git a/internal/platform/implementation/linux/wifi_medium.cc b/internal/platform/implementation/linux/wifi_medium.cc index b6a9048d..bff6f90f 100644 --- a/internal/platform/implementation/linux/wifi_medium.cc +++ b/internal/platform/implementation/linux/wifi_medium.cc @@ -43,7 +43,7 @@ api::WifiCapability &NetworkManagerWifiMedium::GetCapability() { capability_.supports_6_ghz = (cap_mask & 0x00008000) != 0; capability_.support_wifi_direct = true; } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_GET_ERROR(&getProxy(), "WirelessCapabilities", e); + DBUS_LOG_PROPERTY_GET_ERROR(this, "WirelessCapabilities", e); } return capability_; @@ -93,17 +93,17 @@ api::WifiInformation &NetworkManagerWifiMedium::GetInformation() { } void NetworkManagerWifiMedium::onPropertiesChanged( - const std::string &interfaceName, - const std::map &changedProperties, - const std::vector &invalidatedProperties) { + const sdbus::InterfaceName &interfaceName, + const std::map &changedProperties, + const std::vector &invalidatedProperties) { if (interfaceName != org::freedesktop::NetworkManager::Device:: Wireless_proxy::INTERFACE_NAME) { return; } - if (changedProperties.count("LastScan") == 1) { + if (changedProperties.count(sdbus::PropertyName("LastScan")) == 1) { absl::MutexLock l(&last_scan_lock_); - last_scan_ = changedProperties.at("LastScan"); + last_scan_ = changedProperties.at(sdbus::PropertyName("LastScan")).get(); } } @@ -148,7 +148,7 @@ NetworkManagerWifiMedium::SearchBySSID(absl::string_view ssid, // Otherwise, request a Scan first and wait for it to finish. try { RequestScan( - {{"ssids", std::vector>{ssid_bytes}}}); + {{"ssids", sdbus::Variant(std::vector>{ssid_bytes})}}); } catch (const sdbus::Error &e) { DBUS_LOG_METHOD_CALL_ERROR(this, "RequestScan", e); } @@ -211,33 +211,33 @@ NetworkManagerWifiMedium::WifiConnectionStatus NetworkManagerWifiMedium::Connect connection_settings{ {"connection", { - {"uuid", *connection_id}, - {"autoconnect", true}, - {"id", std::string(ssid)}, - {"type", "802-11-wireless"}, - {"zone", "Public"}, + {"uuid", sdbus::Variant(*connection_id)}, + {"autoconnect", sdbus::Variant(true)}, + {"id", sdbus::Variant(std::string(ssid))}, + {"type", sdbus::Variant(std::string("802-11-wireless"))}, + {"zone", sdbus::Variant(std::string("Public"))}, }}, {"802-11-wireless", { - {"ssid", std::vector(ssid.begin(), ssid.end())}, - {"mode", "infrastructure"}, - {"security", "802-11-wireless-security"}, - {"assigned-mac-address", "random"}, + {"ssid", sdbus::Variant(std::vector(ssid.begin(), ssid.end()))}, + {"mode", sdbus::Variant(std::string("infrastructure"))}, + {"security", sdbus::Variant(std::string("802-11-wireless-security"))}, + {"assigned-mac-address", sdbus::Variant(std::string("random"))}, }}, - {"802-11-wireless-security", {{"key-mgmt", key_mgmt}}}}; + {"802-11-wireless-security", {{"key-mgmt", sdbus::Variant(key_mgmt)}}}}; if (!password.empty()) { connection_settings["802-11-wireless-security"]["psk"] = - std::string(password); + sdbus::Variant(std::string(password)); } if (auth_alg.has_value()) { - connection_settings["802-11-wireless-security"]["auth-alg"] = *auth_alg; + connection_settings["802-11-wireless-security"]["auth-alg"] = sdbus::Variant(*auth_alg); } sdbus::ObjectPath connection_path, active_conn_path; try { auto [cp, acp, _r] = network_manager_->AddAndActivateConnection2( connection_settings, getProxy().getObjectPath(), ap->getProxy().getObjectPath(), - {{"persist", "volatile"}, {"bind-activation", "dbus-client"}}); + {{"persist", sdbus::Variant(std::string("volatile"))}, {"bind-activation", sdbus::Variant(std::string("dbus-client"))}}); connection_path = std::move(cp); active_conn_path = std::move(acp); } catch (const sdbus::Error &e) { diff --git a/internal/platform/implementation/linux/wifi_medium.h b/internal/platform/implementation/linux/wifi_medium.h index e9248d04..293ee2b3 100644 --- a/internal/platform/implementation/linux/wifi_medium.h +++ b/internal/platform/implementation/linux/wifi_medium.h @@ -101,9 +101,9 @@ class NetworkManagerWifiMedium protected: void onPropertiesChanged( - const std::string &interfaceName, - const std::map &changedProperties, - const std::vector &invalidatedProperties) override; + const sdbus::InterfaceName &interfaceName, + const std::map &changedProperties, + const std::vector &invalidatedProperties) override; void onAccessPointAdded(const sdbus::ObjectPath &access_point) override ABSL_LOCKS_EXCLUDED(known_access_points_lock_) {