Continued changes from peer review
[ACE_TAO.git] / TAO / tests / Oneways_Invoking_Twoways / client.cpp
blob9195b04f6f99b4c4c1a2be6136db4e8e2b458a67
1 #include "Receiver_i.h"
2 #include "Client_Task.h"
3 #include "Server_Task.h"
4 #include "ace/Get_Opt.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;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <ior>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 try
38 CORBA::ORB_var orb =
39 CORBA::ORB_init (argc, argv);
41 CORBA::Object_var poa_object =
42 orb->resolve_initial_references("RootPOA");
44 if (CORBA::is_nil (poa_object.in ()))
45 ACE_ERROR_RETURN ((LM_ERROR,
46 " (%P|%t) Unable to initialize the POA.\n"),
47 1);
49 PortableServer::POA_var root_poa =
50 PortableServer::POA::_narrow (poa_object.in ());
52 PortableServer::POAManager_var poa_manager =
53 root_poa->the_POAManager ();
55 if (parse_args (argc, argv) != 0)
56 return 1;
58 // Get the sender reference..
59 CORBA::Object_var tmp =
60 orb->string_to_object(ior);
62 Test::Sender_var sender =
63 Test::Sender::_narrow(tmp.in ());
65 if (CORBA::is_nil (sender.in ()))
67 ACE_ERROR_RETURN ((LM_DEBUG,
68 "Nil coordinator reference <%s>\n",
69 ior),
70 1);
73 Receiver_i *receiver_impl;
74 ACE_NEW_RETURN (receiver_impl,
75 Receiver_i (orb.in (),
76 sender.in (),
77 10),
78 1);
80 PortableServer::ServantBase_var receiver_owner_transfer(receiver_impl);
82 PortableServer::ObjectId_var id =
83 root_poa->activate_object (receiver_impl);
85 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
87 Test::Receiver_var receiver =
88 Test::Receiver::_narrow (object.in ());
90 // Activate poa manager
91 poa_manager->activate ();
93 Client_Task client_task (sender.in (),
94 receiver.in (),
95 ACE_Thread_Manager::instance (),
96 receiver_impl);
98 Server_Task server_task (orb.in (),
99 ACE_Thread_Manager::instance ());
101 // Before creating threads we will let the sender know that we
102 // will have two threads that would make invocations..
103 sender->active_objects ((CORBA::Short) 2);
105 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 2,1) == -1)
107 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
110 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 2, 1) == -1)
112 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
115 // wait for oneway sends and twoway replies to be processed
116 client_task.wait ();
118 // shutdown server
119 sender->shutdown ();
121 // shutdown ourself
122 receiver->shutdown ();
124 // wait for event loop to finish
125 server_task.wait ();
127 ACE_DEBUG ((LM_DEBUG,
128 "Event Loop finished\n"));
130 orb->destroy ();
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Exception caught:");
135 return 1;
138 return 0;