Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Benchmark / server.cpp
blob6ee587c261df19a6fd5d0707656bbab12f036568
1 #include "test_i.h"
2 #include "Server_ORBInitializer.h"
3 #include "Interceptor_Type.h"
5 #include "tao/ORBInitializer_Registry.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/OS_NS_stdio.h"
10 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
11 int register_interceptor = 1;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile> -r <register_interceptor>"
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 int interceptor_type;
42 get_interceptor_type (argc, argv, interceptor_type);
44 try
46 PortableInterceptor::ORBInitializer_ptr temp_initializer;
48 ACE_NEW_RETURN (temp_initializer,
49 Server_ORBInitializer (interceptor_type),
50 -1); // No exceptions yet!
51 PortableInterceptor::ORBInitializer_var initializer =
52 temp_initializer;
54 PortableInterceptor::register_orb_initializer (initializer.in ());
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (argc, argv);
59 if (parse_args (argc, argv) != 0)
60 return 1;
62 CORBA::Object_var poa_object =
63 orb->resolve_initial_references("RootPOA");
64 if (CORBA::is_nil (poa_object.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR,
66 " (%P|%t) Unable to initialize the POA.\n"),
67 1);
69 PortableServer::POA_var root_poa =
70 PortableServer::POA::_narrow (poa_object.in ());
72 PortableServer::POAManager_var poa_manager =
73 root_poa->the_POAManager ();
75 poa_manager->activate ();
77 Secure_Vault_i server_impl (orb.in ());
79 PortableServer::ObjectId_var id =
80 root_poa->activate_object (&server_impl);
82 CORBA::Object_var test_obj =
83 root_poa->id_to_reference (id.in ());
85 Test_Interceptors::Secure_Vault_var server =
86 Test_Interceptors::Secure_Vault::_narrow (test_obj.in ());
88 CORBA::String_var ior =
89 orb->object_to_string (server.in ());
91 ACE_DEBUG ((LM_DEBUG,
92 "Test_Interceptors::Secure_Vault: <%s>\n",
93 ior.in ()));
95 // If the ior_output_file exists, output the ior to it
96 if (ior_output_file != 0)
98 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
99 if (output_file == 0)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "Cannot open output file for writing IOR: %s",
102 ior_output_file),
104 ACE_OS::fprintf (output_file, "%s", ior.in ());
105 ACE_OS::fclose (output_file);
108 orb->run ();
110 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
112 root_poa->destroy (true, true);
114 catch (const CORBA::Exception& ex)
116 ex._tao_print_exception ("Caught exception:");
117 return 1;
120 return 0;