2 #include "tao/PortableServer/PortableServer.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
35 class ctest_impl
: public virtual POA_ctest
39 ctest_impl (CORBA::ORB_ptr orb
) : orb_ (CORBA::ORB::_duplicate (orb
)) {}
41 CORBA::Long
ctestfn(CORBA::Long size
, ctest::UCSeq_out data
)
43 data
= new ctest::UCSeq
;
47 for (CORBA::ULong i
= 0; i
< data
->length(); ++i
)
49 data
[i
] = (rand() % 26) + 'A';
56 this->orb_
->shutdown (false);
60 /// Use an ORB reference to convert strings to objects and shutdown
65 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
69 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
71 CORBA::Object_var poa_object
=
72 orb
->resolve_initial_references ("RootPOA");
74 PortableServer::POA_var root_poa
=
75 PortableServer::POA::_narrow (poa_object
.in ());
77 if (CORBA::is_nil (root_poa
.in ()))
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 " (%P|%t) Panic: nil RootPOA\n"),
82 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
84 if (parse_args (argc
, argv
) != 0)
87 ctest_impl
*hello_impl
= 0;
88 ACE_NEW_RETURN (hello_impl
,
89 ctest_impl (orb
.in ()),
91 PortableServer::ServantBase_var
owner_transfer(hello_impl
);
93 PortableServer::ObjectId_var id
=
94 root_poa
->activate_object (hello_impl
);
96 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
98 ctest_var hello
= ctest::_narrow (object
.in ());
100 CORBA::String_var ior
= orb
->object_to_string (hello
.in ());
102 // Output the IOR to the <ior_output_file>
103 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
104 if (output_file
== 0)
105 ACE_ERROR_RETURN ((LM_ERROR
,
106 "Cannot open output file for writing IOR: %s\n",
109 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
110 ACE_OS::fclose (output_file
);
112 poa_manager
->activate ();
115 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
117 root_poa
->destroy (true, true);
121 catch (const CORBA::Exception
& ex
)
123 ex
._tao_print_exception ("Exception caught:");