2 #include "TreeControllerC.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.optarg
;
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
38 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
43 CORBA::ORB_init (argc
, argv
);
45 // All factories are kindly provided by
46 // compiler so we just to put everything in a right order.
48 // Create and register factory for BaseNode.
49 BaseNode_init
*bn_factory
= 0;
50 ACE_NEW_RETURN (bn_factory
,
54 orb
->register_value_factory (bn_factory
->tao_repository_id (),
56 bn_factory
->_remove_ref (); // release ownership
58 // Create and register factory for TreeController.
59 TreeController_init
*tc_factory
= 0;
60 ACE_NEW_RETURN (tc_factory
,
64 orb
->register_value_factory (tc_factory
->tao_repository_id (),
66 tc_factory
->_remove_ref (); // release ownership
68 // Create and register factory for StringNode.
69 StringNode_init
*sn_factory
= 0;
70 ACE_NEW_RETURN (sn_factory
,
74 orb
->register_value_factory (sn_factory
->tao_repository_id (),
76 sn_factory
->_remove_ref (); // release ownership
78 //Well, done with factories.
80 CORBA::Object_var poa_object
=
81 orb
->resolve_initial_references("RootPOA");
83 PortableServer::POA_var root_poa
=
84 PortableServer::POA::_narrow (poa_object
.in ());
86 if (CORBA::is_nil (root_poa
.in ()))
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 " (%P|%t) Panic: nil RootPOA\n"),
91 PortableServer::POAManager_var poa_manager
=
92 root_poa
->the_POAManager ();
94 if (parse_args (argc
, argv
) != 0)
98 ACE_NEW_RETURN (test_impl
,
99 Test_impl (orb
.in ()),
102 PortableServer::ServantBase_var
owner_transfer(test_impl
);
104 PortableServer::ObjectId_var id
=
105 root_poa
->activate_object (test_impl
);
107 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
109 Test_var test
= Test::_narrow (object
.in ());
111 CORBA::String_var ior
=
112 orb
->object_to_string (test
.in ());
114 // If the ior_output_file exists, output the ior to it
115 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
116 if (output_file
== 0)
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 "Cannot open output file for writing IOR: %s",
121 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
122 ACE_OS::fclose (output_file
);
124 poa_manager
->activate ();
128 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
130 root_poa
->destroy (true, true);
134 catch (const CORBA::Exception
& ex
)
136 ex
._tao_print_exception ("Exception caught:");