Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / examples / FaultTolerance / RolyPoly / client.cpp
blob051e09989a5c27805bde9013e45ee17f8e266ab4
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"
8 // IOR manipulation.
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;
17 IOR_QUEUE ior_strs;
19 int
20 parse_args (int argc, ACE_TCHAR *argv[])
22 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
23 int c;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 'k':
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",
34 ior.c_str ()),
35 -1);
36 else
37 ACE_DEBUG ((LM_DEBUG, "Enqueued IOR: %s\n", ior.c_str ()));
39 break;
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "Usage: %s "
43 "-k IOR ...\n",
44 argv[0]),
45 -1);
48 return 0;
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 int status = 0;
56 try
58 CORBA::ORB_var orb = CORBA::ORB_init (argc,
59 argv,
60 "Client ORB");
62 if (::parse_args (argc, argv) != 0) return -1;
64 if (ior_strs.is_empty ())
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "No IOR provided\n"),
67 -1);
69 // Start out with the first IOR. Interaction with the second
70 // IOR occurs during the various interceptions executed during
71 // this test.
73 CORBA::Object_var object;
75 if (ior_strs.size() > 1)
77 // merge case
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 ()));
85 ior_go.advance ();
89 IOR_QUEUE::ITERATOR ior_iter = ior_strs.begin ();
91 ACE_SString *ior = 0;
92 ior_iter.next (ior);
94 CORBA::Object_var object_primary;
96 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);
109 // Create the list
110 TAO_IOP::TAO_IOR_Manipulation::IORList iors (ior_strs.size ());
111 iors.length(ior_strs.size ());
112 size_t cntr = 0;
113 iors [cntr] = CORBA::Object::_duplicate (object_primary.in ());
115 while (ior_iter.advance ())
117 ++cntr;
118 ior_iter.next (ior);
119 ACE_DEBUG ((LM_DEBUG, "IOR%d: %s\n",cntr, ior->c_str ()));
120 iors [cntr] =
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;
133 // Property values
135 // Major and Minor revision numbers
136 ft_tag_component.object_group_ref_version = 0;
138 // Domain id
139 const char *id = "iogr_testing";
140 ft_tag_component.group_domain_id = id;
142 // Object group id
143 ft_tag_component.object_group_id =
144 (CORBA::ULongLong) 10;
146 // Version
147 ft_tag_component.object_group_ref_version =
148 (CORBA::ULong) 5;
150 // Construct the IOGR Property class
151 TAO_FT_IOGR_Property iogr_prop (ft_tag_component);
153 // Set the property
154 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
155 object.in ());
157 retval = iorm->set_primary (&iogr_prop,
158 object_primary.in (),
159 object.in ());
161 ACE_UNUSED_ARG (retval);
163 else
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"),
169 -1);
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)
196 ACE_DEBUG ((LM_INFO,
197 "client: received exception %s .\n",
198 e.s.in ()));
199 continue;
203 ACE_DEBUG ((LM_INFO,
204 "client: received %d\n",
205 number));
206 ACE_OS::sleep (1);
209 server->shutdown ();
211 catch (const CORBA::Exception& ex)
213 ex._tao_print_exception ("Caught exception:");
214 return -1;
217 return status;