/** * @file * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) * @copyright Simplified BSD * * @cond * This program is free software: you can redistribute it and/or modify * it under the terms of the FreeBSD license as published by the FreeBSD * project. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the FreeBSD license along with this * program. If not, see . * @endcond */ #ifndef CHARTTOFSM_H_IOKPYEBY #define CHARTTOFSM_H_IOKPYEBY #include "uscxml/DOMUtils.h" #include "uscxml/interpreter/InterpreterDraft6.h" #include #include #include #include namespace uscxml { class GlobalState; class GlobalTransition; class USCXML_API GlobalState { public: GlobalState() {} GlobalState(const Arabica::XPath::NodeSet& activeStates, const Arabica::XPath::NodeSet& alreadyEnteredStates, // we need to remember for binding=late const std::map >& historyStates); Arabica::XPath::NodeSet activeStates; Arabica::XPath::NodeSet alreadyEnteredStates; std::map > historyStates; std::map incoming; std::map outgoing; std::string stateId; bool isFinal; }; class USCXML_API GlobalTransition { public: class Action { public: Arabica::DOM::Node onEntry; Arabica::DOM::Node onExit; Arabica::DOM::Node transition; Arabica::DOM::Node entered; Arabica::DOM::Node exited; Arabica::DOM::Node invoke; Arabica::DOM::Node uninvoke; }; GlobalTransition(const Arabica::XPath::NodeSet& transitions, DataModel dataModel); bool isValid; // constructor will determine, calling code will delete if not bool isEventless; // whether or not all our transitions are eventless bool isTargetless; // whether or not all our transitions are eventless bool isSubset; // there is a superset to this set std::vector firstElemPerLevel; std::vector nrElemPerLevel; std::vector prioPerLevel; Arabica::XPath::NodeSet transitions; // constituting transitions std::list eventNames; // the list of longest event names that will enable this set std::string eventDesc; // space-seperated eventnames for convenience std::string condition; // conjunction of all the set's conditions // executable content we gathered when we took the transition std::list actions; Arabica::XPath::NodeSet entered; Arabica::XPath::NodeSet exited; Arabica::XPath::NodeSet invoke; Arabica::XPath::NodeSet uninvoke; std::string transitionId; std::string source; std::string destination; protected: std::list getCommonEvents(const Arabica::XPath::NodeSet& transitions); }; class USCXML_API FlatteningInterpreter : public InterpreterDraft6, public InterpreterMonitor { public: FlatteningInterpreter(const Arabica::DOM::Document& doc); virtual ~FlatteningInterpreter(); Arabica::DOM::Document getDocument() const; // overwrite to return flat FSM InterpreterState interpret(); protected: // gather executable content per microstep void executeContent(const Arabica::DOM::Node& content, bool rethrow = false); void executeContent(const Arabica::DOM::NodeList& content, bool rethrow = false); void executeContent(const Arabica::XPath::NodeSet& content, bool rethrow = false); // invoke and uninvoke virtual void invoke(const Arabica::DOM::Node& element); virtual void cancelInvoke(const Arabica::DOM::Node& element); // override to do nothing void send(const Arabica::DOM::Node& element) {} void internalDoneSend(const Arabica::DOM::Node& state); // InterpreterMonitor virtual void beforeMicroStep(Interpreter interpreter); virtual void onStableConfiguration(Interpreter interpreter); virtual void beforeExitingState(Interpreter interpreter, const Arabica::DOM::Element& state, bool moreComing); virtual void beforeEnteringState(Interpreter interpreter, const Arabica::DOM::Element& state, bool moreComing); virtual void beforeTakingTransition(Interpreter interpreter, const Arabica::DOM::Element& transition, bool moreComing); void explode(); void labelTransitions(); void weightTransitions(); void createDocument(); Arabica::DOM::Node globalStateToNode(GlobalState* globalState); Arabica::DOM::Node globalTransitionToNode(GlobalTransition* globalTransition); GlobalState* _start; GlobalTransition* _currGlobalTransition; int maxDepth; int maxOrder; Arabica::DOM::Document _flatDoc; std::map _globalConf; }; class USCXML_API ChartToFSM { public: static Interpreter flatten(const Interpreter& other); }; } #endif /* end of include guard: CHARTTOFSM_H_IOKPYEBY */