27 #include <condition_variable>
30 #include <sigc++/sigc++.h>
31 #include <Poco/JSON/Object.h>
32 #include <Poco/Net/WebSocket.h>
33 #include "UniSetTypes.h"
34 #include "LogAgregator.h"
35 #include "DebugStream.h"
36 #include "SQLiteInterface.h"
37 #include "EventLoopServer.h"
38 #include "UTCPStream.h"
39 #include "LogReader.h"
40 #include "UHttpRequestHandler.h"
41 #include "UHttpServer.h"
179 #ifndef DISABLE_REST_API
180 ,
public Poco::Net::HTTPRequestHandler
184 LogDB(
const std::string& name,
int argc,
const char*
const* argv,
const std::string& prefix );
188 static std::shared_ptr<LogDB>
init_logdb(
int argc,
const char*
const* argv,
const std::string& prefix =
"logdb-" );
193 inline std::shared_ptr<DebugStream> log()
198 void run(
bool async );
199 #ifndef DISABLE_REST_API
200 virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp )
override;
201 void onWebSocketSession( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
209 virtual void evfinish()
override;
210 virtual void evprepare()
override;
211 void onCheckBuffer( ev::timer& t,
int revents );
212 void onActivate( ev::async& watcher,
int revents ) ;
213 void addLog(
Log* log,
const std::string& txt );
214 void log2File(
Log* log,
const std::string& txt );
216 size_t getCountOfRecords(
const std::string& logname =
"" );
217 size_t getFirstOfOldRecord(
size_t maxnum );
220 static std::string qEscapeString(
const std::string& s );
222 #ifndef DISABLE_REST_API
223 Poco::JSON::Object::Ptr respError( Poco::Net::HTTPServerResponse& resp, Poco::Net::HTTPResponse::HTTPStatus s,
const std::string& message );
224 Poco::JSON::Object::Ptr httpGetRequest(
const std::string& cmd,
const Poco::URI::QueryParameters& p );
225 Poco::JSON::Object::Ptr
httpGetList(
const Poco::URI::QueryParameters& p );
226 Poco::JSON::Object::Ptr httpGetLogs(
const Poco::URI::QueryParameters& p );
227 Poco::JSON::Object::Ptr httpGetCount(
const Poco::URI::QueryParameters& p );
228 void httpWebSocketPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
229 void httpWebSocketConnectPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp,
const std::string& logname );
233 static std::string qLast(
const std::string& p );
236 static std::string qDate(
const std::string& p,
const char sep =
'-');
238 std::shared_ptr<LogWebSocket> newWebSocket(Poco::Net::HTTPServerRequest* req, Poco::Net::HTTPServerResponse* resp,
const std::string& logname );
239 void delWebSocket( std::shared_ptr<LogWebSocket>& ws );
242 std::unique_ptr<SQLiteInterface> db;
246 bool activate = {
false };
248 typedef std::queue<std::string> QueryBuffer;
250 size_t qbufSize = { 1000 };
252 ev::timer flushBufferTimer;
253 double tmFlushBuffer_sec = { 1.0 };
257 size_t maxdbRecords = { 200 * 1000 };
258 size_t numOverflow = { 0 };
263 void onTerminate( ev::sig& evsig,
int revents );
265 ev::async wsactivate;
274 std::string peername;
275 std::string description;
277 std::shared_ptr<DebugStream> dblog;
278 std::shared_ptr<DebugStream> logfile;
280 bool isConnected()
const;
282 void set( ev::dynamic_loop& loop );
283 void check( ev::timer& t,
int revents );
284 void event( ev::io& watcher,
int revents );
285 void read( ev::io& watcher );
286 void write( ev::io& io );
289 typedef sigc::signal<void, Log*, const std::string&> ReadSignal;
290 ReadSignal signal_on_read();
293 void setCheckConnectionTime(
double sec );
294 void setReadBufSize(
size_t sz );
298 bool connect() noexcept;
305 double checkConnection_sec = { 5.0 };
307 std::shared_ptr<UTCPStream> tcp;
308 std::vector<char> buf;
310 static const size_t reservsize = { 1000 };
314 std::queue<UTCPCore::Buffer*> wbuf;
317 std::vector< std::shared_ptr<Log> > logservers;
318 std::shared_ptr<DebugStream> dblog;
320 #ifndef DISABLE_REST_API
321 std::shared_ptr<Poco::Net::HTTPServer> httpserv;
322 std::string httpHost = {
"" };
323 int httpPort = { 0 };
324 std::string httpCORS_allow = {
"*" };
325 std::string httpReplyAddr = {
"" };
327 double wsHeartbeatTime_sec = { 3.0 };
328 double wsSendTime_sec = { 0.5 };
329 size_t wsMaxSend = { 200 };
331 std::string fgColor = {
"#c4c4c4" };
332 std::string bgColor = {
"#111111" };
333 std::string bgColorTitle = {
"green" };
334 std::string fgColorTitle = {
"#ececec" };
344 public Poco::Net::WebSocket
348 Poco::Net::HTTPServerResponse* resp,
349 std::shared_ptr<Log>& log );
354 std::shared_ptr<DebugStream> dblog;
357 void set( ev::dynamic_loop& loop );
359 void send( ev::timer& t,
int revents );
360 void ping( ev::timer& t,
int revents );
362 void add(
Log* log,
const std::string& txt );
366 void waitCompletion();
369 void setHearbeatTime(
const double& sec );
370 void setSendPeriod(
const double& sec );
371 void setMaxSendCount(
size_t val );
378 double send_sec = { 0.5 };
379 size_t maxsend = { 200 };
382 double ping_sec = { 3.0 };
384 std::mutex finishmut;
385 std::condition_variable finish;
387 std::atomic_bool cancelled = {
false };
389 sigc::connection con;
391 Poco::Net::HTTPServerRequest* req;
392 Poco::Net::HTTPServerResponse* resp;
395 std::queue<UTCPCore::Buffer*> wbuf;
408 logdb->delWebSocket(ws);
413 std::shared_ptr<LogWebSocket> ws;
419 std::list<std::shared_ptr<LogWebSocket>> wsocks;
421 size_t maxwsocks = { 50 };
425 public Poco::Net::HTTPRequestHandlerFactory
431 virtual Poco::Net::HTTPRequestHandler* createRequestHandler(
const Poco::Net::HTTPServerRequest& req )
override;
The EventLoopServer class Реализация общей части всех процессов использующих libev....
Definition: EventLoopServer.h:18
void ioprepare()
Definition: LogDB.cc:655
std::string tmsFormat
Definition: LogDB.h:244
Poco::JSON::Object::Ptr httpGetList(const Poco::URI::QueryParameters &p)
Definition: LogDB.cc:1005
static std::shared_ptr< LogDB > init_logdb(int argc, const char *const *argv, const std::string &prefix="logdb-")
Definition: LogDB.cc:461
static void help_print()
Definition: LogDB.cc:474
Definition: CommonEventLoop.h:15