2020-05-22 13:18:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2016-01-17 18:13:36 +00:00
|
|
|
#ifndef DAEMON_H__
|
|
|
|
#define DAEMON_H__
|
|
|
|
|
2016-06-15 18:43:29 +00:00
|
|
|
#include <memory>
|
2014-04-24 15:10:46 +00:00
|
|
|
#include <string>
|
2018-05-19 15:03:49 +00:00
|
|
|
#include <ostream>
|
2014-04-20 01:54:34 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2017-09-27 20:28:58 +00:00
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
class Daemon_Singleton_Private;
|
|
|
|
class Daemon_Singleton
|
2014-04-20 01:54:34 +00:00
|
|
|
{
|
2022-04-09 16:57:16 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual bool init (int argc, char* argv[], std::shared_ptr<std::ostream> logstream);
|
|
|
|
virtual bool init (int argc, char* argv[]);
|
|
|
|
virtual bool start ();
|
|
|
|
virtual bool stop ();
|
|
|
|
virtual void run () {};
|
|
|
|
|
|
|
|
virtual void setDataDir (std::string path);
|
|
|
|
|
|
|
|
bool isDaemon;
|
|
|
|
bool running;
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
protected:
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
Daemon_Singleton ();
|
|
|
|
virtual ~Daemon_Singleton ();
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
bool IsService () const;
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
// d-pointer for httpServer, httpProxy, etc.
|
|
|
|
class Daemon_Singleton_Private;
|
|
|
|
Daemon_Singleton_Private &d;
|
2014-04-22 22:07:21 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
private:
|
2014-10-17 13:55:41 +00:00
|
|
|
|
2022-04-09 16:57:16 +00:00
|
|
|
std::string DaemonDataDir;
|
2017-09-27 20:28:58 +00:00
|
|
|
};
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2016-06-15 15:28:59 +00:00
|
|
|
#if defined(QT_GUI_LIB) // check if QT
|
|
|
|
#define Daemon i2p::util::DaemonQT::Instance()
|
2017-09-27 20:28:58 +00:00
|
|
|
// dummy, invoked from RunQT
|
|
|
|
class DaemonQT: public i2p::util::Daemon_Singleton
|
2016-06-15 15:28:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2016-06-15 15:28:59 +00:00
|
|
|
static DaemonQT& Instance()
|
|
|
|
{
|
|
|
|
static DaemonQT instance;
|
|
|
|
return instance;
|
|
|
|
}
|
2017-09-27 20:28:58 +00:00
|
|
|
};
|
2016-06-15 15:28:59 +00:00
|
|
|
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
#define Daemon i2p::util::DaemonWin32::Instance()
|
2017-09-27 20:28:58 +00:00
|
|
|
class DaemonWin32 : public Daemon_Singleton
|
|
|
|
{
|
2014-04-20 01:54:34 +00:00
|
|
|
public:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2014-04-20 01:54:34 +00:00
|
|
|
static DaemonWin32& Instance()
|
|
|
|
{
|
|
|
|
static DaemonWin32 instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2016-03-09 19:41:14 +00:00
|
|
|
bool init(int argc, char* argv[]);
|
|
|
|
bool start();
|
2016-03-29 16:34:53 +00:00
|
|
|
bool stop();
|
2016-03-09 19:41:14 +00:00
|
|
|
void run ();
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
bool isGraceful;
|
2016-03-29 16:34:53 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
DaemonWin32 ():isGraceful(false) {}
|
|
|
|
};
|
2018-04-26 19:28:30 +00:00
|
|
|
#elif (defined(ANDROID) && !defined(ANDROID_BINARY))
|
2018-04-23 18:39:46 +00:00
|
|
|
#define Daemon i2p::util::DaemonAndroid::Instance()
|
|
|
|
// dummy, invoked from android/jni/DaemonAndroid.*
|
|
|
|
class DaemonAndroid: public i2p::util::Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2018-04-23 18:39:46 +00:00
|
|
|
static DaemonAndroid& Instance()
|
|
|
|
{
|
|
|
|
static DaemonAndroid instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
};
|
2017-09-27 20:28:58 +00:00
|
|
|
#else
|
|
|
|
#define Daemon i2p::util::DaemonLinux::Instance()
|
|
|
|
class DaemonLinux : public Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
static DaemonLinux& Instance()
|
|
|
|
{
|
|
|
|
static DaemonLinux instance;
|
|
|
|
return instance;
|
|
|
|
}
|
2016-03-29 16:34:53 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
bool start();
|
|
|
|
bool stop();
|
|
|
|
void run ();
|
2016-03-08 20:02:32 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
private:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
std::string pidfile;
|
|
|
|
int pidFH;
|
2014-04-22 04:15:07 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
public:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2017-09-27 20:28:58 +00:00
|
|
|
int gracefulShutdownInterval; // in seconds
|
|
|
|
};
|
2014-04-20 01:54:34 +00:00
|
|
|
#endif
|
2017-09-27 20:28:58 +00:00
|
|
|
}
|
2014-04-22 04:15:07 +00:00
|
|
|
}
|
2016-01-17 18:13:36 +00:00
|
|
|
|
|
|
|
#endif // DAEMON_H__
|