Use shared_ptrs for dbus connections for top-level classes.

This commit is contained in:
Vibhav Pant
2023-09-09 21:41:37 +05:30
parent 567ee6741b
commit bc4c1e76c9
28 changed files with 154 additions and 176 deletions
@@ -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