Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / MProfile_Connection_Timeout / client.cpp
blob41a117c026c5a710f9c2f9b34139ec713e4653a8
1 // -*- C++ -*-
2 #include "tao/IORManipulation/IORManip_Loader.h"
3 #include "ace/SString.h"
4 #include "ace/Get_Opt.h"
5 #include "testC.h"
6 #include "tao/TimeBaseC.h"
7 #include "tao/Messaging/Messaging.h"
8 #include "tao/AnyTypeCode/Any.h"
10 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
11 int do_shutdown = 0;
13 const ACE_TCHAR *name = ACE_TEXT("file://amba.ior");
14 TimeBase::TimeT timeout_period = 1000000;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:m:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'x':
26 do_shutdown = 1;
27 break;
29 case 'k':
30 ior = get_opts.opt_arg ();
31 break;
33 case 'm':
34 name = get_opts.opt_arg ();
35 break;
37 case '?':
38 default:
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "usage: %s "
41 "-k <ior> "
42 "-i <niterations> "
43 "\n",
44 argv [0]),
45 -1);
47 // Indicates successful parsing of the command line
48 return 0;
51 CORBA::ULongLong
52 run_test (Simple_Server_ptr server);
54 int
55 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
57 try
59 CORBA::ORB_var orb =
60 CORBA::ORB_init (argc, argv);
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 // Primary server
66 CORBA::Object_var object_primary =
67 orb->string_to_object (ior);
69 //Secondary server
70 CORBA::Object_var object_secondary =
71 orb->string_to_object (name);
73 // Get an object reference for the ORBs IORManipultion object!
74 CORBA::Object_var IORM =
75 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION, 0);
77 TAO_IOP::TAO_IOR_Manipulation_var iorm =
78 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in ());
80 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
81 iors.length(2);
82 iors [0] = object_primary;
83 iors [1] = object_secondary;
85 CORBA::Object_var merged = iorm->merge_iors (iors);
87 CORBA::Object_var object =
88 orb->resolve_initial_references ("PolicyCurrent");
90 CORBA::PolicyCurrent_var policy_current =
91 CORBA::PolicyCurrent::_narrow (object.in ());
93 CORBA::Any timeout_as_any;
94 timeout_as_any <<= timeout_period;
96 CORBA::PolicyList policy_list (1);
97 policy_list.length (1);
99 policy_list[0] =
100 orb->create_policy (TAO::CONNECTION_TIMEOUT_POLICY_TYPE,
101 timeout_as_any);
103 policy_current->set_policy_overrides (policy_list,
104 CORBA::ADD_OVERRIDE);
107 for (CORBA::ULong l = 0;
108 l != policy_list.length ();
109 ++l)
111 policy_list[l]->destroy ();
114 // Combined IOR stuff
115 Simple_Server_var server =
116 Simple_Server::_narrow (merged.in ());
118 if (CORBA::is_nil (server.in ()))
120 ACE_ERROR_RETURN ((LM_ERROR,
121 "Object reference <%s> is nil.\n",
122 ior),
126 CORBA::ULongLong freq =
127 run_test (server.in ());
129 if (freq != 919263)
130 ACE_ERROR ((LM_ERROR,
131 ACE_TEXT ("(%P|%t) ERROR in the test\n")));
133 ACE_DEBUG ((LM_DEBUG,
134 ACE_TEXT ("(%P|%t) Shutting server down\n")));
136 server->shutdown ();
138 catch (const CORBA::Exception& ex)
140 ex._tao_print_exception ("Caught an exception\n");
141 return -1;
144 return 0;
147 CORBA::ULongLong
148 run_test (Simple_Server_ptr server)
150 return server->remote_call ();