From 34dd478848cc43bf9520d366207f20bdfe2c4962 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 16:25:19 +0200 Subject: [PATCH] helper class OneRemoteConfigProvider --- src/fsfw/cfdp/VarLenFields.cpp | 4 ++++ src/fsfw/cfdp/VarLenFields.h | 1 + src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/fsfw/cfdp/VarLenFields.cpp b/src/fsfw/cfdp/VarLenFields.cpp index 512c713c..b9e0b3a8 100644 --- a/src/fsfw/cfdp/VarLenFields.cpp +++ b/src/fsfw/cfdp/VarLenFields.cpp @@ -131,3 +131,7 @@ bool cfdp::VarLenField::operator<(const cfdp::VarLenField &other) const { bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const { return getWidth() == other.getWidth() and getValue() == other.getValue(); } + +bool cfdp::VarLenField::operator!=(const cfdp::VarLenField &other) const { + return not(*this == other); +} diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 03664995..37a9cf5c 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -27,6 +27,7 @@ class VarLenField : public SerializeIF { VarLenField(cfdp::WidthInBytes width, size_t value); bool operator==(const VarLenField &other) const; + bool operator!=(const VarLenField &other) const; bool operator<(const VarLenField &other) const; ReturnValue_t setValue(cfdp::WidthInBytes, size_t value); diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index 1cd1ec1d..d0e6121d 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -11,6 +11,25 @@ class RemoteConfigTableIF { virtual bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) = 0; }; +/** + * Helper class for the common case that there is exactly one remote entity + */ +class OneRemoteConfigProvider : public RemoteConfigTableIF { + public: + explicit OneRemoteConfigProvider(RemoteEntityCfg cfg) : cfg(std::move(cfg)) {} + + bool getRemoteCfg(const EntityId& remoteId, cfdp::RemoteEntityCfg** cfg_) override { + if (remoteId != cfg.remoteId) { + return false; + } + *cfg_ = &cfg; + return true; + } + + private: + RemoteEntityCfg cfg; +}; + } // namespace cfdp #endif // FSFW_CFDP_HANDLER_REMOTECONFIGTABLEIF_H