Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_2510_Regression / server.cpp
blobd2bf86eb2b5ca31c5f30f5418b417cbcd23411e2
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "test_i.h"
4 #include "tao/ORBInitializer_Registry.h"
5 #include "Server_ORBInitializer.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-o <iorfile>"
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 // create initializer
40 Server_ORBInitializer * temp_initializer = 0;
42 ACE_NEW_RETURN (temp_initializer,
43 Server_ORBInitializer,
44 -1); // No exceptions yet!
45 PortableInterceptor::ORBInitializer_var initializer = temp_initializer;
47 PortableInterceptor::register_orb_initializer (initializer.in ());
48 // Now create an ORB
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv);
52 CORBA::Object_var poa_object =
53 orb->resolve_initial_references ("RootPOA");
55 if (CORBA::is_nil (poa_object.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Unable to initialize the POA.\n"),
58 1);
60 PortableServer::POA_var root_poa =
61 PortableServer::POA::_narrow (poa_object.in ());
63 PortableServer::POAManager_var poa_manager =
64 root_poa->the_POAManager ();
66 poa_manager->activate ();
68 if (parse_args (argc, argv) != 0)
69 return 1;
71 Visual_i server_impl (orb.in ());
73 PortableServer::ObjectId_var id =
74 root_poa->activate_object (&server_impl);
76 CORBA::Object_var test_obj =
77 root_poa->id_to_reference (id.in ());
79 Test_Interceptors::Visual_var server =
80 Test_Interceptors::Visual::_narrow (test_obj.in ());
82 CORBA::String_var ior =
83 orb->object_to_string (server.in ());
85 ACE_DEBUG ((LM_DEBUG,
86 "Test_Interceptors::Visual: <%C>\n",
87 ior.in ()));
89 // If the ior_output_file exists, output the ior to it
90 if (ior_output_file != 0)
92 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s",
96 ior_output_file),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
102 orb->run ();
104 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
106 root_poa->destroy (1, 1);
108 orb->destroy ();
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception ("Caught exception in server:");
113 return 1;
116 return 0;