14 #include <boost/shared_ptr.hpp>
80 State(
const int value,
const std::string& label, StateHandler handler,
100 StateHandler handler_;
135 void add(
const int value,
const std::string& label, StateHandler handler,
278 static const int NEW_ST = 0;
348 virtual void runModel(
unsigned int event);
417 void defineEvent(
unsigned int value,
const std::string& label);
428 const EventPtr&
getEvent(
unsigned int value);
498 void defineState(
unsigned int value,
const std::string& label,
499 StateHandler handler,
509 const StatePtr
getState(
unsigned int value);
561 void transition(
unsigned int state,
unsigned int event);
572 void abortModel(
const std::string& explanation);
746 void setStateInternal(
unsigned int state);
758 void postNextEventInternal(
unsigned int event);
765 bool isModelNewInternal()
const;
775 std::string getEventLabelInternal(
const int event)
const;
785 std::string getStateLabelInternal(
const int state)
const;
797 std::string getContextStrInternal()
const;
809 std::string getPrevContextStrInternal()
const;
818 bool dictionaries_initted_;
821 unsigned int curr_state_;
824 unsigned int prev_state_;
827 unsigned int last_event_;
830 unsigned int next_event_;
842 boost::shared_ptr<std::mutex> mutex_;
void defineState(unsigned int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
Adds an state value and associated label to the set of states.
static const int NOP_EVT
Signifies that no event has occurred.
bool shouldPause()
Indicates if the state model should pause upon entering this state.
static const int FAIL_EVT
Event issued to abort the model execution.
This file defines classes: LabeledValue and LabeledValueSet.
void add(const int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing)
Adds a state definition to the set of states.
StatePausing
State machine pausing modes.
Implements a finite state machine.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
bool doOnExit()
Checks if on exit flag is true.
const StatePtr getState(unsigned int value)
Fetches the state referred to by value.
std::function< void()> StateHandler
Defines a pointer to an instance method for handling a state.
std::string getStateLabel(const int state) const
Fetches the label associated with an state value.
static const int NEW_ST
State that a state model is in immediately after construction.
void abortModel(const std::string &explanation)
Aborts model execution.
StateModelError(const char *file, size_t line, const char *what)
static const int START_EVT
Event issued to start the model execution.
std::string getPrevContextStr() const
Convenience method which returns a string rendition of the previous state and last event...
State(const int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
Constructor.
unsigned int getLastEvent() const
Fetches the model's last event.
void setState(unsigned int state)
Sets the current state to the given state value.
void run()
Invokes the State's handler.
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
void endModel()
Conducts a normal transition to the end of the model.
unsigned int getCurrState() const
Fetches the model's current state.
LabeledValuePtr EventPtr
Define Event pointer.
virtual void verifyStates()
Validates the contents of the set of states.
boost::shared_ptr< StateModel > StateModelPtr
Defines a pointer to a StateModel.
virtual void runModel(unsigned int event)
Processes events through the state model.
bool isModelRunning() const
Returns whether or not the model is running.
boost::shared_ptr< State > StatePtr
Defines a shared pointer to a State.
bool doOnEntry()
Checks if on entry flag is true.
boost::shared_ptr< LabeledValue > LabeledValuePtr
Defines a shared pointer to a LabeledValue instance.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
virtual ~State()
Destructor.
Implements the concept of a constant value with a text label.
void nopStateHandler()
An empty state handler.
static const int SM_DERIVED_EVENT_MIN
Value at which custom events in a derived class should begin.
LabeledValue Event
Define an Event.
const StatePtr getState(int value)
Fetches a state for the given value.
static const int SM_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool isModelNew() const
Returns whether or not the model is new.
std::string getContextStr() const
Convenience method which returns a string rendition of the current state and next event...
void startModel(const int start_state)
Begins execution of the model.
Defines a State within the State Model.
virtual ~StateSet()
Destructor.
void unpauseModel()
Unpauses state model.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual void defineStates()
Populates the set of states.
unsigned int getPrevState() const
Fetches the model's previous state.
Implements a set of unique LabeledValues.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
bool isModelWaiting() const
Returns whether or not the model is waiting.
void initDictionaries()
Initializes the event and state dictionaries.
const StatePtr getStateInternal(unsigned int value)
Fetches the state referred to by value.
bool didModelFail() const
Returns whether or not the model failed.
static const int END_ST
Final state, all the state model has reached its conclusion.
bool isModelDone() const
Returns whether or not the model has finished execution.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
unsigned int getNextEvent() const
Fetches the model's next event.
Implements a unique set or dictionary of states.
bool isModelPaused() const
Returns whether or not the model is paused.
Thrown if the state machine encounters a general error.
virtual void verifyEvents()
Validates the contents of the set of events.
static const int END_EVT
Event issued to end the model execution.
virtual ~StateModel()
Destructor.
virtual void defineEvents()
Populates the set of events.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.