1 // file : RolyPoly/client.cpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "ace/SString.h"
6 #include "ace/Unbounded_Queue.h"
9 #include "tao/IORManipulation/IORManip_Loader.h"
10 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
11 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
13 #include "RolyPolyC.h"
15 typedef ACE_Unbounded_Queue
<ACE_SString
> IOR_QUEUE
;
20 parse_args (int argc
, ACE_TCHAR
*argv
[])
22 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
25 while ((c
= get_opts ()) != -1)
30 ACE_SString
ior(ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
31 if (ior_strs
.enqueue_tail (ior
) != 0)
32 ACE_ERROR_RETURN ((LM_ERROR
,
33 "Unable to enqueue IOR: %s\n",
37 ACE_DEBUG ((LM_DEBUG
, "Enqueued IOR: %s\n", ior
.c_str ()));
41 ACE_ERROR_RETURN ((LM_ERROR
,
52 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
58 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
62 if (::parse_args (argc
, argv
) != 0) return -1;
64 if (ior_strs
.is_empty ())
65 ACE_ERROR_RETURN ((LM_ERROR
,
69 // Start out with the first IOR. Interaction with the second
70 // IOR occurs during the various interceptions executed during
73 CORBA::Object_var object
;
75 if (ior_strs
.size() > 1)
79 ACE_DEBUG ((LM_DEBUG
, "We got %d iors\n", ior_strs
.size ()));
80 IOR_QUEUE::ITERATOR ior_go
= ior_strs
.begin ();
81 ACE_SString
*pior
= 0;
82 while (ior_go
.next (pior
) != 0)
84 ACE_DEBUG ((LM_DEBUG
, "IOR: %s\n", pior
->c_str ()));
89 IOR_QUEUE::ITERATOR ior_iter
= ior_strs
.begin ();
94 CORBA::Object_var object_primary
;
97 orb
->string_to_object (ior
->c_str());
100 // Get an object reference for the ORBs IORManipultion object!
101 CORBA::Object_ptr IORM
=
102 orb
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
105 TAO_IOP::TAO_IOR_Manipulation_ptr iorm
=
106 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
);
110 TAO_IOP::TAO_IOR_Manipulation::IORList
iors (ior_strs
.size ());
111 iors
.length(ior_strs
.size ());
113 iors
[cntr
] = CORBA::Object::_duplicate (object_primary
.in ());
115 while (ior_iter
.advance ())
119 ACE_DEBUG ((LM_DEBUG
, "IOR%d: %s\n",cntr
, ior
->c_str ()));
121 orb
->string_to_object (ior
->c_str());
125 ACE_DEBUG ((LM_DEBUG
, "Prepare to merge IORs.\n"));
126 // Create a merged set 1;
127 object
= iorm
->merge_iors (iors
);
131 FT::TagFTGroupTaggedComponent ft_tag_component
;
135 // Major and Minor revision numbers
136 ft_tag_component
.object_group_ref_version
= 0;
139 const char *id
= "iogr_testing";
140 ft_tag_component
.group_domain_id
= id
;
143 ft_tag_component
.object_group_id
=
144 (CORBA::ULongLong
) 10;
147 ft_tag_component
.object_group_ref_version
=
150 // Construct the IOGR Property class
151 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
154 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
157 retval
= iorm
->set_primary (&iogr_prop
,
158 object_primary
.in (),
161 ACE_UNUSED_ARG (retval
);
165 ACE_SString
*ior
= 0;
166 if (ior_strs
.get (ior
) != 0)
167 ACE_ERROR_RETURN ((LM_ERROR
,
168 "Unable to extract the only IOR string\n"),
170 object
= orb
->string_to_object (ior
->c_str());
173 RolyPoly_var server
=
174 RolyPoly::_narrow (object
.in ());
176 if (CORBA::is_nil (server
.in ()))
178 ACE_ERROR_RETURN ((LM_ERROR
,
179 "Object reference is nil\n"),
183 CORBA::Short number
= 0;
186 for (int i
= 1; i
< 500; ++i
)
188 CORBA::String_var str
;
192 number
= server
->number (str
.inout ());
194 catch (RolyPoly::E
const& e
)
197 "client: received exception %s .\n",
204 "client: received %d\n",
211 catch (const CORBA::Exception
& ex
)
213 ex
._tao_print_exception ("Caught exception:");