2016-01-17 21:13:36 +03:00
|
|
|
#ifndef DAEMON_H__
|
|
|
|
#define DAEMON_H__
|
|
|
|
|
2016-06-15 21:43:29 +03:00
|
|
|
#include <memory>
|
2014-04-24 19:10:46 +04:00
|
|
|
#include <string>
|
2018-05-19 18:03:49 +03:00
|
|
|
#include <ostream>
|
2014-04-20 05:54:34 +04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2017-09-27 23:28:58 +03:00
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
class Daemon_Singleton_Private;
|
|
|
|
class Daemon_Singleton
|
2014-04-20 05:54:34 +04:00
|
|
|
{
|
|
|
|
public:
|
2018-05-19 18:03:49 +03:00
|
|
|
virtual bool init(int argc, char* argv[], std::shared_ptr<std::ostream> logstream);
|
|
|
|
virtual bool init(int argc, char* argv[]);
|
|
|
|
virtual bool start();
|
2014-04-20 05:54:34 +04:00
|
|
|
virtual bool stop();
|
2016-03-08 23:02:32 +03:00
|
|
|
virtual void run () {};
|
2014-04-20 05:54:34 +04:00
|
|
|
|
2016-01-19 03:00:00 +03:00
|
|
|
bool isDaemon;
|
|
|
|
bool running;
|
2014-04-20 05:54:34 +04:00
|
|
|
|
|
|
|
protected:
|
2014-04-23 02:07:21 +04:00
|
|
|
Daemon_Singleton();
|
|
|
|
virtual ~Daemon_Singleton();
|
|
|
|
|
2016-03-09 22:41:14 +03:00
|
|
|
bool IsService () const;
|
2014-10-17 17:55:41 +04:00
|
|
|
|
2014-04-23 02:07:21 +04:00
|
|
|
// d-pointer for httpServer, httpProxy, etc.
|
|
|
|
class Daemon_Singleton_Private;
|
|
|
|
Daemon_Singleton_Private &d;
|
2017-09-27 23:28:58 +03:00
|
|
|
};
|
2014-04-20 05:54:34 +04:00
|
|
|
|
2016-06-15 18:28:59 +03:00
|
|
|
#if defined(QT_GUI_LIB) // check if QT
|
|
|
|
#define Daemon i2p::util::DaemonQT::Instance()
|
2017-09-27 23:28:58 +03:00
|
|
|
// dummy, invoked from RunQT
|
|
|
|
class DaemonQT: public i2p::util::Daemon_Singleton
|
2016-06-15 18:28:59 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DaemonQT& Instance()
|
|
|
|
{
|
|
|
|
static DaemonQT instance;
|
|
|
|
return instance;
|
|
|
|
}
|
2017-09-27 23:28:58 +03:00
|
|
|
};
|
2016-06-15 18:28:59 +03:00
|
|
|
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#define Daemon i2p::util::DaemonWin32::Instance()
|
2017-09-27 23:28:58 +03:00
|
|
|
class DaemonWin32 : public Daemon_Singleton
|
|
|
|
{
|
2014-04-20 05:54:34 +04:00
|
|
|
public:
|
|
|
|
static DaemonWin32& Instance()
|
|
|
|
{
|
|
|
|
static DaemonWin32 instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:41:14 +03:00
|
|
|
bool init(int argc, char* argv[]);
|
|
|
|
bool start();
|
2016-03-29 19:34:53 +03:00
|
|
|
bool stop();
|
2016-03-09 22:41:14 +03:00
|
|
|
void run ();
|
2014-04-20 05:54:34 +04:00
|
|
|
|
2017-09-27 23:28:58 +03:00
|
|
|
bool isGraceful;
|
2016-03-29 19:34:53 +03:00
|
|
|
|
2017-09-27 23:28:58 +03:00
|
|
|
DaemonWin32 ():isGraceful(false) {}
|
|
|
|
};
|
2018-04-26 22:28:30 +03:00
|
|
|
#elif (defined(ANDROID) && !defined(ANDROID_BINARY))
|
2018-04-23 21:39:46 +03:00
|
|
|
#define Daemon i2p::util::DaemonAndroid::Instance()
|
|
|
|
// dummy, invoked from android/jni/DaemonAndroid.*
|
|
|
|
class DaemonAndroid: public i2p::util::Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DaemonAndroid& Instance()
|
|
|
|
{
|
|
|
|
static DaemonAndroid instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
};
|
2017-09-27 23:28:58 +03:00
|
|
|
#else
|
|
|
|
#define Daemon i2p::util::DaemonLinux::Instance()
|
|
|
|
class DaemonLinux : public Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DaemonLinux& Instance()
|
|
|
|
{
|
|
|
|
static DaemonLinux instance;
|
|
|
|
return instance;
|
|
|
|
}
|
2016-03-29 19:34:53 +03:00
|
|
|
|
2017-09-27 23:28:58 +03:00
|
|
|
bool start();
|
|
|
|
bool stop();
|
|
|
|
void run ();
|
2016-03-08 23:02:32 +03:00
|
|
|
|
2017-09-27 23:28:58 +03:00
|
|
|
private:
|
|
|
|
std::string pidfile;
|
|
|
|
int pidFH;
|
2014-04-22 08:15:07 +04:00
|
|
|
|
2017-09-27 23:28:58 +03:00
|
|
|
public:
|
|
|
|
int gracefulShutdownInterval; // in seconds
|
|
|
|
};
|
2014-04-20 05:54:34 +04:00
|
|
|
#endif
|
2017-09-27 23:28:58 +03:00
|
|
|
}
|
2014-04-22 08:15:07 +04:00
|
|
|
}
|
2016-01-17 21:13:36 +03:00
|
|
|
|
|
|
|
#endif // DAEMON_H__
|