1 #include "sum_server_i.h"
2 #include "Server_IORInterceptor_ORBInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_stdio.h"
8 const ACE_TCHAR
*ior_output_file
= 0;
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
16 while ((c
= get_opts ()) != -1)
20 ior_output_file
= get_opts
.optarg
;
23 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
36 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
40 #if TAO_HAS_INTERCEPTORS == 1
42 PortableInterceptor::ORBInitializer_ptr orb_initializer
=
43 PortableInterceptor::ORBInitializer::_nil ();
45 ACE_NEW_RETURN (orb_initializer
,
46 Server_IORInterceptor_ORBInitializer
,
47 -1); // No CORBA exceptions yet!
49 PortableInterceptor::ORBInitializer_var orb_initializer_var
=
52 PortableInterceptor::register_orb_initializer (orb_initializer_var
.in ());
54 #endif /* TAO_HAS_INTERCEPTORS == 1 */
56 // The usual initialization stuff
58 // Initialize the ORB.
59 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
63 if (parse_args (argc
, argv
) != 0)
66 // Resolve reference to RootPOA
67 CORBA::Object_var obj
=
68 orb
->resolve_initial_references ("RootPOA");
70 // Narrow it down correctly.
71 PortableServer::POA_var root_poa
=
72 PortableServer::POA::_narrow (obj
.in ());
74 // Check for nil references
75 if (CORBA::is_nil (root_poa
.in ()))
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 "Unable to obtain RootPOA reference.\n"),
80 // Get poa_manager reference
81 PortableServer::POAManager_var poa_manager
=
82 root_poa
->the_POAManager ();
85 poa_manager
->activate ();
87 // initialize the sum_server
88 sum_server_i sum_server_impl
;
91 obj
= sum_server_impl
._this ();
94 ORT::sum_server_var sum_server
=
95 ORT::sum_server::_narrow (obj
.in ());
97 // Check for nil reference
98 if (CORBA::is_nil (sum_server
.in ()))
99 ACE_ERROR_RETURN ((LM_ERROR
,
100 "Unable to obtain reference to ORT::sum_server "
104 // Convert the object reference to a string format.
105 CORBA::String_var ior
=
106 orb
->object_to_string (sum_server
.in ());
108 // If the ior_output_file exists, output the IOR to it.
109 if (ior_output_file
!= 0)
111 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
112 if (output_file
== 0)
113 ACE_ERROR_RETURN ((LM_ERROR
,
114 "Cannot open output file for writing "
118 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
119 ACE_OS::fclose (output_file
);
124 ACE_DEBUG ((LM_INFO
, "Successful.\n"));
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("ORT example server:");