Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / MT_IIOP_SSL / server.cpp
blob2e32f9cbe1aa67de05ec6f4963e08e0669a543cd
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "Server_Worker.h"
5 const ACE_TCHAR *ior_output_file = 0;
6 int nthreads = 4;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.opt_arg ();
19 break;
21 case 'n':
22 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile>"
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 try
44 // Initialize the ORB
45 CORBA::ORB_var orb =
46 CORBA::ORB_init (argc, argv);
48 CORBA::Object_var poa_object =
49 orb->resolve_initial_references("RootPOA");
51 if (CORBA::is_nil (poa_object.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR,
53 " (%P|%t) Unable to initialize the POA.\n"),
54 1);
56 // Get a Root POA reference
57 PortableServer::POA_var root_poa =
58 PortableServer::POA::_narrow (poa_object.in ());
60 PortableServer::POAManager_var poa_manager =
61 root_poa->the_POAManager ();
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 Simple_Server_i server_impl (orb.in ());
68 Simple_Server_var server =
69 server_impl._this ();
71 CORBA::String_var ior =
72 orb->object_to_string (server.in ());
74 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
76 // If the ior_output_file exists, output the ior to it
77 if (ior_output_file != 0)
79 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
80 if (output_file == 0)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "Cannot open output file for writing IOR: %s",
83 ior_output_file),
84 1);
85 ACE_OS::fprintf (output_file, "%s", ior.in ());
86 ACE_OS::fclose (output_file);
89 poa_manager->activate ();
91 Server_Worker worker (orb.in ());
92 if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
93 nthreads) != 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot activate client threads\n"),
96 1);
98 worker.thr_mgr ()->wait ();
100 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
102 orb->destroy ();
104 catch (const CORBA::Exception& ex)
106 ex._tao_print_exception ("Exception caught:");
107 return 1;
110 return 0;