From 61b4e1d74d8da159ad88d8e1e6e63ce8c3e93f81 Mon Sep 17 00:00:00 2001 From: Vibhav Pant Date: Sun, 27 Aug 2023 20:48:09 +0530 Subject: [PATCH] Fix more compilation errors. --- .../linux/bluetooth_classic_medium.cc | 6 +-- .../linux/bluetooth_classic_medium.h | 6 --- .../implementation/linux/bluetooth_devices.cc | 15 +++---- .../implementation/linux/bluetooth_devices.h | 6 ++- .../linux/bluetoth_classic_server_socket.cc | 36 ---------------- .../platform/implementation/linux/bluez.cc | 10 ----- .../platform/implementation/linux/bluez.h | 20 ++++----- .../implementation/linux/log_message.cc | 42 +++++++++---------- .../implementation/linux/log_message.h | 2 +- .../platform/implementation/linux/wifi_lan.h | 4 +- 10 files changed, 50 insertions(+), 97 deletions(-) delete mode 100644 internal/platform/implementation/linux/bluetoth_classic_server_socket.cc diff --git a/internal/platform/implementation/linux/bluetooth_classic_medium.cc b/internal/platform/implementation/linux/bluetooth_classic_medium.cc index f8552491..40ecf848 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_medium.cc +++ b/internal/platform/implementation/linux/bluetooth_classic_medium.cc @@ -87,7 +87,7 @@ void BluetoothClassicMedium::onInterfacesRemoved( if (interface == bluez::DEVICE_INTERFACE) { { - auto device = get_device_by_path(object); + auto device = devices_->get_device_by_path(object); if (!device.has_value()) { NEARBY_LOGS(WARNING) << __func__ << ": received InterfacesRemoved for a device " @@ -107,7 +107,7 @@ void BluetoothClassicMedium::onInterfacesRemoved( } discovery_cb_lock_.ReaderUnlock(); } - remove_device_by_path(object); + devices_->remove_device_by_path(object); } } } @@ -195,7 +195,7 @@ BluetoothClassicMedium::ListenForService(const std::string &service_name, api::BluetoothDevice * BluetoothClassicMedium::GetRemoteDevice(const std::string &mac_address) { - auto device = get_device_by_address(mac_address); + auto device = devices_->get_device_by_address(mac_address); if (device.has_value()) return nullptr; diff --git a/internal/platform/implementation/linux/bluetooth_classic_medium.h b/internal/platform/implementation/linux/bluetooth_classic_medium.h index 0154b9a2..27165b14 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_medium.h +++ b/internal/platform/implementation/linux/bluetooth_classic_medium.h @@ -93,12 +93,6 @@ public: observers_.RemoveObserver(observer); }; - std::optional> - get_device_by_path(const sdbus::ObjectPath &); - std::optional> - get_device_by_address(const std::string &); - void remove_device_by_path(const sdbus::ObjectPath &); - protected: void onInterfacesAdded( const sdbus::ObjectPath &objectPath, diff --git a/internal/platform/implementation/linux/bluetooth_devices.cc b/internal/platform/implementation/linux/bluetooth_devices.cc index e3212857..549ae5f0 100644 --- a/internal/platform/implementation/linux/bluetooth_devices.cc +++ b/internal/platform/implementation/linux/bluetooth_devices.cc @@ -3,10 +3,10 @@ #include +#include "absl/synchronization/mutex.h" #include "internal/platform/implementation/linux/bluetooth_classic_device.h" #include "internal/platform/implementation/linux/bluetooth_devices.h" #include "internal/platform/implementation/linux/bluez.h" -#include "absl/synchronization/mutex.h" namespace nearby { namespace linux { @@ -19,8 +19,8 @@ BluetoothDevices::get_device_by_path( return std::nullopt; } - auto &device = devices_by_path_[device_object_path]; - return device; + auto &device = devices_by_path_.at(device_object_path); + return *device; } std::optional> @@ -40,10 +40,11 @@ void BluetoothDevices::remove_device_by_path( BluetoothDevice & BluetoothDevices::add_new_device(sdbus::ObjectPath device_object_path) { absl::MutexLock l(&devices_by_path_lock_); - auto pair = - devices_by_path_.emplace(device_object_path, system_bus_, - std::move(device_object_path), observers_); - return pair.first->second; + auto pair = devices_by_path_.emplace( + std::string(device_object_path), + std::make_unique( + system_bus_, std::move(device_object_path), observers_)); + return *pair.first->second; } } // namespace linux } // namespace nearby diff --git a/internal/platform/implementation/linux/bluetooth_devices.h b/internal/platform/implementation/linux/bluetooth_devices.h index 093ebaa0..a1d9d46c 100644 --- a/internal/platform/implementation/linux/bluetooth_devices.h +++ b/internal/platform/implementation/linux/bluetooth_devices.h @@ -1,6 +1,8 @@ #ifndef PLATFORM_IMPL_LINUX_BLUETOOTH_DEVICES_H_ #define PLATFORM_IMPL_LINUX_BLUETOOTH_DEVICES_H_ +#include + #include #include #include @@ -20,6 +22,7 @@ public: ObserverList &observers) : system_bus_(system_bus), observers_(observers), adapter_object_path_(adapter_object_path) {} + ~BluetoothDevices() = default; std::optional> get_device_by_path(const sdbus::ObjectPath &); @@ -30,7 +33,8 @@ public: private: absl::Mutex devices_by_path_lock_; - std::map devices_by_path_; + std::map> + devices_by_path_; sdbus::IConnection &system_bus_; ObserverList &observers_; diff --git a/internal/platform/implementation/linux/bluetoth_classic_server_socket.cc b/internal/platform/implementation/linux/bluetoth_classic_server_socket.cc deleted file mode 100644 index e6bc2e75..00000000 --- a/internal/platform/implementation/linux/bluetoth_classic_server_socket.cc +++ /dev/null @@ -1,36 +0,0 @@ -#include "absl/strings/str_replace.h" -#include "absl/strings/substitute.h" -#include "internal/platform/exception.h" -#include "internal/platform/implementation/bluetooth_classic.h" -#include "internal/platform/implementation/linux/bluetooth_classic_device.h" -#include "internal/platform/implementation/linux/bluetooth_classic_server_socket.h" -#include "internal/platform/implementation/linux/bluetooth_classic_socket.h" -#include "internal/platform/implementation/linux/bluez.h" -#include "internal/platform/logging.h" -#include - -namespace nearby { -namespace linux { -std::unique_ptr BluetoothServerSocket::Accept() { - auto pair = profile_manager_.GetServiceRecordFD(service_uuid_); - if (!pair.has_value()) { - NEARBY_LOGS(ERROR) << __func__ - << "Failed to get a new connection for profile " - << service_uuid_ << " for device "; - return nullptr; - } - - auto [device, fd] = *pair; - return std::unique_ptr(new BluetoothSocket(device, fd)); -} - -Exception BluetoothServerSocket::Close() { - auto profile_object_path = - absl::Substitute("/com/google/nearby/profiles/$0", service_uuid_); - - profile_manager_.Unregister(service_uuid_); - - return {Exception::kSuccess}; -} -} // namespace linux -} // namespace nearby diff --git a/internal/platform/implementation/linux/bluez.cc b/internal/platform/implementation/linux/bluez.cc index 58c6c188..736a6c49 100644 --- a/internal/platform/implementation/linux/bluez.cc +++ b/internal/platform/implementation/linux/bluez.cc @@ -7,16 +7,6 @@ namespace nearby { namespace linux { namespace bluez { -const char *SERVICE = "org.bluez"; - -const char *ADAPTER_INTEFACE = "org.bluez.Adapter1"; - -const char *DEVICE_INTERFACE = "org.bluez.Device1"; -const char *DEVICE_PROP_ADDRESS = "Address"; -const char *DEVICE_PROP_ALIAS = "Alias"; -const char *DEVICE_PROP_PAIRED = "Paired"; -const char *DEVICE_PROP_CONNECTED = "Connected"; - std::string device_object_path(const sdbus::ObjectPath &adapter_object_path, absl::string_view mac_address) { return absl::Substitute("$0/dev_$1", adapter_object_path, diff --git a/internal/platform/implementation/linux/bluez.h b/internal/platform/implementation/linux/bluez.h index 94591f1b..ace3a142 100644 --- a/internal/platform/implementation/linux/bluez.h +++ b/internal/platform/implementation/linux/bluez.h @@ -20,23 +20,23 @@ namespace nearby { namespace linux { namespace bluez { -extern const char *SERVICE_DEST; +static constexpr const char *SERVICE_DEST = "org.bluez"; -extern const char *ADAPTER_INTERFACE; +static constexpr const char *ADAPTER_INTERFACE = "org.bluez.Adapter1"; -extern const char *DEVICE_INTERFACE; -extern const char *DEVICE_PROP_ADDRESS; -extern const char *DEVICE_PROP_ALIAS; -extern const char *DEVICE_PROP_PAIRED; -extern const char *DEVICE_PROP_CONNECTED; +static constexpr const char *DEVICE_INTERFACE = "org.bluez.Device1"; +static constexpr const char *DEVICE_PROP_ADDRESS = "Address"; +static constexpr const char *DEVICE_PROP_ALIAS = "Alias"; +static constexpr const char *DEVICE_PROP_PAIRED = "Paired"; +static constexpr const char *DEVICE_PROP_CONNECTED = "Connected"; -extern std::string + std::string device_object_path(const sdbus::ObjectPath &adapter_object_path, absl::string_view mac_address); -extern sdbus::ObjectPath profile_object_path(absl::string_view service_uuid); + sdbus::ObjectPath profile_object_path(absl::string_view service_uuid); -extern sdbus::ObjectPath adapter_object_path(absl::string_view name); + sdbus::ObjectPath adapter_object_path(absl::string_view name); class BluezObjectManager : public sdbus::ProxyInterfaces { diff --git a/internal/platform/implementation/linux/log_message.cc b/internal/platform/implementation/linux/log_message.cc index 3fc10a47..bd8f670d 100644 --- a/internal/platform/implementation/linux/log_message.cc +++ b/internal/platform/implementation/linux/log_message.cc @@ -38,7 +38,21 @@ bool LogMessage::ShouldCreateLogMessage(Severity severity) { } // namespace api namespace linux { - +static inline google::LogSeverity +ConvertSeverity(api::LogMessage::Severity severity) { + switch (severity) { + case api::LogMessage::Severity::kWarning: + return google::GLOG_WARNING; + case api::LogMessage::Severity::kError: + return google::GLOG_ERROR; + case api::LogMessage::Severity::kFatal: + return google::GLOG_FATAL; + case api::LogMessage::Severity::kVerbose: + case api::LogMessage::Severity::kInfo: + default: + return google::GLOG_INFO; + } +} static inline int ConvertSeverityToSyslog(google::LogSeverity severity) { switch (severity) { case google::GLOG_WARNING: @@ -53,6 +67,11 @@ static inline int ConvertSeverityToSyslog(google::LogSeverity severity) { } } +// TODO: Set a LogSink depending on the target set by LogControl +LogMessage::LogMessage(const char *file, int line, Severity severity) + : log_streamer_(file, line, ConvertSeverity(severity), + global_log_control_.get(), false) {} + void LogControl::send(google::LogSeverity severity, const char *full_filename, const char *base_filename, int line, const struct ::tm *tm_time, const char *message, @@ -77,27 +96,6 @@ void LogControl::send(google::LogSeverity severity, const char *full_filename, } } -static inline google::LogSeverity -ConvertSeverity(api::LogMessage::Severity severity) { - switch (severity) { - case api::LogMessage::Severity::kWarning: - return google::GLOG_WARNING; - case api::LogMessage::Severity::kError: - return google::GLOG_ERROR; - case api::LogMessage::Severity::kFatal: - return google::GLOG_FATAL; - case api::LogMessage::Severity::kVerbose: - case api::LogMessage::Severity::kInfo: - default: - return google::GLOG_INFO; - } -} - -// TODO: Set a LogSink depending on the target set by LogControl -LogMessage::LogMessage(const char *file, int line, Severity severity) - : log_streamer_(file, line, ConvertSeverity(severity), - global_log_control_.get(), false) {} - void LogMessage::Print(const char *format, ...) { va_list ap; va_start(ap, format); diff --git a/internal/platform/implementation/linux/log_message.h b/internal/platform/implementation/linux/log_message.h index 294c25b0..0a473e3a 100644 --- a/internal/platform/implementation/linux/log_message.h +++ b/internal/platform/implementation/linux/log_message.h @@ -16,7 +16,7 @@ namespace linux { class LogMessage : public api::LogMessage { public: LogMessage(const char *file, int line, Severity severity); - ~LogMessage() override; + ~LogMessage() override {}; void Print(const char *format, ...) override; diff --git a/internal/platform/implementation/linux/wifi_lan.h b/internal/platform/implementation/linux/wifi_lan.h index 24010163..3600f500 100644 --- a/internal/platform/implementation/linux/wifi_lan.h +++ b/internal/platform/implementation/linux/wifi_lan.h @@ -34,7 +34,9 @@ public: std::unique_ptr ListenForService(int port = 0) override; absl::optional> - GetDynamicPortRange() override; + GetDynamicPortRange() override { + return std::nullopt; + } private: DiscoveredServiceCallback discovery_cb_;