Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Crashed_Callback / client.cpp
blob6d730317b1ffbd713386f2541f29e31aa6f5b379
1 #include "Crashed_Callback.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior = get_opts.opt_arg ();
20 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 CORBA::Object_var poa_object =
43 orb->resolve_initial_references("RootPOA");
45 PortableServer::POA_var root_poa =
46 PortableServer::POA::_narrow (poa_object.in ());
48 if (CORBA::is_nil (root_poa.in ()))
49 ACE_ERROR_RETURN ((LM_ERROR,
50 " (%P|%t) Panic: nil RootPOA\n"),
51 1);
53 PortableServer::POAManager_var poa_manager =
54 root_poa->the_POAManager ();
56 // Make all oneways "reliable."
58 CORBA::Object_var manager_object =
59 orb->resolve_initial_references("ORBPolicyManager");
60 CORBA::PolicyManager_var policy_manager =
61 CORBA::PolicyManager::_narrow(manager_object.in());
63 if (CORBA::is_nil (policy_manager.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Panic: nil PolicyManager\n"),
66 1);
67 CORBA::Any policy_value;
68 policy_value <<= Messaging::SYNC_WITH_SERVER;
69 CORBA::PolicyList policies(1); policies.length(1);
70 policies[0] =
71 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
72 policy_value);
74 policy_manager->set_policy_overrides (policies,
75 CORBA::ADD_OVERRIDE);
77 policies[0]->destroy ();
80 if (parse_args (argc, argv) != 0)
81 return 1;
83 CORBA::Object_var tmp =
84 orb->string_to_object(ior);
86 Test::Service_var service =
87 Test::Service::_narrow(tmp.in ());
89 if (CORBA::is_nil (service.in ()))
91 ACE_ERROR_RETURN ((LM_DEBUG,
92 "Nil service reference <%s>\n",
93 ior),
94 1);
97 Crashed_Callback *crashed_callback_impl;
98 ACE_NEW_RETURN (crashed_callback_impl,
99 Crashed_Callback,
101 PortableServer::ServantBase_var owner_transfer(crashed_callback_impl);
103 PortableServer::ObjectId_var id =
104 root_poa->activate_object (crashed_callback_impl);
106 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
108 Test::Crashed_Callback_var crashed_callback =
109 Test::Crashed_Callback::_narrow (object.in ());
111 poa_manager->activate ();
113 service->run_test (crashed_callback.in ());
115 orb->run ();
117 root_poa->destroy (true, true);
119 orb->destroy ();
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Exception caught:");
124 return 1;
127 return 0;