3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
14 while ((c
= get_opts ()) != -1)
18 ior_output_file
= get_opts
.optarg
;
22 ACE_ERROR_RETURN ((LM_ERROR
,
23 ACE_TEXT("usage: %s ")
24 ACE_TEXT("-o <iorfile>")
30 // Indicates successful parsing of the command line
35 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
41 // Create and register factory for BaseNode.
42 BaseNode_init
*bn_factory
= 0;
43 ACE_NEW_RETURN (bn_factory
,
47 orb
->register_value_factory (bn_factory
->tao_repository_id (),
49 bn_factory
->_remove_ref (); // release ownership
51 // Create and register factory for TreeController.
52 TreeController_init
*tc_factory
= 0;
53 ACE_NEW_RETURN (tc_factory
,
57 orb
->register_value_factory (tc_factory
->tao_repository_id (),
59 tc_factory
->_remove_ref (); // release ownership
61 // Create and register factory for StringNode.
62 StringNode_init
*sn_factory
= 0;
63 ACE_NEW_RETURN (sn_factory
,
67 orb
->register_value_factory (sn_factory
->tao_repository_id (),
69 sn_factory
->_remove_ref (); // release ownership
71 CORBA::Object_var poa_object
=
72 orb
->resolve_initial_references ("RootPOA");
74 if (CORBA::is_nil (poa_object
.in ()))
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 " (%P|%t) Unable to initialize the POA.\n"),
81 PortableServer::POA_var root_poa
=
82 PortableServer::POA::_narrow (poa_object
.in ());
84 PortableServer::POAManager_var poa_manager
=
85 root_poa
->the_POAManager ();
87 if (parse_args (argc
, argv
) != 0)
92 passer_i
servant (orb
.in (), root_poa
.in ());
93 PortableServer::ObjectId_var id
=
94 root_poa
->activate_object (&servant
);
96 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
99 passer::_narrow (object
.in ());
101 CORBA::String_var ior
=
102 orb
->object_to_string (server
.in ());
104 ACE_DEBUG ((LM_DEBUG
,
105 "Activated as <%C>\n",
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");
113 if (output_file
== 0)
115 ACE_ERROR_RETURN ((LM_ERROR
,
116 "Can't open output file for writing IOR: %s",
121 ACE_OS::fprintf (output_file
,
124 ACE_OS::fclose (output_file
);
127 poa_manager
->activate ();
131 // Destroy the POA, waiting until the destruction terminates
132 root_poa
->destroy (true, true);
136 catch (const CORBA::Exception
& ex
)
138 ex
._tao_print_exception ("Server: exception caught - ");