Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / DII_AMI_Forward / server.cpp
blob9ba3fd91155dea1821da6631f627cfa2ba89ac63
1 // -*- C++ -*-
4 #include "test_i.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/Task.h"
8 #include "server_interceptor.h"
9 #include "orb_initializer.h"
10 #include "tao/ORBInitializer_Registry.h"
12 const ACE_TCHAR *ior_filename = ACE_TEXT("server.ior");
14 int
15 parse_args (int argc, ACE_TCHAR *argv[])
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:m:n:t"));
18 int c;
20 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'o':
25 ior_filename = get_opts.opt_arg ();
26 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-o <iorfile>"
32 "\n",
33 argv [0]),
34 -1);
37 // Indicates successful parsing of the command line
38 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 // Create the ORB initializer.
47 Server_ORBInitializer *temp_initializer = 0;
48 ACE_NEW_RETURN (temp_initializer,
49 Server_ORBInitializer,
50 -1);
52 PortableInterceptor::ORBInitializer_var initializer =
53 temp_initializer;
55 PortableInterceptor::register_orb_initializer (initializer.in ());
57 // Now initialize the ORB.
58 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
59 CORBA::Object_var poa_object =
60 orb->resolve_initial_references("RootPOA");
62 if (CORBA::is_nil (poa_object.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Unable to initialize the POA.\n"),
66 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 if (parse_args (argc, argv) != 0)
77 return 1;
80 // Create the interceptor.
81 ForwardTest_Request_Interceptor * server_interceptor =
82 temp_initializer->server_interceptor();
84 Forward_Test_i *final_impl = new Forward_Test_i(orb.in ());
85 PortableServer::ServantBase_var servant = final_impl;
86 Forward::Test_var target = final_impl->_this ();
88 server_interceptor->forward_reference (target.in());
90 Forward_Test_i *server_impl = new Forward_Test_i (orb.in());
91 servant = server_impl;
92 Forward::Test_var server = server_impl->_this ();
94 CORBA::String_var iorstr =
95 orb->object_to_string (server.in ());
97 FILE *output_file= ACE_OS::fopen (ior_filename, "w");
98 if (output_file == 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Cannot open output file for writing IOR: %s\n",
101 ior_filename),
103 ACE_OS::fprintf (output_file, "%s", iorstr.in());
104 ACE_OS::fclose (output_file);
106 poa_manager->activate ();
108 orb->run ();
110 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Server: exception caught - ");
115 return 1;
118 return 0;