mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-13 01:20:22 +03:00
[daemon] WIP: use callbacks to work with daemon
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
463d43b0bb
commit
78193fc8f8
@ -423,6 +423,10 @@ namespace util
|
||||
try
|
||||
{
|
||||
d.httpServer = std::unique_ptr<i2p::http::HTTPServer>(new i2p::http::HTTPServer(httpAddr, httpPort));
|
||||
d.httpServer->SetDaemonStop (std::bind (Daemon_Singleton::stop, this));
|
||||
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
|
||||
d.httpServer->SetDaemonGracefulTimer (std::bind (Daemon_Singleton::stop, this));
|
||||
#endif
|
||||
d.httpServer->Start();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
|
@ -27,15 +27,18 @@
|
||||
#include "RouterContext.h"
|
||||
#include "ClientContext.h"
|
||||
#include "HTTPServer.h"
|
||||
#include "Daemon.h"
|
||||
#include "util.h"
|
||||
#include "ECIESX25519AEADRatchetSession.h"
|
||||
#include "I18N.h"
|
||||
|
||||
#ifdef WIN32_APP
|
||||
#include "Daemon.h"
|
||||
#include "Win32App.h"
|
||||
#endif
|
||||
|
||||
// Inja template engine
|
||||
#include "inja/inja.hpp"
|
||||
|
||||
// For image, style and info
|
||||
#include "version.h"
|
||||
#include "HTTPServerResources.h"
|
||||
@ -270,8 +273,10 @@ namespace http {
|
||||
ShowNetworkStatus (s, i2p::context.GetStatusV6 ());
|
||||
s << "<br>\r\n";
|
||||
}
|
||||
|
||||
// TODO: rewrite timer access
|
||||
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
|
||||
if (auto remains = Daemon.gracefulShutdownInterval) {
|
||||
if (auto remains = m_DaemonGracefulTimer) {
|
||||
s << "<b>" << tr("Stopping in") << ":</b> ";
|
||||
ShowUptime(s, remains);
|
||||
s << "<br>\r\n";
|
||||
@ -1240,8 +1245,9 @@ namespace http {
|
||||
else if (cmd == HTTP_COMMAND_SHUTDOWN_START)
|
||||
{
|
||||
i2p::context.SetAcceptsTunnels (false);
|
||||
// TODO: rewrite timer access
|
||||
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
|
||||
Daemon.gracefulShutdownInterval = 10*60;
|
||||
if (m_DaemonGracefulTimer) m_DaemonGracefulTimer = 10 * 60;
|
||||
#elif defined(WIN32_APP)
|
||||
i2p::win32::GracefulShutdown ();
|
||||
#endif
|
||||
@ -1249,16 +1255,18 @@ namespace http {
|
||||
else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL)
|
||||
{
|
||||
i2p::context.SetAcceptsTunnels (true);
|
||||
// TODO: rewrite timer access
|
||||
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
|
||||
Daemon.gracefulShutdownInterval = 0;
|
||||
if (m_DaemonGracefulTimer) m_DaemonGracefulTimer = 0;
|
||||
#elif defined(WIN32_APP)
|
||||
i2p::win32::StopGracefulShutdown ();
|
||||
#endif
|
||||
}
|
||||
else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW)
|
||||
{
|
||||
// TODO: rewrite stop command access
|
||||
#ifndef WIN32_APP
|
||||
Daemon.running = false;
|
||||
if (m_DaemonStop) m_DaemonStop();
|
||||
#else
|
||||
i2p::win32::StopWin32App ();
|
||||
#endif
|
||||
|
@ -69,6 +69,11 @@ namespace http
|
||||
void Start ();
|
||||
void Stop ();
|
||||
|
||||
typedef std::function<void ()> DaemonStop;
|
||||
typedef int DaemonGracefulTimer;
|
||||
void SetDaemonStop (const DaemonStop& f) { m_DaemonStop = f; };
|
||||
void SetDaemonGracefulTimer (const DaemonGracefulTimer& f) { m_DaemonGracefulTimer = f; };
|
||||
|
||||
private:
|
||||
|
||||
void Run ();
|
||||
@ -85,6 +90,11 @@ namespace http
|
||||
boost::asio::io_service::work m_Work;
|
||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||
std::string m_Hostname;
|
||||
|
||||
private:
|
||||
|
||||
DaemonStop m_DaemonStop;
|
||||
DaemonGracefulTimer m_DaemonGracefulTimer;
|
||||
};
|
||||
|
||||
//all the below functions are also used by Qt GUI, see mainwindow.cpp -> getStatusPageHtml
|
||||
|
@ -84,7 +84,7 @@ namespace http
|
||||
" border-radius: 5px; font-size: 12px; }\r\n"
|
||||
" button[type=submit] { padding: 5px 15px; background: transparent; border: 2px solid var(--main-link-color); cursor: pointer;\r\n"
|
||||
" border-radius: 5px; position: relative; height: 36px; display: -webkit-inline-box; margin-top: 10px; }\r\n"
|
||||
"}\r\n"
|
||||
"}\r\n";
|
||||
|
||||
// for external style sheet
|
||||
std::string externalCSS;
|
||||
@ -124,7 +124,7 @@ namespace http
|
||||
<div class=\"content\">{% block content %}{% endblock %}</div> \
|
||||
</div> \
|
||||
</body> \
|
||||
</html>"
|
||||
</html>";
|
||||
|
||||
const std::string pageMain =
|
||||
"{% extends \"base.html\" %} \
|
||||
@ -203,7 +203,7 @@ namespace http
|
||||
</tr> \
|
||||
</tbody> \
|
||||
</table> \
|
||||
{% endblock %}"
|
||||
{% endblock %}";
|
||||
|
||||
} // http
|
||||
} // i2p
|
||||
|
Loading…
Reference in New Issue
Block a user