Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_2084_Regression / Server_Task.cpp
blob37ef71e01a656f06a216e674198974398e29a41e
1 #include "Server_Task.h"
2 #include "TestS.h"
3 #include "EventNode.h"
5 #include "ace/Manual_Event.h"
6 #include "tao/ORB_Core.h"
8 Server_Task::Server_Task (const ACE_TCHAR *output,
9 CORBA::ORB_ptr sorb,
10 ACE_Manual_Event &me,
11 ACE_Thread_Manager *thr_mgr)
12 : ACE_Task_Base (thr_mgr)
13 , output_ (output)
14 , me_ (me)
15 , sorb_ (CORBA::ORB::_duplicate (sorb))
19 int
20 Server_Task::svc ()
22 try
24 CORBA::Object_var poa_object =
25 this->sorb_->resolve_initial_references("RootPOA");
27 PortableServer::POA_var root_poa =
28 PortableServer::POA::_narrow (poa_object.in ());
30 if (CORBA::is_nil (root_poa.in ()))
31 ACE_ERROR_RETURN ((LM_ERROR,
32 " (%P|%t) Panic: nil RootPOA\n"),
33 1);
35 PortableServer::POAManager_var poa_manager =
36 root_poa->the_POAManager ();
38 EventNode *evnode_impl = new EventNode(this->sorb_.in(),ACE_Thread::self());
39 PortableServer::ServantBase_var owner_transfer(evnode_impl);
40 PortableServer::ObjectId_var id =
41 root_poa->activate_object (evnode_impl);
43 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
45 Test::EventNode_var evNode = Test::EventNode::_narrow (object.in ());
47 ACE_DEBUG((LM_DEBUG,"Server (%t) optimize_collocation_objects=%d use_global_collocation=%d\n",
48 sorb_->orb_core()->optimize_collocation_objects(),
49 sorb_->orb_core()->use_global_collocation ()));
51 CORBA::String_var ior =
52 this->sorb_->object_to_string (evNode.in ());
54 // Output the IOR to the <this->output_>
55 FILE *output_file= ACE_OS::fopen (this->output_,
56 "w");
57 if (output_file == 0)
58 ACE_ERROR_RETURN ((LM_ERROR,
59 "Cannot open output file for writing IOR: %s",
60 this->output_),
61 1);
63 ACE_OS::fprintf (output_file, "%s", ior.in ());
64 ACE_OS::fclose (output_file);
66 poa_manager->activate ();
68 // Signal the main thread before we call orb->run ();
69 this->me_.signal ();
71 this->sorb_->run ();
73 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
75 catch (const CORBA::BAD_INV_ORDER&)
77 // Periodically we get a bad inv order on fast machines.
78 // It's a false negative and is safe to ignore.
80 catch (const CORBA::Exception& ex)
82 ex._tao_print_exception ("Exception caught:");
83 return 1;
86 return 0;