37 managerStateMutex(10000,
"managerStateMutex")
39 setTag(
"StatechartManager");
49 StringVariantContainerBaseMap startParameters)
56 toplevelState = newToplevelState;
57 this->startParameters = startParameters;
75 if (!runningTask && managerState !=
eShutDown)
87 if (enterToplevelState)
89 toplevelState->enter(startParameters);
96 throw LocalException(
"No toplevel state was set in StatechartManager!");
118 toplevelState->disableRunFunction();
121 toplevelState =
nullptr;
126 std::unique_lock lock(eventQueueMutex);
130 runningTask->stop(
false);
133 idleCondition.notify_one();
138 runningTask->waitForFinished();
181 idleCondition.notify_all();
191 if (!runningTask || !runningTask->isRunning())
196 if (!newEvent || !receivingState)
201 EventProcessingData
data;
202 data.event = newEvent;
203 data.receivingState = receivingState;
210 std::unique_lock lock(eventQueueMutex);
211 eventQueue.push_back(
data);
213 idleCondition.notify_one();
221 while (!runningTask->isStopped())
223 EventProcessingData nextEvent;
226 std::unique_lock lock(eventQueueMutex);
228 if (eventQueue.size() > 0)
230 nextEvent = eventQueue.front();
231 eventQueue.pop_front();
237 if (nextEvent.receivingState)
243 nextEvent.receivingState->__processEvent(nextEvent.event);
251 std::unique_lock lock(eventQueueMutex);
254 if (runningTask->isStopped())
259 while (eventQueue.size() == 0 && !runningTask->isStopped())
263 idleCondition.wait(lock);
269StatechartManager::checkEvent(
const StatechartManager::EventProcessingData& eventData)
const
271 std::unique_lock lock(eventQueueMutex);
272 std::list<EventProcessingData>::const_iterator it = eventQueue.begin();
274 for (; it != eventQueue.end(); it++)
276 if (eventData.receivingState == it->receivingState)
void setTag(const LogTag &tag)
void wakeUp()
wakeUp signals the event processing thread to wake up and check for new events or shutdown conditions
void start(bool enterToplevelState=true)
StatePtr getToplevelState() const
bool setToplevelState(const armarx::StatePtr &newToplevelState, StringVariantContainerBaseMap startParameters=StringVariantContainerBaseMap())
setToplevelState sets the toplevel state of this manager.
bool addEvent(const EventPtr &newEvent, const StateControllerPtr &receivingState)
~StatechartManager() override
virtual void processEvents()
StatechartManagerState getManagerState() const
static void WaitForNextTick()
block until the next tick of the timeserver.
static bool HasTimeServer()
check if we have been initialized with a Timeserver
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
boost::unique_lock< HiddenTimedMutex > ScopedLock
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< State > StatePtr
IceInternal::Handle< Event > EventPtr
Typedef of EventPtr as IceInternal::Handle<Event> for convenience.
IceInternal::Handle< StateController > StateControllerPtr