summaryrefslogtreecommitdiff
path: root/comm/TimeOut.h
blob: aaaae632d9073d22d5d6ef8e4edbd6c5dbb27bfd (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
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *	The Unix Channel
 *
 *	by Michel Beaudouin-Lafon and Stephane Chatty
 *
 *	Copyright 1990-1997
 *	Laboratoire de Recherche en Informatique (LRI)
 *	Centre d'Etudes de la Navigation Aerienne
 *
 *	Multiplexer-based timers
 *
 *	$Id$
 *	$CurLog$
 */

#ifndef UchTimeOut_H_
#define UchTimeOut_H_

#include "ccu/Timer.h"
#include "Multiplexer.h"

class UchBaseTimeOut : public CcuCoreTimer {
friend	class	UchBaseMultiplexer;

protected:
	UchBaseMultiplexer*	MyMpx;
	void	SetAlarm (Millisecond);
	void	StopAlarm ();

public:	
		UchBaseTimeOut (Millisecond, int = -1, UchBaseMultiplexer* = UchMpx);
		~UchBaseTimeOut ();
};

class UchTimeOut : public UchBaseTimeOut {
protected:
	void	(*Handler) (Millisecond);
	void	Handle (Millisecond);

public:
		UchTimeOut (Millisecond, void (*) (Millisecond), int = -1, UchBaseMultiplexer* = UchMpx);
		~UchTimeOut ();
inline	void	SetHandler (void (*h) (Millisecond))	{ Handler = h; }
};

#define SpecializedTimeOut(R,S) \
class R : public UchBaseTimeOut { \
protected: \
	S&	Object; \
	void	(S::*Handler)	(Millisecond); \
public: \
		R (Millisecond t, S& s, void (S::*sc) (Millisecond), int nb = -1, UchBaseMultiplexer* m = UchMpx) : UchBaseTimeOut (t, nb, m), Object (s), Handler (sc)	{} \
		~R ()	{} \
	void	Handle (Millisecond t)	{ (Object.*Handler) (t); } \
inline	void	SetHandler (void (S::*h) (Millisecond))	{ Handler = h; } \
};

template <class T> class UchTimeOutFor : public UchBaseTimeOut {
protected:
	T&	Object;
	void	(T::*Handler) (Millisecond);

	void	Handle (Millisecond ref) { (Object.*Handler) (ref); }

public:
		UchTimeOutFor (Millisecond t, T& o, void (T::*h) (Millisecond), int nb = -1, UchBaseMultiplexer* m = UchMpx) : UchBaseTimeOut (t, nb, m), Object (o), Handler (h) {}
		~UchTimeOutFor ()	{}
inline	void	SetHandler (void(T::*h)(Millisecond))	{ Handler = h; }
};

#endif	/* UchTimeOut_H_ */