#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #include #include #include #include #include #include #include #include namespace lpool { static constexpr lp_id_t uint8VarId = 0; static constexpr lp_id_t floatVarId = 1; static constexpr lp_id_t uint32VarId = 2; static constexpr lp_id_t uint16Vec3Id = 3; static constexpr lp_id_t int64Vec2Id = 4; static constexpr uint32_t testSetId = 0; } class LocalPoolTestDataSet: public StaticLocalDataSet<3> { public: LocalPoolTestDataSet(HasLocalDataPoolIF* owner, uint32_t setId): StaticLocalDataSet(owner, setId) { } ReturnValue_t assignPointers() { PoolVariableIF** rawVarArray = getContainer(); localPoolVarUint8 = dynamic_cast*>(rawVarArray[0]); localPoolVarFloat = dynamic_cast*>(rawVarArray[1]); localPoolUint16Vec = dynamic_cast*>( rawVarArray[2]); if(localPoolVarUint8 == nullptr or localPoolVarFloat == nullptr or localPoolUint16Vec == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } return HasReturnvaluesIF::RETURN_OK; } lp_var_t* localPoolVarUint8 = nullptr; lp_var_t* localPoolVarFloat = nullptr; lp_vec_t* localPoolUint16Vec = nullptr; private: }; class LocalPoolOwnerBase: public SystemObject, public HasLocalDataPoolIF { public: LocalPoolOwnerBase( object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE): SystemObject(objectId), hkManager(this, messageQueue), dataset(this, lpool::testSetId) { messageQueue = new MessageQueueMockBase(); } ~LocalPoolOwnerBase() { QueueFactory::instance()->deleteMessageQueue(messageQueue); } object_id_t getObjectId() const override { return SystemObject::getObjectId(); } ReturnValue_t initializeHkManager() { if(not initialized) { initialized = true; return hkManager.initialize(messageQueue); } return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t initializeHkManagerAfterTaskCreation() { if(not initializedAfterTaskCreation) { initializedAfterTaskCreation = true; return hkManager.initializeAfterTaskCreation(); } return HasReturnvaluesIF::RETURN_OK; } /** Command queue for housekeeping messages. */ MessageQueueId_t getCommandQueue() const override { return messageQueue->getId(); } // This is called by initializeAfterTaskCreation of the HK manager. virtual ReturnValue_t initializeLocalDataPool( LocalDataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { // Default initialization empty for now. localDataPoolMap.emplace(lpool::uint8VarId, new PoolEntry({0})); localDataPoolMap.emplace(lpool::floatVarId, new PoolEntry({0})); localDataPoolMap.emplace(lpool::uint32VarId, new PoolEntry({0})); localDataPoolMap.emplace(lpool::uint16Vec3Id, new PoolEntry({0, 0, 0})); localDataPoolMap.emplace(lpool::int64Vec2Id, new PoolEntry({0, 0})); return HasReturnvaluesIF::RETURN_OK; } LocalDataPoolManager* getHkManagerHandle() override { return &hkManager; } uint32_t getPeriodicOperationFrequency() const override { return 0; } /** * This function is used by the pool manager to get a valid dataset * from a SID * @param sid Corresponding structure ID * @return */ virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { return &dataset; } MessageQueueMockBase* getMockQueueHandle() const { return dynamic_cast(messageQueue); } void subscribeWrapperSetUpdate() { hkManager.subscribeForSetUpdateMessages(lpool::testSetId, objects::NO_OBJECT, MessageQueueIF::NO_QUEUE, false); } LocalDataPoolManager hkManager; LocalPoolTestDataSet dataset; private: lp_var_t testUint8 = lp_var_t(this, lpool::uint8VarId, &dataset); lp_var_t testFloat = lp_var_t(this, lpool::floatVarId, &dataset); lp_var_t testUint32 = lp_var_t(this, lpool::uint32VarId); lp_vec_t testUint16Vec = lp_vec_t(this, lpool::uint16Vec3Id, &dataset); lp_vec_t testInt64Vec = lp_vec_t(this, lpool::int64Vec2Id); MessageQueueIF* messageQueue = nullptr; bool initialized = false; bool initializedAfterTaskCreation = false; }; #endif /* FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ */