File: Daemon.h

package info (click to toggle)
i2pd 2.58.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,612 kB
  • sloc: cpp: 59,663; makefile: 224; sh: 138
file content (129 lines) | stat: -rw-r--r-- 2,338 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* 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
*/

#ifndef DAEMON_H__
#define DAEMON_H__

#include <memory>
#include <string>
#include <ostream>

namespace i2p
{
namespace util
{
	class Daemon_Singleton_Private;
	class Daemon_Singleton
	{
	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;

	protected:

		Daemon_Singleton ();
		virtual ~Daemon_Singleton ();

		bool IsService () const;

		// d-pointer for httpServer, httpProxy, etc.
		class Daemon_Singleton_Private;
		Daemon_Singleton_Private &d;

	private:

		std::string DaemonDataDir;
	};

#if defined(QT_GUI_LIB) // check if QT
#define Daemon i2p::util::DaemonQT::Instance()
	// dummy, invoked from RunQT
	class DaemonQT: public i2p::util::Daemon_Singleton
	{
		public:

			static DaemonQT& Instance()
			{
				static DaemonQT instance;
				return instance;
			}
	};

#elif defined(_WIN32)
#define Daemon i2p::util::DaemonWin32::Instance()
	class DaemonWin32 : public Daemon_Singleton
	{
		public:

			static DaemonWin32& Instance()
			{
				static DaemonWin32 instance;
				return instance;
			}

			bool init(int argc, char* argv[]);
			bool start();
			bool stop();
			void run ();

			bool isGraceful;

			DaemonWin32 ():isGraceful(false) {}
	};
#elif (defined(ANDROID) && !defined(ANDROID_BINARY))
#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;
			}
	};
#else
#define Daemon i2p::util::DaemonLinux::Instance()
	class DaemonLinux : public Daemon_Singleton
	{
		public:

			static DaemonLinux& Instance()
			{
				static DaemonLinux instance;
				return instance;
			}

			bool start();
			bool stop();
			void run ();

		private:

			std::string pidfile;
			int pidFH;

		public:

			int gracefulShutdownInterval; // in seconds
	};
#endif
}
}

#endif // DAEMON_H__