1 #include "Server_Task.h"
3 #include "TreeControllerS.h"
7 #include "ace/Manual_Event.h"
9 Server_Task::Server_Task (const ACE_TCHAR
*output
,
12 ACE_Thread_Manager
*thr_mgr
)
13 : ACE_Task_Base (thr_mgr
)
16 , sorb_ (CORBA::ORB::_duplicate (sorb
))
25 // All factories are kindly provided by
26 // compiler so we just to put everything in a right order.
28 // Create and register factory for BaseNode.
29 BaseNode_init
*bn_factory
= 0;
30 ACE_NEW_RETURN (bn_factory
,
34 this->sorb_
->register_value_factory (bn_factory
->tao_repository_id (),
36 bn_factory
->_remove_ref (); // release ownership
38 // Create and register factory for TreeController.
39 TreeController_init
*tc_factory
= 0;
40 ACE_NEW_RETURN (tc_factory
,
44 this->sorb_
->register_value_factory (tc_factory
->tao_repository_id (),
46 tc_factory
->_remove_ref (); // release ownership
48 // Create and register factory for StringNode.
49 StringNode_init
*sn_factory
= 0;
50 ACE_NEW_RETURN (sn_factory
,
54 this->sorb_
->register_value_factory (sn_factory
->tao_repository_id (),
56 sn_factory
->_remove_ref (); // release ownership
58 //Well, done with factories.
60 CORBA::Object_var poa_object
=
61 this->sorb_
->resolve_initial_references("RootPOA");
63 PortableServer::POA_var root_poa
=
64 PortableServer::POA::_narrow (poa_object
.in ());
66 if (CORBA::is_nil (root_poa
.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 " (%P|%t) Panic: nil RootPOA\n"),
71 PortableServer::POAManager_var poa_manager
=
72 root_poa
->the_POAManager ();
75 ACE_NEW_RETURN (test_impl
,
76 Test_impl (this->sorb_
.in ()),
79 PortableServer::ServantBase_var
owner_transfer(test_impl
);
81 PortableServer::ObjectId_var id
=
82 root_poa
->activate_object (test_impl
);
84 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
86 Test_var test
= Test::_narrow (object
.in ());
88 CORBA::String_var ior
=
89 this->sorb_
->object_to_string (test
.in ());
91 // If the this->output_ exists, output the ior to it
92 FILE *output_file
= ACE_OS::fopen (this->output_
, "w");
94 ACE_ERROR_RETURN ((LM_ERROR
,
95 "Cannot open output file for writing IOR: %s",
98 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
99 ACE_OS::fclose (output_file
);
101 poa_manager
->activate ();
107 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
109 root_poa
->destroy (true, true);
111 this->sorb_
->destroy ();
113 catch (const CORBA::Exception
& ex
)
115 ex
._tao_print_exception ("Exception caught:");