DDS  ver. 3.6
PipeLogEngine.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef LOGENGINE_H
6 #define LOGENGINE_H
7 //=============================================================================
8 #include <boost/thread/thread.hpp>
9 #include <csignal>
10 #include <string>
11 //=============================================================================
12 namespace dds
13 {
14  namespace pipe_log_engine
15  {
16  class CLogEngine
17  {
18  public:
19  typedef std::function<void(const std::string&)> onLogEvent_t;
20 
21  public:
22  CLogEngine(bool _debugMode = false);
23  ~CLogEngine();
24 
25  void start(const std::string& _pipeFilePath, onLogEvent_t _callback = nullptr);
26  void stop();
27  void operator()(const std::string& _msg, const std::string& _id = "**", bool _debugMsg = false) const;
28  void debug_msg(const std::string& _msg, const std::string& _id = "**") const
29  {
30  operator()(_msg, _id, true);
31  }
32  void setDbgFlag(bool _dbgFlag)
33  {
34  m_debugMode = _dbgFlag;
35  }
36 
37  private:
38  void thread_worker(int _fd, const std::string& _pipename);
39  void logMsg(const std::string& _msg);
40 
41  private:
42  int m_fd;
43  boost::thread* m_thread;
44  std::string m_pipeName;
45  bool m_debugMode;
46  volatile sig_atomic_t m_stopLogEngine;
47  onLogEvent_t m_callback;
48  };
49  } // namespace pipe_log_engine
50 } // namespace dds
51 //=============================================================================
52 #endif
void setDbgFlag(bool _dbgFlag)
Definition: PipeLogEngine.h:32
void stop()
Definition: PipeLogEngine.cpp:57
void operator()(const std::string &_msg, const std::string &_id="**", bool _debugMsg=false) const
Definition: PipeLogEngine.cpp:80
void start(const std::string &_pipeFilePath, onLogEvent_t _callback=nullptr)
Definition: PipeLogEngine.cpp:35
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
void debug_msg(const std::string &_msg, const std::string &_id="**") const
Definition: PipeLogEngine.h:28
~CLogEngine()
Definition: PipeLogEngine.cpp:30
Definition: PipeLogEngine.h:16
std::function< void(const std::string &)> onLogEvent_t
Definition: PipeLogEngine.h:19
CLogEngine(bool _debugMode=false)
Definition: PipeLogEngine.cpp:21