Merge pull request #1710 from likema/cfg-assign-not-null-str
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Collocated / Dynamic / Server_Task.cpp
blob02379f9d59341bb44a1fe260ba1720a51695440c
1 #include "Server_Task.h"
2 #include "test_i.h"
3 #include "interceptors.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 sorb_->resolve_initial_references ("RootPOA");
26 if (CORBA::is_nil (poa_object.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR,
28 " (%P|%t) Unable to initialize the POA.\n"),
29 1);
31 PortableServer::POA_var root_poa =
32 PortableServer::POA::_narrow (poa_object.in ());
34 PortableServer::POAManager_var poa_manager =
35 root_poa->the_POAManager ();
37 poa_manager->activate ();
39 Visual_i * server_impl = 0;
40 ACE_NEW_RETURN (server_impl, Visual_i (sorb_.in ()), 1);
42 PortableServer::ObjectId_var id =
43 root_poa->activate_object (server_impl);
45 CORBA::Object_var test_obj =
46 root_poa->id_to_reference (id.in ());
48 Test_Interceptors::Visual_var server =
49 Test_Interceptors::Visual::_narrow (test_obj.in ());
51 CORBA::String_var ior =
52 this->sorb_->object_to_string (server.in ());
54 ACE_DEBUG ((LM_DEBUG, "Test_Interceptors::Visual: <%C>\n", ior.in ()));
56 // If the ior_output_file exists, output the ior to it
57 if (output_ != 0)
59 FILE *output_file= ACE_OS::fopen (this->output_, "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);
65 ACE_OS::fprintf (output_file, "%s", ior.in ());
66 ACE_OS::fclose (output_file);
69 // Signal the main thread before we call orb->run ();
70 this->me_.signal ();
72 this->sorb_->run ();
74 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
76 root_poa->destroy (true, true);
78 catch (const CORBA::Exception& ex)
80 ex._tao_print_exception ("Exception caught in server task:");
81 return 1;
84 return 0;