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" 180 #ifndef DISABLE_REST_API 181 ,
public Poco::Net::HTTPRequestHandler
185 LogDB(
const std::string& name,
int argc,
const char*
const* argv,
const std::string& prefix );
189 static std::shared_ptr<LogDB>
init_logdb(
int argc,
const char*
const* argv,
const std::string& prefix =
"logdb-" );
194 inline std::shared_ptr<DebugStream> log()
199 void run(
bool async );
200 #ifndef DISABLE_REST_API 201 virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp )
override;
202 void onWebSocketSession( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
210 virtual void evfinish()
override;
211 virtual void evprepare()
override;
212 void onCheckBuffer( ev::timer& t,
int revents );
213 void onActivate( ev::async& watcher,
int revents ) ;
214 void addLog(
Log* log,
const std::string& txt );
215 void log2File(
Log* log,
const std::string& txt );
217 size_t getCountOfRecords(
const std::string& logname =
"" );
218 size_t getFirstOfOldRecord(
size_t maxnum );
220 #ifndef DISABLE_REST_API 221 Poco::JSON::Object::Ptr respError( Poco::Net::HTTPServerResponse& resp, Poco::Net::HTTPResponse::HTTPStatus s,
const std::string& message );
222 Poco::JSON::Object::Ptr httpGetRequest(
const std::string& cmd,
const Poco::URI::QueryParameters& p );
223 Poco::JSON::Object::Ptr
httpGetList(
const Poco::URI::QueryParameters& p );
224 Poco::JSON::Object::Ptr httpGetLogs(
const Poco::URI::QueryParameters& p );
225 Poco::JSON::Object::Ptr httpGetCount(
const Poco::URI::QueryParameters& p );
226 void httpWebSocketPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
227 void httpWebSocketConnectPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp,
const std::string& logname );
231 static std::string qLast(
const std::string& p );
234 static std::string qDate(
const std::string& p ,
const char sep =
'-');
237 static std::string qEscapeString(
const std::string& s );
239 std::shared_ptr<LogWebSocket> newWebSocket(Poco::Net::HTTPServerRequest* req, Poco::Net::HTTPServerResponse* resp,
const std::string& logname );
240 void delWebSocket( std::shared_ptr<LogWebSocket>& ws );
243 std::unique_ptr<SQLiteInterface> db;
247 bool activate = {
false };
249 typedef std::queue<std::string> QueryBuffer;
251 size_t qbufSize = { 1000 };
253 ev::timer flushBufferTimer;
254 double tmFlushBuffer_sec = { 1.0 };
258 size_t maxdbRecords = { 200 * 1000 };
259 size_t numOverflow = { 0 };
264 void onTerminate( ev::sig& evsig ,
int revents );
266 ev::async wsactivate;
275 std::string peername;
276 std::string description;
278 std::shared_ptr<DebugStream> dblog;
279 std::shared_ptr<DebugStream> logfile;
281 bool isConnected()
const;
283 void set( ev::dynamic_loop& loop );
284 void check( ev::timer& t,
int revents );
285 void event( ev::io& watcher,
int revents );
286 void read( ev::io& watcher );
287 void write( ev::io& io );
290 typedef sigc::signal<void, Log*, const std::string&> ReadSignal;
291 ReadSignal signal_on_read();
294 void setCheckConnectionTime(
double sec );
295 void setReadBufSize(
size_t sz );
299 bool connect() noexcept;
306 double checkConnection_sec = { 5.0 };
308 std::shared_ptr<UTCPStream> tcp;
309 std::vector<char> buf;
311 static const size_t reservsize = { 1000 };
315 std::queue<UTCPCore::Buffer*> wbuf;
318 std::vector< std::shared_ptr<Log> > logservers;
319 std::shared_ptr<DebugStream> dblog;
321 #ifndef DISABLE_REST_API 322 std::shared_ptr<Poco::Net::HTTPServer> httpserv;
323 std::string httpHost = {
"" };
324 int httpPort = { 0 };
325 std::string httpCORS_allow = {
"*" };
326 std::string httpReplyAddr = {
"" };
328 double wsHeartbeatTime_sec = { 3.0 };
329 double wsSendTime_sec = { 0.5 };
330 size_t wsMaxSend = { 200 };
332 std::string fgColor = {
"#c4c4c4" };
333 std::string bgColor = {
"#111111" };
334 std::string bgColorTitle = {
"green" };
335 std::string fgColorTitle = {
"#ececec" };
345 public Poco::Net::WebSocket
349 Poco::Net::HTTPServerResponse* resp,
350 std::shared_ptr<Log>& log );
355 std::shared_ptr<DebugStream> dblog;
358 void set( ev::dynamic_loop& loop );
360 void send( ev::timer& t,
int revents );
361 void ping( ev::timer& t,
int revents );
363 void add(
Log* log,
const std::string& txt );
367 void waitCompletion();
370 void setHearbeatTime(
const double& sec );
371 void setSendPeriod(
const double& sec );
372 void setMaxSendCount(
size_t val );
379 double send_sec = { 0.5 };
380 size_t maxsend = { 200 };
383 double ping_sec = { 3.0 };
385 std::mutex finishmut;
386 std::condition_variable finish;
388 std::atomic_bool cancelled = {
false };
390 sigc::connection con;
392 Poco::Net::HTTPServerRequest* req;
393 Poco::Net::HTTPServerResponse* resp;
396 std::queue<UTCPCore::Buffer*> wbuf;
409 logdb->delWebSocket(ws);
414 std::shared_ptr<LogWebSocket> ws;
420 std::list<std::shared_ptr<LogWebSocket>> wsocks;
422 size_t maxwsocks = { 50 };
426 public Poco::Net::HTTPRequestHandlerFactory
432 virtual Poco::Net::HTTPRequestHandler* createRequestHandler(
const Poco::Net::HTTPServerRequest& req )
override;
std::string tmsFormat
Definition: LogDB.h:245
Definition: CommonEventLoop.h:14
Poco::JSON::Object::Ptr httpGetList(const Poco::URI::QueryParameters &p)
Definition: LogDB.cc:973
static void help_print()
Definition: LogDB.cc:464
void ioprepare()
Definition: LogDB.cc:638
static std::shared_ptr< LogDB > init_logdb(int argc, const char *const *argv, const std::string &prefix="logdb-")
Definition: LogDB.cc:451
The EventLoopServer class Реализация общей части всех процессов использующих libev....
Definition: EventLoopServer.h:17