Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FBContainer for all Function Blocks #198

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arch/be_m1/fortemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ SINT32 CFORTEModule::AppEOI(VOID){
*-------------------------------------------------------------------------*/
SINT32 CFORTEModule::AppStop(VOID){
if(0 != mDev){
mDev->changeFBExecutionState(EMGMCommandType::Stop);
mDev->changeExecutionState(EMGMCommandType::Stop);
}

return OK;
Expand Down
29 changes: 11 additions & 18 deletions src/core/basicfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ bool CBasicFB::initialize() {
if(!CFunctionBlock::initialize()) {
return false;
}
// initialize all internal FBs
for(TFBContainerList::iterator it(getChildren().begin()); it != getChildren().end(); ++it){
if((*it)->isFB()) {
if(!static_cast<CFunctionBlock &>(**it).initialize()){
return false;
}
}
}

if((nullptr != cmVarInternals) && (cmVarInternals->mNumIntVars)) {
size_t basicVarsDataSize = calculateBasicFBVarsDataSize(*cmVarInternals);
mBasicFBVarsData = basicVarsDataSize ? operator new(basicVarsDataSize) : nullptr;
Expand All @@ -53,6 +62,8 @@ CBasicFB::~CBasicFB() {
}
operator delete(mBasicFBVarsData);
mBasicFBVarsData = nullptr;
//CFBContainer shall not handle internal function blocks therefore we are clearing the list here
getChildren().clear();
}

void CBasicFB::setInitialValues() {
Expand Down Expand Up @@ -103,24 +114,6 @@ CIEC_ANY* CBasicFB::getInternalVar(CStringDictionary::TStringId paInternalName)
return retVal;
}

TFunctionBlockPtr *CBasicFB::createInternalFBs(const size_t paAmountOfInternalFBs, const SCFB_FBInstanceData *const paInternalFBData, forte::core::CFBContainer &paContainer) {
TFunctionBlockPtr *internalFBs = nullptr;
if (paAmountOfInternalFBs) {
internalFBs = new TFunctionBlockPtr[paAmountOfInternalFBs];
for(size_t i = 0; i < paAmountOfInternalFBs; ++i) {
internalFBs[i] = CTypeLib::createFB(paInternalFBData[i].mFBInstanceNameId, paInternalFBData[i].mFBTypeNameId, paContainer);
}
}
return internalFBs;
}

void CBasicFB::deleteInternalFBs(const size_t paAmountOfInternalFBs, TFunctionBlockPtr *const paInternalFBs) {
for (size_t i = 0; i < paAmountOfInternalFBs; ++i) {
delete paInternalFBs[i];
}
delete[] paInternalFBs;
};

int CBasicFB::toString(char *paValue, size_t paBufferSize) const {
int usedBuffer = CFunctionBlock::toString(paValue, paBufferSize);
if (usedBuffer < 1 || cmVarInternals == nullptr || (cmVarInternals != nullptr && cmVarInternals->mNumIntVars == 0)) {
Expand Down
20 changes: 0 additions & 20 deletions src/core/basicfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,9 @@ class CBasicFB : public CFunctionBlock {
return const_cast<CBasicFB *>(this)->getVarInternal(paVarIntNum);
}

virtual size_t getInternalFBNum() const {
return 0;
}

virtual const SCFB_FBInstanceData *getInternalFBDefinition(size_t) const {
return nullptr;
}

virtual CFunctionBlock *getInternalFB(size_t) {
return nullptr;
}

const CFunctionBlock *getInternalFB(size_t paIntFBNum) const {
return const_cast<CBasicFB *>(this)->getInternalFB(paIntFBNum);
}

CIEC_STATE mECCState; //! the current state of the ecc. start value is 0 = initial state id
const SInternalVarsInformation *const cmVarInternals; //!< struct holding the information on the internal vars.

static TFunctionBlockPtr *createInternalFBs(const size_t paAmountOfInternalFBs, const SCFB_FBInstanceData *const pa_InternalFBData, forte::core::CFBContainer &paContainer);

static void deleteInternalFBs(const size_t paAmountOfInternalFBs, TFunctionBlockPtr *paInternalFBs);

static size_t calculateBasicFBVarsDataSize(const SInternalVarsInformation &paVarInternals);

void *mBasicFBVarsData;
Expand Down
29 changes: 3 additions & 26 deletions src/core/cfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
CCompositeFB::CCompositeFB(forte::core::CFBContainer &paContainer, const SFBInterfaceSpec *paInterfaceSpec,
CStringDictionary::TStringId paInstanceNameId, const SCFB_FBNData & paFBNData) :
CFunctionBlock(paContainer, paInterfaceSpec, paInstanceNameId),
forte::core::CFBContainer(paInstanceNameId, paContainer, paFBNData.mNumFBs),
mIf2InDConns(nullptr),
mIn2IfDConns(nullptr),
cmFBNData(paFBNData),
Expand Down Expand Up @@ -117,38 +116,16 @@ bool CCompositeFB::configureGenericDO(TPortId paDOPortId, const CIEC_ANY &paRefV
return bRetVal;
}

EMGMResponse CCompositeFB::changeFBExecutionState(EMGMCommandType paCommand){
EMGMResponse nRetVal = CFunctionBlock::changeFBExecutionState(paCommand);
if (EMGMResponse::Ready == nRetVal) {
nRetVal = CFBContainer::changeContainedFBsExecutionState(paCommand);
}
EMGMResponse CCompositeFB::changeExecutionState(EMGMCommandType paCommand){
EMGMResponse nRetVal = CFunctionBlock::changeExecutionState(paCommand);

//Update FB parameters that maybe got overwritten by default values of the FB
if((EMGMCommandType::Reset == paCommand) && (E_FBStates::Idle == getState())){
setParams();
}
return nRetVal;
}

#ifdef FORTE_SUPPORT_MONITORING

CFunctionBlock *CCompositeFB::getFB(forte::core::TNameIdentifier::CIterator &paNameListIt){
CFunctionBlock *retVal = forte::core::CFBContainer::getFB(*paNameListIt);

if(retVal != nullptr){
if(!paNameListIt.isLastEntry()){
//we are looking for a child of this fB
++paNameListIt;
retVal = retVal->getFB(paNameListIt);
}
} else {
//check if it is an adapter of the function block
retVal = CFunctionBlock::getFB(paNameListIt);
}
return retVal;
}

#endif

CIEC_ANY *CCompositeFB::getVar(CStringDictionary::TStringId *paNameList, unsigned int paNameListSize){
CIEC_ANY *retVal = nullptr;

Expand Down
8 changes: 2 additions & 6 deletions src/core/cfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ GENERATE_CONNECTION_PORT_ID_2_ARG(CStringDictionary::scmInvalidStringId, PortNam
/*!\ingroup CORE
* \brief Class for handling firmware composite function blocks.
*/
class CCompositeFB: public CFunctionBlock, public forte::core::CFBContainer {
class CCompositeFB: public CFunctionBlock {

public:
/*! \brief Indicator that the given FB id is an adapter.
Expand Down Expand Up @@ -124,11 +124,7 @@ class CCompositeFB: public CFunctionBlock, public forte::core::CFBContainer {
CIEC_ANY* getVar(CStringDictionary::TStringId *paNameList,
unsigned int paNameListSize) override;

EMGMResponse changeFBExecutionState(EMGMCommandType paCommand) override;

#ifdef FORTE_SUPPORT_MONITORING
CFunctionBlock *getFB(forte::core::TNameIdentifier::CIterator &paNameListIt) override;
#endif
EMGMResponse changeExecutionState(EMGMCommandType paCommand) override;

protected:
CDataConnection *getIn2IfConUnchecked(TPortId paIndex) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/cominfra/basecommfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ CBaseCommFB::~CBaseCommFB() {
}
}

EMGMResponse CBaseCommFB::changeFBExecutionState(EMGMCommandType paCommand) {
EMGMResponse retVal = CEventSourceFB::changeFBExecutionState(paCommand);
EMGMResponse CBaseCommFB::changeExecutionState(EMGMCommandType paCommand) {
EMGMResponse retVal = CEventSourceFB::changeExecutionState(paCommand);
if ((EMGMResponse::Ready == retVal) && (EMGMCommandType::Kill == paCommand)) {
//when we are killed we'll close the connection so that it can safely be opened again after an reset
closeConnection();
Expand Down
2 changes: 1 addition & 1 deletion src/core/cominfra/basecommfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace forte {
public:
~CBaseCommFB() override;

EMGMResponse changeFBExecutionState(EMGMCommandType paCommand) override;
EMGMResponse changeExecutionState(EMGMCommandType paCommand) override;

forte::com_infra::EComServiceType getComServiceType() const {
return mCommServiceType;
Expand Down
4 changes: 2 additions & 2 deletions src/core/cominfra/commfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ CCommFB::CCommFB(const CStringDictionary::TStringId paInstanceNameId, forte::cor

CCommFB::~CCommFB() = default;

EMGMResponse CCommFB::changeFBExecutionState(EMGMCommandType paCommand) {
EMGMResponse retVal = CEventSourceFB::changeFBExecutionState(paCommand);
EMGMResponse CCommFB::changeExecutionState(EMGMCommandType paCommand) {
EMGMResponse retVal = CEventSourceFB::changeExecutionState(paCommand);
if ((EMGMResponse::Ready == retVal) && (EMGMCommandType::Kill == paCommand)) {
//when we are killed we'll close the connection so that it can safely be opened again after an reset
closeConnection();
Expand Down
2 changes: 1 addition & 1 deletion src/core/cominfra/commfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace forte {
public:
~CCommFB() override;

EMGMResponse changeFBExecutionState(EMGMCommandType paCommand) override;
EMGMResponse changeExecutionState(EMGMCommandType paCommand) override;

protected:
CCommFB(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer, forte::com_infra::EComServiceType paCommServiceType);
Expand Down
6 changes: 3 additions & 3 deletions src/core/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EMGMResponse CDevice::executeMGMCommand(forte::core::SManagementCMD &paCommand){
retval = CResource::executeMGMCommand(paCommand);
}
else{
CResource *res = static_cast<CResource *>(CFBContainer::getFB(paCommand.mDestination));
CResource *res = static_cast<CResource *>(CFBContainer::getChild(paCommand.mDestination));
if(nullptr != res){
paCommand.mDestination = CStringDictionary::scmInvalidStringId;
retval = res->executeMGMCommand(paCommand);
Expand All @@ -33,9 +33,9 @@ EMGMResponse CDevice::executeMGMCommand(forte::core::SManagementCMD &paCommand){
return retval;
}

EMGMResponse CDevice::changeFBExecutionState(EMGMCommandType paCommand){
EMGMResponse CDevice::changeExecutionState(EMGMCommandType paCommand){
if(EMGMCommandType::Kill == paCommand){
mDeviceExecution.disableHandlers();
}
return CResource::changeFBExecutionState(paCommand);
return CResource::changeExecutionState(paCommand);
}
4 changes: 2 additions & 2 deletions src/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CDevice : public CResource {
* \return 0 on success -1 on error
*/
virtual int startDevice() {
changeFBExecutionState(EMGMCommandType::Start);
changeExecutionState(EMGMCommandType::Start);
return 1;
}

Expand All @@ -65,7 +65,7 @@ class CDevice : public CResource {
*/
EMGMResponse executeMGMCommand(forte::core::SManagementCMD &paCommand) override;

EMGMResponse changeFBExecutionState(EMGMCommandType paCommand) override;
EMGMResponse changeExecutionState(EMGMCommandType paCommand) override;

//! Retrieve the device execution of this device
CDeviceExecution &getDeviceExecution() {
Expand Down
Loading