to avoid dynamic casting, introuced CookieIF

This commit is contained in:
Robin Müller 2020-03-23 19:09:42 +01:00
parent f7bd661e69
commit b6bf9d7147
11 changed files with 82 additions and 68 deletions

View File

@ -15,9 +15,8 @@ public:
/** /**
* Default empty virtual destructor. * Default empty virtual destructor.
*/ */
virtual ~AcceptsDeviceResponsesIF() { virtual ~AcceptsDeviceResponsesIF() {}
} virtual MessageQueueId_t getDeviceQueue() = 0;
virtual MessageQueueId_t getDeviceQueue() = 0;
}; };
#endif /* ACCEPTSDEVICERESPONSESIF_H_ */ #endif /* ACCEPTSDEVICERESPONSESIF_H_ */

View File

@ -2,12 +2,12 @@
#include <framework/devicehandlers/ChildHandlerBase.h> #include <framework/devicehandlers/ChildHandlerBase.h>
#include <framework/subsystem/SubsystemBase.h> #include <framework/subsystem/SubsystemBase.h>
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, address_t logicalAddress, ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
object_id_t deviceCommunication, Cookie * cookie, object_id_t deviceCommunication, CookieIF * cookie,
uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) : uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, logicalAddress, deviceCommunication, cookie, DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId, maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId,
thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir),
cmdQueueSize), cmdQueueSize),

View File

@ -6,9 +6,8 @@
class ChildHandlerBase: public DeviceHandlerBase { class ChildHandlerBase: public DeviceHandlerBase {
public: public:
ChildHandlerBase(object_id_t setObjectId, uint32_t logicalAddress, ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
object_id_t deviceCommunication, Cookie * cookie, CookieIF * cookie, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch,
uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
uint32_t parent, FailureIsolationBase* customFdir = nullptr, uint32_t parent, FailureIsolationBase* customFdir = nullptr,
size_t cmdQueueSize = 20); size_t cmdQueueSize = 20);

View File

@ -5,12 +5,12 @@
*/ */
#include <framework/devicehandlers/Cookie.h> #include <framework/devicehandlers/Cookie.h>
//Cookie::Cookie(address_t logicalAddress_, size_t maxReplyLen_):
// logicalAddress(logicalAddress_), maxReplyLen(maxReplyLen_){}
Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) { Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) {
} }
void Cookie::setAddress(address_t logicalAddress_) {
logicalAddress = logicalAddress_;
}
void Cookie::setMaxReplyLen(size_t maxReplyLen_) { void Cookie::setMaxReplyLen(size_t maxReplyLen_) {
maxReplyLen = maxReplyLen_; maxReplyLen = maxReplyLen_;
} }
@ -22,3 +22,5 @@ address_t Cookie::getAddress() const {
size_t Cookie::getMaxReplyLen() const { size_t Cookie::getMaxReplyLen() const {
return maxReplyLen; return maxReplyLen;
} }

View File

@ -1,31 +1,35 @@
#ifndef COOKIE_H_ #ifndef COOKIE_H_
#define COOKIE_H_ #define COOKIE_H_
#include <framework/devicehandlers/DeviceHandlerIF.h> #include <framework/devicehandlers/CookieIF.h>
/** /**
* @brief This datatype is used to identify different connection over a single interface * @brief This datatype is used to identify different connection over a single interface
* (like RMAP or I2C) * (like RMAP or I2C)
* @details * @details
* To use this class, implement a communication specific child cookie. This cookie * To use this class, implement a communication specific child cookie which
* can be used in the device communication interface by performing * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling
* a C++ dynamic cast and passing it to a child device handler, which stores * CookieIF* childCookie = new ChildCookie(...).´
* it and passes the Cookie to the communication interface where it can be used *
* by again performing a dynamic cast. * This cookie is then passed to the child device handlers, which stores the
* pointer and passes it to the communication interface functions.
*
* The cookie can be used to store all kinds of information * The cookie can be used to store all kinds of information
* about the communication, like slave addresses, communication status, * about the communication, like slave addresses, communication status,
* communication parameters etc. * communication parameters etc.
*
* @ingroup comm * @ingroup comm
*/ */
class Cookie{ class Cookie: public CookieIF {
public: public:
Cookie() = default; Cookie();
Cookie(address_t logicalAddress_); Cookie(address_t logicalAddress_);
virtual ~Cookie(){} virtual ~Cookie() {};
void setMaxReplyLen(size_t maxReplyLen_); virtual void setAddress(address_t logicalAddres_);
virtual void setMaxReplyLen(size_t maxReplyLen_);
address_t getAddress() const; virtual address_t getAddress() const;
size_t getMaxReplyLen() const; virtual size_t getMaxReplyLen() const;
private: private:
address_t logicalAddress = 0; address_t logicalAddress = 0;
size_t maxReplyLen = 0; size_t maxReplyLen = 0;

25
devicehandlers/CookieIF.h Normal file
View File

@ -0,0 +1,25 @@
/**
* @file CookieIF.h
*
* @date 23 Mar 2020
*/
#ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#include <framework/devicehandlers/DeviceHandlerIF.h>
class CookieIF {
public:
/**
* Default empty virtual destructor.
*/
virtual ~CookieIF() {};
virtual void setAddress(address_t logicalAddress_) = 0;
virtual address_t getAddress() const = 0;
virtual void setMaxReplyLen(size_t maxReplyLen_) = 0;
virtual size_t getMaxReplyLen() const = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ */

View File

@ -57,7 +57,7 @@ public:
* - Everything else triggers sending failed event with * - Everything else triggers sending failed event with
* returnvalue as parameter 1 * returnvalue as parameter 1
*/ */
virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t * sendData, virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
size_t sendLen) = 0; size_t sendLen) = 0;
/** /**
@ -68,7 +68,7 @@ public:
* - Everything else triggers sending failed event with * - Everything else triggers sending failed event with
* returnvalue as parameter 1 * returnvalue as parameter 1
*/ */
virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
/** /**
* Called by DHB in the SEND_WRITE doSendRead(). * Called by DHB in the SEND_WRITE doSendRead().
@ -76,7 +76,7 @@ public:
* @param cookie * @param cookie
* @return * @return
*/ */
virtual ReturnValue_t requestReceiveMessage(Cookie *cookie, size_t requestLen) = 0; virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0;
/** /**
* Called by DHB in the GET_WRITE doGetRead(). * Called by DHB in the GET_WRITE doGetRead().
@ -89,7 +89,7 @@ public:
* - Everything else triggers receiving failed with * - Everything else triggers receiving failed with
* returnvalue as parameter 1 * returnvalue as parameter 1
*/ */
virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) = 0; size_t *size) = 0;
}; };

View File

@ -16,23 +16,22 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0;
object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
object_id_t deviceCommunication, Cookie * cookie_, size_t maxReplyLen, CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch,
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
FailureIsolationBase* fdirInstance, size_t cmdQueueSize) : FailureIsolationBase* fdirInstance, size_t cmdQueueSize) :
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS), wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
deviceCommunicationId(deviceCommunication), cookie(cookie_), deviceCommunicationId(deviceCommunication), comCookie(comCookie_),
deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId), deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId),
healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this), healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this),
fdirInstance(fdirInstance), hkSwitcher(this), fdirInstance(fdirInstance), hkSwitcher(this),
defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false), defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false),
executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(), executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(),
logicalAddress(logicalAddress_), childTransitionDelay(5000), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN),
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch)
deviceSwitch(setDeviceSwitch)
{ {
this->cookie->setMaxReplyLen(maxReplyLen); this->comCookie->setMaxReplyLen(maxReplyLen);
commandQueue = QueueFactory::instance()-> commandQueue = QueueFactory::instance()->
createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE);
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
@ -44,6 +43,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalA
} }
DeviceHandlerBase::~DeviceHandlerBase() { DeviceHandlerBase::~DeviceHandlerBase() {
delete comCookie;
if (defaultFDIRUsed) { if (defaultFDIRUsed) {
delete fdirInstance; delete fdirInstance;
} }
@ -506,7 +506,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter,
void DeviceHandlerBase::doSendWrite() { void DeviceHandlerBase::doSendWrite() {
if (cookieInfo.state == COOKIE_WRITE_READY) { if (cookieInfo.state == COOKIE_WRITE_READY) {
ReturnValue_t result = communicationInterface->sendMessage(cookie, ReturnValue_t result = communicationInterface->sendMessage(comCookie,
rawPacket, rawPacketLen); rawPacket, rawPacketLen);
if (result == RETURN_OK) { if (result == RETURN_OK) {
@ -527,7 +527,7 @@ void DeviceHandlerBase::doGetWrite() {
return; return;
} }
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
ReturnValue_t result = communicationInterface->getSendSuccess(cookie); ReturnValue_t result = communicationInterface->getSendSuccess(comCookie);
if (result == RETURN_OK) { if (result == RETURN_OK) {
if (wiretappingMode == RAW) { if (wiretappingMode == RAW) {
replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true); replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true);
@ -548,7 +548,7 @@ void DeviceHandlerBase::doGetWrite() {
void DeviceHandlerBase::doSendRead() { void DeviceHandlerBase::doSendRead() {
ReturnValue_t result; ReturnValue_t result;
result = communicationInterface->requestReceiveMessage(cookie, requestLen); result = communicationInterface->requestReceiveMessage(comCookie, requestLen);
if (result == RETURN_OK) { if (result == RETURN_OK) {
cookieInfo.state = COOKIE_READ_SENT; cookieInfo.state = COOKIE_READ_SENT;
} else { } else {
@ -575,7 +575,7 @@ void DeviceHandlerBase::doGetRead() {
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
result = communicationInterface->readReceivedMessage(cookie, &receivedData, result = communicationInterface->readReceivedMessage(comCookie, &receivedData,
&receivedDataLen); &receivedDataLen);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -1277,7 +1277,7 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t obje
} }
uint32_t DeviceHandlerBase::getLogicalAddress() { uint32_t DeviceHandlerBase::getLogicalAddress() {
return logicalAddress; return this->comCookie->getAddress();
} }
void DeviceHandlerBase::performOperationHook() { void DeviceHandlerBase::performOperationHook() {

View File

@ -17,6 +17,7 @@
#include <framework/tasks/ExecutableObjectIF.h> #include <framework/tasks/ExecutableObjectIF.h>
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h> #include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
#include <framework/datapool/HkSwitchHelper.h> #include <framework/datapool/HkSwitchHelper.h>
#include <framework/devicehandlers/CookieIF.h>
#include <framework/serialize/SerialFixedArrayListAdapter.h> #include <framework/serialize/SerialFixedArrayListAdapter.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
#include <framework/tasks/PeriodicTaskIF.h> #include <framework/tasks/PeriodicTaskIF.h>
@ -93,9 +94,9 @@ public:
* @param fdirInstance * @param fdirInstance
* @param cmdQueueSize * @param cmdQueueSize
*/ */
DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
object_id_t deviceCommunication, Cookie* cookie_, size_t maxReplyLen, CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch,
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER,
uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER,
FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20); FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20);
@ -422,22 +423,6 @@ protected:
*/ */
size_t requestLen = 0; 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. * The mode the device handler is currently in.
* *
@ -515,7 +500,7 @@ protected:
* Cookie used for communication. This is passed to the communication * Cookie used for communication. This is passed to the communication
* interface. * interface.
*/ */
Cookie *cookie; CookieIF *comCookie;
/** /**
* The MessageQueue used to receive device handler commands and to send replies. * The MessageQueue used to receive device handler commands and to send replies.
@ -959,7 +944,7 @@ private:
/** /**
* cached from ctor for initialize() * cached from ctor for initialize()
*/ */
const uint32_t logicalAddress; //const uint32_t logicalAddress = 0;
/** /**
* Used for timing out mode transitions. * Used for timing out mode transitions.

View File

@ -93,10 +93,10 @@ RMAPCookie::~RMAPCookie() {
} }
uint32_t RMAPCookie::getMaxReplyLen() const { //uint32_t RMAPCookie::getMaxReplyLen() const {
return maxReplyLen; // return maxReplyLen;
} //}
//
void RMAPCookie::setMaxReplyLen(uint32_t maxReplyLen) { void RMAPCookie::setMaxReplyLen(uint32_t maxReplyLen) {
this->maxReplyLen = maxReplyLen; this->maxReplyLen = maxReplyLen;
} }

View File

@ -6,7 +6,7 @@
class RMAPChannelIF; class RMAPChannelIF;
class RMAPCookie : public Cookie{ class RMAPCookie : public Cookie {
public: public:
//To Uli: Sorry, I need an empty ctor to initialize an array of cookies. //To Uli: Sorry, I need an empty ctor to initialize an array of cookies.
RMAPCookie(); RMAPCookie();
@ -28,7 +28,7 @@ public:
void setCommandMask(uint8_t commandMask); void setCommandMask(uint8_t commandMask);
uint8_t getCommandMask(); uint8_t getCommandMask();
uint32_t getMaxReplyLen() const; //size_t getMaxReplyLen() const;
void setMaxReplyLen(uint32_t maxReplyLen); void setMaxReplyLen(uint32_t maxReplyLen);
uint16_t getTransactionIdentifier() const; uint16_t getTransactionIdentifier() const;