Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / MProfile_Connection_Timeout / client.cpp
blobc53a5b09e680e4a6cdddde4c9b74e3557a735a3b
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[])
58 try
60 CORBA::ORB_var orb =
61 CORBA::ORB_init (argc, argv);
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 // Primary server
67 CORBA::Object_var object_primary =
68 orb->string_to_object (ior);
70 //Secondary server
71 CORBA::Object_var object_secondary =
72 orb->string_to_object (name);
74 // Get an object reference for the ORBs IORManipultion object!
75 CORBA::Object_var IORM =
76 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION, 0);
78 TAO_IOP::TAO_IOR_Manipulation_var iorm =
79 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in ());
81 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
82 iors.length(2);
83 iors [0] = object_primary;
84 iors [1] = object_secondary;
86 CORBA::Object_var merged = iorm->merge_iors (iors);
88 CORBA::Object_var object =
89 orb->resolve_initial_references ("PolicyCurrent");
91 CORBA::PolicyCurrent_var policy_current =
92 CORBA::PolicyCurrent::_narrow (object.in ());
94 CORBA::Any timeout_as_any;
95 timeout_as_any <<= timeout_period;
97 CORBA::PolicyList policy_list (1);
98 policy_list.length (1);
100 policy_list[0] =
101 orb->create_policy (TAO::CONNECTION_TIMEOUT_POLICY_TYPE,
102 timeout_as_any);
104 policy_current->set_policy_overrides (policy_list,
105 CORBA::ADD_OVERRIDE);
108 for (CORBA::ULong l = 0;
109 l != policy_list.length ();
110 ++l)
112 policy_list[l]->destroy ();
115 // Combined IOR stuff
116 Simple_Server_var server =
117 Simple_Server::_narrow (merged.in ());
119 if (CORBA::is_nil (server.in ()))
121 ACE_ERROR_RETURN ((LM_ERROR,
122 "Object reference <%s> is nil.\n",
123 ior),
127 CORBA::ULongLong freq =
128 run_test (server.in ());
130 if (freq != 919263)
131 ACE_ERROR ((LM_ERROR,
132 ACE_TEXT ("(%P|%t) ERROR in the test\n")));
134 ACE_DEBUG ((LM_DEBUG,
135 ACE_TEXT ("(%P|%t) Shutting server down\n")));
137 server->shutdown ();
139 catch (const CORBA::Exception& ex)
141 ex._tao_print_exception ("Caught an exception\n");
142 return -1;
145 return 0;
148 CORBA::ULongLong
149 run_test (Simple_Server_ptr server)
151 return server->remote_call ();