Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / DII_Collocation_Tests / oneway / Server_Task.cpp
blob31d7959a26918aa4c7365913621a1c2ce57fabe5
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 const ACE_TCHAR *simple_test_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 , simple_test_output_ (simple_test_output)
15 , me_ (me)
16 , sorb_ (CORBA::ORB::_duplicate (sorb))
17 , error_count_ (0)
21 int
22 Server_Task::svc ()
24 try
26 CORBA::Object_var poa_object =
27 this->sorb_->resolve_initial_references("RootPOA");
29 PortableServer::POA_var root_poa =
30 PortableServer::POA::_narrow (poa_object.in ());
32 if (CORBA::is_nil (root_poa.in ()))
33 ACE_ERROR_RETURN ((LM_ERROR,
34 " (%P|%t) Panic: nil RootPOA\n"),
35 1);
37 PortableServer::POAManager_var poa_manager =
38 root_poa->the_POAManager ();
40 Hello *hello_impl;
41 ACE_NEW_RETURN (hello_impl,
42 Hello (this->sorb_.in (),
43 ACE_Thread::self ()),
44 1);
46 PortableServer::ServantBase_var owner_transfer(hello_impl);
48 PortableServer::ObjectId_var id =
49 root_poa->activate_object (hello_impl);
51 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
53 Test::Hello_var hello =
54 Test::Hello::_narrow (object.in ());
56 CORBA::String_var ior =
57 this->sorb_->object_to_string (hello.in ());
59 // Output the IOR to the <this->output_>
60 FILE *output_file= ACE_OS::fopen (this->output_,
61 "w");
62 if (output_file == 0)
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "Cannot open output file for writing Hello IOR: %s",
65 this->output_),
66 1);
68 ACE_OS::fprintf (output_file, "%s", ior.in ());
69 ACE_OS::fclose (output_file);
71 Test_Simple_Test_i *simple_impl;
72 ACE_NEW_RETURN (simple_impl,
73 Test_Simple_Test_i (),
74 1);
76 PortableServer::ServantBase_var owner_transfer_simple(simple_impl);
78 id = root_poa->activate_object (simple_impl);
80 object = root_poa->id_to_reference (id.in ());
82 Test::Simple_Test_var simple_test =
83 Test::Simple_Test::_narrow (object.in ());
85 CORBA::String_var simple_test_ior =
86 this->sorb_->object_to_string (simple_test.in ());
88 // Output the IOR to the <this->output_>
89 FILE *simple_test_output_file= ACE_OS::fopen (this->simple_test_output_,
90 "w");
91 if (simple_test_output_file == 0)
92 ACE_ERROR_RETURN ((LM_ERROR,
93 "Cannot open output file for writing Simple_Test IOR: %s",
94 this->simple_test_output_),
95 1);
97 ACE_OS::fprintf (simple_test_output_file, "%s", simple_test_ior.in ());
98 ACE_OS::fclose (simple_test_output_file);
100 poa_manager->activate ();
102 // Signal the main thread before we call orb->run ();
103 this->me_.signal ();
105 this->sorb_->run ();
107 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
109 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - verifing results\n"));
111 CORBA::ULong errors = hello_impl->error_count ();
113 error_count_ += errors;
115 catch (const CORBA::Exception& ex)
117 error_count_ ++;
118 ex._tao_print_exception ("Exception caught:");
119 return 1;
121 catch (...)
123 error_count_ ++;
124 ACE_ERROR ((LM_ERROR, "(%P|%t)Server_Task::svc - caught unknown exception\n"));
125 return 1;
128 return 0;
131 CORBA::ULong
132 Server_Task::error_count () const
134 return error_count_;