ConnectionChecker.h 1.32 KB
Newer Older
legoc's avatar
legoc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * Copyright 2015 Institut Laue-Langevin
 *
 * Licensed under the EUPL, Version 1.1 only (the "License");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */

17
18
#ifndef CAMEO_CONNECTIONCHECKER_H_
#define CAMEO_CONNECTIONCHECKER_H_
legoc's avatar
legoc committed
19

legoc's avatar
legoc committed
20
21
#include <functional>
#include <thread>
legoc's avatar
legoc committed
22
23
24
25
26
27
28
#include <memory>
#include <string>
#include <map>

namespace cameo {

class Server;
29
class TimeCondition;
legoc's avatar
legoc committed
30
31

/**
32
 * Class providing a simple connection checker.
legoc's avatar
legoc committed
33
 */
34
35
36
class ConnectionChecker {

	friend class Server;
legoc's avatar
legoc committed
37
38

public:
legoc's avatar
legoc committed
39
	typedef std::function<void (bool)> FunctionType;
legoc's avatar
legoc committed
40

41
42
	ConnectionChecker(Server * server, FunctionType handler);
	~ConnectionChecker();
legoc's avatar
legoc committed
43

44
private:
legoc's avatar
legoc committed
45
46
47
48
49
50
	void startThread(int timeoutMs, int pollingTimeMs);
	void stopThread();

	void loop(int timeoutMs, int pollingTimeMs);

	Server * m_server;
legoc's avatar
legoc committed
51
	std::unique_ptr<TimeCondition> m_waitCondition;
52
	FunctionType m_function;
legoc's avatar
legoc committed
53
	std::unique_ptr<std::thread> m_thread;
legoc's avatar
legoc committed
54
55
56
57
58
};

}

#endif