Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_2289_Regression / server.cpp
blobec3454f657820b62bc8ee965628a9b1a1e6cddb5
2 #include "MyInterfaceImpl.h"
3 #include "TestS.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "tao/IORTable/IORTable.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
9 const ACE_TCHAR *client_ior = ACE_TEXT("file://client.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 client_ior = get_opts.opt_arg ();
22 break;
23 case 'o':
24 ior_output_file = get_opts.opt_arg ();
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-o <iorfile>"
32 "\n",
33 argv [0]),
34 -1);
36 // Indicates successful parsing of the command line
37 return 0;
40 int
41 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
43 try
45 CORBA::ORB_var orb =
46 CORBA::ORB_init (argc, argv);
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"),
57 1);
59 PortableServer::POAManager_var poa_manager =
60 root_poa->the_POAManager ();
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 MyInterfaceImpl *test_impl = 0;
66 ACE_NEW_RETURN (test_impl,
67 MyInterfaceImpl (orb.in ()),
68 1);
70 PortableServer::ServantBase_var owner_transfer(test_impl);
72 PortableServer::ObjectId_var id =
73 root_poa->activate_object (test_impl);
75 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
77 MyInterface_var test_ref =
78 MyInterface::_narrow (object.in ());
80 CORBA::String_var ior =
81 orb->object_to_string (test_ref.in ());
83 // Output the IOR to the <ior_output_file>
84 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
85 if (output_file != 0)
87 ACE_OS::fprintf (output_file, "%s", ior.in ());
88 ACE_OS::fclose (output_file);
91 poa_manager->activate ();
93 CORBA::Object_var table_object =
94 orb->resolve_initial_references ("IORTable");
96 IORTable::Table_var adapter =
97 IORTable::Table::_narrow (table_object.in ());
99 if (CORBA::is_nil (adapter.in ()))
101 ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
103 else
105 adapter->bind ("collocated_ior_bound_in_remote_iortable",
106 ACE_TEXT_ALWAYS_CHAR(client_ior));
109 orb->run ();
111 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
113 root_poa->destroy (true, true);
115 orb->destroy ();
117 catch (const CORBA::Exception& ex)
119 ex._tao_print_exception ("Exception caught:");
120 return 1;
123 return 0;