Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / MT_SSLIOP / server.cpp
blob889cb91a09eb03c13d03a7f8a833105a2203fc2a
1 #include "ace/Get_Opt.h"
2 #include "tao/IORTable/IORTable.h"
3 #include "test_i.h"
4 #include "Server_Worker.h"
6 const ACE_TCHAR *ior_output_file = 0;
7 ACE_TCHAR *another_output_file = 0;
8 ACE_CString ior_table_name = "";
9 char *another_table_name = 0;
10 int nthreads = 4;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:o:n:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'i':
23 ior_table_name = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
24 int len = ACE_OS::strlen(ior_table_name.c_str ()) + 1;
25 another_table_name = new char[len + 1];
26 ACE_OS::strcpy(another_table_name, ior_table_name.c_str ());
27 another_table_name[len-1] = '1';
28 another_table_name[len] = '\0';
29 break;
31 case 'o':
33 ior_output_file = get_opts.opt_arg ();
34 int len = ACE_OS::strlen(ior_output_file) + 1;
35 another_output_file = new ACE_TCHAR[len + 1];
36 ACE_OS::strcpy(another_output_file, ior_output_file);
37 another_output_file[len-1] = '1';
38 another_output_file[len] = '\0';
39 break;
41 case 'n':
42 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
43 break;
45 case '?':
46 default:
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "usage: %s "
49 "[-i <iortable name>]"
50 "-o <iorfile>"
51 "\n",
52 argv [0]),
53 -1);
55 // Indicates successful parsing of the command line
56 return 0;
60 int
61 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
63 try
65 // Initialize the ORB
66 CORBA::ORB_var orb =
67 CORBA::ORB_init (argc, argv);
69 CORBA::Object_var poa_object =
70 orb->resolve_initial_references("RootPOA");
72 if (CORBA::is_nil (poa_object.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR,
74 " (%P|%t) Unable to initialize the POA.\n"),
75 1);
77 // Get a Root POA reference
78 PortableServer::POA_var root_poa =
79 PortableServer::POA::_narrow (poa_object.in ());
81 PortableServer::POAManager_var poa_manager =
82 root_poa->the_POAManager ();
84 if (parse_args (argc, argv) != 0)
85 return 1;
87 Simple_Server_i server_impl (orb.in ());
88 Another_One_i another_one_impl (orb.in());
90 Simple_Server_var server =
91 server_impl._this ();
93 Another_One_var another_one =
94 another_one_impl._this ();
96 CORBA::String_var ior =
97 orb->object_to_string (server.in ());
99 CORBA::String_var another_ior =
100 orb->object_to_string (another_one.in ());
102 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Activated as <%C>\n"), ior.in ()));
104 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Activated another one as <%C>\n"),
105 another_ior.in ()));
107 if (ior_table_name.length () != 0)
109 CORBA::Object_var table_object =
110 orb->resolve_initial_references ("IORTable");
112 IORTable::Table_var adapter =
113 IORTable::Table::_narrow (table_object.in ());
115 if (CORBA::is_nil (adapter.in ()))
117 ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
118 return -1;
121 adapter->bind ( ior_table_name.c_str (), ior.in ());
122 adapter->bind ( another_table_name, another_ior.in());
126 // If the ior_output_file exists, output the ior to it
127 if (ior_output_file != 0)
129 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
130 if (output_file == 0)
131 ACE_ERROR_RETURN ((LM_ERROR,
132 "Cannot open output file for writing IOR: %s",
133 ior_output_file),
135 ACE_DEBUG ((LM_DEBUG,"Wrote ior to %s\n",
136 ior_output_file));
137 ACE_OS::fprintf (output_file, "%s", ior.in ());
138 ACE_OS::fclose (output_file);
139 output_file = ACE_OS::fopen (another_output_file, "w");
140 if (output_file == 0)
141 ACE_ERROR_RETURN ((LM_ERROR,
142 "Cannot open output file for writing IOR: %s",
143 another_output_file),
145 ACE_DEBUG ((LM_DEBUG,"Wrote another ior to %s\n",
146 another_output_file));
147 ACE_OS::fprintf (output_file, "%s", another_ior.in ());
148 ACE_OS::fclose (output_file);
151 poa_manager->activate ();
153 Server_Worker worker (orb.in ());
154 if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
155 nthreads) != 0)
156 ACE_ERROR_RETURN ((LM_ERROR,
157 "Cannot activate client threads\n"),
160 worker.thr_mgr ()->wait ();
162 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
164 orb->destroy ();
166 catch (const CORBA::Exception& ex)
168 ex._tao_print_exception ("Exception caught:");
169 return 1;
172 return 0;