Continued changes from peer review
[ACE_TAO.git] / TAO / tests / COIOP / Server_Task.cpp
blob04abb027a27c746fa09c9f8a6d4e1670e3bc8c59
1 // -*- C++ -*-
2 #include "Server_Task.h"
3 #include "TestS.h"
4 #include "Hello.h"
6 #include "ace/Manual_Event.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 (void)
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 Hello *hello_impl = 0;
39 ACE_NEW_RETURN (hello_impl,
40 Hello (this->sorb_.in (),
41 ACE_Thread::self ()),
42 1);
44 PortableServer::ServantBase_var owner_transfer(hello_impl);
46 PortableServer::ObjectId_var id =
47 root_poa->activate_object (hello_impl);
49 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
51 Test::Hello_var hello =
52 Test::Hello::_narrow (object.in ());
54 CORBA::String_var ior =
55 this->sorb_->object_to_string (hello.in ());
57 // Output the IOR to the <this->output_>
58 FILE *output_file= ACE_OS::fopen (this->output_,
59 "w");
60 if (output_file == 0)
61 ACE_ERROR_RETURN ((LM_ERROR,
62 "Cannot open output file for writing IOR: %s",
63 this->output_),
64 1);
66 ACE_OS::fprintf (output_file, "%s", ior.in ());
67 ACE_OS::fclose (output_file);
69 poa_manager->activate ();
71 // Signal the main thread before we call orb->run ();
72 this->me_.signal ();
74 ACE_Time_Value runtime (10);
75 this->sorb_->run (runtime);
77 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
79 catch (const CORBA::Exception& ex)
81 ex._tao_print_exception ("Exception caught:");
82 return 1;
85 return 0;