FACT++  1.0
string StateMachineImp::SetCurrentState ( int  state,
const char *  txt = "",
const std::string &  cmd = "" 
)
protectedvirtual

This is an internal function to do some action in case of a state change, like updating the corresponding service.

This function is a helpter function to do all the corresponding action if the state machine decides to change its state.

If state is equal to the current state (fCurrentState) nothing is done. Then the service STATE (fSrcState) is updated with the new state and the text message and updateService() is called to distribute the update to all clients.

In addition a log message is created and set via UpdateMsg.

Parameters
stateThe new state which should be applied
txtA text corresponding to the state change which is distributed together with the state itself for convinience.
cmdThis argument can be used to give an additional name of the function which is reponsible for the state change. It will be included in the message
Returns
return the new state which was set or -1 in case of no change

Reimplemented in StateMachineDim.

Definition at line 772 of file StateMachineImp.cc.

References fCurrentState, Time::GetAsStr(), GetStateDescription(), MessageImp::Message(), MessageImp::Out(), and str.

Referenced by HandleNewState(), Run(), StateMachineDim::SetCurrentState(), SetNotReady(), SetReady(), and Wrapper().

773 {
774  if (state==fCurrentState)
775  {
776  Out() << " -- " << Time().GetAsStr("%H:%M:%S.%f") << " - State " << GetStateDescription(state) << " already set... ";
777  if (!cmd.empty())
778  Out() << "'" << cmd << "' ignored.";
779  Out() << endl;
780  return "";
781  }
782 
783  const int old = fCurrentState;
784 
785  const string nold = GetStateDescription(old);
786  const string nnew = GetStateDescription(state);
787 
788  string msg = nnew + " " + txt;
789  if (!cmd.empty())
790  msg += " (" + cmd + ")";
791 
792  fCurrentState = state;
793 
794  // State might have changed already again...
795  // Not very likely, but possible. That's why state is used
796  // instead of fCurrentState.
797 
798  ostringstream str;
799  str << "State Transition from " << nold << " to " << nnew << " (" << txt;
800  if (!cmd.empty())
801  str << ": " << cmd;
802  str << ")";
803  Message(str);
804 
805  return msg;
806 }
int fCurrentState
Name of the state-machine / server (e.g. DRIVE)
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
std::ostream & Out() const
Definition: MessageImp.h:73
const std::string GetStateDescription() const
int Message(const std::string &str)
Definition: MessageImp.h:46
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240

+ Here is the call graph for this function:

+ Here is the caller graph for this function: