1 #include "ace/OS_NS_unistd.h"
3 #include "Server_Task.h"
5 //////////////////////////////////////////////////////////////////////////
7 Server_Task::Server_Task (const ACE_TCHAR
*output
,
10 ACE_Thread_Manager
*thr_mgr
) :
11 ACE_Task_Base(thr_mgr
),
19 Server_Task::svc (void)
23 CORBA::Object_var poa_object
=
24 sorb_
->resolve_initial_references ("RootPOA");
26 if (CORBA::is_nil (poa_object
.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR
, " (%P|%t) Unable to initialize the POA.\n"), 1);
29 PortableServer::POA_var root_poa
=
30 PortableServer::POA::_narrow (poa_object
.in ());
32 PortableServer::POAManager_var poa_manager
=
33 root_poa
->the_POAManager ();
35 poa_manager
->activate ();
37 TestImpl
* server_impl
= 0;
38 ACE_NEW_RETURN (server_impl
, TestImpl (sorb_
.in ()), 1);
40 PortableServer::ObjectId_var id
=
41 root_poa
->activate_object (server_impl
);
43 CORBA::Object_var test_obj
=
44 root_poa
->id_to_reference (id
.in ());
46 Test_var server
= Test::_narrow (test_obj
.in ());
48 CORBA::String_var ior
=
49 sorb_
->object_to_string (test_obj
.in ());
51 // Output the IOR to the <ior_output_file>
52 FILE *output_file
= ACE_OS::fopen (output_
, "w");
55 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
56 ACE_OS::fclose (output_file
);
58 ACE_DEBUG ((LM_ERROR
, "(%P): Server's IOR was written to file: %s.\n", output_
) );
61 // Signal the main thread before we call orb->run ();
66 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
68 root_poa
->destroy (1, 1);
70 catch (const CORBA::Exception
& ex
)
72 ex
._tao_print_exception ("Exception caught in server task:");