Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / POA / Bug_1592_Regression / server.cpp
blobc875f45768dbf3638f87dbbc3498efd7ae6c4099
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "test_i.h"
4 #include "ServantLocator.h"
5 #include "Server_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR * ior_file = 0;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_file = get_opts.opt_arg ();
22 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "Usage: %s "
27 "-o IOR\n",
28 argv[0]),
29 -1);
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
40 Server_ORBInitializer *temp_initializer = 0;
41 ACE_NEW_RETURN (temp_initializer,
42 Server_ORBInitializer,
43 -1); // No exceptions yet!
44 PortableInterceptor::ORBInitializer_var orb_initializer =
45 temp_initializer;
47 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv, "Server ORB");
52 CORBA::Object_var poa_object =
53 orb->resolve_initial_references ("RootPOA");
55 if (CORBA::is_nil (poa_object.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Unable to initialize the POA.\n"),
58 1);
60 PortableServer::POA_var root_poa =
61 PortableServer::POA::_narrow (poa_object.in ());
63 PortableServer::POAManager_var poa_manager =
64 root_poa->the_POAManager ();
66 // Create a child POA configured to use a ServantLocator.
67 CORBA::PolicyList policies (2);
69 policies.length (2);
70 policies[0] =
71 root_poa->create_request_processing_policy (
72 PortableServer::USE_SERVANT_MANAGER);
74 policies[1] =
75 root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN);
77 PortableServer::POA_var child_poa =
78 root_poa->create_POA ("child",
79 poa_manager.in (),
80 policies);
82 ServantLocator* sl = 0;
83 ACE_NEW_THROW_EX (sl,
84 ServantLocator (orb.in ()),
85 CORBA::NO_MEMORY ());
87 PortableServer::ServantLocator_var servant_locator = sl;
89 child_poa->set_servant_manager (servant_locator.in ());
91 poa_manager->activate ();
93 CORBA::Object_var obj =
94 child_poa->create_reference ("IDL:test:1.0");
96 CORBA::String_var ior = orb->object_to_string (obj.in ());
98 if (::parse_args (argc, argv) != 0)
99 return -1;
101 // Write IOR to a file.
102 FILE *output_file= ACE_OS::fopen (ior_file, "w");
103 if (output_file == 0)
104 ACE_ERROR_RETURN ((LM_ERROR,
105 "Cannot open output file <%s> for writing "
106 "IOR:\n%s\n",
107 ior_file,
108 ior.in ()),
110 ACE_OS::fprintf (output_file, "%s", ior.in ());
111 ACE_OS::fclose (output_file);
113 // Run the ORB event loop.
114 orb->run ();
116 root_poa->destroy (true, true);
118 orb->destroy ();
120 if (sl->error_status_ == false)
122 ACE_DEBUG ((LM_DEBUG,
123 "PortableInterceptor / ServantLocator test passed.\n"));
125 else
127 ACE_ERROR ((LM_ERROR,
128 "PortableInterceptor / ServantLocator test failed.\n"));
129 return 1;
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Caught exception:");
135 return -1;
138 return 0;