1 #include "ace/Service_Config.h"
2 #include "ace/Logging_Strategy.h"
3 #include "ace/Sig_Adapter.h"
4 #include "TS_Clerk_Handler.h"
5 #include "TS_Server_Handler.h"
6 #include "Client_Logging_Handler.h"
7 #include "Name_Handler.h"
8 #include "Token_Handler.h"
9 #include "Server_Logging_Handler.h"
12 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
14 // Try to link in the svc.conf entries dynamically, enabling the
15 // "ignore_debug_flag" as the last parameter so that we can override
16 // the default ACE_Log_Priority settings in the svc.conf file.
18 // Warning - do not try to move the ACE_Reactor signal handling work
19 // up to before this call - if the user specified -b (be a daemon),
20 // all handles will be closed, including the Reactor's pipe.
22 if (ACE_Service_Config::open (argc
, argv
, ACE_DEFAULT_LOGGER_KEY
, 1, 0, 1) == -1)
25 ACE_ERROR_RETURN ((LM_ERROR
,
29 else // Use static linking.
31 if (ACE::debug () == 0)
32 ACE_LOG_MSG
->priority_mask (~LM_DEBUG
,
33 ACE_Log_Msg::PROCESS
);
35 // Calling ACE_SVC_INVOKE to create a new Service_Object.
36 // Stash the newly created Service_Object into an
37 // ACE_Service_Object_Ptr which is an <auto_ptr> specialized
38 // for ACE_Service_Object.
41 ACE_TCHAR name_port
[] =
42 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_NAME_SERVER_PORT_STR
);
44 l_argv
[0] = name_port
;
46 ACE_Service_Object_Ptr sp_1
= ACE_SVC_INVOKE (ACE_Name_Acceptor
);
48 if (sp_1
->init (1, l_argv
) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR
,
51 ACE_TEXT ("Name Service")),
54 ACE_TCHAR time_port
[] =
55 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_TIME_SERVER_PORT_STR
);
56 l_argv
[0] = time_port
;
58 ACE_Service_Object_Ptr sp_2
= ACE_SVC_INVOKE (ACE_TS_Server_Acceptor
);
60 if (sp_2
->init (1, l_argv
) == -1)
61 ACE_ERROR_RETURN ((LM_ERROR
,
63 ACE_TEXT ("TS Server Acceptor")),
66 ACE_TCHAR clerk_port
[] = ACE_TEXT ("-p 10011");
68 l_argv
[1] = clerk_port
;
70 ACE_Service_Object_Ptr sp_3
= ACE_SVC_INVOKE (ACE_TS_Clerk_Processor
);
72 if (sp_3
->init (2, l_argv
) == -1)
73 ACE_ERROR_RETURN ((LM_ERROR
,
75 ACE_TEXT ("TS Clerk Processor")),
78 #if defined (ACE_HAS_TOKENS_LIBRARY)
79 ACE_TCHAR token_port
[] =
80 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_TOKEN_SERVER_PORT_STR
);
81 l_argv
[0] = token_port
;
83 ACE_Service_Object_Ptr sp_4
= ACE_SVC_INVOKE (ACE_Token_Acceptor
);
85 if (sp_4
->init (1, l_argv
) == -1)
86 ACE_ERROR_RETURN ((LM_ERROR
,
88 ACE_TEXT ("Token Service")),
90 #endif /* ACE_HAS_TOKENS_LIBRARY */
92 ACE_TCHAR thr_logging_port
[] =
93 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_THR_LOGGING_SERVER_PORT_STR
);
94 l_argv
[0] = thr_logging_port
;
96 ACE_Service_Object_Ptr sp_5
=
97 ACE_SVC_INVOKE (ACE_Thr_Server_Logging_Acceptor
);
99 if (sp_5
->init (1, l_argv
) == -1)
100 ACE_ERROR_RETURN ((LM_ERROR
,
102 ACE_TEXT ("Threaded Logging Server")),
105 ACE_TCHAR logging_port
[] =
106 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_LOGGING_SERVER_PORT_STR
);
107 l_argv
[0] = logging_port
;
109 ACE_Service_Object_Ptr sp_6
=
110 ACE_SVC_INVOKE (ACE_Server_Logging_Acceptor
);
112 if (sp_6
->init (1, l_argv
) == -1)
113 ACE_ERROR_RETURN ((LM_ERROR
,
115 ACE_TEXT ("Logging Server")),
118 l_argv
[0] = logging_port
;
120 ACE_Service_Object_Ptr sp_7
=
121 ACE_SVC_INVOKE (ACE_Client_Logging_Acceptor
);
123 if (sp_7
->init (1, l_argv
) == -1)
124 ACE_ERROR_RETURN ((LM_ERROR
,
126 ACE_TEXT ("Logging Client")),
129 // Run forever, performing the configured services until we
130 // are shut down by a SIGINT/SIGQUIT signal.
131 // Create an adapter to end the event loop.
132 ACE_Sig_Adapter
sa ((ACE_Sig_Handler_Ex
) ACE_Reactor::end_event_loop
);
135 sig_set
.sig_add (SIGINT
);
136 sig_set
.sig_add (SIGQUIT
);
137 if (ACE_Reactor::instance ()->register_handler (sig_set
,
140 ACE_ERROR_RETURN ((LM_ERROR
,
142 ACE_TEXT ("register signals")),
147 ACE_Reactor::instance ()->run_reactor_event_loop ();
149 // Back from running the reactor we have to remove our signal handler
150 ACE_Reactor::instance ()->remove_handler (sig_set
);
153 // Destructors of ACE_Service_Object_Ptr's automagically
157 else // Use dynamic linking.
159 // Run forever, performing the configured services until we are
160 // shut down by a SIGINT/SIGQUIT signal.
161 // Create an adapter to end the event loop.
162 ACE_Sig_Adapter
sa ((ACE_Sig_Handler_Ex
) ACE_Reactor::end_event_loop
);
165 sig_set
.sig_add (SIGINT
);
166 sig_set
.sig_add (SIGQUIT
);
168 // Register ourselves to receive signals so we can shut down
170 if (ACE_Reactor::instance ()->register_handler (sig_set
, &sa
) == -1)
172 ACE_ERROR_RETURN ((LM_ERROR
,
174 ACE_TEXT ("register signals2")),
179 ACE_Reactor::instance ()->run_reactor_event_loop ();
181 // Back from running the reactor we have to remove our signal handler
182 ACE_Reactor::instance ()->remove_handler (sig_set
);