Skip to content

Commit

Permalink
ScpiClient: getters/setters/CTORs/assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
willeccles committed May 14, 2024
1 parent dd8eae6 commit 02f6b14
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
24 changes: 21 additions & 3 deletions include/bci/abs/ScpiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,29 @@ namespace bci::abs {

class ScpiClient {
public:
ScpiClient(std::shared_ptr<drivers::CommDriver> driver);
ScpiClient() = default;

ScpiClient(std::nullptr_t) = delete;
explicit ScpiClient(std::shared_ptr<drivers::CommDriver> driver) noexcept;

~ScpiClient();
ScpiClient(ScpiClient&& other) noexcept;

ScpiClient(const ScpiClient&) = delete;

ScpiClient& operator=(ScpiClient&& rhs) noexcept;

ScpiClient& operator=(const ScpiClient&) = delete;

~ScpiClient() = default;

std::shared_ptr<drivers::CommDriver> GetDriver() noexcept;

std::shared_ptr<const drivers::CommDriver> GetDriver() const noexcept;

void SetDriver(std::shared_ptr<drivers::CommDriver> driver) noexcept;

void SetDeviceID(unsigned int id);

unsigned int GetDeviceID() const;

/* System */

Expand Down
39 changes: 36 additions & 3 deletions src/ScpiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,43 @@ static constexpr unsigned int kReadTimeoutMs = 500;
using util::Err;
using ec = ErrorCode;

ScpiClient::ScpiClient(std::shared_ptr<drivers::CommDriver> driver)
: driver_(std::move(driver)) {}
ScpiClient::ScpiClient(std::shared_ptr<drivers::CommDriver> driver) noexcept
: driver_{std::move(driver)} {}

ScpiClient::~ScpiClient() {}
ScpiClient::ScpiClient(ScpiClient&& other) noexcept
: driver_{std::move(other.driver_)} {}

ScpiClient& ScpiClient::operator=(ScpiClient&& rhs) noexcept {
driver_ = std::move(rhs.driver_);
return *this;
}

std::shared_ptr<drivers::CommDriver> ScpiClient::GetDriver() noexcept {
return driver_;
}

std::shared_ptr<const drivers::CommDriver> ScpiClient::GetDriver()
const noexcept {
return driver_;
}

void ScpiClient::SetDriver(
std::shared_ptr<drivers::CommDriver> driver) noexcept {
driver_ = std::move(driver);
}

void ScpiClient::SetDeviceID(unsigned int id) {
if (driver_) {
driver_->SetDeviceID(id);
}
}

unsigned int ScpiClient::GetDeviceID() const {
if (!driver_) {
return 0;
}
return driver_->GetDeviceID();
}

ErrorCode ScpiClient::Send(std::string_view buf) const {
if (!driver_) {
Expand Down

0 comments on commit 02f6b14

Please sign in to comment.