UniSet  2.7.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  void setReadCount( size_t n );
56  void setCommandOnlyMode( bool s );
57 
58  void setinTimeout( timeout_t msec );
59  void setoutTimeout( timeout_t msec );
60  void setReconnectDelay( timeout_t msec );
61  void setTextFilter( const std::string& f );
62 
63  DebugStream::StreamEvent_Signal signal_stream_event();
64 
65  void setLogLevel( Debug::type t );
66 
67  std::shared_ptr<DebugStream> log();
68 
69  protected:
70 
71  void connect( const std::string& addr, int port, timeout_t tout = UniSetTimer::WaitUpTime );
72  void disconnect();
73  void logOnEvent( const std::string& s );
74  void sendCommand(LogServerTypes::lsMessage& msg, bool verbose = false );
75 
76  timeout_t inTimeout = { 10000 };
77  timeout_t outTimeout = { 6000 };
78  timeout_t reconDelay = { 5000 };
79 
80  private:
81  std::shared_ptr<UTCPStream> tcp;
82  std::string iaddr = { "" };
83  int port = { 0 };
84  bool cmdonly { false };
85  size_t readcount = { 0 }; // количество циклов чтения
86  std::string textfilter = { "" };
87 
88  DebugStream rlog;
89  std::shared_ptr<DebugStream> outlog; // рабочий лог в который выводиться полученная информация..
90 
91  DebugStream::StreamEvent_Signal m_logsig;
92  };
93  // -------------------------------------------------------------------------
94 } // end of uniset namespace
95 // -------------------------------------------------------------------------
96 #endif // LogReader_H_
97 // -------------------------------------------------------------------------
Definition: DebugStream.h:91
Definition: CallbackTimer.h:29
Definition: LogReader.h:38
Definition: LogServerTypes.h:53
Definition: LogReader.h:31
static const timeout_t WaitUpTime
Definition: PassiveTimer.h:69