1 #include "Server_ORBInitializer.h"
2 #include "Server_Request_Interceptor.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
7 #include "tao/ORBInitializer_Registry.h"
9 const ACE_TCHAR
*ior_output_file
= 0;
10 const ACE_TCHAR
*merged_iorstr
= 0;
11 const ACE_TCHAR
*key
= 0;
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:k:f:"));
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
26 key
= get_opts
.opt_arg ();
29 merged_iorstr
= get_opts
.opt_arg ();
34 ACE_ERROR_RETURN ((LM_ERROR
,
43 // Indicates successful parsing of the command line
48 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
54 Server_ORBInitializer
*temp_initializer
= 0;
55 ACE_NEW_RETURN (temp_initializer
,
56 Server_ORBInitializer
,
57 -1); // No exceptions yet!
58 PortableInterceptor::ORBInitializer_var orb_initializer
=
61 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
64 CORBA::ORB_init (argc
, argv
);
66 // We do the command line parsing first
67 if (parse_args (argc
, argv
) != 0)
69 CORBA::Object_var poa_object
=
70 orb
->resolve_initial_references("RootPOA");
72 if (CORBA::is_nil (poa_object
.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR
,
74 " (%P|%t) Unable to initialize the POA.\n"),
77 PortableServer::POA_var root_poa
=
78 PortableServer::POA::_narrow (poa_object
.in ());
80 PortableServer::POAManager_var poa_manager
=
81 root_poa
->the_POAManager ();
83 CORBA::PolicyList policies
;
85 policies
[0] = root_poa
->create_id_assignment_policy (
86 PortableServer::USER_ID
);
87 policies
[1] = root_poa
->create_implicit_activation_policy (
88 PortableServer::NO_IMPLICIT_ACTIVATION
);
89 policies
[2] = root_poa
->create_lifespan_policy (
90 PortableServer::PERSISTENT
);
92 PortableServer::POA_var poa
= root_poa
->create_POA (
93 "PERS_POA", poa_manager
.in (), policies
);
95 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
97 policies
[i
]->destroy ();
100 // Instantiate the LCD_Display implementation class
101 Simple_Server_i
display_impl (orb
.in (), ACE_TEXT_ALWAYS_CHAR(key
));
102 PortableServer::ObjectId_var id
=
103 PortableServer::string_to_ObjectId ("IOGR_OID");
105 poa
->activate_object_with_id (id
.in(), &display_impl
);
107 CORBA::Object_var server
=
108 poa
->id_to_reference (id
.in ());
110 CORBA::String_var ior
=
111 orb
->object_to_string (server
.in ());
113 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
115 // If the ior_output_file exists, output the ior to it
116 if (ior_output_file
!= 0)
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
);
128 // Set the forward references in the server request interceptor.
129 PortableInterceptor::ServerRequestInterceptor_var
130 server_interceptor
= temp_initializer
->server_interceptor ();
132 Simple_ServerRequestInterceptor_var interceptor
=
133 Simple_ServerRequestInterceptor::_narrow (
134 server_interceptor
.in ());
136 if (CORBA::is_nil (interceptor
.in ()))
137 ACE_ERROR_RETURN ((LM_ERROR
,
138 "(%P|%t) Could not obtain reference to "
139 "server request interceptor.\n"),
142 interceptor
->forward_reference (ACE_TEXT_ALWAYS_CHAR(merged_iorstr
));
144 poa_manager
->activate ();
148 catch (const CORBA::Exception
& ex
)
150 ex
._tao_print_exception ("Caught exception:");