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
@@ -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;