summaryrefslogtreecommitdiff
path: root/netsvcs/servers/main.cpp
blob: 6c7503c88bab81e4e4e828fcd9c5b1aba30b5267 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// $Id$

#include "ace/Service_Config.h"
#include "ace/Logging_Strategy.h"
#include "TS_Clerk_Handler.h"
#include "TS_Server_Handler.h"
#include "Client_Logging_Handler.h"
#include "Name_Handler.h"
#include "Token_Handler.h"
#include "Server_Logging_Handler.h"

ACE_RCSID(servers, main, "$Id$")

int
main (int argc, char *argv[])
{
  // Create an adapter to end the event loop.
  ACE_Sig_Adapter sa ((ACE_Sig_Handler_Ex) ACE_Reactor::end_event_loop);

  ACE_Sig_Set sig_set;
  sig_set.sig_add (SIGINT);
  sig_set.sig_add (SIGQUIT);

  // Register ourselves to receive signals so we can shut down
  // gracefully.
  if (ACE_Reactor::instance ()->register_handler (sig_set,
                                                  &sa) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n"),
                      -1);

  // Try to link in the svc.conf entries dynamically.
  if (ACE_Service_Config::open (argc, argv) == -1)
    {
      if (errno != ENOENT)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "open"),
                          1);
      else // Use static linking.
        {
          if (ACE::debug () == 0)
            ACE_Log_Msg::disable_debug_messages ();

          // Calling ACE_SVC_INVOKE to create a new Service_Object.
          // Stash the newly created Service_Object into an
          // ACE_Service_Object_Ptr which is an <auto_ptr> specialized
          // for ACE_Service_Object.

          char *l_argv[3];
          char name_port[] = "-p " ACE_DEFAULT_NAME_SERVER_PORT_STR;

          l_argv[0] = name_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_1 = ACE_SVC_INVOKE (ACE_Name_Acceptor);

          if (sp_1->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "Name Service",
                        1));

          char time_port[] = "-p " ACE_DEFAULT_TIME_SERVER_PORT_STR;
          l_argv[0] = time_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_2 = ACE_SVC_INVOKE (ACE_TS_Server_Acceptor);

          if (sp_2->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "TS Server Acceptor", 1));

          char clerk_port[] = "-p 10011";
          l_argv[0] = argv[0];
          l_argv[1] = clerk_port;
          l_argv[2] = 0;
          ACE_Service_Object_Ptr sp_3 = ACE_SVC_INVOKE (ACE_TS_Clerk_Processor);

          if (sp_3->init (2, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "TS Clerk Processor",
                        1));

#if defined (ACE_HAS_TOKENS_LIBRARY)
          char token_port[] = "-p " ACE_DEFAULT_TOKEN_SERVER_PORT_STR;
          l_argv[0] = token_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_4 = ACE_SVC_INVOKE (ACE_Token_Acceptor);

          if (sp_4->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "Token Service",
                        1));
#endif /* ACE_HAS_TOKENS_LIBRARY */

          char thr_logging_port[] = "-p " ACE_DEFAULT_THR_LOGGING_SERVER_PORT_STR;
          l_argv[0] = thr_logging_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_5 =
            ACE_SVC_INVOKE (ACE_Thr_Server_Logging_Acceptor);

          if (sp_5->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "Threaded Logging Server",
                        1));

          char logging_port[] = "-p " ACE_DEFAULT_LOGGING_SERVER_PORT_STR;
          l_argv[0] = logging_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_6 =
            ACE_SVC_INVOKE (ACE_Server_Logging_Acceptor);

          if (sp_6->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "Logging Server", 1));

          l_argv[0] = logging_port;
          l_argv[1] = 0;
          ACE_Service_Object_Ptr sp_7 =
            ACE_SVC_INVOKE (ACE_Client_Logging_Acceptor);

          if (sp_7->init (1, l_argv) == -1)
            ACE_ERROR ((LM_ERROR,
                        "%p\n%a",
                        "Logging Client",
                        1));

          // Run forever, performing the configured services until we
          // are shut down by a SIGINT/SIGQUIT signal.

          ACE_Reactor::run_event_loop ();

          // Destructors of ACE_Service_Object_Ptr's automagically
          // call fini().
        }
    }
  else // Use dynamic linking.
    {
      if (ACE::debug () == 0)
        ACE_Log_Msg::disable_debug_messages ();

      // Run forever, performing the configured services until we are
      // shut down by a SIGINT/SIGQUIT signal.

      ACE_Reactor::run_event_loop ();
    }

  return 0;
}