UniSet  2.6.0
LogReader.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // -------------------------------------------------------------------------
17 #ifndef LogReader_H_
18 #define LogReader_H_
19 // -------------------------------------------------------------------------
20 #include <string>
21 #include <memory>
22 #include <queue>
23 #include <vector>
24 #include "UTCPStream.h"
25 #include "DebugStream.h"
26 #include "LogServerTypes.h"
27 // -------------------------------------------------------------------------
28 namespace uniset
29 {
30 
31  class LogReader
32  {
33  public:
34 
35  LogReader();
36  ~LogReader();
37 
38  struct Command
39  {
40  Command( LogServerTypes::Command c, unsigned int d, const std::string& f = "" ): cmd(c), data(d), logfilter(f) {}
41 
42  LogServerTypes::Command cmd = { LogServerTypes::cmdNOP };
43  unsigned int data = {0};
44  std::string logfilter = { "" };
45  };
46 
47  void sendCommand( const std::string& addr, int port,
48  std::vector<Command>& vcmd, bool cmd_only = true,
49  bool verbose = false );
50 
51  void readlogs( const std::string& addr, int port, LogServerTypes::Command c = LogServerTypes::cmdNOP, const std::string logfilter = "", bool verbose = false );
52 
53  bool isConnection() const;
54 
55  inline void setReadCount( unsigned int n )
56  {
57  readcount = n;
58  }
59 
60  inline void setCommandOnlyMode( bool s )
61  {
62  cmdonly = s;
63  }
64 
65  inline void setinTimeout( timeout_t msec )
66  {
67  inTimeout = msec;
68  }
69  inline void setoutTimeout( timeout_t msec )
70  {
71  outTimeout = msec;
72  }
73  inline void setReconnectDelay( timeout_t msec )
74  {
75  reconDelay = msec;
76  }
77 
78  DebugStream::StreamEvent_Signal signal_stream_event();
79 
80  void setLogLevel( Debug::type t );
81 
82  inline std::shared_ptr<DebugStream> log()
83  {
84  return outlog;
85  }
86 
87  protected:
88 
89  void connect( const std::string& addr, int port, timeout_t tout = UniSetTimer::WaitUpTime );
90  void disconnect();
91  void logOnEvent( const std::string& s );
92  void sendCommand(LogServerTypes::lsMessage& msg, bool verbose = false );
93 
94  timeout_t inTimeout = { 10000 };
95  timeout_t outTimeout = { 6000 };
96  timeout_t reconDelay = { 5000 };
97 
98  private:
99  std::shared_ptr<UTCPStream> tcp;
100  std::string iaddr = { "" };
101  int port = { 0 };
102  bool cmdonly { false };
103  unsigned int readcount = { 0 }; // количество циклов чтения
104 
105  DebugStream rlog;
106  std::shared_ptr<DebugStream> outlog; // рабочий лог в который выводиться полученная информация..
107 
108  DebugStream::StreamEvent_Signal m_logsig;
109  };
110  // -------------------------------------------------------------------------
111 } // end of uniset namespace
112 // -------------------------------------------------------------------------
113 #endif // LogReader_H_
114 // -------------------------------------------------------------------------
Definition: DebugStream.h:91
Definition: CallbackTimer.h:29
Definition: LogReader.h:38
Definition: LogReader.h:31
static const timeout_t WaitUpTime
Definition: PassiveTimer.h:69