00001 #ifndef artdaq_Application_Commandable_hh
00002 #define artdaq_Application_Commandable_hh
00003
00004 #include <string>
00005 #include <vector>
00006 #include <mutex>
00007
00008 #include "fhiclcpp/ParameterSet.h"
00009 #include "canvas/Persistency/Provenance/RunID.h"
00010 #include "artdaq/Application/Commandable_sm.h"
00011
00012 namespace artdaq
00013 {
00014 class Commandable;
00015 }
00016
00020 class artdaq::Commandable
00021 {
00022 public:
00026 Commandable();
00027
00031 Commandable(Commandable const&) = delete;
00032
00036 virtual ~Commandable() = default;
00037
00042 Commandable& operator=(Commandable const&) = delete;
00043
00051 bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
00052
00060 bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
00061
00068 bool stop(uint64_t timeout, uint64_t timestamp);
00069
00076 bool pause(uint64_t timeout, uint64_t timestamp);
00077
00084 bool resume(uint64_t timeout, uint64_t timestamp);
00085
00091 bool shutdown(uint64_t timeout);
00092
00100 bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
00101
00109 bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
00110
00115 bool in_run_failure();
00116
00121 virtual std::string report(std::string const&) const
00122 {
00123 std::lock_guard<std::mutex> lk(primary_mutex_);
00124 return report_string_;
00125 }
00126
00131 std::string status() const;
00132
00138 virtual bool reset_stats(std::string const& which)
00139 {
00140 std::lock_guard<std::mutex> lk(primary_mutex_);
00141 if (which == "fail")
00142 {
00143 return false;
00144 }
00145 else
00146 {
00147 return true;
00148 }
00149 }
00150
00157 virtual std::string register_monitor(fhicl::ParameterSet const&)
00158 {
00159 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";
00160 }
00161
00168 virtual std::string unregister_monitor(std::string const&)
00169 {
00170 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";
00171 }
00172
00177 std::vector<std::string> legal_commands() const;
00178
00179
00186 virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
00187
00194 virtual bool do_start(art::RunID, uint64_t, uint64_t);
00195
00202 virtual bool do_stop(uint64_t, uint64_t);
00203
00210 virtual bool do_pause(uint64_t, uint64_t);
00211
00218 virtual bool do_resume(uint64_t, uint64_t);
00219
00226 virtual bool do_shutdown(uint64_t);
00227
00234 virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
00235
00242 virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
00243
00248 virtual void badTransition(const std::string& trans);
00249
00255 virtual void BootedEnter();
00256
00262 virtual void InRunExit();
00263
00264 protected:
00269 std::string current_state() const;
00270
00271 CommandableContext fsm_;
00272 bool external_request_status_;
00273 std::string report_string_;
00274
00275 private:
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 mutable std::mutex primary_mutex_;
00287 };
00288
00289 #endif