artdaq  v3_00_01
Commandable.hh
1 #ifndef artdaq_Application_Commandable_hh
2 #define artdaq_Application_Commandable_hh
3 
4 #include <string>
5 #include <vector>
6 #include <mutex>
7 
8 #include "fhiclcpp/ParameterSet.h"
9 #include "canvas/Persistency/Provenance/RunID.h"
10 #include "artdaq/Application/Commandable_sm.h" // must be included after others
11 
12 namespace artdaq
13 {
14  class Commandable;
15 }
16 
21 {
22 public:
26  Commandable();
27 
31  Commandable(Commandable const&) = delete;
32 
36  virtual ~Commandable() = default;
37 
42  Commandable& operator=(Commandable const&) = delete;
43 
51  bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
52 
60  bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
61 
68  bool stop(uint64_t timeout, uint64_t timestamp);
69 
76  bool pause(uint64_t timeout, uint64_t timestamp);
77 
84  bool resume(uint64_t timeout, uint64_t timestamp);
85 
91  bool shutdown(uint64_t timeout);
92 
100  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
101 
109  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
110 
115  bool in_run_failure();
116 
121  virtual std::string report(std::string const&) const
122  {
123  std::lock_guard<std::mutex> lk(primary_mutex_);
124  return report_string_;
125  }
126 
131  std::string status() const;
132 
139  virtual std::string register_monitor(fhicl::ParameterSet const&)
140  {
141  return "This string is returned from Commandable::register_monitor; register_monitor should either be overridden in a derived class or this process should not have been sent the register_monitor call";
142  }
143 
150  virtual std::string unregister_monitor(std::string const&)
151  {
152  return "This string is returned from Commandable::unregister_monitor; unregister_monitor should either be overridden in a derived class or this process should not have been sent the unregister_monitor call";
153  }
154 
159  std::vector<std::string> legal_commands() const;
160 
161  // these methods provide the operations that are used by the state machine
168  virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
169 
176  virtual bool do_start(art::RunID, uint64_t, uint64_t);
177 
184  virtual bool do_stop(uint64_t, uint64_t);
185 
192  virtual bool do_pause(uint64_t, uint64_t);
193 
200  virtual bool do_resume(uint64_t, uint64_t);
201 
208  virtual bool do_shutdown(uint64_t);
209 
216  virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
217 
224  virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
225 
230  virtual void badTransition(const std::string& trans);
231 
237  virtual void BootedEnter();
238 
244  virtual void InRunExit();
245 
246 protected:
251  std::string current_state() const;
252 
253  CommandableContext fsm_;
255  std::string report_string_;
256 
257 private:
258  // 06-May-2015, KAB: added a mutex to be used in avoiding problems when
259  // requests are sent to a Commandable object from different threads. The
260  // reason that we're doing this now is that we've added the in_run_failure()
261  // transition that will generally be called from inside the Application.
262  // Prior to this, the only way that transitions were requested was via
263  // external XMLRPC commands, and those were presumed to be called one
264  // at a time. The use of scoped locks based on the mutex will prevent
265  // the in_run_failure() transition from being called at the same time as
266  // an externally requested transition. We only lock the methods that
267  // are externally called.
268  mutable std::mutex primary_mutex_;
269 };
270 
271 #endif /* artdaq_Application_Commandable_hh */
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
Definition: Commandable.cc:11
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:233
Commandable & operator=(Commandable const &)=delete
Copy Assignment operator is deleted.
virtual std::string report(std::string const &) const
Default report implementation returns current report_string.
Definition: Commandable.hh:121
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:20
virtual void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
Definition: Commandable.cc:282
virtual void InRunExit()
Perform actions upon leaving the InRun state.
Definition: Commandable.cc:306
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
Definition: Commandable.hh:150
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:254
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
Definition: Commandable.cc:247
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
Definition: Commandable.cc:144
std::string current_state() const
Return the name of the current state.
Definition: Commandable.cc:315
virtual void BootedEnter()
Perform actions upon entering the Booted state.
Definition: Commandable.cc:301
std::string status() const
Returns the current state of the Commandable.
Definition: Commandable.cc:182
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
Definition: Commandable.cc:261
virtual ~Commandable()=default
Default Destructor.
virtual bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the soft_initialize transition.
Definition: Commandable.cc:275
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
Definition: Commandable.hh:139
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
Definition: Commandable.cc:87
CommandableContext fsm_
The generated State Machine (using smc_compiler)
Definition: Commandable.hh:253
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
Definition: Commandable.cc:68
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:255
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
Definition: Commandable.cc:240
bool in_run_failure()
Actions taken when the in_run_failure state is set.
Definition: Commandable.cc:163
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
Definition: Commandable.cc:194
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
Definition: Commandable.cc:125
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
Definition: Commandable.cc:254
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
Definition: Commandable.cc:30
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
Definition: Commandable.cc:268
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
Definition: Commandable.cc:49
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:226
bool shutdown(uint64_t timeout)
Processes the shutdown transition.
Definition: Commandable.cc:106