From 59812199fdfe32ee3817a3a61de4834e1a4d4906 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 19:16:01 +0100 Subject: [PATCH] new cookieIF --- devicehandlers/DeviceHandlerBase.cpp | 31 ++++++++++++++-------------- devicehandlers/DeviceHandlerBase.h | 29 +++++++------------------- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 5834db2f5..33e441460 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,23 +16,22 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, - object_id_t deviceCommunication, Cookie * cookie_, size_t maxReplyLen, - uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, +DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, + CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, size_t cmdQueueSize) : SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS), - deviceCommunicationId(deviceCommunication), cookie(cookie_), + deviceCommunicationId(deviceCommunication), comCookie(comCookie_), deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId), healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false), executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(), - logicalAddress(logicalAddress_), childTransitionDelay(5000), - transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), - deviceSwitch(setDeviceSwitch) + childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), + transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { - this->cookie->setMaxReplyLen(maxReplyLen); + this->comCookie->setMaxReplyLen(maxReplyLen); commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; @@ -44,6 +43,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalA } DeviceHandlerBase::~DeviceHandlerBase() { + delete comCookie; if (defaultFDIRUsed) { delete fdirInstance; } @@ -66,7 +66,7 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { return RETURN_OK; } - switch (getRmapAction()) { + switch (getComAction()) { case SEND_WRITE: if ((cookieInfo.state == COOKIE_UNUSED)) { buildInternalCommand(); @@ -506,7 +506,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter, void DeviceHandlerBase::doSendWrite() { if (cookieInfo.state == COOKIE_WRITE_READY) { - ReturnValue_t result = communicationInterface->sendMessage(cookie, + ReturnValue_t result = communicationInterface->sendMessage(comCookie, rawPacket, rawPacketLen); if (result == RETURN_OK) { @@ -527,7 +527,7 @@ void DeviceHandlerBase::doGetWrite() { return; } cookieInfo.state = COOKIE_UNUSED; - ReturnValue_t result = communicationInterface->getSendSuccess(cookie); + ReturnValue_t result = communicationInterface->getSendSuccess(comCookie); if (result == RETURN_OK) { if (wiretappingMode == RAW) { replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true); @@ -548,7 +548,7 @@ void DeviceHandlerBase::doGetWrite() { void DeviceHandlerBase::doSendRead() { ReturnValue_t result; - result = communicationInterface->requestReceiveMessage(cookie, requestLen); + result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } else { @@ -575,7 +575,7 @@ void DeviceHandlerBase::doGetRead() { cookieInfo.state = COOKIE_UNUSED; - result = communicationInterface->readReceivedMessage(cookie, &receivedData, + result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); if (result != RETURN_OK) { @@ -688,7 +688,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, //Default child implementations -DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getRmapAction() { +DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getComAction() { switch (pstStep) { case 0: return SEND_WRITE; @@ -1050,6 +1050,7 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND); } else { // rework in progress + result = RETURN_OK; //result = switchCookieChannel( // DeviceHandlerMessage::getIoBoardObjectId(message)); if (result == RETURN_OK) { @@ -1276,7 +1277,7 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t obje } uint32_t DeviceHandlerBase::getLogicalAddress() { - return logicalAddress; + return this->comCookie->getAddress(); } void DeviceHandlerBase::performOperationHook() { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index e9288921d..05be2d458 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -93,9 +94,9 @@ public: * @param fdirInstance * @param cmdQueueSize */ - DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, - object_id_t deviceCommunication, Cookie* cookie_, size_t maxReplyLen, - uint8_t setDeviceSwitch, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, + DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, + CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20); @@ -422,22 +423,6 @@ protected: */ size_t requestLen = 0; -// /** -// * This union (or std::variant) type can be used to set comParameters which -// * are passed in the open() and reOpen() calls to the communication -// * interface -// * TODO: I don't know if we should use C++17 features but if we do we propably -// * should also write a function to get either a storeId handle -// * or an array handle so these values can be set conveniently. -// * The good think is that if there are many parameters, they can -// * be stored in the IPC pool. But maybe two uint32_t parameters are enough. -// * Simple = Good. It is downwards compatible and one can still store -// * 4 bytes of parameters AND a store ID. -// */ -// comParameters_t comParameters; - // uint32_t comParameter1 = 0; - // uint32_t comParameter2 = 0; - /** * The mode the device handler is currently in. * @@ -515,7 +500,7 @@ protected: * Cookie used for communication. This is passed to the communication * interface. */ - Cookie *cookie; + CookieIF *comCookie; /** * The MessageQueue used to receive device handler commands and to send replies. @@ -666,7 +651,7 @@ protected: * * @return The Rmap action to execute in this step */ - virtual CommunicationAction_t getRmapAction(); + virtual CommunicationAction_t getComAction(); /** * Build the device command to send for raw mode. @@ -959,7 +944,7 @@ private: /** * cached from ctor for initialize() */ - const uint32_t logicalAddress; + //const uint32_t logicalAddress = 0; /** * Used for timing out mode transitions.