3 #include "tao/ImR_Client/ImR_Client.h"
5 #include <ace/Get_Opt.h>
6 #include "ace/OS_NS_unistd.h"
8 const ACE_TCHAR
* ior_output_file
= ACE_TEXT ("serverB.ior");
9 // server_notify_delay between resolving RootPOA init ref and create_POA.
10 int server_notify_delay
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, "o:l:");
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
26 server_notify_delay
= ACE_OS::atoi (get_opts
.opt_arg ());
30 ACE_ERROR_RETURN ((LM_ERROR
,
32 "-o <iorfile> -l <server_notify_delay>"
42 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
46 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
48 if (parse_args (argc
, argv
) != 0)
53 CORBA::Object_var object
=
54 orb
->resolve_initial_references ("RootPOA");
56 ORB_Task
worker (orb
.in ());
57 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
60 PortableServer::POA_var rootPOA
=
61 PortableServer::POA::_narrow (object
.in ());
62 PortableServer::POAManager_var poa_manager
=
63 rootPOA
->the_POAManager ();
65 CORBA::PolicyList
policies (5);
70 rootPOA
->create_lifespan_policy (PortableServer::PERSISTENT
);
72 // Servant Retention Policy
74 rootPOA
->create_servant_retention_policy (PortableServer::RETAIN
);
76 // ID Assignment Policy
78 rootPOA
->create_id_assignment_policy (PortableServer::USER_ID
);
80 // Request Processing Policy
82 rootPOA
->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
);
86 rootPOA
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
88 if (server_notify_delay
> 0)
90 ACE_OS::sleep (server_notify_delay
);
91 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)ServerB Now register with IMR \n"));
94 PortableServer::POA_var poa_a
= rootPOA
->create_POA ("poaB",
98 for (CORBA::ULong i
= 0;
99 i
< policies
.length ();
102 CORBA::Policy_ptr policy
= policies
[i
];
106 Test_Dummy_i
* dummy
= new Test_Dummy_i();
108 PortableServer::ObjectId_var oid
=
109 PortableServer::string_to_ObjectId ("Server_B");
110 poa_a
->activate_object_with_id (oid
.in (), dummy
);
111 CORBA::Object_var dummy_obj
= poa_a
->id_to_reference(oid
.in());
112 CORBA::String_var ior
=
113 orb
->object_to_string (dummy_obj
.in ());
115 poa_manager
->activate ();
117 // Output the IOR to the <ior_output_file>
118 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
119 if (output_file
== 0)
120 ACE_ERROR_RETURN ((LM_ERROR
,
121 "Cannot open output file for writing IOR: %s",
124 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
125 ACE_OS::fclose (output_file
);
129 rootPOA
->destroy (1, 1);
132 catch (const CORBA::Exception
&ex
)
134 ex
._tao_print_exception ("Exception caught by serverB:");