Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / OBV / Collocated / Forward / Server_Task.cpp
bloba23aab2b223b8b3e9b65728b6d4fec61ff1a2cd2
1 #include "Server_Task.h"
2 #include "TreeBaseS.h"
3 #include "TreeControllerS.h"
4 #include "TreeNodeS.h"
5 #include "Test_impl.h"
7 #include "ace/Manual_Event.h"
9 Server_Task::Server_Task (const ACE_TCHAR *output,
10 CORBA::ORB_ptr sorb,
11 ACE_Manual_Event &me,
12 ACE_Thread_Manager *thr_mgr)
13 : ACE_Task_Base (thr_mgr)
14 , output_ (output)
15 , me_ (me)
16 , sorb_ (CORBA::ORB::_duplicate (sorb))
20 int
21 Server_Task::svc ()
23 try
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,
31 BaseNode_init,
32 1);
34 this->sorb_->register_value_factory (bn_factory->tao_repository_id (),
35 bn_factory);
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,
41 TreeController_init,
42 1);
44 this->sorb_->register_value_factory (tc_factory->tao_repository_id (),
45 tc_factory);
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,
51 StringNode_init,
52 1);
54 this->sorb_->register_value_factory (sn_factory->tao_repository_id (),
55 sn_factory);
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"),
69 1);
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 Test_impl *test_impl;
75 ACE_NEW_RETURN (test_impl,
76 Test_impl (this->sorb_.in ()),
77 1);
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");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s",
96 this->output_),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
101 poa_manager->activate ();
103 this->me_.signal ();
105 this->sorb_->run ();
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:");
116 return 1;
119 return 0;