Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / netsvcs / servers / main.cpp
blob0cc853b3630f42eacd765ed6fb5c194394248b48
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"
11 int
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)
24 if (errno != ENOENT)
25 ACE_ERROR_RETURN ((LM_ERROR,
26 ACE_TEXT ("%p\n"),
27 ACE_TEXT ("open")),
28 1);
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.
40 ACE_TCHAR *l_argv[3];
41 ACE_TCHAR name_port[] =
42 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_NAME_SERVER_PORT_STR);
44 l_argv[0] = name_port;
45 l_argv[1] = 0;
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,
50 ACE_TEXT ("%p\n"),
51 ACE_TEXT ("Name Service")),
52 1);
54 ACE_TCHAR time_port[] =
55 ACE_TEXT ("-p ") ACE_TEXT (ACE_DEFAULT_TIME_SERVER_PORT_STR);
56 l_argv[0] = time_port;
57 l_argv[1] = 0;
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,
62 ACE_TEXT ("%p\n"),
63 ACE_TEXT ("TS Server Acceptor")),
64 1);
66 ACE_TCHAR clerk_port[] = ACE_TEXT ("-p 10011");
67 l_argv[0] = argv[0];
68 l_argv[1] = clerk_port;
69 l_argv[2] = 0;
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,
74 ACE_TEXT ("%p\n"),
75 ACE_TEXT ("TS Clerk Processor")),
76 1);
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;
82 l_argv[1] = 0;
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,
87 ACE_TEXT ("%p\n"),
88 ACE_TEXT ("Token Service")),
89 1);
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;
95 l_argv[1] = 0;
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,
101 ACE_TEXT ("%p\n"),
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;
108 l_argv[1] = 0;
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,
114 ACE_TEXT ("%p\n"),
115 ACE_TEXT ("Logging Server")),
118 l_argv[0] = logging_port;
119 l_argv[1] = 0;
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,
125 ACE_TEXT ("%p\n"),
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);
134 ACE_Sig_Set sig_set;
135 sig_set.sig_add (SIGINT);
136 sig_set.sig_add (SIGQUIT);
137 if (ACE_Reactor::instance ()->register_handler (sig_set,
138 &sa) == -1)
140 ACE_ERROR_RETURN ((LM_ERROR,
141 ACE_TEXT ("%p\n"),
142 ACE_TEXT ("register signals")),
145 else
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
154 // call fini().
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);
164 ACE_Sig_Set sig_set;
165 sig_set.sig_add (SIGINT);
166 sig_set.sig_add (SIGQUIT);
168 // Register ourselves to receive signals so we can shut down
169 // gracefully.
170 if (ACE_Reactor::instance ()->register_handler (sig_set, &sa) == -1)
172 ACE_ERROR_RETURN ((LM_ERROR,
173 ACE_TEXT ("%p\n"),
174 ACE_TEXT ("register signals2")),
177 else
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);
186 return 0;