1 #include "ace/Get_Opt.h"
2 #include "Receiver_i.h"
4 #include "tao/BiDir_GIOP/BiDirGIOP.h"
5 #include "tao/AnyTypeCode/Any.h"
6 #include "Client_Task.h"
8 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
16 while ((c
= get_opts ()) != -1)
20 ior
= get_opts
.optarg
;
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
36 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_init (argc
, argv
);
43 if (parse_args (argc
, argv
) != 0)
46 CORBA::Object_var poa_object
=
47 orb
->resolve_initial_references ("RootPOA");
49 if (CORBA::is_nil (poa_object
.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 " (%P|%t) Unable to initialize the POA.\n"),
54 PortableServer::POA_var root_poa
=
55 PortableServer::POA::_narrow (poa_object
.in ());
57 PortableServer::POAManager_var poa_manager
=
58 root_poa
->the_POAManager ();
60 // Policies for the childPOA to be created.
61 CORBA::PolicyList
policies (1);
65 pol
<<= BiDirPolicy::BOTH
;
67 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
70 // Create POA as child of RootPOA with the above policies. This POA
71 // will receive request in the same connection in which it sent
73 PortableServer::POA_var child_poa
=
74 root_poa
->create_POA ("childPOA",
78 // Creation of childPOA is over. Destroy the Policy objects.
79 for (CORBA::ULong i
= 0;
80 i
< policies
.length ();
83 policies
[i
]->destroy ();
86 poa_manager
->activate ();
88 CORBA::Object_var object
=
89 orb
->string_to_object (ior
);
92 Sender::_narrow (object
.in ());
94 if (CORBA::is_nil (sender
.in ()))
96 ACE_ERROR_RETURN ((LM_ERROR
,
97 "Object reference <%s> is nil.\n",
103 Receiver_i
*receiver
;
104 ACE_NEW_RETURN (receiver
,
108 PortableServer::ServantBase_var
owner_transfer (receiver
);
110 PortableServer::ObjectId_var id
=
111 root_poa
->activate_object (receiver
);
113 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
115 Receiver_var receiver_obj
=
116 Receiver::_narrow (object_act
.in ());
118 // Send the callback object to the server
119 sender
->receiver_object (receiver_obj
.in ());
121 // Threads that will handle the call backs
122 Client_Task
client_task (orb
.in (),
123 ACE_Thread_Manager::instance ());
125 if (client_task
.activate (THR_NEW_LWP
| THR_JOINABLE
, 4, 1) == -1)
127 ACE_ERROR ((LM_ERROR
, "Error activating client task\n"));
130 ACE_Thread_Manager::instance ()->wait ();
133 receiver
->get_event_count ();
135 ACE_DEBUG ((LM_DEBUG
,
136 "(%P|%t) Number of events received.. [%d]\n",
139 root_poa
->destroy (true, true);
141 catch (const CORBA::Exception
& ex
)
143 ex
._tao_print_exception ("Caught exception:");