Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / twoway / Server_Task.cpp
blob2f8dd3327cbf274b4111626a4d703084f5c74a04
1 #include "Server_Task.h"
2 #include "TestS.h"
3 #include "Hello.h"
5 Server_Task::Server_Task (const ACE_TCHAR *output,
6 const ACE_TCHAR *simple_test_output,
7 CORBA::ORB_ptr sorb,
8 ACE_Manual_Event &me,
9 ACE_Thread_Manager *thr_mgr)
10 : ACE_Task_Base (thr_mgr)
11 , output_ (output)
12 , simple_test_output_ (simple_test_output)
13 , me_ (me)
14 , sorb_ (CORBA::ORB::_duplicate (sorb))
15 , error_count_ (0)
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 Hello IOR: %s",
63 this->output_),
64 1);
66 ACE_OS::fprintf (output_file, "%s", ior.in ());
67 ACE_OS::fclose (output_file);
69 Test_Simple_Test_i *simple_impl = 0;
70 ACE_NEW_RETURN (simple_impl,
71 Test_Simple_Test_i (),
72 1);
74 PortableServer::ServantBase_var owner_transfer_simple(simple_impl);
76 id = root_poa->activate_object (simple_impl);
78 object = root_poa->id_to_reference (id.in ());
80 Test::Simple_Test_var simple_test =
81 Test::Simple_Test::_narrow (object.in ());
83 CORBA::String_var simple_test_ior =
84 this->sorb_->object_to_string (simple_test.in ());
86 // Output the IOR to the <this->output_>
87 FILE *simple_test_output_file= ACE_OS::fopen (this->simple_test_output_,
88 "w");
89 if (simple_test_output_file == 0)
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "Cannot open output file for writing Simple_Test IOR: %s",
92 this->simple_test_output_),
93 1);
95 ACE_OS::fprintf (simple_test_output_file, "%s", simple_test_ior.in ());
96 ACE_OS::fclose (simple_test_output_file);
98 poa_manager->activate ();
100 // Signal the main thread before we call orb->run ();
101 this->me_.signal ();
103 this->sorb_->run ();
105 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
107 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - verifing results\n"));
109 CORBA::ULong errors = hello_impl->error_count ();
111 error_count_ += errors;
113 catch (const CORBA::Exception& ex)
115 error_count_ ++;
116 ex._tao_print_exception ("Exception caught:");
117 return 1;
119 catch (...)
121 error_count_ ++;
122 ACE_ERROR ((LM_ERROR, "(%P|%t)Server_Task::svc - caught unknown exception\n"));
123 return 1;
126 return 0;
129 CORBA::ULong
130 Server_Task::error_count () const
132 return error_count_;