blob: 915edf014fa47b8f2843f67a46d6ed4a5d06f9ba (
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
|
// Listing 1 code/ch13
#include "ace/Task.h"
#include "ace/Log_Msg.h"
class ExitHandler : public ACE_At_Thread_Exit
{
public:
virtual void apply (void)
{
ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%t) is exiting\n")));
// Shut down all devices.
}
};
// Listing 1
// Listing 2 code/ch13
class HA_CommandHandler : public ACE_Task_Base
{
public:
HA_CommandHandler(ExitHandler& eh) : eh_(eh)
{ }
virtual int svc (void)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) starting up\n")));
this->thr_mgr ()->at_exit (eh_);
// Do something.
// Forcefully exit.
ACE_Thread::exit ();
// NOT REACHED
return 0;
}
private:
ExitHandler& eh_;
};
// Listing 2
// Listing 3 code/ch13
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ExitHandler eh;
HA_CommandHandler handler (eh);
handler.activate ();
ACE_Thread_Manager::instance ()->wait ();
return 0;
}
// Listing 3
#if 0
// Listing 4 code/ch13
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ExitHandler eh;
ACE_Thread_Manager tm;
HA_CommandHandler handler (eh);
handler.thr_mgr (&tm);
handler.activate ();
tm.wait();
return 0;
}
// Listing 4
#endif
|