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 _tao_rh
);
34 /***************************/
35 /*** Servant Definition ***/
37 Simple_C::Simple_C (CORBA::ORB_ptr orb
)
38 : orb_ (CORBA::ORB::_duplicate (orb
))
43 Simple_C::op1(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
)
49 Simple_C::op2(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh
)
55 Simple_C::op3(Foo::Bar::AMH_BResponseHandler_ptr _tao_rh
)
61 Simple_C::op4(Baz::AMH_CResponseHandler_ptr _tao_rh
)
67 Simple_C::shutdown (Baz::AMH_CResponseHandler_ptr
)
69 this->orb_
->shutdown (0);
72 // ****************************************************************
74 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
77 parse_args (int argc
, ACE_TCHAR
*argv
[])
79 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
82 while ((c
= get_opts ()) != -1)
86 ior_output_file
= get_opts
.opt_arg ();
91 ACE_ERROR_RETURN ((LM_ERROR
,
98 // Indicates successful parsing of the command line
103 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
108 CORBA::ORB_init (argc
, argv
);
110 CORBA::Object_var poa_object
=
111 orb
->resolve_initial_references("RootPOA");
113 PortableServer::POA_var root_poa
=
114 PortableServer::POA::_narrow (poa_object
.in ());
116 if (CORBA::is_nil (root_poa
.in ()))
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 " (%P|%t) Panic: nil RootPOA\n"),
121 PortableServer::POAManager_var poa_manager
=
122 root_poa
->the_POAManager ();
124 if (parse_args (argc
, argv
) != 0)
127 PortableServer::Servant_var
<Simple_C
> simple_c_impl(
128 new Simple_C(orb
.in()));
130 PortableServer::ObjectId_var id
=
131 root_poa
->activate_object (simple_c_impl
.in ());
133 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
135 Baz::C_var simple_c
=
136 Baz::C::_narrow (object
.in ());
138 CORBA::String_var ior
=
139 orb
->object_to_string (simple_c
.in ());
141 // Output the IOR to the <ior_output_file>
142 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
143 if (output_file
== 0)
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Cannot open output file for writing IOR: %s",
148 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
149 ACE_OS::fclose (output_file
);
151 poa_manager
->activate ();
155 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
157 root_poa
->destroy (1, 1);
161 catch (const CORBA::Exception
& ex
)
163 ex
._tao_print_exception ("Exception caught:");