EUDAQ
 All Classes Namespaces Files Functions Variables Pages
CommandReceiver.hh
1 #ifndef EUDAQ_INCLUDED_CommandReceiver
2 #define EUDAQ_INCLUDED_CommandReceiver
3 
4 #include "eudaq/ConnectionState.hh"
5 #include "eudaq/Platform.hh"
6 
7 #include <thread>
8 #include <memory>
9 //#include <pthread.h>
10 #include <string>
11 #include <iosfwd>
12 #include <iostream>
13 
14 namespace eudaq {
15 
16  class TransportClient;
17  class TransportEvent;
18  class Configuration;
19 
20  class DLLEXPORT CommandReceiver {
21  public:
22  CommandReceiver(const std::string &type, const std::string &name,
23  const std::string &runcontrol, bool startthread = true);
24  void SetConnectionState(ConnectionState::State state = ConnectionState::STATE_UNCONF, const std::string &info = "");
25 
26  int GetConnectionState() { return m_connectionstate.GetState();}
27 
28  virtual ~CommandReceiver();
29 
30  virtual void OnInitialise(const Configuration &param) { SetConnectionState(eudaq::ConnectionState::STATE_UNCONF);}
31  virtual void OnConfigure(const Configuration &param);
32  virtual void OnPrepareRun(unsigned /*runnumber*/) {}
33  virtual void OnStartRun(unsigned /*runnumber*/) { SetConnectionState(eudaq::ConnectionState::STATE_CONF);}
34  virtual void OnStopRun() {}
35  virtual void OnTerminate() {}
36  virtual void OnReset() {}
37  virtual void OnStatus() {}
38  virtual void OnData(const std::string & /*param*/) {}
39  virtual void OnLog(const std::string & /*param*/);
40  virtual void OnServer() {}
41  virtual void OnGetRun() {}
42  virtual void OnIdle();
43  virtual void OnClear();
44  virtual void OnUnrecognised(const std::string & /*cmd*/,
45  const std::string & /*param*/) {}
46 
47  void Process(int timeout);
48  void CommandThread();
49  void StartThread();
50 
51  protected:
52  ConnectionState m_connectionstate;
53  TransportClient *m_cmdclient;
54 
55  private:
56  bool m_done;
57  std::string m_type, m_name;
58  void CommandHandler(TransportEvent &);
59  std::unique_ptr<std::thread> m_thread;
60  bool m_threadcreated;
61  };
62 }
63 
64 #endif // EUDAQ_INCLUDED_CommandReceiver
Definition: TransportBase.hh:80
Definition: CommandReceiver.hh:20
Definition: Configuration.hh:12
Definition: ConnectionState.hh:15
Definition: TransportClient.hh:9