Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Collocation_Exception_Test / Server_Task.cpp
blob57680cb8ed3c1dd62574cd6f33690db2bfd75a1b
1 #include "Server_Task.h"
2 #include "TestS.h"
3 #include "Hello.h"
5 #include "ace/Manual_Event.h"
7 Server_Task::Server_Task (const ACE_TCHAR *output,
8 CORBA::ORB_ptr sorb,
9 ACE_Manual_Event &me,
10 ACE_Thread_Manager *thr_mgr)
11 : ACE_Task_Base (thr_mgr)
12 , output_ (output)
13 , me_ (me)
14 , sorb_ (CORBA::ORB::_duplicate (sorb))
18 int
19 Server_Task::svc (void)
21 try
23 CORBA::Object_var poa_object =
24 this->sorb_->resolve_initial_references("RootPOA");
26 PortableServer::POA_var root_poa =
27 PortableServer::POA::_narrow (poa_object.in ());
29 if (CORBA::is_nil (root_poa.in ()))
30 ACE_ERROR_RETURN ((LM_ERROR,
31 " (%P|%t) Panic: nil RootPOA\n"),
32 1);
34 PortableServer::POAManager_var poa_manager =
35 root_poa->the_POAManager ();
37 Hello *hello_impl = 0;
38 ACE_NEW_RETURN (hello_impl,
39 Hello (this->sorb_.in (),
40 ACE_Thread::self ()),
41 1);
43 PortableServer::ServantBase_var owner_transfer(hello_impl);
45 PortableServer::ObjectId_var id =
46 root_poa->activate_object (hello_impl);
48 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
50 Test::Hello_var hello =
51 Test::Hello::_narrow (object.in ());
53 CORBA::String_var ior =
54 this->sorb_->object_to_string (hello.in ());
56 // Output the IOR to the <this->output_>
57 FILE *output_file= ACE_OS::fopen (this->output_,
58 "w");
59 if (output_file == 0)
60 ACE_ERROR_RETURN ((LM_ERROR,
61 "Cannot open output file for writing IOR: %s",
62 this->output_),
63 1);
65 ACE_OS::fprintf (output_file, "%s", ior.in ());
66 ACE_OS::fclose (output_file);
68 poa_manager->activate ();
70 // Signal the main thread before we call orb->run ();
71 this->me_.signal ();
73 this->sorb_->run ();
75 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
77 root_poa->destroy (1, 1);
79 this->sorb_->destroy ();
81 catch (const CORBA::Exception& ex)
83 ex._tao_print_exception ("Exception caught:");
84 return 1;
87 return 0;