Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / ReconnectServer / serverB.cpp
blob9d9afb07ecd6dcba104a6347aa33e6b9bdeaa6cc
1 #include "test_i.h"
2 #include "ORB_Task.h"
3 #include "tao/ImR_Client/ImR_Client.h"
4 #include <ace/Task.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;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, "o:l:");
16 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case 'l':
26 server_notify_delay = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-o <iorfile> -l <server_notify_delay>"
33 "\n",
34 argv [0]),
35 -1);
38 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
48 if (parse_args (argc, argv) != 0)
50 return 1;
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,
58 1);
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);
66 policies.length (5);
68 // Lifespan policy
69 policies[0] =
70 rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);
72 // Servant Retention Policy
73 policies[1] =
74 rootPOA->create_servant_retention_policy (PortableServer::RETAIN);
76 // ID Assignment Policy
77 policies[2] =
78 rootPOA->create_id_assignment_policy (PortableServer::USER_ID);
80 // Request Processing Policy
81 policies[3] =
82 rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);
84 // Threading policy
85 policies[4] =
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",
95 poa_manager.in (),
96 policies);
98 for (CORBA::ULong i = 0;
99 i < policies.length ();
100 ++i)
102 CORBA::Policy_ptr policy = policies[i];
103 policy->destroy ();
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",
122 ior_output_file),
124 ACE_OS::fprintf (output_file, "%s", ior.in ());
125 ACE_OS::fclose (output_file);
127 worker.wait ();
129 rootPOA->destroy (1, 1);
130 orb->destroy ();
132 catch (const CORBA::Exception &ex)
134 ex._tao_print_exception ("Exception caught by serverB:");
135 return 1;
138 return 0;