Skip to content

Commit

Permalink
Use handledescriptor references instead of pointers in io infrastructure
Browse files Browse the repository at this point in the history
Change-Id: I280a220c7013058dea41ee1ac14f45e1742d9f07
  • Loading branch information
azoitl authored and MartinMelikMerkumians committed Feb 23, 2024
1 parent c60794d commit a5773b2
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/core/io/configFB/io_configFB_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ bool IOConfigFBController::init(CEventChainExecutionThread * const paECET, int p
return true;
}

void IOConfigFBController::initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) {
void IOConfigFBController::initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) {

if(paHandleDescriptor->mId.empty()) {
if(paHandleDescriptor.mId.empty()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/io/configFB/io_configFB_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace forte {
*
* @param paHandleDescriptor Descriptor of the handle
*/
void initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor);
void initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor);

/*! @brief Deinitializes the configuration fb
*
Expand Down
2 changes: 1 addition & 1 deletion src/core/io/configFB/io_controller_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ void IOConfigFBPartController::executeEvent(TEventID paEIID, CEventChainExecutio
}
}

void IOConfigFBPartController::initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) {
void IOConfigFBPartController::initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) {
mMaster->initHandle(paHandleDescriptor);
}
2 changes: 1 addition & 1 deletion src/core/io/configFB/io_controller_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace forte {

virtual void initHandles() = 0;

void initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor);
void initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor);

private:
IOConfigFBSplitController* mMaster;
Expand Down
2 changes: 1 addition & 1 deletion src/core/io/configFB/io_slave_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void IOConfigFBMultiSlave::executeEvent(TEventID paEIID, CEventChainExecutionThr
}
}

void IOConfigFBMultiSlave::initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) {
void IOConfigFBMultiSlave::initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) {
mMaster->initHandle(paHandleDescriptor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/io/configFB/io_slave_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace forte {

virtual void initHandles() = 0;

void initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor);
void initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor);

static const CIEC_WSTRING scmOK;
static const char* const scmMasterNotFound;
Expand Down
8 changes: 4 additions & 4 deletions src/core/io/device/io_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ void IODeviceController::run() {
}
}

void IODeviceController::addHandle(HandleDescriptor *paHandleDescriptor) {
void IODeviceController::addHandle(HandleDescriptor &paHandleDescriptor) {
IOHandle* handle = initHandle(paHandleDescriptor);

if(nullptr == handle) {
DEVLOG_WARNING("[IODeviceController] Failed to initialize handle '%s'. Check initHandle method.\n", paHandleDescriptor->mId.c_str());
DEVLOG_WARNING("[IODeviceController] Failed to initialize handle '%s'. Check initHandle method.\n", paHandleDescriptor.mId.c_str());
return;
}

switch(handle->getDirection()){
case IOMapper::In:
addHandle(&mInputHandles, paHandleDescriptor->mId, handle);
addHandle(&mInputHandles, paHandleDescriptor.mId, handle);
break;
case IOMapper::Out:
addHandle(&mOutputHandles, paHandleDescriptor->mId, handle);
addHandle(&mOutputHandles, paHandleDescriptor.mId, handle);
break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/core/io/device/io_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace forte {
*
* @param paHandleDescriptor Descriptor of the handle
*/
virtual void addHandle(HandleDescriptor *paHandleDescriptor);
virtual void addHandle(HandleDescriptor &paHandleDescriptor);

/*! @brief Initializer for all IO handles.
*
Expand All @@ -163,7 +163,7 @@ namespace forte {
*
* @param paHandleDescriptor Descriptor of the handle
*/
virtual IOHandle* initHandle(HandleDescriptor *paHandleDescriptor) = 0;
virtual IOHandle* initHandle(HandleDescriptor &paHandleDescriptor) = 0;

/*! @brief Iterates over all input handles and fires an indication event in case of a change.
*
Expand Down
10 changes: 5 additions & 5 deletions src/core/io/device/io_controller_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ IODeviceMultiController::IODeviceMultiController(CDeviceExecution& paDeviceExecu
IODeviceController(paDeviceExecution) {
}

void IODeviceMultiController::addHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) {
HandleDescriptor* desc = static_cast<HandleDescriptor*>(paHandleDescriptor);
void IODeviceMultiController::addHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) {
HandleDescriptor& desc = static_cast<HandleDescriptor&>(paHandleDescriptor);
IOHandle* handle = initHandle(desc);

if(nullptr == handle) {
DEVLOG_WARNING("[IODeviceMultiController] Failed to initialize handle '%s'. Check initHandle method.\n", desc->mId.c_str());
DEVLOG_WARNING("[IODeviceMultiController] Failed to initialize handle '%s'. Check initHandle method.\n", desc.mId.c_str());
return;
}

if(IOMapper::getInstance().registerHandle(desc->mId, handle)) {
addSlaveHandle(desc->mSlaveIndex, handle);
if(IOMapper::getInstance().registerHandle(desc.mId, handle)) {
addSlaveHandle(desc.mSlaveIndex, handle);
} else {
delete handle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/io/device/io_controller_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace forte {
protected:
explicit IODeviceMultiController(CDeviceExecution& paDeviceExecution);

void addHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) override;
void addHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) override;

IOHandle* initHandle(IODeviceController::HandleDescriptor *paHandleDescriptor) override = 0;
IOHandle* initHandle(IODeviceController::HandleDescriptor &paHandleDescriptor) override = 0;

private:

Expand Down
4 changes: 2 additions & 2 deletions src/modules/PLC01A1/plc01a1_config_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ void PLC01A1ConfigFB::onStartup() {
forte::core::io::IOMapper::In,
0 /*offset is always 0 */,
static_cast<uint8_t>(i));
initHandle(&desc);
initHandle(desc);
}

for(size_t i = 0; i < numberOfOutputs; i++) {
PLC01A1Controller::HandleDescriptor
desc = PLC01A1Controller::HandleDescriptor(*static_cast<CIEC_WSTRING*>(getDI(initialDIOffset + numberOfInputs + i)),
forte::core::io::IOMapper::Out, 0 /*offset is always 0 */, static_cast<uint8_t>(numberOfOutputs - i - 1));
initHandle(&desc);
initHandle(desc);
}

started();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/PLC01A1/plc01a1_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ bool PLC01A1Controller::isHandleValueEqual(forte::core::io::IOHandle *paHandle)
return ((forte::core::io::IOHandleBit*) paHandle)->equal(mInputArrayOld);
}

forte::core::io::IOHandle* PLC01A1Controller::initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) {
HandleDescriptor desc = *static_cast<HandleDescriptor*>(paHandleDescriptor);
forte::core::io::IOHandle* PLC01A1Controller::initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) {
HandleDescriptor& desc = static_cast<HandleDescriptor&>(paHandleDescriptor);

return new forte::core::io::IOHandleBit(this, desc.mDirection, desc.mOffset, desc.mPosition,
desc.mDirection == forte::core::io::IOMapper::In ? mInputArray : mOutputArray);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/PLC01A1/plc01a1_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PLC01A1Controller : public forte::core::io::IODevicePollController {

virtual bool isHandleValueEqual(forte::core::io::IOHandle* paHandle);

forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor);
forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor);

protected:
const char* init();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/PLCnext/deviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void PLCnextDeviceController::registerSlaveHandler(PLCnextSlaveHandler *slave) {
mSlaves->pushBack(slave);
}

forte::core::io::IOHandle* PLCnextDeviceController::initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) {
HandleDescriptor desc = *static_cast<HandleDescriptor*>(paHandleDescriptor);
forte::core::io::IOHandle* PLCnextDeviceController::initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) {
HandleDescriptor& desc = static_cast<HandleDescriptor&>(paHandleDescriptor);
PLCnextSlaveHandler* slave = getSlave(desc.mSlaveIndex);

if (slave == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/PLCnext/deviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PLCnextDeviceController : public forte::core::io::IODeviceMultiController
protected:
const char* init() override;

forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) override;
forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) override;

void deInit() override;
void runLoop() override;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/PLCnext/types/PLCnextAXLSEDI16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void FORTE_PLCnextAXLSEDI16::initHandles() {
(uint16_t) i,
PLCnextDeviceController::Bit);

initHandle(&desc);
initHandle(desc);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/PLCnext/types/PLCnextAXLSEDO16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void FORTE_PLCnextAXLSEDO16::initHandles() {
(uint16_t) i,
PLCnextDeviceController::Bit);

initHandle(&desc);
initHandle(desc);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/modules/eliteboard/handler/EliteBoardDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ EliteBoardDeviceController::EliteBoardDeviceController(CDeviceExecution& paDevic

EliteBoardDeviceController::~EliteBoardDeviceController() {}

EliteBoardDeviceController::IOHandle *
EliteBoardDeviceController::initHandle(HandleDescriptor *paHandleDescriptor) {
auto desc = static_cast<EliteBoardHandleDescriptor *>(paHandleDescriptor);
IOHandle *handle = new IOHandleGPIO(this, desc->mGPIO_Port, desc->mPin);
EliteBoardDeviceController::IOHandle *EliteBoardDeviceController::initHandle(HandleDescriptor &paHandleDescriptor) {
auto desc = static_cast<EliteBoardHandleDescriptor &>(paHandleDescriptor);
IOHandle *handle = new IOHandleGPIO(this, desc.mGPIO_Port, desc.mPin);
return static_cast<IOHandle *>(handle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EliteBoardDeviceController : public forte::core::io::IODeviceController {
};


IOHandle* initHandle(HandleDescriptor* paHandleDescriptor);
IOHandle* initHandle(HandleDescriptor& paHandleDescriptor);

void setConfig(Config *paConfig) {}
const char *init() {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/eliteboard/types/Port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void FORTE_Port::register_handles() {
EliteBoardDeviceController::EliteBoardHandleDescriptor descr(id->getValue(), port, 1 << i);
auto ctrl = getExtEvHandler<EliteBoardDeviceController>(*this);

IOMapper::getInstance().registerHandle(id->getValue(), ctrl.initHandle(&descr));
IOMapper::getInstance().registerHandle(id->getValue(), ctrl.initHandle(descr));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/embrick/handler/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ void EmbrickBusHandler::deInit() {
}

forte::core::io::IOHandle* EmbrickBusHandler::initHandle(
forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) {
HandleDescriptor &desc = static_cast<HandleDescriptor&>(*paHandleDescriptor);
forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) {
HandleDescriptor &desc = static_cast<HandleDescriptor&>(paHandleDescriptor);

EmbrickSlaveHandler *slave = getSlave(desc.mSlaveIndex);
if(slave == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/embrick/handler/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class EmbrickBusHandler : public forte::core::io::IODeviceMultiController {
const char* init();
void deInit();

forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor);
forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor);

void prepareLoop();
virtual void runLoop();
Expand Down
4 changes: 2 additions & 2 deletions src/modules/embrick/types/EBSlave2181.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ void FORTE_EBSlave2181::initHandles() {
EmbrickBusHandler::HandleDescriptor desc = EmbrickBusHandler::HandleDescriptor(
static_cast<CIEC_WSTRING*>(getDI(iOffset + i))->getValue(), forte::core::io::IOMapper::In, mIndex,
EmbrickBusHandler::Bit, (uint8_t) (i / 8), (uint8_t) (i % 8));
initHandle(&desc);
initHandle(desc);
}

for (int i = 0; i < oCount; i++) {
EmbrickBusHandler::HandleDescriptor desc = EmbrickBusHandler::HandleDescriptor(
static_cast<CIEC_WSTRING*>(getDI(oOffset + i))->getValue(), forte::core::io::IOMapper::Out, mIndex,
EmbrickBusHandler::Bit, (uint8_t) (i / 8), (uint8_t) (i % 8));
initHandle(&desc);
initHandle(desc);
}
}
2 changes: 1 addition & 1 deletion src/modules/embrick/types/EBSlave2301.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ void FORTE_EBSlave2301::initHandles() {
EmbrickBusHandler::HandleDescriptor desc = EmbrickBusHandler::HandleDescriptor(
static_cast<CIEC_WSTRING*>(getDI(oOffset + i))->getValue(), forte::core::io::IOMapper::Out, mIndex,
EmbrickBusHandler::Bit, (uint8_t) (i / 8), (uint8_t) (i % 8));
initHandle(&desc);
initHandle(desc);
}
}
8 changes: 4 additions & 4 deletions src/modules/wagokbus/modular/types/wagoSlaveBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ void WagoSlaveBase::initHandlesBase(size_t paNumberOfBoolInputs, size_t paNumber
for(size_t i = 0; i < paNumberOfBoolInputs; i++) {
WagoDeviceController::WagoHandleDescriptor desc = WagoDeviceController::WagoHandleDescriptor(*static_cast<CIEC_WSTRING*>(getDI(offset + i)),
forte::core::io::IOMapper::In, mIndex, CIEC_ANY::e_BOOL, static_cast<TForteUInt32>(i));
initHandle(&desc);
initHandle(desc);
}

offset += paNumberOfBoolInputs;

for(size_t i = 0; i < paNumberOfBoolOutputs; i++) {
WagoDeviceController::WagoHandleDescriptor desc = WagoDeviceController::WagoHandleDescriptor(*static_cast<CIEC_WSTRING*>(getDI(offset + i)),
forte::core::io::IOMapper::Out, mIndex, CIEC_ANY::e_BOOL, static_cast<TForteUInt32>(i));
initHandle(&desc);
initHandle(desc);
}

offset += paNumberOfBoolOutputs;

for(size_t i = 0; i < paNumberOfAnalogInputs; i++) {
WagoDeviceController::WagoHandleDescriptor desc = WagoDeviceController::WagoHandleDescriptor(*static_cast<CIEC_WSTRING*>(getDI(offset + i)),
forte::core::io::IOMapper::In, mIndex, CIEC_ANY::e_WORD, static_cast<TForteUInt32>(i));
initHandle(&desc);
initHandle(desc);
}

offset += paNumberOfAnalogInputs;

for(size_t i = 0; i < paNumberOfAnalogOutputs; i++) {
WagoDeviceController::WagoHandleDescriptor desc = WagoDeviceController::WagoHandleDescriptor(*static_cast<CIEC_WSTRING*>(getDI(offset + i)),
forte::core::io::IOMapper::Out, mIndex, CIEC_ANY::e_WORD, static_cast<TForteUInt32>(i));
initHandle(&desc);
initHandle(desc);
}
}
4 changes: 2 additions & 2 deletions src/modules/wagokbus/modular/wagoDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const char* WagoDeviceController::init() {
return 0;
}

forte::core::io::IOHandle* WagoDeviceController::initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) {
WagoHandleDescriptor desc = *static_cast<WagoHandleDescriptor*>(paHandleDescriptor);
forte::core::io::IOHandle* WagoDeviceController::initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) {
WagoHandleDescriptor &desc = *static_cast<WagoHandleDescriptor&>(paHandleDescriptor);

TForteUInt32 outputOffset;
TForteUInt32 inputOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wagokbus/modular/wagoDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WagoDeviceController : public forte::core::io::IODeviceMultiController {
protected:
const char* init();

forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor *paHandleDescriptor) override;
forte::core::io::IOHandle* initHandle(forte::core::io::IODeviceController::HandleDescriptor &paHandleDescriptor) override;

void deInit() override;

Expand Down

0 comments on commit a5773b2

Please sign in to comment.