Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_2429_Regression / client.cpp
blob7614508edcf55c136fe46a4fcb61ac61f2ef4f7c
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 (void)
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 (void)
37 ACE_DEBUG ((LM_DEBUG,
38 "client: parentMethod reply %d @ %T\n",
39 ++parentMethod_count));
43 virtual void
44 parentMethod_excep (Messaging::ExceptionHolder * excep_holder)
46 try
48 ++parentMethod_excep_count;
49 excep_holder->raise_exception ();
51 catch (const CORBA::INTERNAL&)
53 ACE_DEBUG ((LM_DEBUG, "Successfully received an Internal Excep*ion as expected.\n"));
55 catch (const CORBA::SystemException& ex)
57 ex._tao_print_exception ("Reply_Handler::childMethod_excep: ");
61 CORBA::ULong reply_count (void) { return parentMethod_count + parentMethod_excep_count; };
63 private:
64 // Count of replies and excep
65 CORBA::ULong parentMethod_count;
66 CORBA::ULong parentMethod_excep_count;
69 // Server ior.
70 static const ACE_TCHAR *server_ior = ACE_TEXT("file://server.ior");
72 static int
73 client_parse_args(int argc, ACE_TCHAR *argv[])
75 ACE_Get_Opt
76 get_opts(argc, argv, "f:");
77 int c;
79 while ((c = get_opts()) != -1)
81 switch (c)
83 case 'f':
84 server_ior = get_opts.opt_arg();
85 break;
86 case '?':
87 default:
88 ACE_DEBUG((LM_ERROR,
89 "usage: %s "
90 "-f server IOR file\n"));
91 return 1;
95 // Indicates successful parsing of the command line
96 return 0;
99 int
100 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
103 CORBA::ORB_var orb;
107 // Initialize the ORB.
108 orb = CORBA::ORB_init(argc, argv);
110 // Initialize options based on command-line arguments.
111 int parse_args_result = client_parse_args(argc, argv);
112 if (parse_args_result != 0)
114 return 1;
117 CORBA::Object_var object =
118 orb->resolve_initial_references ("RootPOA");
120 PortableServer::POA_var root_poa =
121 PortableServer::POA::_narrow (object.in ());
123 // Get an object reference from the nominated file
124 object = orb->string_to_object (server_ior);
127 PortableServer::POAManager_var poa_manager =
128 root_poa->the_POAManager();
130 poa_manager->activate();
132 Child_var child = Child::_narrow (object.in());
134 Reply_Handler reply_handler_servant;
136 PortableServer::ObjectId_var id =
137 root_poa->activate_object (&reply_handler_servant);
139 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
141 AMI_ChildHandler_var reply_handler_object =
142 AMI_ChildHandler::_narrow (object_act.in ());
144 // Invoke the AMI parentMethod
145 child->sendc_parentMethod (reply_handler_object.in ());
147 // Loop until all replies have been received.
148 while (reply_handler_servant.reply_count () == 0)
150 orb->perform_work ();
153 // Shutdown server.
154 child->shutdown ();
156 orb->destroy ();
158 catch (const CORBA::Exception& ex)
160 ex._tao_print_exception ("Exception caught:");
161 return 1;
164 return 0;