Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_2186_Regression / client.cpp
blobc4a4c126fe140459320eef1760264911c6178431
1 #include "Hello.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR *server_ior = ACE_TEXT("file://server.ior");
6 const ACE_TCHAR *ior_output_file = ACE_TEXT("client.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 server_ior = get_opts.opt_arg ();
19 break;
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-k <ior> "
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 CORBA::ORB_var orb =
42 CORBA::ORB_init (argc, argv);
44 if (parse_args (argc, argv) != 0)
45 return 1;
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references("RootPOA");
50 PortableServer::POA_var root_poa =
51 PortableServer::POA::_narrow (poa_object.in ());
53 if (CORBA::is_nil (root_poa.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR,
55 " (%P|%t) Panic: nil RootPOA\n"),
56 1);
58 PortableServer::POAManager_var poa_manager =
59 root_poa->the_POAManager ();
61 Hello *hello_impl;
62 ACE_NEW_RETURN (hello_impl,
63 Hello (orb.in ()),
64 1);
65 PortableServer::ServantBase_var owner_transfer(hello_impl);
67 PortableServer::ObjectId_var id =
68 root_poa->activate_object (hello_impl);
70 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
72 Test::Hello_var hello =
73 Test::Hello::_narrow (object.in ());
75 CORBA::String_var ior =
76 orb->object_to_string (hello.in ());
78 // Output the IOR to the <ior_output_file>
79 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
80 if (output_file == 0)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "Cannot open output file for writing IOR: %s",
83 ior_output_file),
84 1);
85 ACE_OS::fprintf (output_file, "%s", ior.in ());
86 ACE_OS::fclose (output_file);
88 poa_manager->activate ();
90 CORBA::Object_var tmp =
91 orb->string_to_object(server_ior);
93 Test::Hello_var server =
94 Test::Hello::_narrow(tmp.in ());
96 if (CORBA::is_nil (server.in ()))
98 ACE_ERROR_RETURN ((LM_DEBUG,
99 "Nil Test::Hello reference <%s>\n",
100 ior.in ()),
104 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Sending client obj ref to the server and requesting a callback.\n"));
106 server->request_callback (hello.in ());
108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Test (client) Succeeded !!!\n"));
110 orb->destroy ();
112 catch (const CORBA::Exception& ex)
114 ACE_DEBUG ((LM_ERROR, "(%P|%t) - Test (client) Failed !!!\n"));
115 ex._tao_print_exception ("Exception caught:");
116 return 1;
119 return 0;