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");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:o:"));
14 while ((c
= get_opts ()) != -1)
18 server_ior
= get_opts
.opt_arg ();
21 ior_output_file
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
32 // Indicates successful parsing of the command line
37 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
42 CORBA::ORB_init (argc
, argv
);
44 if (parse_args (argc
, argv
) != 0)
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"),
58 PortableServer::POAManager_var poa_manager
=
59 root_poa
->the_POAManager ();
62 ACE_NEW_RETURN (hello_impl
,
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");
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 "Cannot open output file for writing IOR: %s",
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",
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"));
112 catch (const CORBA::Exception
& ex
)
114 ACE_DEBUG ((LM_ERROR
, "(%P|%t) - Test (client) Failed !!!\n"));
115 ex
._tao_print_exception ("Exception caught:");