2016-01-17 18:13:36 +00:00
|
|
|
#ifndef DAEMON_H__
|
|
|
|
#define DAEMON_H__
|
|
|
|
|
2014-04-24 15:10:46 +00:00
|
|
|
#include <string>
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2014-04-22 22:07:21 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define Daemon i2p::util::DaemonWin32::Instance()
|
|
|
|
#else
|
|
|
|
#define Daemon i2p::util::DaemonLinux::Instance()
|
|
|
|
#endif
|
2014-04-20 01:54:34 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2014-04-22 22:07:21 +00:00
|
|
|
class Daemon_Singleton_Private;
|
2014-04-20 01:54:34 +00:00
|
|
|
class Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
2014-04-22 22:07:21 +00:00
|
|
|
virtual bool init(int argc, char* argv[]);
|
2014-04-20 01:54:34 +00:00
|
|
|
virtual bool start();
|
|
|
|
virtual bool stop();
|
|
|
|
|
2016-01-19 00:00:00 +00:00
|
|
|
bool isLogging;
|
|
|
|
bool isDaemon;
|
2014-04-20 01:54:34 +00:00
|
|
|
|
2016-01-19 00:00:00 +00:00
|
|
|
bool running;
|
2014-04-20 01:54:34 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-22 22:07:21 +00:00
|
|
|
Daemon_Singleton();
|
|
|
|
virtual ~Daemon_Singleton();
|
|
|
|
|
2014-10-17 13:55:41 +00:00
|
|
|
bool IsService () const;
|
|
|
|
|
2014-04-22 22:07:21 +00:00
|
|
|
// d-pointer for httpServer, httpProxy, etc.
|
|
|
|
class Daemon_Singleton_Private;
|
|
|
|
Daemon_Singleton_Private &d;
|
2014-04-20 01:54:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
class DaemonWin32 : public Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DaemonWin32& Instance()
|
|
|
|
{
|
|
|
|
static DaemonWin32 instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2014-04-22 22:07:21 +00:00
|
|
|
virtual bool init(int argc, char* argv[]);
|
2014-04-20 01:54:34 +00:00
|
|
|
virtual bool start();
|
|
|
|
virtual bool stop();
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
class DaemonLinux : public Daemon_Singleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DaemonLinux& Instance()
|
|
|
|
{
|
|
|
|
static DaemonLinux instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool start();
|
|
|
|
virtual bool stop();
|
2014-04-22 04:15:07 +00:00
|
|
|
private:
|
|
|
|
std::string pidfile;
|
2016-01-11 10:58:39 +00:00
|
|
|
int pidFH;
|
2014-04-22 04:15:07 +00:00
|
|
|
|
2014-04-20 01:54:34 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
}
|
2014-04-22 04:15:07 +00:00
|
|
|
}
|
2016-01-17 18:13:36 +00:00
|
|
|
|
|
|
|
#endif // DAEMON_H__
|