mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Use shared_ptrs for dbus connections for top-level classes.
This commit is contained in:
@@ -33,17 +33,17 @@
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
BleV2Medium::BleV2Medium(sdbus::IConnection &system_bus,
|
||||
BluetoothAdapter &adapter)
|
||||
: system_bus_(system_bus),
|
||||
BleV2Medium::BleV2Medium(BluetoothAdapter &adapter)
|
||||
: system_bus_(adapter.GetConnection()),
|
||||
adapter_(adapter),
|
||||
devices_(std::make_unique<BluetoothDevices>(
|
||||
system_bus_, adapter_.GetObjectPath(), observers_)),
|
||||
*system_bus_, adapter_.GetObjectPath(), observers_)),
|
||||
root_object_manager_(std::make_unique<RootObjectManager>(*system_bus_)),
|
||||
adv_monitor_manager_(
|
||||
bluez::AdvertisementMonitorManager::
|
||||
DiscoverAdvertisementMonitorManager(system_bus, adapter_)),
|
||||
adv_manager_(
|
||||
std::make_unique<bluez::LEAdvertisementManager>(system_bus, adapter)),
|
||||
DiscoverAdvertisementMonitorManager(*system_bus_, adapter_)),
|
||||
adv_manager_(std::make_unique<bluez::LEAdvertisementManager>(*system_bus_,
|
||||
adapter)),
|
||||
cur_adv_(nullptr) {
|
||||
if (adv_monitor_manager_) {
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
@@ -81,7 +81,7 @@ bool BleV2Medium::StartAdvertising(
|
||||
}
|
||||
|
||||
cur_adv_ = bluez::LEAdvertisement::CreateLEAdvertisement(
|
||||
system_bus_, advertising_data, advertise_set_parameters);
|
||||
*system_bus_, advertising_data, advertise_set_parameters);
|
||||
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Registering advertisement "
|
||||
<< cur_adv_->getObjectPath() << " on bluetooth adapter "
|
||||
@@ -136,7 +136,7 @@ BleV2Medium::StartAdvertising(
|
||||
}
|
||||
|
||||
std::shared_ptr<sdbus::IProxy> proxy =
|
||||
sdbus::createProxy(system_bus_, "org.bluez", adapter_.GetObjectPath());
|
||||
sdbus::createProxy(*system_bus_, "org.bluez", adapter_.GetObjectPath());
|
||||
proxy->finishRegistration();
|
||||
|
||||
std::shared_ptr<AdvertisingCallback> shared_cb =
|
||||
@@ -144,7 +144,7 @@ BleV2Medium::StartAdvertising(
|
||||
|
||||
absl::MutexLock lock(&advs_mutex_);
|
||||
advs_.push_front(bluez::LEAdvertisement::CreateLEAdvertisement(
|
||||
system_bus_, advertising_data, advertise_set_parameters));
|
||||
*system_bus_, advertising_data, advertise_set_parameters));
|
||||
auto adv_it = advs_.begin();
|
||||
|
||||
auto pending_call =
|
||||
@@ -201,7 +201,7 @@ BleV2Medium::StartAdvertising(
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) {
|
||||
return std::make_unique<GattServer>(system_bus_, adapter_, devices_,
|
||||
return std::make_unique<GattServer>(*system_bus_, adapter_, devices_,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ bool BleV2Medium::StartScanning(const Uuid &service_uuid,
|
||||
}
|
||||
|
||||
auto monitor = std::make_unique<bluez::AdvertisementMonitor>(
|
||||
system_bus_, service_uuid, tx_power_level, "or_patterns", devices_,
|
||||
*system_bus_, service_uuid, tx_power_level, "or_patterns", devices_,
|
||||
std::move(callback));
|
||||
try {
|
||||
monitor->emitInterfacesAddedSignal(
|
||||
@@ -279,7 +279,7 @@ bool BleV2Medium::StartScanning(const Uuid &service_uuid,
|
||||
}
|
||||
|
||||
auto device_watcher = std::make_unique<DeviceWatcher>(
|
||||
system_bus_, adapter_.GetObjectPath(), devices_);
|
||||
*system_bus_, adapter_.GetObjectPath(), devices_);
|
||||
if (!StartLEDiscovery()) {
|
||||
NEARBY_LOGS(ERROR) << __func__
|
||||
<< ": Could not start LE discovery on adapter "
|
||||
@@ -360,7 +360,7 @@ BleV2Medium::StartScanning(const Uuid &service_uuid,
|
||||
}
|
||||
|
||||
auto monitor = std::make_unique<bluez::AdvertisementMonitor>(
|
||||
system_bus_, service_uuid, tx_power_level, "or_patterns", devices_,
|
||||
*system_bus_, service_uuid, tx_power_level, "or_patterns", devices_,
|
||||
std::move(callback));
|
||||
try {
|
||||
monitor->emitInterfacesAddedSignal(
|
||||
@@ -375,7 +375,7 @@ BleV2Medium::StartScanning(const Uuid &service_uuid,
|
||||
}
|
||||
|
||||
auto device_watcher = std::make_unique<DeviceWatcher>(
|
||||
system_bus_, adapter_.GetObjectPath(), devices_);
|
||||
*system_bus_, adapter_.GetObjectPath(), devices_);
|
||||
if (!StartLEDiscovery()) {
|
||||
NEARBY_LOGS(ERROR) << __func__
|
||||
<< ": Could not start LE discovery on adapter "
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "internal/platform/implementation/linux/bluez_advertisement_monitor.h"
|
||||
#include "internal/platform/implementation/linux/bluez_advertisement_monitor_manager.h"
|
||||
#include "internal/platform/implementation/linux/bluez_le_advertisement.h"
|
||||
#include "internal/platform/implementation/linux/dbus.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -40,8 +41,7 @@ class BleV2Medium final : public api::ble_v2::BleMedium {
|
||||
BleV2Medium &operator=(const BleV2Medium &) = delete;
|
||||
BleV2Medium &operator=(BleV2Medium &&) = delete;
|
||||
|
||||
BleV2Medium(sdbus::IConnection &system_bus ABSL_ATTRIBUTE_LIFETIME_BOUND,
|
||||
BluetoothAdapter &adapter);
|
||||
explicit BleV2Medium(BluetoothAdapter &adapter);
|
||||
~BleV2Medium() override = default;
|
||||
|
||||
bool StartAdvertising(
|
||||
@@ -113,11 +113,12 @@ class BleV2Medium final : public api::ble_v2::BleMedium {
|
||||
end;
|
||||
}
|
||||
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
BluetoothAdapter adapter_;
|
||||
ObserverList<api::BluetoothClassicMedium::Observer> observers_ = {};
|
||||
std::shared_ptr<BluetoothDevices> devices_;
|
||||
|
||||
std::unique_ptr<RootObjectManager> root_object_manager_;
|
||||
std::unique_ptr<bluez::AdvertisementMonitorManager> adv_monitor_manager_;
|
||||
absl::Mutex active_adv_monitors_mutex_;
|
||||
absl::flat_hash_map<
|
||||
|
||||
@@ -37,15 +37,11 @@ class BluezAdapter : public sdbus::ProxyInterfaces<org::bluez::Adapter1_proxy> {
|
||||
|
||||
class BluetoothAdapter : public api::BluetoothAdapter {
|
||||
public:
|
||||
BluetoothAdapter(const BluetoothAdapter &) = default;
|
||||
BluetoothAdapter(BluetoothAdapter &&) = delete;
|
||||
BluetoothAdapter &operator=(const BluetoothAdapter &) = default;
|
||||
BluetoothAdapter &operator=(BluetoothAdapter &&) = delete;
|
||||
|
||||
BluetoothAdapter(sdbus::IConnection &system_bus,
|
||||
BluetoothAdapter(std::shared_ptr<sdbus::IConnection> system_bus,
|
||||
const sdbus::ObjectPath &adapter_object_path)
|
||||
: bluez_adapter_(
|
||||
std::make_shared<BluezAdapter>(system_bus, adapter_object_path)) {}
|
||||
: system_bus_(std::move(system_bus)),
|
||||
bluez_adapter_(std::make_shared<BluezAdapter>(*system_bus_,
|
||||
adapter_object_path)) {}
|
||||
|
||||
~BluetoothAdapter() override = default;
|
||||
|
||||
@@ -76,8 +72,10 @@ class BluetoothAdapter : public api::BluetoothAdapter {
|
||||
}
|
||||
|
||||
BluezAdapter &GetBluezAdapterObject() { return *bluez_adapter_; }
|
||||
std::shared_ptr<sdbus::IConnection> GetConnection() { return system_bus_; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::shared_ptr<BluezAdapter> bluez_adapter_;
|
||||
};
|
||||
} // namespace linux
|
||||
|
||||
@@ -33,21 +33,20 @@
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
BluetoothClassicMedium::BluetoothClassicMedium(sdbus::IConnection &system_bus,
|
||||
BluetoothAdapter &adapter)
|
||||
: system_bus_(system_bus),
|
||||
BluetoothClassicMedium::BluetoothClassicMedium(BluetoothAdapter &adapter)
|
||||
: system_bus_(adapter.GetConnection()),
|
||||
adapter_(adapter),
|
||||
observers_(std::make_shared<ObserverList<Observer>>()),
|
||||
devices_(std::make_shared<BluetoothDevices>(
|
||||
system_bus, adapter.GetObjectPath(), *observers_)),
|
||||
*system_bus_, adapter.GetObjectPath(), *observers_)),
|
||||
device_watcher_(nullptr),
|
||||
profile_manager_(
|
||||
std::make_unique<ProfileManager>(system_bus, *devices_)) {}
|
||||
std::make_unique<ProfileManager>(*system_bus_, *devices_)) {}
|
||||
|
||||
bool BluetoothClassicMedium::StartDiscovery(
|
||||
DiscoveryCallback discovery_callback) {
|
||||
device_watcher_ = std::make_unique<DeviceWatcher>(
|
||||
system_bus_, adapter_.GetObjectPath(), devices_,
|
||||
*system_bus_, adapter_.GetObjectPath(), devices_,
|
||||
std::make_unique<DiscoveryCallback>(std::move(discovery_callback)),
|
||||
observers_);
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ namespace linux {
|
||||
// medium.
|
||||
class BluetoothClassicMedium : public api::BluetoothClassicMedium {
|
||||
public:
|
||||
BluetoothClassicMedium(sdbus::IConnection &system_bus,
|
||||
BluetoothAdapter &adapter);
|
||||
explicit BluetoothClassicMedium(BluetoothAdapter &adapter);
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#startDiscovery()
|
||||
//
|
||||
@@ -101,7 +100,7 @@ class BluetoothClassicMedium : public api::BluetoothClassicMedium {
|
||||
};
|
||||
|
||||
private:
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
|
||||
BluetoothAdapter adapter_;
|
||||
std::shared_ptr<ObserverList<Observer>> observers_;
|
||||
|
||||
@@ -19,47 +19,29 @@
|
||||
#include <sdbus-c++/IConnection.h>
|
||||
|
||||
#include "absl/base/call_once.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/linux/dbus.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
static std::unique_ptr<sdbus::IConnection> global_system_bus_connection =
|
||||
nullptr;
|
||||
static std::unique_ptr<sdbus::IConnection> global_default_bus_connection =
|
||||
nullptr;
|
||||
static std::unique_ptr<RootObjectManager> system_root_object_manager = nullptr;
|
||||
static std::unique_ptr<RootObjectManager> default_root_object_manager = nullptr;
|
||||
static absl::once_flag bus_connection_init_;
|
||||
|
||||
static void disconnectBus() {
|
||||
system_root_object_manager = nullptr;
|
||||
default_root_object_manager = nullptr;
|
||||
global_system_bus_connection = nullptr;
|
||||
global_default_bus_connection = nullptr;
|
||||
}
|
||||
namespace {
|
||||
static absl::Mutex global_system_bus_mutex;
|
||||
static std::weak_ptr<sdbus::IConnection> global_system_bus_connection
|
||||
ABSL_GUARDED_BY(global_system_bus_mutex);
|
||||
} // namespace
|
||||
|
||||
static void initBusConnections() {
|
||||
global_system_bus_connection = sdbus::createSystemBusConnection();
|
||||
global_system_bus_connection->enterEventLoopAsync();
|
||||
global_default_bus_connection = sdbus::createDefaultBusConnection();
|
||||
global_default_bus_connection->enterEventLoopAsync();
|
||||
system_root_object_manager =
|
||||
std::make_unique<RootObjectManager>(*global_system_bus_connection);
|
||||
default_root_object_manager =
|
||||
std::make_unique<RootObjectManager>(*global_default_bus_connection);
|
||||
std::shared_ptr<sdbus::IConnection> getSystemBusConnection() {
|
||||
absl::MutexLock lock(&global_system_bus_mutex);
|
||||
auto bus = global_system_bus_connection.lock();
|
||||
if (bus == nullptr) {
|
||||
bus =
|
||||
std::shared_ptr<sdbus::IConnection>(sdbus::createSystemBusConnection());
|
||||
bus->enterEventLoopAsync();
|
||||
global_system_bus_connection = bus;
|
||||
}
|
||||
|
||||
atexit(disconnectBus);
|
||||
}
|
||||
|
||||
sdbus::IConnection &getSystemBusConnection() {
|
||||
absl::call_once(bus_connection_init_, initBusConnections);
|
||||
assert(global_system_bus_connection != nullptr);
|
||||
return *global_system_bus_connection;
|
||||
}
|
||||
sdbus::IConnection &getDefaultBusConnection() {
|
||||
absl::call_once(bus_connection_init_, initBusConnections);
|
||||
assert(global_default_bus_connection != nullptr);
|
||||
return *global_default_bus_connection;
|
||||
return bus;
|
||||
}
|
||||
} // namespace linux
|
||||
} // namespace nearby
|
||||
|
||||
@@ -46,8 +46,7 @@
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
extern sdbus::IConnection &getSystemBusConnection();
|
||||
extern sdbus::IConnection &getDefaultBusConnection();
|
||||
extern std::shared_ptr<sdbus::IConnection> getSystemBusConnection();
|
||||
class RootObjectManager final
|
||||
: public sdbus::AdaptorInterfaces<sdbus::ObjectManager_adaptor,
|
||||
sdbus::Properties_adaptor> {
|
||||
|
||||
@@ -58,13 +58,13 @@ void CurrentUserSession::onUnlock() {
|
||||
}
|
||||
}
|
||||
|
||||
DeviceInfo::DeviceInfo(sdbus::IConnection &system_bus)
|
||||
: system_bus_(system_bus),
|
||||
current_user_session_(std::make_unique<CurrentUserSession>(system_bus_)),
|
||||
login_manager_(std::make_unique<LoginManager>(system_bus_)) {}
|
||||
DeviceInfo::DeviceInfo(std::shared_ptr<sdbus::IConnection> system_bus)
|
||||
: system_bus_(std::move(system_bus)),
|
||||
current_user_session_(std::make_unique<CurrentUserSession>(*system_bus_)),
|
||||
login_manager_(std::make_unique<LoginManager>(*system_bus_)) {}
|
||||
|
||||
std::optional<std::u16string> DeviceInfo::GetOsDeviceName() const {
|
||||
avahi::Server avahi(system_bus_);
|
||||
avahi::Server avahi(*system_bus_);
|
||||
try {
|
||||
std::string hostname = avahi.GetHostNameFqdn();
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
@@ -76,7 +76,7 @@ std::optional<std::u16string> DeviceInfo::GetOsDeviceName() const {
|
||||
}
|
||||
|
||||
api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const {
|
||||
Hostnamed hostnamed(system_bus_);
|
||||
Hostnamed hostnamed(*system_bus_);
|
||||
try {
|
||||
std::string chasis = hostnamed.Chassis();
|
||||
api::DeviceInfo::DeviceType device = api::DeviceInfo::DeviceType::kUnknown;
|
||||
|
||||
@@ -119,7 +119,7 @@ class LoginManager final
|
||||
|
||||
class DeviceInfo final : public api::DeviceInfo {
|
||||
public:
|
||||
explicit DeviceInfo(sdbus::IConnection &system_bus);
|
||||
explicit DeviceInfo(std::shared_ptr<sdbus::IConnection> system_bus);
|
||||
|
||||
std::optional<std::u16string> GetOsDeviceName() const override;
|
||||
api::DeviceInfo::DeviceType GetDeviceType() const override;
|
||||
@@ -160,7 +160,7 @@ class DeviceInfo final : public api::DeviceInfo {
|
||||
bool AllowSleep() override;
|
||||
|
||||
private:
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::unique_ptr<CurrentUserSession> current_user_session_;
|
||||
std::unique_ptr<LoginManager> login_manager_;
|
||||
std::optional<sdbus::UnixFd> inhibit_fd_;
|
||||
|
||||
@@ -47,7 +47,7 @@ NetworkManagerObjectManager::GetActiveConnectionForAccessPoint(
|
||||
for (auto &path : devices) {
|
||||
if (path == device_path) {
|
||||
return std::make_unique<NetworkManagerActiveConnection>(
|
||||
getProxy().getConnection(), object_path);
|
||||
system_bus_, object_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,8 @@ NetworkManagerObjectManager::GetIp4Config(
|
||||
sdbus::ObjectPath specific_object = props["SpecificObject"];
|
||||
if (specific_object == active_connection) {
|
||||
sdbus::ObjectPath ip4config = props["Ip4Config"];
|
||||
return std::make_unique<NetworkManagerIP4Config>(
|
||||
getProxy().getConnection(), ip4config);
|
||||
return std::make_unique<NetworkManagerIP4Config>(system_bus_,
|
||||
ip4config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ class NetworkManager final
|
||||
NetworkManager(NetworkManager &&) = delete;
|
||||
NetworkManager &operator=(const NetworkManager &) = delete;
|
||||
NetworkManager &operator=(NetworkManager &&) = delete;
|
||||
explicit NetworkManager(sdbus::IConnection &system_bus)
|
||||
: ProxyInterfaces(system_bus, "org.freedesktop.NetworkManager",
|
||||
explicit NetworkManager(std::shared_ptr<sdbus::IConnection> system_bus)
|
||||
: ProxyInterfaces(*system_bus, "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager"),
|
||||
system_bus_(std::move(system_bus)),
|
||||
state_(kNMStateUnknown) {
|
||||
registerProxy();
|
||||
try {
|
||||
@@ -60,6 +61,7 @@ class NetworkManager final
|
||||
};
|
||||
|
||||
NMState getState() const { return state_; }
|
||||
std::shared_ptr<sdbus::IConnection> GetConnection() { return system_bus_; }
|
||||
|
||||
protected:
|
||||
void onCheckPermissions() override {}
|
||||
@@ -90,6 +92,7 @@ class NetworkManager final
|
||||
#undef NM_STATE_CASE_SET
|
||||
};
|
||||
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::atomic<NMState> state_;
|
||||
};
|
||||
|
||||
@@ -101,13 +104,17 @@ class NetworkManagerIP4Config
|
||||
NetworkManagerIP4Config(NetworkManagerIP4Config &&) = delete;
|
||||
NetworkManagerIP4Config &operator=(const NetworkManagerIP4Config &) = delete;
|
||||
NetworkManagerIP4Config &operator=(NetworkManagerIP4Config &&) = delete;
|
||||
NetworkManagerIP4Config(sdbus::IConnection &system_bus,
|
||||
NetworkManagerIP4Config(std::shared_ptr<sdbus::IConnection> system_bus,
|
||||
const sdbus::ObjectPath &config_object_path)
|
||||
: ProxyInterfaces(system_bus, "org.freedesktop.NetworkManager",
|
||||
config_object_path) {
|
||||
: ProxyInterfaces(*system_bus, "org.freedesktop.NetworkManager",
|
||||
config_object_path),
|
||||
system_bus_(std::move(system_bus)) {
|
||||
registerProxy();
|
||||
}
|
||||
~NetworkManagerIP4Config() { unregisterProxy(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
};
|
||||
|
||||
class NetworkManagerObjectManager final
|
||||
@@ -119,9 +126,11 @@ class NetworkManagerObjectManager final
|
||||
delete;
|
||||
NetworkManagerObjectManager &operator=(NetworkManagerObjectManager &&) =
|
||||
delete;
|
||||
explicit NetworkManagerObjectManager(sdbus::IConnection &system_bus)
|
||||
: ProxyInterfaces(system_bus, "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop") {
|
||||
explicit NetworkManagerObjectManager(
|
||||
std::shared_ptr<sdbus::IConnection> system_bus)
|
||||
: ProxyInterfaces(*system_bus, "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop"),
|
||||
system_bus_(std::move(system_bus)) {
|
||||
registerProxy();
|
||||
}
|
||||
~NetworkManagerObjectManager() { unregisterProxy(); }
|
||||
@@ -140,6 +149,9 @@ class NetworkManagerObjectManager final
|
||||
void onInterfacesRemoved(
|
||||
const sdbus::ObjectPath &objectPath,
|
||||
const std::vector<std::string> &interfaces) override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
};
|
||||
|
||||
} // namespace linux
|
||||
|
||||
@@ -79,7 +79,7 @@ std::vector<std::string> NetworkManagerActiveConnection::GetIP4Addresses() {
|
||||
return {};
|
||||
}
|
||||
|
||||
NetworkManagerIP4Config ip4config(getProxy().getConnection(), ip4config_path);
|
||||
NetworkManagerIP4Config ip4config(system_bus_, ip4config_path);
|
||||
std::vector<std::map<std::string, sdbus::Variant>> address_data;
|
||||
try {
|
||||
address_data = ip4config.AddressData();
|
||||
|
||||
@@ -63,9 +63,11 @@ class NetworkManagerActiveConnection
|
||||
NetworkManagerActiveConnection &operator=(NetworkManagerActiveConnection &&) =
|
||||
delete;
|
||||
explicit NetworkManagerActiveConnection(
|
||||
sdbus::IConnection &system_bus, sdbus::ObjectPath active_connection_path)
|
||||
: ProxyInterfaces(system_bus, "org.freedesktop.NetworkManager",
|
||||
std::shared_ptr<sdbus::IConnection> system_bus,
|
||||
sdbus::ObjectPath active_connection_path)
|
||||
: ProxyInterfaces(*system_bus, "org.freedesktop.NetworkManager",
|
||||
std::move(active_connection_path)),
|
||||
system_bus_(std::move(system_bus)),
|
||||
state_(kStateUnknown),
|
||||
reason_(kStateReasonUnknown) {
|
||||
registerProxy();
|
||||
@@ -99,6 +101,8 @@ class NetworkManagerActiveConnection
|
||||
std::vector<std::string> GetIP4Addresses();
|
||||
|
||||
private:
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
|
||||
absl::Mutex state_mutex_;
|
||||
ActiveConnectionState state_ ABSL_GUARDED_BY(state_mutex_);
|
||||
ActiveConnectionStateReason reason_ ABSL_GUARDED_BY(state_mutex_);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "internal/platform/implementation/input_file.h"
|
||||
#include "internal/platform/implementation/linux/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/linux/atomic_uint32.h"
|
||||
#include "internal/platform/implementation/linux/ble_medium.h"
|
||||
#include "internal/platform/implementation/linux/ble_v2_medium.h"
|
||||
#include "internal/platform/implementation/linux/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/linux/bluetooth_classic_medium.h"
|
||||
@@ -166,15 +165,14 @@ ImplementationPlatform::CreateScheduledExecutor() {
|
||||
|
||||
std::unique_ptr<api::BluetoothAdapter>
|
||||
ImplementationPlatform::CreateBluetoothAdapter() {
|
||||
auto manager =
|
||||
linux::bluez::BluezObjectManager(linux::getSystemBusConnection());
|
||||
auto system_bus = linux::getSystemBusConnection();
|
||||
auto manager = linux::bluez::BluezObjectManager(*system_bus);
|
||||
try {
|
||||
auto interfaces = manager.GetManagedObjects();
|
||||
for (auto &[object, properties] : interfaces) {
|
||||
if (properties.count(org::bluez::Adapter1_proxy::INTERFACE_NAME) == 1) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": found bluetooth adapter " << object;
|
||||
return std::make_unique<linux::BluetoothAdapter>(
|
||||
linux::getSystemBusConnection(), object);
|
||||
return std::make_unique<linux::BluetoothAdapter>(system_bus, object);
|
||||
}
|
||||
}
|
||||
} catch (const sdbus::Error &e) {
|
||||
@@ -191,19 +189,17 @@ std::unique_ptr<api::BluetoothClassicMedium>
|
||||
ImplementationPlatform::CreateBluetoothClassicMedium(
|
||||
BluetoothAdapter &adapter) {
|
||||
return std::make_unique<linux::BluetoothClassicMedium>(
|
||||
linux::getSystemBusConnection(),
|
||||
dynamic_cast<linux::BluetoothAdapter &>(adapter));
|
||||
}
|
||||
|
||||
std::unique_ptr<BleMedium> ImplementationPlatform::CreateBleMedium(
|
||||
BluetoothAdapter &adapter) {
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium>
|
||||
ImplementationPlatform::CreateBleV2Medium(api::BluetoothAdapter &adapter) {
|
||||
return std::make_unique<linux::BleV2Medium>(
|
||||
linux::getSystemBusConnection(),
|
||||
dynamic_cast<linux::BluetoothAdapter &>(adapter));
|
||||
}
|
||||
|
||||
@@ -219,8 +215,7 @@ static std::unique_ptr<linux::NetworkManagerWifiMedium> createWifiMedium(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto manager =
|
||||
linux::NetworkManagerObjectManager(linux::getSystemBusConnection());
|
||||
auto manager = linux::NetworkManagerObjectManager(nm->GetConnection());
|
||||
|
||||
std::map<sdbus::ObjectPath,
|
||||
std::map<std::string, std::map<std::string, sdbus::Variant>>>
|
||||
@@ -239,8 +234,8 @@ static std::unique_ptr<linux::NetworkManagerWifiMedium> createWifiMedium(
|
||||
Wireless_proxy::INTERFACE_NAME) == 1) {
|
||||
NEARBY_LOGS(INFO) << __func__
|
||||
<< ": Found a wireless device at :" << device_path;
|
||||
return std::make_unique<linux::NetworkManagerWifiMedium>(
|
||||
nm, linux::getSystemBusConnection(), device_path);
|
||||
return std::make_unique<linux::NetworkManagerWifiMedium>(nm,
|
||||
device_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,8 +254,9 @@ std::unique_ptr<api::WifiMedium> ImplementationPlatform::CreateWifiMedium() {
|
||||
|
||||
std::unique_ptr<api::WifiLanMedium>
|
||||
ImplementationPlatform::CreateWifiLanMedium() {
|
||||
return std::make_unique<linux::WifiLanMedium>(
|
||||
linux::getSystemBusConnection());
|
||||
auto nm =
|
||||
std::make_shared<linux::NetworkManager>(linux::getSystemBusConnection());
|
||||
return std::make_unique<linux::WifiLanMedium>(nm);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WifiHotspotMedium>
|
||||
@@ -275,7 +271,7 @@ ImplementationPlatform::CreateWifiHotspotMedium() {
|
||||
}
|
||||
|
||||
return std::make_unique<linux::NetworkManagerWifiHotspotMedium>(
|
||||
linux::getSystemBusConnection(), nm, std::move(wifiMedium));
|
||||
nm, std::move(wifiMedium));
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WifiDirectMedium>
|
||||
@@ -290,7 +286,7 @@ ImplementationPlatform::CreateWifiDirectMedium() {
|
||||
}
|
||||
|
||||
return std::make_unique<linux::NetworkManagerWifiDirectMedium>(
|
||||
linux::getSystemBusConnection(), nm, std::move(wifiMedium));
|
||||
nm, std::move(wifiMedium));
|
||||
}
|
||||
|
||||
std::unique_ptr<api::Timer> ImplementationPlatform::CreateTimer() {
|
||||
|
||||
@@ -104,7 +104,7 @@ NetworkManagerWifiDirectMedium::ListenForService(int port) {
|
||||
}
|
||||
|
||||
return std::make_unique<NetworkManagerWifiDirectServerSocket>(
|
||||
sock, system_bus_, active_connection->getObjectPath(), network_manager_);
|
||||
sock, std::move(active_connection), network_manager_);
|
||||
}
|
||||
|
||||
bool NetworkManagerWifiDirectMedium::ConnectWifiDirect(
|
||||
@@ -159,7 +159,8 @@ bool NetworkManagerWifiDirectMedium::StartWifiDirect(
|
||||
// medium is currently just a regular wifi hotspot.
|
||||
// auto wireless_device = std::make_unique<NetworkManagerWifiMedium>(
|
||||
// network_manager_, system_bus_, wireless_device_->getObjectPath());
|
||||
// auto hotspot = NetworkManagerWifiHotspotMedium(system_bus_, network_manager_,
|
||||
// auto hotspot = NetworkManagerWifiHotspotMedium(system_bus_,
|
||||
// network_manager_,
|
||||
// std::move(wireless_device));
|
||||
|
||||
// HotspotCredentials hotspot_creds;
|
||||
@@ -168,17 +169,18 @@ bool NetworkManagerWifiDirectMedium::StartWifiDirect(
|
||||
// wifi_direct_credentials->SetSSID(hotspot_creds.GetSSID());
|
||||
// wifi_direct_credentials->SetPassword(hotspot_creds.GetPassword());
|
||||
// return true;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkManagerWifiDirectMedium::StopWifiDirect() {
|
||||
// auto wireless_device = std::make_unique<NetworkManagerWifiMedium>(
|
||||
// network_manager_, system_bus_, wireless_device_->getObjectPath());
|
||||
// auto hotspot = NetworkManagerWifiHotspotMedium(system_bus_, network_manager_,
|
||||
// auto hotspot = NetworkManagerWifiHotspotMedium(system_bus_,
|
||||
// network_manager_,
|
||||
// std::move(wireless_device));
|
||||
|
||||
// return hotspot.DisconnectWifiHotspot();
|
||||
return false;
|
||||
// return hotspot.DisconnectWifiHotspot();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace linux
|
||||
|
||||
@@ -28,10 +28,9 @@ namespace linux {
|
||||
class NetworkManagerWifiDirectMedium : public api::WifiDirectMedium {
|
||||
public:
|
||||
NetworkManagerWifiDirectMedium(
|
||||
sdbus::IConnection &system_bus,
|
||||
std::shared_ptr<NetworkManager> network_manager,
|
||||
std::unique_ptr<NetworkManagerWifiMedium> wireless_device)
|
||||
: system_bus_(system_bus),
|
||||
: system_bus_(network_manager->GetConnection()),
|
||||
network_manager_(std::move(network_manager)),
|
||||
wireless_device_(std::move(wireless_device)) {}
|
||||
|
||||
@@ -56,7 +55,7 @@ class NetworkManagerWifiDirectMedium : public api::WifiDirectMedium {
|
||||
private:
|
||||
bool ConnectedToWifi();
|
||||
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
std::unique_ptr<NetworkManagerWifiMedium> wireless_device_;
|
||||
};
|
||||
|
||||
@@ -22,14 +22,12 @@
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
std::string NetworkManagerWifiDirectServerSocket::GetIPAddress() const {
|
||||
NetworkManagerActiveConnection active_conn(system_bus_,
|
||||
active_connection_path_);
|
||||
auto ip4addresses = active_conn.GetIP4Addresses();
|
||||
auto ip4addresses = active_conn_->GetIP4Addresses();
|
||||
if (ip4addresses.empty()) {
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< __func__
|
||||
<< ": Could not find any IPv4 addresses for active connection "
|
||||
<< active_connection_path_;
|
||||
<< active_conn_->getObjectPath();
|
||||
return std::string();
|
||||
}
|
||||
return ip4addresses[0];
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define PLATFORM_IMPL_LINUX_WIFI_DIRECT_SERVER_SOCKET_H_
|
||||
|
||||
#include <sdbus-c++/IConnection.h>
|
||||
#include "internal/platform/implementation/linux/network_manager_active_connection.h"
|
||||
#include "internal/platform/implementation/linux/wifi_medium.h"
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
namespace nearby {
|
||||
@@ -24,12 +25,10 @@ class NetworkManagerWifiDirectServerSocket
|
||||
: public api::WifiDirectServerSocket {
|
||||
public:
|
||||
NetworkManagerWifiDirectServerSocket(
|
||||
int socket, sdbus::IConnection &system_bus,
|
||||
sdbus::ObjectPath active_connection_path,
|
||||
int socket, std::unique_ptr<NetworkManagerActiveConnection> active_conn,
|
||||
std::shared_ptr<NetworkManager> network_manager)
|
||||
: fd_(socket),
|
||||
system_bus_(system_bus),
|
||||
active_connection_path_(std::move(active_connection_path)),
|
||||
active_conn_(std::move(active_conn)),
|
||||
network_manager_(std::move(network_manager)) {}
|
||||
|
||||
std::string GetIPAddress() const override;
|
||||
@@ -39,8 +38,7 @@ class NetworkManagerWifiDirectServerSocket
|
||||
|
||||
private:
|
||||
sdbus::UnixFd fd_;
|
||||
sdbus::IConnection &system_bus_;
|
||||
sdbus::ObjectPath active_connection_path_;
|
||||
std::unique_ptr<NetworkManagerActiveConnection> active_conn_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
};
|
||||
} // namespace linux
|
||||
|
||||
@@ -122,7 +122,7 @@ NetworkManagerWifiHotspotMedium::ListenForService(int port) {
|
||||
}
|
||||
|
||||
return std::make_unique<NetworkManagerWifiHotspotServerSocket>(
|
||||
sock, system_bus_, active_connection->getObjectPath(), network_manager_);
|
||||
sock, std::move(active_connection), network_manager_);
|
||||
}
|
||||
|
||||
bool NetworkManagerWifiHotspotMedium::StartWifiHotspot(
|
||||
|
||||
@@ -26,22 +26,19 @@ namespace linux {
|
||||
class NetworkManagerWifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
public:
|
||||
NetworkManagerWifiHotspotMedium(
|
||||
sdbus::IConnection &system_bus,
|
||||
std::shared_ptr<NetworkManager> network_manager,
|
||||
sdbus::ObjectPath wireless_device_object_path)
|
||||
: system_bus_(system_bus),
|
||||
: system_bus_(network_manager->GetConnection()),
|
||||
wireless_device_(std::make_unique<NetworkManagerWifiMedium>(
|
||||
network_manager, system_bus,
|
||||
std::move(wireless_device_object_path))),
|
||||
network_manager, std::move(wireless_device_object_path))),
|
||||
network_manager_(std::move(network_manager)) {}
|
||||
NetworkManagerWifiHotspotMedium(
|
||||
sdbus::IConnection &system_bus,
|
||||
std::shared_ptr<NetworkManager> network_manager,
|
||||
std::unique_ptr<NetworkManagerWifiMedium> wireless_device)
|
||||
: system_bus_(system_bus),
|
||||
: system_bus_(network_manager->GetConnection()),
|
||||
wireless_device_(std::move(wireless_device)),
|
||||
network_manager_(std::move(network_manager)) {}
|
||||
|
||||
|
||||
bool IsInterfaceValid() const override { return true; }
|
||||
std::unique_ptr<api::WifiHotspotSocket> ConnectToService(
|
||||
absl::string_view ip_address, int port,
|
||||
@@ -64,7 +61,7 @@ class NetworkManagerWifiHotspotMedium : public api::WifiHotspotMedium {
|
||||
bool WifiHotspotActive();
|
||||
bool ConnectedToWifi();
|
||||
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::unique_ptr<NetworkManagerWifiMedium> wireless_device_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
};
|
||||
|
||||
@@ -22,14 +22,12 @@
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
std::string NetworkManagerWifiHotspotServerSocket::GetIPAddress() const {
|
||||
NetworkManagerActiveConnection active_conn(system_bus_,
|
||||
active_connection_path_);
|
||||
auto ip4addresses = active_conn.GetIP4Addresses();
|
||||
auto ip4addresses = active_conn_->GetIP4Addresses();
|
||||
if (ip4addresses.empty()) {
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< __func__
|
||||
<< ": Could not find any IPv4 addresses for active connection "
|
||||
<< active_connection_path_;
|
||||
<< active_conn_->getObjectPath();
|
||||
return {};
|
||||
}
|
||||
return ip4addresses[0];
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <sdbus-c++/IConnection.h>
|
||||
|
||||
#include "internal/platform/implementation/linux/network_manager_active_connection.h"
|
||||
#include "internal/platform/implementation/linux/wifi_medium.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
|
||||
@@ -26,12 +27,10 @@ class NetworkManagerWifiHotspotServerSocket
|
||||
: public api::WifiHotspotServerSocket {
|
||||
public:
|
||||
NetworkManagerWifiHotspotServerSocket(
|
||||
int socket, sdbus::IConnection &system_bus,
|
||||
sdbus::ObjectPath active_connection_path,
|
||||
int socket, std::unique_ptr<NetworkManagerActiveConnection> active_conn,
|
||||
std::shared_ptr<NetworkManager> network_manager)
|
||||
: fd_(socket),
|
||||
system_bus_(system_bus),
|
||||
active_connection_path_(std::move(active_connection_path)),
|
||||
active_conn_(std::move(active_conn)),
|
||||
network_manager_(std::move(network_manager)) {}
|
||||
|
||||
std::string GetIPAddress() const override;
|
||||
@@ -41,8 +40,7 @@ class NetworkManagerWifiHotspotServerSocket
|
||||
|
||||
private:
|
||||
sdbus::UnixFd fd_;
|
||||
sdbus::IConnection &system_bus_;
|
||||
sdbus::ObjectPath active_connection_path_;
|
||||
std::unique_ptr<NetworkManagerActiveConnection> active_conn_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
};
|
||||
} // namespace linux
|
||||
|
||||
@@ -31,16 +31,16 @@
|
||||
#include "internal/platform/implementation/linux/wifi_lan.h"
|
||||
#include "internal/platform/implementation/linux/wifi_lan_server_socket.h"
|
||||
#include "internal/platform/implementation/linux/wifi_lan_socket.h"
|
||||
#include "internal/platform/implementation/linux/wifi_medium.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
WifiLanMedium::WifiLanMedium(sdbus::IConnection &system_bus)
|
||||
: system_bus_(system_bus),
|
||||
network_manager_(std::make_shared<linux::NetworkManager>(system_bus)),
|
||||
avahi_(std::make_shared<avahi::Server>(system_bus)) {}
|
||||
WifiLanMedium::WifiLanMedium(
|
||||
std::shared_ptr<linux::NetworkManager> network_manager)
|
||||
: system_bus_(network_manager->GetConnection()),
|
||||
network_manager_(std::move(network_manager)),
|
||||
avahi_(std::make_shared<avahi::Server>(*system_bus_)) {}
|
||||
|
||||
bool WifiLanMedium::IsNetworkConnected() const {
|
||||
auto state = network_manager_->getState();
|
||||
@@ -99,7 +99,7 @@ bool WifiLanMedium::StartAdvertising(const NsdServiceInfo &nsd_service_info) {
|
||||
}
|
||||
|
||||
auto entry_group =
|
||||
std::make_unique<avahi::EntryGroup>(system_bus_, entry_group_path);
|
||||
std::make_unique<avahi::EntryGroup>(*system_bus_, entry_group_path);
|
||||
|
||||
try {
|
||||
entry_group->AddService(
|
||||
@@ -166,7 +166,7 @@ bool WifiLanMedium::StartDiscovery(
|
||||
service_browsers_.emplace(
|
||||
service_type,
|
||||
std::make_unique<avahi::ServiceBrowser>(
|
||||
system_bus_, browser_object_path, std::move(callback), avahi_));
|
||||
*system_bus_, browser_object_path, std::move(callback), avahi_));
|
||||
} catch (const sdbus::Error &e) {
|
||||
DBUS_LOG_METHOD_CALL_ERROR(avahi_, "ServiceBrowserPrepare", e);
|
||||
return false;
|
||||
@@ -261,8 +261,7 @@ std::unique_ptr<api::WifiLanServerSocket> WifiLanMedium::ListenForService(
|
||||
|
||||
NEARBY_LOGS(VERBOSE) << __func__ << "Listening for services on port " << port;
|
||||
|
||||
return std::make_unique<WifiLanServerSocket>(sock, network_manager_,
|
||||
system_bus_);
|
||||
return std::make_unique<WifiLanServerSocket>(sock, network_manager_);
|
||||
}
|
||||
|
||||
absl::optional<std::pair<std::int32_t, std::int32_t>> GetDynamicPortRange() {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#ifndef PLATFORM_IMPL_LINUX_WIFI_LAN_H_
|
||||
#define PLATFORM_IMPL_LINUX_WIFI_LAN_H_
|
||||
#include <sdbus-c++/IConnection.h>
|
||||
#include <memory>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
@@ -27,7 +28,7 @@ namespace nearby {
|
||||
namespace linux {
|
||||
class WifiLanMedium : public api::WifiLanMedium {
|
||||
public:
|
||||
explicit WifiLanMedium(sdbus::IConnection &system_bus);
|
||||
explicit WifiLanMedium(std::shared_ptr<linux::NetworkManager> network_manager);
|
||||
|
||||
bool IsNetworkConnected() const override;
|
||||
|
||||
@@ -59,8 +60,7 @@ class WifiLanMedium : public api::WifiLanMedium {
|
||||
}
|
||||
|
||||
private:
|
||||
sdbus::IConnection &system_bus_;
|
||||
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
|
||||
std::shared_ptr<avahi::Server> avahi_;
|
||||
|
||||
@@ -42,7 +42,7 @@ std::string WifiLanServerSocket::GetIPAddress() const {
|
||||
}
|
||||
|
||||
for (auto &path : connection_paths) {
|
||||
auto active_connection =
|
||||
auto active_connection =
|
||||
std::make_unique<NetworkManagerActiveConnection>(system_bus_, path);
|
||||
std::string conn_type;
|
||||
try {
|
||||
|
||||
@@ -21,19 +21,18 @@
|
||||
#include <sdbus-c++/Types.h>
|
||||
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/linux/wifi_medium.h"
|
||||
#include "internal/platform/implementation/linux/network_manager.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
class WifiLanServerSocket : public api::WifiLanServerSocket {
|
||||
public:
|
||||
explicit WifiLanServerSocket(int socket,
|
||||
std::shared_ptr<NetworkManager> network_manager,
|
||||
sdbus::IConnection &system_bus)
|
||||
explicit WifiLanServerSocket(int socket,
|
||||
std::shared_ptr<NetworkManager> network_manager)
|
||||
: fd_(sdbus::UnixFd(socket)),
|
||||
network_manager_(std::move(network_manager)),
|
||||
system_bus_(system_bus) {}
|
||||
system_bus_(network_manager_->GetConnection()) {}
|
||||
|
||||
std::string GetIPAddress() const override;
|
||||
int GetPort() const override;
|
||||
@@ -44,7 +43,7 @@ class WifiLanServerSocket : public api::WifiLanServerSocket {
|
||||
private:
|
||||
sdbus::UnixFd fd_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
sdbus::IConnection &system_bus_;
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
};
|
||||
} // namespace linux
|
||||
} // namespace nearby
|
||||
|
||||
@@ -64,8 +64,8 @@ api::WifiInformation &NetworkManagerWifiMedium::GetInformation() {
|
||||
information_ = api::WifiInformation{false};
|
||||
return information_;
|
||||
}
|
||||
active_access_point = std::make_unique<NetworkManagerAccessPoint>(
|
||||
getProxy().getConnection(), ap_path);
|
||||
active_access_point =
|
||||
std::make_unique<NetworkManagerAccessPoint>(*system_bus_, ap_path);
|
||||
} catch (const sdbus::Error &e) {
|
||||
DBUS_LOG_PROPERTY_GET_ERROR(this, "ActiveAccessPoint", e);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ api::WifiInformation &NetworkManagerWifiMedium::GetInformation() {
|
||||
information_ =
|
||||
api::WifiInformation{true, ssid, active_access_point->HwAddress(),
|
||||
to_signed(active_access_point->Frequency())};
|
||||
NetworkManagerObjectManager manager(getProxy().getConnection());
|
||||
NetworkManagerObjectManager manager(system_bus_);
|
||||
auto ip4config = manager.GetIp4Config(active_access_point->getObjectPath());
|
||||
|
||||
if (ip4config != nullptr) {
|
||||
@@ -211,7 +211,6 @@ static inline std::pair<std::string, std::string> AuthAlgAndKeyMgmt(
|
||||
api::WifiAuthType auth_type) {
|
||||
switch (auth_type) {
|
||||
case api::WifiAuthType::kUnknown:
|
||||
return {"open", "none"};
|
||||
case api::WifiAuthType::kOpen:
|
||||
return {"open", "none"};
|
||||
case api::WifiAuthType::kWpaPsk:
|
||||
@@ -289,8 +288,8 @@ api::WifiConnectionStatus NetworkManagerWifiMedium::ConnectToNetwork(
|
||||
|
||||
NEARBY_LOGS(INFO) << __func__ << ": " << getObjectPath()
|
||||
<< ": Added a new connection at " << connection_path;
|
||||
auto active_connection = NetworkManagerActiveConnection(
|
||||
getProxy().getConnection(), active_conn_path);
|
||||
auto active_connection =
|
||||
NetworkManagerActiveConnection(system_bus_, active_conn_path);
|
||||
auto [reason, timeout] = active_connection.WaitForConnection();
|
||||
if (timeout) {
|
||||
NEARBY_LOGS(ERROR)
|
||||
@@ -345,7 +344,7 @@ NetworkManagerWifiMedium::GetActiveConnection() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto object_manager = NetworkManagerObjectManager(getProxy().getConnection());
|
||||
auto object_manager = NetworkManagerObjectManager(system_bus_);
|
||||
auto conn = object_manager.GetActiveConnectionForAccessPoint(active_ap_path,
|
||||
getObjectPath());
|
||||
|
||||
@@ -357,6 +356,5 @@ NetworkManagerWifiMedium::GetActiveConnection() {
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
} // namespace linux
|
||||
} // namespace nearby
|
||||
|
||||
@@ -48,10 +48,11 @@ class NetworkManagerWifiMedium
|
||||
delete;
|
||||
NetworkManagerWifiMedium &operator=(NetworkManagerWifiMedium &&) = delete;
|
||||
NetworkManagerWifiMedium(std::shared_ptr<NetworkManager> network_manager,
|
||||
sdbus::IConnection &system_bus,
|
||||
const sdbus::ObjectPath &wireless_device_object_path)
|
||||
: ProxyInterfaces(system_bus, "org.freedesktop.NetworkManager",
|
||||
: ProxyInterfaces(*network_manager->GetConnection(),
|
||||
"org.freedesktop.NetworkManager",
|
||||
wireless_device_object_path),
|
||||
system_bus_(network_manager->GetConnection()),
|
||||
network_manager_(std::move(network_manager)),
|
||||
last_scan_(-1) {
|
||||
registerProxy();
|
||||
@@ -111,6 +112,7 @@ class NetworkManagerWifiMedium
|
||||
std::vector<std::uint8_t> &ssid)
|
||||
ABSL_LOCKS_EXCLUDED(known_access_points_lock_);
|
||||
|
||||
std::shared_ptr<sdbus::IConnection> system_bus_;
|
||||
std::shared_ptr<NetworkManager> network_manager_;
|
||||
|
||||
api::WifiCapability capability_;
|
||||
|
||||
Reference in New Issue
Block a user