Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Collocated_DerivedIF / Server_Task.cpp
blob17b998b45ca41e0278d1bea317fb7b2238c1f77c
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 ()
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 ());
30 if (CORBA::is_nil (root_poa.in ()))
31 ACE_ERROR_RETURN ((LM_ERROR,
32 " (%P|%t) Panic: nil RootPOA\n"),
33 1);
36 PortableServer::POAManager_var poa_manager =
37 root_poa->the_POAManager ();
39 HelloAgain *hello_impl;
40 ACE_NEW_RETURN (hello_impl,
41 HelloAgain (this->sorb_.in (),
42 ACE_Thread::self ()),
43 1);
44 PortableServer::ServantBase_var owner1_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::HelloAgain_var hello =
52 Test::HelloAgain::_narrow (object.in ());
54 CORBA::String_var ior =
55 this->sorb_->object_to_string (hello.in ());
58 // Output the IOR to the <this->output_>
59 FILE *output_file= ACE_OS::fopen (this->output_,
60 "w");
61 if (output_file == 0)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "Cannot open output file for writing IOR: %s",
64 this->output_),
65 1);
67 ACE_OS::fprintf (output_file, "%s", ior.in ());
68 // ACE_OS::fprintf (output_file, "%s", ior1.in ());
70 ACE_OS::fclose (output_file);
72 poa_manager->activate ();
74 // Signal the main thread before we call orb->run ();
75 this->me_.signal ();
77 this->sorb_->run ();
79 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
81 catch (const CORBA::Exception& ex)
83 ex._tao_print_exception ("Exception caught:");
84 return 1;
87 return 0;