Skip to content

Commit

Permalink
FSMA: Moved several non-trivial functions to the CC file.
Browse files Browse the repository at this point in the history
This fixes the build on Windows MinGW, because the Fsm symbol was eliminated and thus missing during linking.
  • Loading branch information
levy committed Nov 11, 2024
1 parent 1c73889 commit c45bd42
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 34 deletions.
59 changes: 59 additions & 0 deletions src/inet/common/FSMA.cc
Original file line number Diff line number Diff line change
@@ -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<void()> 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
40 changes: 6 additions & 34 deletions src/inet/common/FSMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);}
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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<void ()> action) {
delayedActions.push_back(action);
}
void insertDelayedAction(std::function<void()> action);

void executeDelayedActions() {
auto actions = delayedActions;
delayedActions.clear();
for (auto action : actions)
action();
}
void executeDelayedActions();
//@}
};

Expand Down

0 comments on commit c45bd42

Please sign in to comment.