CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RBStateMachine.cc
Go to the documentation of this file.
1 //
3 // RBStateMachine.cc
4 // -------
5 //
6 // Finite state machine for the Resource Broker.
7 //
8 // Created on: Dec 9, 2011
9 // Andrei Spataru : aspataru@cern.ch
11 
14 
15 #include <typeinfo>
16 #include <fstream>
17 
18 using std::cout;
19 using std::endl;
20 using std::string;
21 using namespace evf::rb_statemachine;
22 
24  app_(app),
25  sharedResources_(sr),
26  rcmsStateNotifier_(app_->getApplicationLogger(),
27  app_->getApplicationDescriptor(),
28  app_->getApplicationContext()), visibleStateName_("N/A"),
29  internalStateName_("N/A"), firstTimeInHalted_(true) {
30 
31  // pass pointer of FSM to shared resources
32  sharedResources_->setFsmPointer(this);
33 
34  // make the RW Lock writer-biased
35  pthread_rwlockattr_t attr;
36  pthread_rwlockattr_init(&attr);
37 
38 #ifndef __APPLE__
39  // unsupported on Mac OS
40  pthread_rwlockattr_setkind_np(&attr,
41  PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
42 #endif
43 
44  pthread_rwlock_init(&transitionLock_, &attr);
45 
46 }
47 
49  pthread_rwlock_destroy(&transitionLock_);
50  cout << "State machine DESTROYED!" << endl;
51 }
52 
53 BaseState const& RBStateMachine::getCurrentState() const throw (std::bad_cast) {
54  return state_cast<BaseState const&> ();
55 }
56 
58  return const_cast<BaseState &> (state_cast<BaseState const&> ());
59 }
60 
61 void RBStateMachine::setExternallyVisibleState(const std::string& s) {
64 }
65 
66 void RBStateMachine::setInternalStateName(const std::string& s) {
69 }
70 
71 // get the RCMS StateListener parameter (classname/instance)
72 xdata::Bag<xdaq2rc::ClassnameAndInstance>* RBStateMachine::rcmsStateListener() {
73  return rcmsStateNotifier_.getRcmsStateListenerParameter();
74 }
75 
76 // report if RCMS StateListener was found
78  return rcmsStateNotifier_.getFoundRcmsStateListenerParameter();
79 }
80 
81 void RBStateMachine::findRcmsStateListener(xdaq::Application* app) {
82  rcmsStateNotifier_.findRcmsStateListener(); //might not be needed
83  rcmsStateNotifier_.subscribeToChangesInRcmsStateListener(
84  app->getApplicationInfoSpace());
85 }
86 
89  try {
90  cout << "-->RCMS state change notify: " << state << endl;
91  rcmsStateNotifier_.stateChanged(state,
92  "ResourceBroker has reached target state " + state);
93  } catch (...) {
94  cout << "Failed to notify state change: " << state << endl;
95  }
96 }
97 
98 void RBStateMachine::updateWebGUIExternalState(string newStateName) const {
99  sharedResources_->updateGUIExternalState(newStateName);
100 }
101 
102 void RBStateMachine::updateWebGUIInternalState(string newStateName) const {
103  sharedResources_->updateGUIInternalState(newStateName);
104 }
boost::shared_ptr< SharedResources > SharedResourcesPtr_t
xdaq2rc::RcmsStateNotifier rcmsStateNotifier_
RBStateMachine(xdaq::Application *app, SharedResourcesPtr_t sr)
void updateWebGUIInternalState(std::string newStateName) const
void updateWebGUIExternalState(std::string newStateName) const
BaseState & getCurrentStateNC() const
void findRcmsStateListener(xdaq::Application *app)
tuple attr
Definition: asciidump.py:432
xdata::Bag< xdaq2rc::ClassnameAndInstance > * rcmsStateListener()
void setInternalStateName(const std::string &s)
void setExternallyVisibleState(const std::string &s)
char state
Definition: procUtils.cc:75
BaseState const & getCurrentState() const
tuple cout
Definition: gather_cfg.py:121