4 * @author Carlos O'Ryan <coryan@atdesk.com>
9 #include "tao/ORB_Core.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Reactor.h"
16 * @brief A simple implementation of the 'C' object.
19 : public virtual POA_Baz::AMH_C
22 Simple_C (CORBA::ORB_ptr orb
);
24 void op1 (Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
);
25 void op2 (Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
);
26 void op3 (Foo::Bar::AMH_BResponseHandler_ptr _tao_rh
);
27 void op4 (Baz::AMH_CResponseHandler_ptr _tao_rh
);
28 void shutdown (Baz::AMH_CResponseHandler_ptr
);
35 /***************************/
36 /*** Servant Definition ***/
38 Simple_C::Simple_C (CORBA::ORB_ptr orb
)
39 : orb_ (CORBA::ORB::_duplicate (orb
))
44 Simple_C::op1(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
)
50 Simple_C::op2(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
)
56 Simple_C::op3(Foo::Bar::AMH_BResponseHandler_ptr _tao_rh
)
62 Simple_C::op4(Baz::AMH_CResponseHandler_ptr _tao_rh
)
68 Simple_C::shutdown (Baz::AMH_CResponseHandler_ptr
)
70 this->orb_
->shutdown ();
73 // ****************************************************************
75 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
78 parse_args (int argc
, ACE_TCHAR
*argv
[])
80 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
83 while ((c
= get_opts ()) != -1)
87 ior_output_file
= get_opts
.opt_arg ();
92 ACE_ERROR_RETURN ((LM_ERROR
,
99 // Indicates successful parsing of the command line
104 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
109 CORBA::ORB_init (argc
, argv
);
111 CORBA::Object_var poa_object
=
112 orb
->resolve_initial_references("RootPOA");
114 PortableServer::POA_var root_poa
=
115 PortableServer::POA::_narrow (poa_object
.in ());
117 if (CORBA::is_nil (root_poa
.in ()))
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 " (%P|%t) Panic: nil RootPOA\n"),
122 PortableServer::POAManager_var poa_manager
=
123 root_poa
->the_POAManager ();
125 if (parse_args (argc
, argv
) != 0)
128 PortableServer::Servant_var
<Simple_C
> simple_c_impl(
129 new Simple_C(orb
.in()));
131 PortableServer::ObjectId_var id
=
132 root_poa
->activate_object (simple_c_impl
.in ());
134 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
136 Baz::C_var simple_c
=
137 Baz::C::_narrow (object
.in ());
139 CORBA::String_var ior
=
140 orb
->object_to_string (simple_c
.in ());
142 // Output the IOR to the <ior_output_file>
143 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
144 if (output_file
== 0)
145 ACE_ERROR_RETURN ((LM_ERROR
,
146 "Cannot open output file for writing IOR: %s",
149 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
150 ACE_OS::fclose (output_file
);
152 poa_manager
->activate ();
156 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
158 root_poa
->destroy (1, 1);
162 catch (const CORBA::Exception
& ex
)
164 ex
._tao_print_exception ("Exception caught:");