2 #include "Middle_Impl.h"
4 #include "tao/Utils/PolicyList_Destroyer.h"
5 #include "tao/Utils/RIR_Narrow.h"
6 #include "tao/Strategies/advanced_resource.h"
7 #include "tao/Messaging/Messaging.h"
8 #include "tao/AnyTypeCode/Any.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/OS_NS_stdio.h"
13 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("middle.ior");
14 const ACE_TCHAR
*ior
= ACE_TEXT ("file://backend.ior");
15 Messaging::SyncScope scope
= Messaging::SYNC_NONE
;
19 usage(ACE_TCHAR
const *cmd
,
23 ACE_TEXT("Usage: %s ")
26 ACE_TEXT("-o <iorfile> ")
27 ACE_TEXT("-s <NONE|TRANSPORT|SERVER|TARGET|DELAYED> ")
28 ACE_TEXT("-t timeout ")
35 parse_args (int argc
, ACE_TCHAR
*argv
[])
37 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("vo:k:s:t:"));
39 ACE_TCHAR
const *sname
= ACE_TEXT("NONE");
40 ACE_TCHAR
const *stimeout
= 0;
42 while ((c
= get_opts ()) != -1)
50 ior_output_file
= get_opts
.opt_arg ();
54 ior
= get_opts
.opt_arg ();
58 sname
= get_opts
.opt_arg ();
62 stimeout
= get_opts
.opt_arg();
67 usage(argv
[0], ACE_TEXT("unknown argument"));
71 if (ACE_OS::strcmp(sname
, ACE_TEXT("NONE")) == 0) {
72 scope
= Messaging::SYNC_NONE
;
73 } else if (ACE_OS::strcmp(sname
, ACE_TEXT("TRANSPORT")) == 0) {
74 scope
= Messaging::SYNC_WITH_TRANSPORT
;
75 } else if (ACE_OS::strcmp(sname
, ACE_TEXT("SERVER")) == 0) {
76 scope
= Messaging::SYNC_WITH_SERVER
;
77 } else if (ACE_OS::strcmp(sname
, ACE_TEXT("TARGET")) == 0) {
78 scope
= Messaging::SYNC_WITH_TARGET
;
79 } else if (ACE_OS::strcmp(sname
, ACE_TEXT("DELAYED")) == 0) {
80 scope
= TAO::SYNC_DELAYED_BUFFERING
;
82 usage(argv
[0], ACE_TEXT("Invalid scope value"));
89 long tmp
= ACE_OS::strtol(stimeout
, &end
, 10);
90 if (end
== 0 || *end
!= '\0')
92 usage(argv
[0], ACE_TEXT("Invalid timeout value"));
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 ()))
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "backend_server(%P|%t) - panic: nil RootPOA\n"),
123 PortableServer::POAManager_var poa_manager
=
124 root_poa
->the_POAManager ();
126 if (parse_args (argc
, argv
) != 0)
129 CORBA::Object_var tmp
= orb
->string_to_object(ior
);
131 // one second in TimeT units
132 TimeBase::TimeT
const second
= 10 * TimeBase::TimeT(1000000);
134 CORBA::Any timeout_as_any
;
135 timeout_as_any
<<= TimeBase::TimeT(timeout
* second
);
137 CORBA::Any scope_as_any
;
138 scope_as_any
<<= scope
;
140 TAO::Utils::PolicyList_Destroyer
plist(1);
143 orb
->create_policy(Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
146 orb
->create_policy(Messaging::SYNC_SCOPE_POLICY_TYPE
,
149 CORBA::PolicyCurrent_var policy_current
=
150 TAO::Utils::RIR_Narrow
<CORBA::PolicyCurrent
>::narrow(
154 policy_current
->set_policy_overrides(
155 plist
, CORBA::ADD_OVERRIDE
);
157 Bug_3647_Regression::Backend_var backend
=
158 Bug_3647_Regression::Backend::_narrow(tmp
.in ());
160 if (CORBA::is_nil (backend
.in ()))
162 ACE_ERROR_RETURN ((LM_DEBUG
,
163 "middle_server(%P|%t) - nil backend reference <%s>\n",
168 using namespace Bug_3647_Regression
;
169 PortableServer::ServantBase_var
impl(
170 new Middle_Impl(backend
.in(), orb
.in(), verbose
));
172 PortableServer::ObjectId_var id
=
173 root_poa
->activate_object (impl
.in());
175 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
178 Bug_3647_Regression::Middle_var middle
=
179 Bug_3647_Regression::Middle::_narrow (object
.in ());
181 CORBA::String_var ior
= orb
->object_to_string (middle
.in ());
183 // Output the IOR to the <ior_output_file>
184 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
185 if (output_file
== 0)
186 ACE_ERROR_RETURN ((LM_ERROR
,
187 "middle_server(%P|%t) - Cannot open output file "
188 "for writing IOR: %s\n",
191 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
192 ACE_OS::fclose (output_file
);
194 poa_manager
->activate ();
198 ACE_DEBUG ((LM_DEBUG
,
199 "middle_server(%P|%t) - event loop finished\n"));
201 root_poa
->destroy (true, true);
205 catch (const CORBA::Exception
& ex
)
207 ACE_DEBUG ((LM_DEBUG
,
209 ex
._tao_print_exception ("Exception caught:");