blob: c1d9916d578bbaeb1d370ce78898493616913256 (
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
|
// $Id$
#include "ace/Thread_Hook.h"
#include "ace/Task.h"
#include "ace/Log_Msg.h"
#include "SecurityContext.h"
// Listing 1 code/ch13
class HA_ThreadHook : public ACE_Thread_Hook
{
public:
virtual ACE_THR_FUNC_RETURN start (ACE_THR_FUNC func, void* arg)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%t) New Thread Spawned\n")));
// Create the context on the thread's own stack.
ACE_TSS<SecurityContext> secCtx;
// Special initialization.
add_sec_context_thr (secCtx);
return (*func) (arg);
}
void add_sec_context_thr (ACE_TSS<SecurityContext> &secCtx);
};
// Listing 1
void
HA_ThreadHook::add_sec_context_thr(ACE_TSS<SecurityContext> &secCtx)
{
secCtx->user = 0;
}
class HA_CommandHandler : public ACE_Task_Base
{
public:
virtual int svc (void)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) starting up \n")));
// Do something.
return 0;
}
};
// Listing 2 code/ch13
int ACE_TMAIN (int, ACE_TCHAR *[])
{
HA_ThreadHook hook;
ACE_Thread_Hook::thread_hook (&hook);
HA_CommandHandler handler;
handler.activate ();
handler.wait();
return 0;
}
// Listing 2
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_TSS<SecurityContext>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_TSS<SecurityContext>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|