Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2429_Regression / client.cpp
blobb2714df57a5adb755bf98f4bb8553a2a73206c66
1 #include "ace/Get_Opt.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "ChildS.h"
5 class Reply_Handler
6 : public POA_AMI_ChildHandler
8 public:
9 Reply_Handler()
10 : parentMethod_count (0),
11 parentMethod_excep_count (0)
15 virtual void
16 childMethod ()
20 virtual void
21 childMethod_excep (Messaging::ExceptionHolder *
22 excep_holder)
24 try
26 excep_holder->raise_exception ();
28 catch (const CORBA::SystemException& ex)
30 ex._tao_print_exception ("Reply_Handler::childMethod_excep: ");
34 virtual void
35 parentMethod ()
37 ACE_DEBUG ((LM_DEBUG,
38 "client: parentMethod reply %d @ %T\n",
39 ++parentMethod_count));
42 virtual void
43 parentMethod_excep (Messaging::ExceptionHolder * excep_holder)
45 try
47 ++parentMethod_excep_count;
48 excep_holder->raise_exception ();
50 catch (const CORBA::INTERNAL&)
52 ACE_DEBUG ((LM_DEBUG, "Successfully received an Internal Excep*ion as expected.\n"));
54 catch (const CORBA::SystemException& ex)
56 ex._tao_print_exception ("Reply_Handler::childMethod_excep: ");
60 CORBA::ULong reply_count () { return parentMethod_count + parentMethod_excep_count; };
62 private:
63 // Count of replies and excep
64 CORBA::ULong parentMethod_count;
65 CORBA::ULong parentMethod_excep_count;
68 // Server ior.
69 static const ACE_TCHAR *server_ior = ACE_TEXT("file://server.ior");
71 static int
72 client_parse_args(int argc, ACE_TCHAR *argv[])
74 ACE_Get_Opt
75 get_opts(argc, argv, "f:");
76 int c;
78 while ((c = get_opts()) != -1)
80 switch (c)
82 case 'f':
83 server_ior = get_opts.opt_arg();
84 break;
85 case '?':
86 default:
87 ACE_DEBUG((LM_ERROR,
88 "usage: %s "
89 "-f server IOR file\n"));
90 return 1;
94 // Indicates successful parsing of the command line
95 return 0;
98 int
99 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
101 CORBA::ORB_var orb;
105 // Initialize the ORB.
106 orb = CORBA::ORB_init(argc, argv);
108 // Initialize options based on command-line arguments.
109 int parse_args_result = client_parse_args(argc, argv);
110 if (parse_args_result != 0)
112 return 1;
115 CORBA::Object_var object =
116 orb->resolve_initial_references ("RootPOA");
118 PortableServer::POA_var root_poa =
119 PortableServer::POA::_narrow (object.in ());
121 // Get an object reference from the nominated file
122 object = orb->string_to_object (server_ior);
125 PortableServer::POAManager_var poa_manager =
126 root_poa->the_POAManager();
128 poa_manager->activate();
130 Child_var child = Child::_narrow (object.in());
132 Reply_Handler reply_handler_servant;
134 PortableServer::ObjectId_var id =
135 root_poa->activate_object (&reply_handler_servant);
137 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
139 AMI_ChildHandler_var reply_handler_object =
140 AMI_ChildHandler::_narrow (object_act.in ());
142 // Invoke the AMI parentMethod
143 child->sendc_parentMethod (reply_handler_object.in ());
145 // Loop until all replies have been received.
146 while (reply_handler_servant.reply_count () == 0)
148 orb->perform_work ();
151 // Shutdown server.
152 child->shutdown ();
154 orb->destroy ();
156 catch (const CORBA::Exception& ex)
158 ex._tao_print_exception ("Exception caught:");
159 return 1;
162 return 0;