Update bug_report.md
[ACE_TAO.git] / TAO / orbsvcs / examples / FaultTolerance / RolyPoly / client.cpp
bloba13dffdb184398c0acebb2cd119ffe8a8226f7c2
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());
124 ACE_DEBUG ((LM_DEBUG, "Prepare to merge IORs.\n"));
125 // Create a merged set 1;
126 object = iorm->merge_iors (iors);
129 FT::TagFTGroupTaggedComponent ft_tag_component;
131 // Property values
133 // Major and Minor revision numbers
134 ft_tag_component.object_group_ref_version = 0;
136 // Domain id
137 const char *id = "iogr_testing";
138 ft_tag_component.group_domain_id = id;
140 // Object group id
141 ft_tag_component.object_group_id =
142 (CORBA::ULongLong) 10;
144 // Version
145 ft_tag_component.object_group_ref_version =
146 (CORBA::ULong) 5;
148 // Construct the IOGR Property class
149 TAO_FT_IOGR_Property iogr_prop (ft_tag_component);
151 // Set the property
152 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
153 object.in ());
155 retval = iorm->set_primary (&iogr_prop,
156 object_primary.in (),
157 object.in ());
159 ACE_UNUSED_ARG (retval);
161 else
163 ACE_SString *ior = 0;
164 if (ior_strs.get (ior) != 0)
165 ACE_ERROR_RETURN ((LM_ERROR,
166 "Unable to extract the only IOR string\n"),
167 -1);
168 object = orb->string_to_object (ior->c_str());
171 RolyPoly_var server =
172 RolyPoly::_narrow (object.in ());
174 if (CORBA::is_nil (server.in ()))
176 ACE_ERROR_RETURN ((LM_ERROR,
177 "Object reference is nil\n"),
181 CORBA::Short number = 0;
184 for (int i = 1; i < 500; ++i)
186 CORBA::String_var str;
190 number = server->number (str.inout ());
192 catch (RolyPoly::E const& e)
194 ACE_DEBUG ((LM_INFO,
195 "client: received exception %s .\n",
196 e.s.in ()));
197 continue;
201 ACE_DEBUG ((LM_INFO,
202 "client: received %d\n",
203 number));
204 ACE_OS::sleep (1);
207 server->shutdown ();
209 catch (const CORBA::Exception& ex)
211 ex._tao_print_exception ("Caught exception:");
212 return -1;
215 return status;