2020-05-17 22:16:25 +02:00
|
|
|
#ifndef GLOBALPOOLVECTOR_H_
|
|
|
|
#define GLOBALPOOLVECTOR_H_
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
#include <framework/datapool/DataSetIF.h>
|
|
|
|
#include <framework/datapool/PoolEntry.h>
|
|
|
|
#include <framework/datapool/PoolVariableIF.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
|
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief This is the access class for array-type data pool entries.
|
2020-05-17 01:17:11 +02:00
|
|
|
*
|
2020-05-17 22:16:25 +02:00
|
|
|
* @details
|
|
|
|
* To ensure safe usage of the data pool, operation is not done directly on the
|
|
|
|
* data pool entries, but on local copies. This class provides simple type-
|
|
|
|
* and length-safe access to vector-style data pool entries (i.e. entries with
|
|
|
|
* length > 1). The class can be instantiated as read-write and read only.
|
|
|
|
*
|
|
|
|
* It provides a commit-and-roll-back semantic, which means that no array
|
|
|
|
* entry in the data pool is changed until the commit call is executed.
|
|
|
|
* There are two template parameters:
|
|
|
|
* @tparam T
|
|
|
|
* This template parameter specifies the data type of an array entry. Currently,
|
|
|
|
* all plain data types are supported, but in principle any type is possible.
|
|
|
|
* @tparam vector_size
|
|
|
|
* This template parameter specifies the vector size of this entry. Using a
|
|
|
|
* template parameter for this is not perfect, but avoids
|
|
|
|
* dynamic memory allocation.
|
|
|
|
* @ingroup data_pool
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
2020-05-17 22:16:25 +02:00
|
|
|
template<typename T, uint16_t vectorSize>
|
2020-05-17 01:17:11 +02:00
|
|
|
class GlobPoolVector: public PoolVariableIF {
|
|
|
|
public:
|
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief In the constructor, the variable can register itself in a
|
|
|
|
* DataSet (if no nullptr is passed).
|
|
|
|
* @details
|
|
|
|
* It DOES NOT fetch the current value from the data pool, but sets the
|
|
|
|
* value attribute to default (0). The value is fetched within the
|
|
|
|
* read() operation.
|
|
|
|
* @param set_id
|
|
|
|
* This is the id in the global data pool this instance of the access
|
|
|
|
* class corresponds to.
|
|
|
|
* @param dataSet
|
|
|
|
* The data set in which the variable shall register itself. If nullptr,
|
|
|
|
* the variable is not registered.
|
|
|
|
* @param setWritable
|
|
|
|
* If this flag is set to true, changes in the value attribute can be
|
|
|
|
* written back to the data pool, otherwise not.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
GlobPoolVector(uint32_t set_id, DataSetIF* set,
|
2020-05-17 22:16:25 +02:00
|
|
|
ReadWriteMode_t setReadWriteMode);
|
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief This is the local copy of the data pool entry.
|
|
|
|
* @details The user can work on this attribute
|
|
|
|
* just like he would on a local array of this type.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
2020-05-17 22:16:25 +02:00
|
|
|
T value[vectorSize];
|
2020-05-17 01:17:11 +02:00
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief The classes destructor is empty.
|
|
|
|
* @details If commit() was not called, the local value is
|
2020-05-17 01:17:11 +02:00
|
|
|
* discarded and not written back to the data pool.
|
|
|
|
*/
|
2020-05-17 22:16:25 +02:00
|
|
|
~GlobPoolVector() {};
|
2020-05-17 01:17:11 +02:00
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief The operation returns the number of array entries
|
|
|
|
* in this variable.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
uint8_t getSize() {
|
2020-05-17 22:16:25 +02:00
|
|
|
return vectorSize;
|
2020-05-17 01:17:11 +02:00
|
|
|
}
|
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief This operation returns the data pool id of the variable.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
uint32_t getDataPoolId() const {
|
|
|
|
return dataPoolId;
|
|
|
|
}
|
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief This operation sets the data pool id of the variable.
|
|
|
|
* @details
|
|
|
|
* The method is necessary to set id's of data pool member variables
|
|
|
|
* with bad initialization.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
void setDataPoolId(uint32_t poolId) {
|
|
|
|
dataPoolId = poolId;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This method returns if the variable is write-only, read-write or read-only.
|
|
|
|
*/
|
|
|
|
ReadWriteMode_t getReadWriteMode() const {
|
|
|
|
return readWriteMode;
|
|
|
|
}
|
2020-05-17 22:16:25 +02:00
|
|
|
|
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
/**
|
2020-05-17 22:16:25 +02:00
|
|
|
* @brief With this call, the valid information of the variable is returned.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
bool isValid() const {
|
|
|
|
if (valid != INVALID)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-17 22:16:25 +02:00
|
|
|
void setValid(uint8_t valid) {this->valid = valid;}
|
|
|
|
uint8_t getValid() {return valid;}
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-05-17 22:16:25 +02:00
|
|
|
T &operator [](int i) {return value[i];}
|
|
|
|
const T &operator [](int i) const {return value[i];}
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
2020-05-17 22:16:25 +02:00
|
|
|
const size_t max_size, bool bigEndian) const override;
|
|
|
|
virtual size_t getSerializedSize() const override;
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
2020-05-17 22:16:25 +02:00
|
|
|
bool bigEndian) override;
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief This is a call to read the array's values
|
|
|
|
* from the global data pool.
|
|
|
|
* @details
|
|
|
|
* When executed, this operation tries to fetch the pool entry with matching
|
|
|
|
* data pool id from the global data pool and copies all array values
|
|
|
|
* and the valid information to its local attributes.
|
|
|
|
* In case of a failure (wrong type, size or pool id not found), the
|
|
|
|
* variable is set to zero and invalid. The operation does NOT provide
|
|
|
|
* any mutual exclusive protection by itself.
|
|
|
|
*/
|
|
|
|
ReturnValue_t read();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The commit call copies the array values back to the data pool.
|
|
|
|
* @details
|
|
|
|
* It checks type and size, as well as if the variable is writable. If so,
|
|
|
|
* the value is copied and the valid flag is automatically set to "valid".
|
|
|
|
* The operation does NOT provide any mutual exclusive protection by itself.
|
|
|
|
*/
|
|
|
|
ReturnValue_t commit();
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @brief To access the correct data pool entry on read and commit calls,
|
|
|
|
* the data pool id is stored.
|
|
|
|
*/
|
|
|
|
uint32_t dataPoolId;
|
|
|
|
/**
|
|
|
|
* @brief The valid information as it was stored in the data pool
|
|
|
|
* is copied to this attribute.
|
|
|
|
*/
|
|
|
|
uint8_t valid;
|
|
|
|
/**
|
|
|
|
* @brief The information whether the class is read-write or
|
|
|
|
* read-only is stored here.
|
|
|
|
*/
|
|
|
|
ReadWriteMode_t readWriteMode;
|
2020-05-17 01:17:11 +02:00
|
|
|
};
|
|
|
|
|
2020-05-17 22:16:25 +02:00
|
|
|
#include <framework/datapoolglob/GlobalPoolVector.tpp>
|
|
|
|
|
2020-05-17 14:13:31 +02:00
|
|
|
template<typename T, uint16_t vectorSize>
|
|
|
|
using gp_vec_t = GlobPoolVector<T, vectorSize>;
|
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
#endif /* POOLVECTOR_H_ */
|