From c45bd42e20563c9964440ce74550f5906ab51c43 Mon Sep 17 00:00:00 2001 From: Levente Meszaros Date: Mon, 11 Nov 2024 12:07:36 +0100 Subject: [PATCH] FSMA: Moved several non-trivial functions to the CC file. This fixes the build on Windows MinGW, because the Fsm symbol was eliminated and thus missing during linking. --- src/inet/common/FSMA.cc | 59 +++++++++++++++++++++++++++++++++++++++++ src/inet/common/FSMA.h | 40 +++++----------------------- 2 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 src/inet/common/FSMA.cc diff --git a/src/inet/common/FSMA.cc b/src/inet/common/FSMA.cc new file mode 100644 index 00000000000..fbfeb341049 --- /dev/null +++ b/src/inet/common/FSMA.cc @@ -0,0 +1,59 @@ +// +// Copyright (C) 2024 OpenSim Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later +// + +#include "inet/common/FSMA.h" + +namespace inet { + +Register_Class(Fsm); + +void Fsm::copy(const Fsm &other) +{ + stateName = other.stateName; + state = other.state; +} + +Fsm& Fsm::operator=(const Fsm &vs) +{ + if (this == &vs) + return *this; + cOwnedObject::operator=(vs); + copy(vs); + return *this; +} + +void Fsm::setState(int state, const char *stateName) +{ + this->state = state; + this->stateName = stateName; + if (stateChangedSignal != -1) + cSimulation::getActiveSimulation()->getContextModule()->emit(stateChangedSignal, state); +} + +void Fsm::insertDelayedAction(std::function action) +{ + delayedActions.push_back(action); +} + +inline void Fsm::executeDelayedActions() +{ + auto actions = delayedActions; + delayedActions.clear(); + for (auto action : actions) + action(); +} + +std::string Fsm::str() const +{ + std::stringstream out; + if (!stateName) + out << "state: " << state; + else + out << "state: " << stateName << " (" << state << ")"; + return out.str(); +} + +} // namespace inet diff --git a/src/inet/common/FSMA.h b/src/inet/common/FSMA.h index 7e8d59fbeb0..1e73b891306 100644 --- a/src/inet/common/FSMA.h +++ b/src/inet/common/FSMA.h @@ -106,10 +106,7 @@ class SIM_API Fsm : public cOwnedObject bool busy = false; private: - void copy(const Fsm& other) { - stateName = other.stateName; - state = other.state; - } + void copy(const Fsm &other); virtual void parsimPack(cCommBuffer *) const override {throw cRuntimeError(this, E_CANTPACK);} virtual void parsimUnpack(cCommBuffer *) override {throw cRuntimeError(this, E_CANTPACK);} @@ -135,13 +132,7 @@ class SIM_API Fsm : public cOwnedObject * Assignment operator. The name member is not copied; * see cOwnedObject's operator=() for more details. */ - Fsm& operator=(const Fsm& vs) { - if (this == &vs) - return *this; - cOwnedObject::operator=(vs); - copy(vs); - return *this; - } + Fsm& operator =(const Fsm &vs); //@} /** @name Redefined cObject member functions. */ @@ -157,14 +148,7 @@ class SIM_API Fsm : public cOwnedObject * Produces a one-line description of the object's contents. * See cObject for more details. */ - virtual std::string str() const override { - std::stringstream out; - if (!stateName) - out << "state: " << state; - else - out << "state: " << stateName << " (" << state << ")"; - return out.str(); - } + virtual std::string str() const override; //@} /** @name FSM functions. */ @@ -194,23 +178,11 @@ class SIM_API Fsm : public cOwnedObject * * @see FSM_Goto */ - void setState(int state, const char *stateName) { - this->state = state; - this->stateName = stateName; - if (stateChangedSignal != -1) - cSimulation::getActiveSimulation()->getContextModule()->emit(stateChangedSignal, state); - } + void setState(int state, const char *stateName); - void insertDelayedAction(std::function action) { - delayedActions.push_back(action); - } + void insertDelayedAction(std::function action); - void executeDelayedActions() { - auto actions = delayedActions; - delayedActions.clear(); - for (auto action : actions) - action(); - } + void executeDelayedActions(); //@} };