#include <CStateMonitor.h>CStateMonitorBase
CStateMonitorBase(std::string transitionRequestUri, std::string statePublisherUri, CStateMonitorBase::InitCallback cb) throws ;
std::string requestTransition(std::string transitionName) throws ;
void run() throws ;
CZMQEventLoop& getEventLoop() throws ;
zmq::context_t* getContext() throws ;
std::string getState() throws ;
protected:virtual void initialState(std::string state) throws ;
virtual void transition(std::string newState) throws ;
This class is intended to be used as a base class for programs
that must monitor the state of the state manager program. The
methods initialState
and
transition
are intended to be
overidden by the actual application, as these methods are the
ones that are called when state are entered. See also
CStateMonitor
which is a good concrete
example of a derived class.
This object contains a CZMQEventLoop
which
can also be obtained by the application software.
CStateMonitorBase(std::string transitionRequestUri, std::string statePublisherUri, CStateMonitorBase::InitCallback cb)
throws ;
Constructs the object. The transitionRequestUri
is the URI that specifies the end point on which the state
manager is listening for transition requests. This is normally
constructed by looking up the StateRequest service
in the system that is running the state manager to get the port
number. The form of the URI is
tcp://hostname:portnum
Similarly, statePublisherUri
is the
URI of the endpoint on which the state manager periodically
publishes it state and publishes state transitions. It
can usually be found by using the port manager to look
up the StatePublish service in the
host that is running the state manager.
std::string requestTransition(std::string transitionName)
throws ;
Requests that the state transition perform the state
transition indicated by transitionName
the function retuns the reply from the state manager.
This is a string that is either OK if the
transition could be performed or FAIL followed
by human readable text that indicates why the state
transition could not be performed.
void run()
throws ;
Runs the event loop. The event loop runs until the program
exits. If you need more complex behavior you can invoke
getEventLoop
to obtain the event
loop and use either its poll
or
pollForever
with a callback to
achieve that.
CZMQEventLoop& getEventLoop()
throws ;
Returns a reference to the event loop that will be used
to monitor the state manager. This event loop
is the one that is used by the run
method above.
zmq::context_t* getContext()
throws ;
Returns a pointer to the ZeroMQ context object that is
used by the CStateMonitor
to
create zmq::socket_t
objects.
If you will create your own sockets, it is best to use
this context rather than creating a new one.
std::string getState()
throws ;
Returns the current state of the state manager. If that is not yet known, the function returns an empty string.
virtual void initialState(std::string state)
throws ;
This method is called when the event loop either gets a state broadcast or when the state manager makes a state transition when the state is not yet known. Derived classes that override this should invoke this base class method at some meaningful point in their initial state processing.
In the base class implementation:
The current state is set to state
, and
the subscription for state broacasts is removed. From this
point on, only state transitions will activate us.
virtual void transition(std::string newState)
throws ;
This method is called when the evetn loop gets a state transition message from the state manager. If you override this method in a derived class you should invoke this method at some point during your processing of state transitions.
If the prior state is not known, initialState
is invoked. Otherwise, the new state (newState
)
is memorized by the function, so that getState
will return it.
This is a pointer to a function that takes as a single parameter
a pointer to the CStateMonitorBase
that is
being constructed.
When called, any of the CStateMonitorBase
methods can be safely called. The intent is that this
callback might need to obtain the event loop and register
callbacks for other objects besides the sockets registered
with the state and transition publications.
The callback might also obtain the ZeroMQ context and use it to create additional ZeroMQ sockets.