UniSet  2.6.0
LogReader.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // -------------------------------------------------------------------------
00017 #ifndef LogReader_H_
00018 #define LogReader_H_
00019 // -------------------------------------------------------------------------
00020 #include <string>
00021 #include <memory>
00022 #include <queue>
00023 #include <vector>
00024 #include "UTCPStream.h"
00025 #include "DebugStream.h"
00026 #include "LogServerTypes.h"
00027 // -------------------------------------------------------------------------
00028 namespace uniset
00029 {
00030 
00031 class LogReader
00032 {
00033     public:
00034 
00035         LogReader();
00036         ~LogReader();
00037 
00038         struct Command
00039         {
00040             Command( LogServerTypes::Command c, unsigned int d, const std::string& f = "" ): cmd(c), data(d), logfilter(f) {}
00041 
00042             LogServerTypes::Command cmd = { LogServerTypes::cmdNOP };
00043             unsigned int data = {0};
00044             std::string logfilter = { "" };
00045         };
00046 
00047         void sendCommand( const std::string& addr, int port,
00048                           std::vector<Command>& vcmd, bool cmd_only = true,
00049                           bool verbose = false );
00050 
00051         void readlogs( const std::string& addr, int port, LogServerTypes::Command c = LogServerTypes::cmdNOP, const std::string logfilter = "", bool verbose = false );
00052 
00053         bool isConnection() const;
00054 
00055         inline void setReadCount( unsigned int n )
00056         {
00057             readcount = n;
00058         }
00059 
00060         inline void setCommandOnlyMode( bool s )
00061         {
00062             cmdonly = s;
00063         }
00064 
00065         inline void setinTimeout( timeout_t msec )
00066         {
00067             inTimeout = msec;
00068         }
00069         inline void setoutTimeout( timeout_t msec )
00070         {
00071             outTimeout = msec;
00072         }
00073         inline void setReconnectDelay( timeout_t msec )
00074         {
00075             reconDelay = msec;
00076         }
00077 
00078         DebugStream::StreamEvent_Signal signal_stream_event();
00079 
00080         void setLogLevel( Debug::type t );
00081 
00082         inline std::shared_ptr<DebugStream> log()
00083         {
00084             return outlog;
00085         }
00086 
00087     protected:
00088 
00089         void connect( const std::string& addr, int port, timeout_t tout = UniSetTimer::WaitUpTime );
00090         void disconnect();
00091         void logOnEvent( const std::string& s );
00092         void sendCommand(LogServerTypes::lsMessage& msg, bool verbose = false );
00093 
00094         timeout_t inTimeout = { 10000 };
00095         timeout_t outTimeout = { 6000 };
00096         timeout_t reconDelay = { 5000 };
00097 
00098     private:
00099         std::shared_ptr<UTCPStream> tcp;
00100         std::string iaddr = { "" };
00101         int port = { 0 };
00102         bool cmdonly { false };
00103         unsigned int readcount = { 0 }; // количество циклов чтения
00104 
00105         DebugStream rlog;
00106         std::shared_ptr<DebugStream> outlog; // рабочий лог в который выводиться полученная информация..
00107 
00108         DebugStream::StreamEvent_Signal m_logsig;
00109 };
00110 // -------------------------------------------------------------------------
00111 } // end of uniset namespace
00112 // -------------------------------------------------------------------------
00113 #endif // LogReader_H_
00114 // -------------------------------------------------------------------------