EUDAQ
 All Classes Namespaces Files Functions Variables Pages
LogCollector.hh
1 #ifndef EUDAQ_INCLUDED_LogCollector
2 #define EUDAQ_INCLUDED_LogCollector
3 
4 //#include <pthread.h>
5 #include <string>
6 #include <fstream>
7 #include "eudaq/Platform.hh"
8 #include "eudaq/Configuration.hh"
9 #include "eudaq/TransportServer.hh"
10 #include "eudaq/CommandReceiver.hh"
11 #include <memory>
12 #include <thread>
13 
14 namespace eudaq {
15 
16  class LogMessage;
17 
21  class DLLEXPORT LogCollector : public CommandReceiver {
22  public:
23  LogCollector(const std::string &runcontrol,
24  const std::string &listenaddress);
25 
26  virtual void OnConnect(const ConnectionInfo & /*id*/) {}
27  virtual void OnDisconnect(const ConnectionInfo & /*id*/) {}
28  virtual void OnServer();
29  virtual void OnReceive(const LogMessage &msg) = 0;
30  virtual ~LogCollector();
31 
32  virtual void OnStopRun()
33  {
34  if (m_connectionstate.GetState() != eudaq::ConnectionState::STATE_ERROR)
35  SetConnectionState(eudaq::ConnectionState::STATE_CONF);
36  }
37 
38  void LogThread();
39 
40  private:
41  void LogHandler(TransportEvent &ev);
42  void DoReceive(const LogMessage &msg);
43  bool m_done, m_listening;
44  TransportServer *m_logserver;
45  // pthread_t m_thread;
46  // pthread_attr_t m_threadattr;
47  std::unique_ptr<std::thread> m_thread;
48  std::string m_filename;
49  std::ofstream m_file;
50  };
51 }
52 
53 #endif // EUDAQ_INCLUDED_LogCollector
Definition: TransportBase.hh:80
Definition: CommandReceiver.hh:20
Definition: LogCollector.hh:21
Definition: LogMessage.hh:15
Definition: TransportServer.hh:10
Definition: TransportBase.hh:22