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" 175 #ifndef DISABLE_REST_API 176 ,
public Poco::Net::HTTPRequestHandler
180 LogDB(
const std::string& name,
int argc,
const char*
const* argv,
const std::string& prefix );
184 static std::shared_ptr<LogDB>
init_logdb(
int argc,
const char*
const* argv,
const std::string& prefix =
"logdb-" );
189 inline std::shared_ptr<DebugStream> log()
194 void run(
bool async );
195 #ifndef DISABLE_REST_API 196 virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp )
override;
197 void onWebSocketSession( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
205 virtual void evfinish()
override;
206 virtual void evprepare()
override;
207 void onCheckBuffer( ev::timer& t,
int revents );
208 void onActivate( ev::async& watcher,
int revents ) ;
209 void addLog(
Log* log,
const std::string& txt );
211 size_t getCountOfRecords(
const std::string& logname =
"" );
212 size_t getFirstOfOldRecord(
size_t maxnum );
214 #ifndef DISABLE_REST_API 215 Poco::JSON::Object::Ptr respError( Poco::Net::HTTPServerResponse& resp, Poco::Net::HTTPResponse::HTTPStatus s,
const std::string& message );
216 Poco::JSON::Object::Ptr httpGetRequest(
const std::string& cmd,
const Poco::URI::QueryParameters& p );
217 Poco::JSON::Object::Ptr
httpGetList(
const Poco::URI::QueryParameters& p );
218 Poco::JSON::Object::Ptr httpGetLogs(
const Poco::URI::QueryParameters& p );
219 Poco::JSON::Object::Ptr httpGetCount(
const Poco::URI::QueryParameters& p );
220 void httpWebSocketPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
221 void httpWebSocketConnectPage( std::ostream& out, Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp,
const std::string& logname );
225 static std::string qLast(
const std::string& p );
228 static std::string qDate(
const std::string& p ,
const char sep =
'-');
231 static std::string qEscapeString(
const std::string& s );
233 std::shared_ptr<LogWebSocket> newWebSocket(Poco::Net::HTTPServerRequest* req, Poco::Net::HTTPServerResponse* resp,
const std::string& logname );
234 void delWebSocket( std::shared_ptr<LogWebSocket>& ws );
237 std::unique_ptr<SQLiteInterface> db;
241 bool activate = {
false };
243 typedef std::queue<std::string> QueryBuffer;
245 size_t qbufSize = { 1000 };
247 ev::timer flushBufferTimer;
248 double tmFlushBuffer_sec = { 1.0 };
252 size_t maxdbRecords = { 200 * 1000 };
253 size_t numOverflow = { 0 };
258 void onTerminate( ev::sig& evsig ,
int revents );
260 ev::async wsactivate;
269 std::string peername;
270 std::string description;
272 std::shared_ptr<DebugStream> dblog;
274 bool isConnected()
const;
276 void set( ev::dynamic_loop& loop );
277 void check( ev::timer& t,
int revents );
278 void event( ev::io& watcher,
int revents );
279 void read( ev::io& watcher );
280 void write( ev::io& io );
283 typedef sigc::signal<void, Log*, const std::string&> ReadSignal;
284 ReadSignal signal_on_read();
287 void setCheckConnectionTime(
double sec );
288 void setReadBufSize(
size_t sz );
292 bool connect() noexcept;
299 double checkConnection_sec = { 5.0 };
301 std::shared_ptr<UTCPStream> tcp;
302 std::vector<char> buf;
304 static const size_t reservsize = { 1000 };
308 std::queue<UTCPCore::Buffer*> wbuf;
311 std::vector< std::shared_ptr<Log> > logservers;
312 std::shared_ptr<DebugStream> dblog;
314 #ifndef DISABLE_REST_API 315 std::shared_ptr<Poco::Net::HTTPServer> httpserv;
316 std::string httpHost = {
"" };
317 int httpPort = { 0 };
318 std::string httpCORS_allow = {
"*" };
319 std::string httpReplyAddr = {
"" };
321 double wsHeartbeatTime_sec = { 3.0 };
322 double wsSendTime_sec = { 0.5 };
323 size_t wsMaxSend = { 200 };
325 std::string fgColor = {
"#c4c4c4" };
326 std::string bgColor = {
"#111111" };
327 std::string bgColorTitle = {
"green" };
328 std::string fgColorTitle = {
"#ececec" };
338 public Poco::Net::WebSocket
342 Poco::Net::HTTPServerResponse* resp,
343 std::shared_ptr<Log>& log );
348 std::shared_ptr<DebugStream> dblog;
351 void set( ev::dynamic_loop& loop );
353 void send( ev::timer& t,
int revents );
354 void ping( ev::timer& t,
int revents );
356 void add(
Log* log,
const std::string& txt );
360 void waitCompletion();
363 void setHearbeatTime(
const double& sec );
364 void setSendPeriod(
const double& sec );
365 void setMaxSendCount(
size_t val );
372 double send_sec = { 0.5 };
373 size_t maxsend = { 200 };
376 double ping_sec = { 3.0 };
378 std::mutex finishmut;
379 std::condition_variable finish;
381 std::atomic_bool cancelled = {
false };
383 sigc::connection con;
385 Poco::Net::HTTPServerRequest* req;
386 Poco::Net::HTTPServerResponse* resp;
389 std::queue<UTCPCore::Buffer*> wbuf;
402 logdb->delWebSocket(ws);
407 std::shared_ptr<LogWebSocket> ws;
413 std::list<std::shared_ptr<LogWebSocket>> wsocks;
415 size_t maxwsocks = { 50 };
419 public Poco::Net::HTTPRequestHandlerFactory
425 virtual Poco::Net::HTTPRequestHandler* createRequestHandler(
const Poco::Net::HTTPServerRequest& req )
override;
std::string tmsFormat
Definition: LogDB.h:239
Definition: CallbackTimer.h:29
Poco::JSON::Object::Ptr httpGetList(const Poco::URI::QueryParameters &p)
Definition: LogDB.cc:953
static void help_print()
Definition: LogDB.cc:444
void ioprepare()
Definition: LogDB.cc:618
static std::shared_ptr< LogDB > init_logdb(int argc, const char *const *argv, const std::string &prefix="logdb-")
Definition: LogDB.cc:431
The EventLoopServer class Реализация общей части всех процессов использующих libev. Содержит свой (динамический) eventloop;.
Definition: EventLoopServer.h:17