2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/SString.h"
5 #include "tao/IORTable/IORTable.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
8 const ACE_TCHAR
*ior_output_file2
= ACE_TEXT ("forward_forever.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:"));
16 while ((c
= get_opts ()) != -1)
20 ior_output_file
= get_opts
.opt_arg ();
23 ior_output_file2
= get_opts
.opt_arg ();
27 ACE_ERROR_RETURN ((LM_ERROR
,
34 // Indicates successful parsing of the command line
39 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
43 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - ORB_init\n"));
45 CORBA::ORB_init (argc
, argv
);
47 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - Obtain RootPOA\n"));
48 CORBA::Object_var poa_object
=
49 orb
->resolve_initial_references("RootPOA");
51 PortableServer::POA_var root_poa
=
52 PortableServer::POA::_narrow (poa_object
.in ());
54 if (CORBA::is_nil (root_poa
.in ()))
55 ACE_ERROR_RETURN ((LM_ERROR
,
56 " (%P|%t) Panic: nil RootPOA\n"),
59 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
61 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - parse args\n"));
62 if (parse_args (argc
, argv
) != 0)
65 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - init hello\n"));
66 Hello
*hello_impl
= 0;
67 ACE_NEW_RETURN (hello_impl
,
70 PortableServer::ServantBase_var
owner_transfer(hello_impl
);
72 PortableServer::ObjectId_var id
=
73 root_poa
->activate_object (hello_impl
);
75 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
77 Test::Hello_var hello
= Test::Hello::_narrow (object
.in ());
79 CORBA::String_var ior
= orb
->object_to_string (hello
.in ());
81 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - Create the forwarding loop\n"));
82 CORBA::Object_var iorTableObj
=
83 orb
->resolve_initial_references ("IORTable");
85 IORTable::Table_var iorTable
86 = IORTable::Table::_narrow (iorTableObj
.in ());
88 // We are using this test with ObjRefStyle == URL ... or at
89 // least we better be. The IOR is therefore a corbaloc
90 ACE_CString
full_corbaloc (ior
.in (), 0, 1);
92 // Create a corbaloc for an IOR table binding that points to
93 // itself. Acessing this will make the server reply with LOCATION_FORWARD
96 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - Corbaloc is\n \"%C\"\n", full_corbaloc
.c_str()));
97 // Get the endpoint info only...
98 CORBA::ULong first_slash
= full_corbaloc
.find ("/", 0);
99 ACE_CString forward_forever
= full_corbaloc
.substring (0,
102 // .. add the string we are going to bind against and then bind
103 forward_forever
+= "/hello";
104 iorTable
->bind("hello", forward_forever
.c_str ());
106 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - Forward forever is\n \"%C\"\n", forward_forever
.c_str()));
108 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
109 if (output_file
== 0)
110 ACE_ERROR_RETURN ((LM_ERROR
,
111 "Cannot open output file for writing IOR: %s\n",
114 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
115 ACE_OS::fclose (output_file
);
117 output_file
= ACE_OS::fopen (ior_output_file2
, "w");
118 if (output_file
== 0)
119 ACE_ERROR_RETURN ((LM_ERROR
,
120 "Cannot open output file for writing IOR: %s\n",
123 ACE_OS::fprintf (output_file
, "%s", forward_forever
.c_str ());
124 ACE_OS::fclose (output_file
);
126 poa_manager
->activate ();
128 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - orb->run()\n"));
131 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
133 root_poa
->destroy (true, true);
137 catch (const CORBA::Exception
& ex
)
139 ex
._tao_print_exception ("Exception caught:");