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
[])
52 Server_ORBInitializer
*temp_initializer
= 0;
53 ACE_NEW_RETURN (temp_initializer
,
54 Server_ORBInitializer
,
55 -1); // No exceptions yet!
56 PortableInterceptor::ORBInitializer_var orb_initializer
=
59 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
62 CORBA::ORB_init (argc
, argv
);
64 // We do the command line parsing first
65 if (parse_args (argc
, argv
) != 0)
67 CORBA::Object_var poa_object
=
68 orb
->resolve_initial_references("RootPOA");
70 if (CORBA::is_nil (poa_object
.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 " (%P|%t) Unable to initialize the POA.\n"),
75 PortableServer::POA_var root_poa
=
76 PortableServer::POA::_narrow (poa_object
.in ());
78 PortableServer::POAManager_var poa_manager
=
79 root_poa
->the_POAManager ();
81 CORBA::PolicyList policies
;
83 policies
[0] = root_poa
->create_id_assignment_policy (
84 PortableServer::USER_ID
);
85 policies
[1] = root_poa
->create_implicit_activation_policy (
86 PortableServer::NO_IMPLICIT_ACTIVATION
);
87 policies
[2] = root_poa
->create_lifespan_policy (
88 PortableServer::PERSISTENT
);
90 PortableServer::POA_var poa
= root_poa
->create_POA (
91 "PERS_POA", poa_manager
.in (), policies
);
93 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
95 policies
[i
]->destroy ();
98 // Instantiate the LCD_Display implementation class
99 Simple_Server_i
display_impl (orb
.in (), ACE_TEXT_ALWAYS_CHAR(key
));
100 PortableServer::ObjectId_var id
=
101 PortableServer::string_to_ObjectId ("IOGR_OID");
103 poa
->activate_object_with_id (id
.in(), &display_impl
);
105 CORBA::Object_var server
=
106 poa
->id_to_reference (id
.in ());
108 CORBA::String_var ior
=
109 orb
->object_to_string (server
.in ());
111 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
113 // If the ior_output_file exists, output the ior to it
114 if (ior_output_file
!= 0)
116 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
117 if (output_file
== 0)
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "Cannot open output file for writing IOR: %s",
122 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
123 ACE_OS::fclose (output_file
);
126 // Set the forward references in the server request interceptor.
127 PortableInterceptor::ServerRequestInterceptor_var
128 server_interceptor
= temp_initializer
->server_interceptor ();
130 Simple_ServerRequestInterceptor_var interceptor
=
131 Simple_ServerRequestInterceptor::_narrow (
132 server_interceptor
.in ());
134 if (CORBA::is_nil (interceptor
.in ()))
135 ACE_ERROR_RETURN ((LM_ERROR
,
136 "(%P|%t) Could not obtain reference to "
137 "server request interceptor.\n"),
140 interceptor
->forward_reference (ACE_TEXT_ALWAYS_CHAR(merged_iorstr
));
142 poa_manager
->activate ();
146 catch (const CORBA::Exception
& ex
)
148 ex
._tao_print_exception ("Caught exception:");