Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_1482_Regression / client.cpp
blob7ebbcbc1418dc642da28a96d5a9661213af33805
1 #include "TestS.h"
2 #include "Client_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "tao/AnyTypeCode/Any.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior> "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 CORBA::ORB_var orb =
40 CORBA::ORB_init (argc, argv);
42 if (parse_args (argc, argv) != 0)
43 return 1;
45 CORBA::Object_var tmp =
46 orb->string_to_object(ior);
48 Test::Hello_var hello =
49 Test::Hello::_narrow(tmp.in ());
51 if (CORBA::is_nil (hello.in ()))
53 ACE_ERROR_RETURN ((LM_DEBUG,
54 "Nil Test::Hello reference <%s>\n",
55 ior),
56 1);
59 CORBA::Object_var poa_object =
60 orb->resolve_initial_references("RootPOA");
62 PortableServer::POA_var root_poa =
63 PortableServer::POA::_narrow (poa_object.in ());
65 PortableServer::POAManager_var poa_manager =
66 root_poa->the_POAManager ();
68 poa_manager->activate ();
70 CORBA::Object_var object =
71 orb->resolve_initial_references ("PolicyCurrent");
72 CORBA::PolicyCurrent_var policy_current =
73 CORBA::PolicyCurrent::_narrow (object.in ());
75 TimeBase::TimeT timeout_period = 10 * 1000;
77 CORBA::Any timeout_as_any;
78 timeout_as_any <<= timeout_period;
80 CORBA::PolicyList policy_list (1);
81 policy_list.length (1);
82 policy_list[0] =
83 orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
84 timeout_as_any);
86 policy_current->set_policy_overrides (policy_list,
87 CORBA::ADD_OVERRIDE);
90 // Let the client perform the test in a separate thread
91 Client_Task client (hello.in (),
92 orb.in (),
93 ACE_Thread_Manager::instance ());
95 if (client.activate (THR_NEW_LWP | THR_JOINABLE,
96 8) != 0)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "Cannot activate client threads\n"),
99 1);
101 client.thr_mgr ()->wait ();
103 root_poa->destroy (true, // ethernalize objects
104 false); // wait for completion
106 orb->destroy ();
108 catch (const CORBA::Exception& ex)
110 ex._tao_print_exception ("Exception caught:");
111 return 1;
114 return 0;