Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / HTIOP / BiDirectional / server.cpp
blob890e6c4631ad6d264a9b34b53616064a629a6006
1 #include "ace/OS_NS_stdio.h"
2 #include "ace/Get_Opt.h"
3 #include "test_i.h"
4 #include "tao/BiDir_GIOP/BiDirGIOP.h"
5 #include "tao/AnyTypeCode/Any.h"
8 const ACE_TCHAR *ior_output_file = 0;
9 int no_iterations = 10;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:i:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
23 case 'i':
24 no_iterations = ACE_OS::atoi (get_opts.opt_arg ());
25 break;
26 case '?':
27 default:
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "usage: %s "
30 "-o <iorfile>"
31 "-i <no_iterations>"
32 "\n",
33 argv [0]),
34 -1);
36 // Indicates successful parsing of the command line
37 return 0;
40 int
41 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
43 try
45 CORBA::ORB_var orb =
46 CORBA::ORB_init (argc, argv);
48 CORBA::Object_var poa_object =
49 orb->resolve_initial_references ("RootPOA");
51 if (CORBA::is_nil (poa_object.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR,
53 " (%P|%t) Unable to initialize the POA.\n"),
54 1);
56 PortableServer::POA_var root_poa =
57 PortableServer::POA::_narrow (poa_object.in ());
59 PortableServer::POAManager_var poa_manager =
60 root_poa->the_POAManager ();
62 // Policies for the childPOA to be created.
63 CORBA::PolicyList policies (1);
64 policies.length (1);
66 CORBA::Any pol;
67 pol <<= BiDirPolicy::BOTH;
68 policies[0] =
69 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
70 pol);
72 // Create POA as child of RootPOA with the above policies. This POA
73 // will receive request in the same connection in which it sent
74 // the request
75 PortableServer::POA_var child_poa =
76 root_poa->create_POA ("childPOA",
77 poa_manager.in (),
78 policies);
80 // Creation of childPOA is over. Destroy the Policy objects.
81 for (CORBA::ULong i = 0;
82 i < policies.length ();
83 ++i)
85 policies[i]->destroy ();
88 poa_manager->activate ();
90 if (parse_args (argc, argv) != 0)
91 return 1;
93 Simple_Server_i *server_impl = new Simple_Server_i (orb.in (),
94 no_iterations);
96 PortableServer::ObjectId_var id =
97 PortableServer::string_to_ObjectId ("simple_server");
99 child_poa->activate_object_with_id (id.in (),
100 server_impl);
102 server_impl->_remove_ref();
104 CORBA::Object_var obj =
105 child_poa->id_to_reference (id.in ());
107 CORBA::String_var ior =
108 orb->object_to_string (obj.in ());
110 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
112 // If the ior_output_file exists, output the ior to it
113 if (ior_output_file != 0)
115 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
116 if (output_file == 0)
117 ACE_ERROR_RETURN ((LM_ERROR,
118 "Cannot open output file for writing IOR: %s",
119 ior_output_file),
121 ACE_OS::fprintf (output_file, "%s", ior.in ());
122 ACE_OS::fclose (output_file);
125 int retval = 0;
126 while (retval == 0)
128 // Just process one upcall. We know that we would get the
129 // clients IOR in that call.
130 CORBA::Boolean pending =
131 orb->work_pending();
133 if (pending)
135 orb->perform_work();
137 // Now that hopefully we have the clients IOR, just start
138 // making remote calls to the client.
139 retval = server_impl->call_client ();
141 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
143 root_poa->destroy (true, true);
145 catch (const CORBA::Exception& ex)
147 ex._tao_print_exception ("Caught exception:");
148 return 1;
151 return 0;