2 #include "ace/Get_Opt.h"
4 #include "ServantLocator.h"
5 #include "Server_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR
* ior_file
= 0;
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_file
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
36 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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
=
47 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
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"),
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);
71 root_poa
->create_request_processing_policy (
72 PortableServer::USE_SERVANT_MANAGER
);
75 root_poa
->create_servant_retention_policy (PortableServer::NON_RETAIN
);
77 PortableServer::POA_var child_poa
=
78 root_poa
->create_POA ("child",
82 ServantLocator
* sl
= 0;
84 ServantLocator (orb
.in ()),
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)
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 "
110 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
111 ACE_OS::fclose (output_file
);
113 // Run the ORB event loop.
116 root_poa
->destroy (true, true);
120 if (sl
->error_status_
== false)
122 ACE_DEBUG ((LM_DEBUG
,
123 "PortableInterceptor / ServantLocator test passed.\n"));
127 ACE_ERROR ((LM_ERROR
,
128 "PortableInterceptor / ServantLocator test failed.\n"));
132 catch (const CORBA::Exception
& ex
)
134 ex
._tao_print_exception ("Caught exception:");