From 099e6281ecdaccf39127da33e7b86b6eaa3f2335 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 2 Jul 2020 16:54:53 +0200 Subject: [PATCH] DataSetBase not bound to max size anymore --- datapool/DataSetBase.cpp | 9 ++++++--- datapool/DataSetBase.h | 13 ++++++------- datapoolglob/GlobalDataSet.cpp | 4 +++- datapoolglob/GlobalDataSet.h | 6 ++++++ datapoollocal/LocalDataSet.cpp | 14 ++++++++++++-- datapoollocal/LocalDataSet.h | 10 ++++++++-- datapoollocal/StaticLocalDataSet.cpp | 6 ++++++ datapoollocal/StaticLocalDataSet.h | 11 +++++++++++ 8 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 datapoollocal/StaticLocalDataSet.cpp create mode 100644 datapoollocal/StaticLocalDataSet.h diff --git a/datapool/DataSetBase.cpp b/datapool/DataSetBase.cpp index b788d05d..3d38e143 100644 --- a/datapool/DataSetBase.cpp +++ b/datapool/DataSetBase.cpp @@ -1,8 +1,11 @@ #include #include -DataSetBase::DataSetBase() { - for (uint8_t count = 0; count < DATA_SET_MAX_SIZE; count++) { +DataSetBase::DataSetBase(PoolVariableIF** registeredVariablesArray, + const size_t maxFillCount): + registeredVariables(registeredVariablesArray), + maxFillCount(maxFillCount) { + for (uint8_t count = 0; count < maxFillCount; count++) { registeredVariables[count] = nullptr; } } @@ -21,7 +24,7 @@ ReturnValue_t DataSetBase::registerVariable( "Pool variable is nullptr." << std::endl; return DataSetIF::POOL_VAR_NULL; } - if (fillCount >= DATA_SET_MAX_SIZE) { + if (fillCount >= maxFillCount) { sif::error << "DataSet::registerVariable: " "DataSet is full." << std::endl; return DataSetIF::DATA_SET_FULL; diff --git a/datapool/DataSetBase.h b/datapool/DataSetBase.h index 8f7d892a..12ae2b53 100644 --- a/datapool/DataSetBase.h +++ b/datapool/DataSetBase.h @@ -37,7 +37,8 @@ public: * supply a pointer to this dataset to PoolVariable * initializations to register pool variables. */ - DataSetBase(); + DataSetBase(PoolVariableIF** registeredVariablesArray, + const size_t maxFillCount); virtual~ DataSetBase(); /** @@ -110,11 +111,6 @@ public: virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) override; - // SHOULDDO we could use a linked list of datapool variables - //!< This definition sets the maximum number of variables to - //! register in one DataSet. - static const uint8_t DATA_SET_MAX_SIZE = 63; - protected: /** * @brief The fill_count attribute ensures that the variables @@ -137,8 +133,11 @@ protected: /** * @brief This array represents all pool variables registered in this set. + * Child classes can use a static or dynamic container to create + * an array of registered variables and assign the first entry here. */ - PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE] = { }; + PoolVariableIF** registeredVariables = nullptr; + const size_t maxFillCount = 0; private: ReturnValue_t readVariable(uint16_t count); diff --git a/datapoolglob/GlobalDataSet.cpp b/datapoolglob/GlobalDataSet.cpp index 9da8d524..883f6157 100644 --- a/datapoolglob/GlobalDataSet.cpp +++ b/datapoolglob/GlobalDataSet.cpp @@ -2,7 +2,9 @@ #include #include -GlobDataSet::GlobDataSet(): DataSetBase() {} +GlobDataSet::GlobDataSet(): DataSetBase( + reinterpret_cast(®isteredVariables), + DATA_SET_MAX_SIZE) {} // Don't do anything with your variables, they are dead already! // (Destructor is already called) diff --git a/datapoolglob/GlobalDataSet.h b/datapoolglob/GlobalDataSet.h index f0bf7daa..519b08c0 100644 --- a/datapoolglob/GlobalDataSet.h +++ b/datapoolglob/GlobalDataSet.h @@ -61,6 +61,10 @@ public: */ void setEntriesValid(bool valid); + //!< This definition sets the maximum number of variables to + //! register in one DataSet. + static const uint8_t DATA_SET_MAX_SIZE = 63; + private: /** * If the valid state of a dataset is always relevant to the whole @@ -85,6 +89,8 @@ private: void handleAlreadyReadDatasetCommit(); ReturnValue_t handleUnreadDatasetCommit(); + + PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE]; }; #endif /* DATASET_H_ */ diff --git a/datapoollocal/LocalDataSet.cpp b/datapoollocal/LocalDataSet.cpp index 3fc8592e..c5142bfc 100644 --- a/datapoollocal/LocalDataSet.cpp +++ b/datapoollocal/LocalDataSet.cpp @@ -5,20 +5,30 @@ #include #include -LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner): DataSetBase() { +LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner, + const size_t maxNumberOfVariables): + DataSetBase(poolVarList.data(), maxNumberOfVariables) { + poolVarList.reserve(maxNumberOfVariables); + poolVarList.resize(maxNumberOfVariables); if(hkOwner == nullptr) { sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!" << std::endl; + return; } hkManager = hkOwner->getHkManagerHandle(); } -LocalDataSet::LocalDataSet(object_id_t ownerId): DataSetBase() { +LocalDataSet::LocalDataSet(object_id_t ownerId, + const size_t maxNumberOfVariables): + DataSetBase(poolVarList.data(), maxNumberOfVariables) { + poolVarList.reserve(maxNumberOfVariables); + poolVarList.resize(maxNumberOfVariables); OwnsLocalDataPoolIF* hkOwner = objectManager->get( ownerId); if(hkOwner == nullptr) { sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!" << std::endl; + return; } hkManager = hkOwner->getHkManagerHandle(); } diff --git a/datapoollocal/LocalDataSet.h b/datapoollocal/LocalDataSet.h index aea699d8..1a894130 100644 --- a/datapoollocal/LocalDataSet.h +++ b/datapoollocal/LocalDataSet.h @@ -5,6 +5,8 @@ #include #include +#include + class LocalDataPoolManager; /** @@ -35,7 +37,8 @@ public: * The constructor simply sets the fill_count to zero and sets * the state to "uninitialized". */ - LocalDataSet(OwnsLocalDataPoolIF* hkOwner); + LocalDataSet(OwnsLocalDataPoolIF *hkOwner, + const size_t maxNumberOfVariables); /** * @brief Constructor for users of local pool data. The passed pool @@ -43,7 +46,8 @@ public: * The constructor simply sets the fill_count to zero and sets * the state to "uninitialized". */ - LocalDataSet(object_id_t ownerId); + LocalDataSet(object_id_t ownerId, + const size_t maxNumberOfVariables); /** * @brief The destructor automatically manages writing the valid @@ -102,6 +106,8 @@ private: * (most significant bit) to 7 (least significant bit) */ void bitSetter(uint8_t* byte, uint8_t position) const; + + std::vector poolVarList; }; #endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */ diff --git a/datapoollocal/StaticLocalDataSet.cpp b/datapoollocal/StaticLocalDataSet.cpp new file mode 100644 index 00000000..15d4251a --- /dev/null +++ b/datapoollocal/StaticLocalDataSet.cpp @@ -0,0 +1,6 @@ +#include + + + + + diff --git a/datapoollocal/StaticLocalDataSet.h b/datapoollocal/StaticLocalDataSet.h new file mode 100644 index 00000000..15a79aae --- /dev/null +++ b/datapoollocal/StaticLocalDataSet.h @@ -0,0 +1,11 @@ +#ifndef FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_ +#define FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_ +#include + + +class StaticLocalDataSet: public DataSetBase { + +}; + + +#endif /* FRAMEWORK_DATAPOOLLOCAL_STATICLOCALDATASET_H_ */