summaryrefslogtreecommitdiff
path: root/orkbasecxx/Daemon.h
blob: ba7c42f47ac2be60dacd1f64af9767ae6bd84e3b (plain)
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
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

#ifndef __DAEMON_H__
#define __DAEMON_H__

#include "StdString.h"
#include "ace/Singleton.h"
#include "ace/Thread_Mutex.h"

typedef void (*DaemonHandler)(void);

class DLL_IMPORT_EXPORT_ORKBASE Daemon
{
public:
	static void Initialize(CStdString serviceName, DaemonHandler runHandler, DaemonHandler stopHandler);
	static Daemon* Singleton();
	void Start();
	void Stop();
	void Install();
	void Uninstall();
	bool IsStopping();

	void SetShortLived();
	bool GetShortLived();

private:
	Daemon();
	static Daemon* m_singleton;

#ifdef WIN32
	static void WINAPI Run( DWORD /*argc*/, TCHAR* /*argv*/[] );
#else
	static void Run();
#endif

	DaemonHandler m_runHandler;
	DaemonHandler m_stopHandler;
	CStdString m_serviceName;

	bool m_stopping;
	bool m_shortLived;
};

//typedef ACE_Singleton<Daemon, ACE_Thread_Mutex> DaemonSingleton;

#endif