DDTRC.h
Go to the documentation of this file.
1 #ifndef _NGT_RC_H
2 #define _NGT_RC_H
3 
4 #include <NovaRunControlClient/RunControlReceiver.h>
5 #include <DAQMessages/ccpp_RunControlMessages.h>
6 #include <boost/shared_ptr.hpp>
7 #include <boost/thread/mutex.hpp>
8 
10 
11 namespace rcm=runcontrolmessages;
12 
13 namespace novaddt{
14 
15 class Lockable{
16  protected:
18 };
19 
20 //Helper functions to make code somewhat cleaner
21 
22 template <class response_t>
23 boost::shared_ptr<response_t> Response(int code=0, std::string message="Success"){
24  boost::shared_ptr<response_t> response;
25  response.reset(new response_t());
26 
27  rmscore::RequestStatus reqStatus;
28  reqStatus.code = code;
29  reqStatus.message = DDS::string_dup(message.data());
30 
31  response->status = reqStatus;
32  return response;
33 }
34 
35 
36 template<class request_t, class response_t>
37 class Responder: public Lockable{
38  public:
39  virtual ~Responder(){};
40 
41  boost::shared_ptr<response_t>
42  handleMessage( boost::shared_ptr<request_t> message ){
43  boost::mutex::scoped_lock sl(_callbackMutex);
44  // create the reply
45  try{
46  handle(*message);
47  }
48  catch(std::exception e){
49  return Response<response_t>(1,std::string("Reques failed: ")+e.what());
50  }
51 
52  return Response<response_t>(0,"Success");
53  }
54 
55  virtual void handle(const request_t& request) = 0;
56 };
57 
58 class DDTRC:
59  public Responder<rcm::StatusRequest,rcm::StatusResponse>,
60  public Responder<rcm::RolloverRunRequest,rcm::RolloverRunResponse>,
61  public Responder<rcm::BeginRunRequest,rcm::BeginRunResponse>
62 {
63 public:
64 
65  DDTRC(std::string applicationName, int partNumber);
66  ~DDTRC();
67 
68  /**
69  * Handle run control messages
70  */
71  virtual void handle(const rcm::StatusRequest& message) override;
72  virtual void handle(const rcm::RolloverRunRequest& message) override;
73  virtual void handle(const rcm::BeginRunRequest& message) override;
74 
75 private:
76  // variables
78  boost::shared_ptr<novadaq::rcclient::RunControlReceiver> _rcReceiver;
79  boost::shared_ptr<mf::Presence> _mfPresence;
81 
82 protected:
83  //current state
86 };
87 
88 
89 
90 }//namespace novaddt
91 #endif
boost::shared_ptr< novadaq::rcclient::RunControlReceiver > _rcReceiver
Definition: DDTRC.h:78
int _partNumber
Definition: DDTRC.h:80
int _subrunNumber
Definition: DDTRC.h:85
virtual ~Responder()
Definition: DDTRC.h:39
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
int _runNumber
Definition: DDTRC.h:84
boost::shared_ptr< response_t > Response(int code=0, std::string message="Success")
Definition: DDTRC.h:23
boost::shared_ptr< response_t > handleMessage(boost::shared_ptr< request_t > message)
Definition: DDTRC.h:42
boost::mutex _callbackMutex
Definition: DDTRC.h:17
Definition: inftrees.h:24
boost::shared_ptr< mf::Presence > _mfPresence
Definition: DDTRC.h:79
Float_t e
Definition: plot.C:35
std::string _applicationName
Definition: DDTRC.h:77
enum BeamMode string