Rewrite dbus code using sdbus-c++

This commit is contained in:
Vibhav Pant
2023-08-15 20:52:51 +05:30
parent 295f9d6b2e
commit f9fb3d259e
30 changed files with 1656 additions and 740 deletions
@@ -2,7 +2,9 @@
#define PLATFORM_IMPL_LINUX_BLUETOOTH_SOCKET_H_
#include <memory>
#include <optional>
#include <sdbus-c++/Types.h>
#include <systemd/sd-bus.h>
#include "internal/platform/byte_array.h"
@@ -14,7 +16,7 @@ namespace linux {
class BluetoothInputStream : public InputStream {
public:
BluetoothInputStream(int fd) { fd_ = fd; };
BluetoothInputStream(sdbus::UnixFd &fd) : fd_(fd){};
ExceptionOr<ByteArray> Read(std::int64_t size) override;
ExceptionOr<size_t> Skip(size_t offset) override;
@@ -23,33 +25,29 @@ public:
Exception Close() override;
private:
int fd_;
friend class BluetoothSocket;
std::optional<sdbus::UnixFd> fd_;
};
class BluetoothOutputStream : public OutputStream {
public:
BluetoothOutputStream(int fd) { fd_ = fd; };
BluetoothOutputStream(sdbus::UnixFd &fd) : fd_(fd){};
Exception Write(const ByteArray &data) override;
Exception Flush() override;
Exception Close() override;
private:
int fd_;
friend class BluetoothSocket;
std::optional<sdbus::UnixFd> fd_;
};
class BluetoothSocket : public api::BluetoothSocket {
public:
BluetoothSocket(api::BluetoothDevice &device,
absl::string_view device_object_path,
absl::string_view connected_profile_uuid, int fd)
: device_(device) {
fd_ = fd;
device_object_path_ = device_object_path;
connected_profile_uuid_ = connected_profile_uuid;
input_stream_ = BluetoothInputStream(fd_);
output_stream_ = BluetoothOutputStream(fd_);
}
BluetoothSocket(api::BluetoothDevice &device, sdbus::UnixFd fd)
: device_(device), output_stream_(fd), input_stream_(fd) {}
InputStream &GetInputStream() override { return input_stream_; }
OutputStream &GetOutputStream() override { return output_stream_; }
@@ -57,12 +55,9 @@ public:
api::BluetoothDevice *GetRemoteDevice() override { return &device_; };
private:
int fd_;
std::string device_object_path_;
api::BluetoothDevice &device_;
std::string connected_profile_uuid_;
BluetoothInputStream input_stream_ = {-1};
BluetoothOutputStream output_stream_ = {-1};
BluetoothOutputStream output_stream_;
BluetoothInputStream input_stream_;
};
} // namespace linux
} // namespace nearby