UniSet  2.2.1
LogReader.h
00001 #ifndef LogReader_H_
00002 #define LogReader_H_
00003 // -------------------------------------------------------------------------
00004 #include <string>
00005 #include <memory>
00006 #include <queue>
00007 #include <vector>
00008 #include <cc++/socket.h>
00009 #include "UTCPStream.h"
00010 #include "DebugStream.h"
00011 #include "LogServerTypes.h"
00012 // -------------------------------------------------------------------------
00013 class LogReader
00014 {
00015     public:
00016 
00017         LogReader();
00018         ~LogReader();
00019 
00020         struct Command
00021         {
00022             Command( LogServerTypes::Command c, unsigned int d, const std::string& f = "" ): cmd(c), data(d), logfilter(f) {}
00023 
00024             LogServerTypes::Command cmd = { LogServerTypes::cmdNOP };
00025             unsigned int data = {0};
00026             std::string logfilter = { "" };
00027         };
00028 
00029         void sendCommand( const std::string& addr, ost::tpport_t port,
00030                           std::vector<Command>& vcmd, bool cmd_only = true,
00031                           bool verbose = false );
00032 
00033         void readlogs( const std::string& addr, ost::tpport_t port, LogServerTypes::Command c = LogServerTypes::cmdNOP, const std::string logfilter = "", bool verbose = false );
00034 
00035         bool isConnection();
00036 
00037         inline void setReadCount( unsigned int n )
00038         {
00039             readcount = n;
00040         }
00041 
00042         inline void setCommandOnlyMode( bool s )
00043         {
00044             cmdonly = s;
00045         }
00046 
00047         inline void setinTimeout( timeout_t msec )
00048         {
00049             inTimeout = msec;
00050         }
00051         inline void setoutTimeout( timeout_t msec )
00052         {
00053             outTimeout = msec;
00054         }
00055         inline void setReconnectDelay( timeout_t msec )
00056         {
00057             reconDelay = msec;
00058         }
00059 
00060         DebugStream::StreamEvent_Signal signal_stream_event();
00061 
00062         void setLogLevel( Debug::type );
00063 
00064     protected:
00065 
00066         void connect( const std::string& addr, ost::tpport_t port, timeout_t tout = TIMEOUT_INF );
00067         void connect( ost::InetAddress addr, ost::tpport_t port, timeout_t tout = TIMEOUT_INF );
00068         void disconnect();
00069         void logOnEvent( const std::string& s );
00070         void sendCommand(LogServerTypes::lsMessage& msg, bool verbose = false );
00071 
00072         timeout_t inTimeout = { 10000 };
00073         timeout_t outTimeout = { 6000 };
00074         timeout_t reconDelay = { 5000 };
00075 
00076     private:
00077         std::shared_ptr<UTCPStream> tcp;
00078         std::string iaddr = { "" };
00079         ost::tpport_t port = { 0 };
00080         bool cmdonly { false };
00081         unsigned int readcount = { 0 }; // количество циклов чтения
00082 
00083         DebugStream rlog;
00084         DebugStream log; // рабочий лог в который выводиться полученная информация..
00085 
00086         DebugStream::StreamEvent_Signal m_logsig;
00087 };
00088 // -------------------------------------------------------------------------
00089 #endif // LogReader_H_
00090 // -------------------------------------------------------------------------