Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "EventFilter/ResourceBroker/interface/RBStateMachine.h"
00013 #include "EventFilter/ResourceBroker/interface/SharedResources.h"
00014
00015 #include <typeinfo>
00016 #include <fstream>
00017
00018 using std::cout;
00019 using std::endl;
00020 using std::string;
00021 using namespace evf::rb_statemachine;
00022
00023 RBStateMachine::RBStateMachine(xdaq::Application* app, SharedResourcesPtr_t sr) :
00024 app_(app),
00025 sharedResources_(sr),
00026 rcmsStateNotifier_(app_->getApplicationLogger(),
00027 app_->getApplicationDescriptor(),
00028 app_->getApplicationContext()), visibleStateName_("N/A"),
00029 internalStateName_("N/A"), firstTimeInHalted_(true) {
00030
00031
00032 sharedResources_->setFsmPointer(this);
00033
00034
00035 pthread_rwlockattr_t attr;
00036 pthread_rwlockattr_init(&attr);
00037
00038 #ifndef __APPLE__
00039
00040 pthread_rwlockattr_setkind_np(&attr,
00041 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
00042 #endif
00043
00044 pthread_rwlock_init(&transitionLock_, &attr);
00045
00046 }
00047
00048 RBStateMachine::~RBStateMachine() {
00049 pthread_rwlock_destroy(&transitionLock_);
00050 cout << "State machine DESTROYED!" << endl;
00051 }
00052
00053 BaseState const& RBStateMachine::getCurrentState() const throw (std::bad_cast) {
00054 return state_cast<BaseState const&> ();
00055 }
00056
00057 void RBStateMachine::setExternallyVisibleState(const std::string& s) {
00058 visibleStateName_ = s;
00059 updateWebGUIExternalState(visibleStateName_);
00060 }
00061
00062 void RBStateMachine::setInternalStateName(const std::string& s) {
00063 internalStateName_ = s;
00064 updateWebGUIInternalState(internalStateName_);
00065 }
00066
00067
00068 xdata::Bag<xdaq2rc::ClassnameAndInstance>* RBStateMachine::rcmsStateListener() {
00069 return rcmsStateNotifier_.getRcmsStateListenerParameter();
00070 }
00071
00072
00073 xdata::Boolean* RBStateMachine::foundRcmsStateListener() {
00074 return rcmsStateNotifier_.getFoundRcmsStateListenerParameter();
00075 }
00076
00077 void RBStateMachine::findRcmsStateListener(xdaq::Application* app) {
00078 rcmsStateNotifier_.findRcmsStateListener();
00079 rcmsStateNotifier_.subscribeToChangesInRcmsStateListener(
00080 app->getApplicationInfoSpace());
00081 }
00082
00083 void RBStateMachine::rcmsStateChangeNotify() {
00084 string state = getExternallyVisibleState();
00085 try {
00086 cout << "-->RCMS state change notify: " << state << endl;
00087 rcmsStateNotifier_.stateChanged(state,
00088 "ResourceBroker has reached target state " + state);
00089 } catch (...) {
00090 cout << "Failed to notify state change: " << state << endl;
00091 }
00092 }
00093
00094 void RBStateMachine::updateWebGUIExternalState(string newStateName) const {
00095 sharedResources_->updateGUIExternalState(newStateName);
00096 }
00097
00098 void RBStateMachine::updateWebGUIInternalState(string newStateName) const {
00099 sharedResources_->updateGUIInternalState(newStateName);
00100 }