Fix more compilation errors.

This commit is contained in:
Vibhav Pant
2023-08-27 20:48:09 +05:30
parent bf4c0c5d3a
commit 61b4e1d74d
10 changed files with 50 additions and 97 deletions
@@ -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;
@@ -93,12 +93,6 @@ public:
observers_.RemoveObserver(observer);
};
std::optional<std::reference_wrapper<BluetoothDevice>>
get_device_by_path(const sdbus::ObjectPath &);
std::optional<std::reference_wrapper<BluetoothDevice>>
get_device_by_address(const std::string &);
void remove_device_by_path(const sdbus::ObjectPath &);
protected:
void onInterfacesAdded(
const sdbus::ObjectPath &objectPath,
@@ -3,10 +3,10 @@
#include <sdbus-c++/Types.h>
#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<std::reference_wrapper<BluetoothDevice>>
@@ -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<MonitoredBluetoothDevice>(
system_bus_, std::move(device_object_path), observers_));
return *pair.first->second;
}
} // namespace linux
} // namespace nearby
@@ -1,6 +1,8 @@
#ifndef PLATFORM_IMPL_LINUX_BLUETOOTH_DEVICES_H_
#define PLATFORM_IMPL_LINUX_BLUETOOTH_DEVICES_H_
#include <memory>
#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/IProxy.h>
#include <sdbus-c++/Types.h>
@@ -20,6 +22,7 @@ public:
ObserverList<api::BluetoothClassicMedium::Observer> &observers)
: system_bus_(system_bus), observers_(observers),
adapter_object_path_(adapter_object_path) {}
~BluetoothDevices() = default;
std::optional<std::reference_wrapper<BluetoothDevice>>
get_device_by_path(const sdbus::ObjectPath &);
@@ -30,7 +33,8 @@ public:
private:
absl::Mutex devices_by_path_lock_;
std::map<std::string, MonitoredBluetoothDevice> devices_by_path_;
std::map<std::string, std::unique_ptr<MonitoredBluetoothDevice>>
devices_by_path_;
sdbus::IConnection &system_bus_;
ObserverList<api::BluetoothClassicMedium::Observer> &observers_;
@@ -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 <systemd/sd-bus.h>
namespace nearby {
namespace linux {
std::unique_ptr<api::BluetoothSocket> 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<api::BluetoothSocket>(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
@@ -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,
+10 -10
View File
@@ -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<sdbus::ObjectManager_proxy> {
@@ -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);
@@ -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;
@@ -34,7 +34,9 @@ public:
std::unique_ptr<api::WifiLanServerSocket>
ListenForService(int port = 0) override;
absl::optional<std::pair<std::int32_t, std::int32_t>>
GetDynamicPortRange() override;
GetDynamicPortRange() override {
return std::nullopt;
}
private:
DiscoveredServiceCallback discovery_cb_;