summaryrefslogtreecommitdiff
path: root/TAO/tests/DII_Collocation_Tests/oneway/Server_Task.cpp
blob: f7bc2ceb483857352d78bcfa8b2e14d31008c278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// $Id$
//
#include "Server_Task.h"
#include "TestS.h"
#include "Hello.h"

#include "ace/Manual_Event.h"

ACE_RCSID(DII_Collocation_Tests,
          Server_Task,
          "$Id$")


Server_Task::Server_Task (const char *output,
                          const char *simple_test_output,
                          CORBA::ORB_ptr sorb,
                          ACE_Manual_Event &me,
                          ACE_Thread_Manager *thr_mgr)
  : ACE_Task_Base (thr_mgr)
    , output_ (output)
    , simple_test_output_ (simple_test_output)
    , me_ (me)
    , sorb_ (CORBA::ORB::_duplicate (sorb))
    , error_count_ (0)
{
}

int
Server_Task::svc (void)
{
 try
   {
     CORBA::Object_var poa_object =
       this->sorb_->resolve_initial_references("RootPOA");

     PortableServer::POA_var root_poa =
       PortableServer::POA::_narrow (poa_object.in ());

     if (CORBA::is_nil (root_poa.in ()))
       ACE_ERROR_RETURN ((LM_ERROR,
                          " (%P|%t) Panic: nil RootPOA\n"),
                         1);

     PortableServer::POAManager_var poa_manager =
       root_poa->the_POAManager ();

     Hello *hello_impl;
     ACE_NEW_RETURN (hello_impl,
                     Hello (this->sorb_.in (),
                            ACE_Thread::self ()),
                     1);

     PortableServer::ServantBase_var owner_transfer(hello_impl);

     PortableServer::ObjectId_var id =
       root_poa->activate_object (hello_impl);

     CORBA::Object_var object = root_poa->id_to_reference (id.in ());

     Test::Hello_var hello =
       Test::Hello::_narrow (object.in ());

     CORBA::String_var ior =
       this->sorb_->object_to_string (hello.in ());

     // Output the IOR to the <this->output_>
     FILE *output_file= ACE_OS::fopen (this->output_,
                                       "w");
     if (output_file == 0)
       ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file for writing Hello IOR: %s",
                          this->output_),
                         1);

     ACE_OS::fprintf (output_file, "%s", ior.in ());
     ACE_OS::fclose (output_file);

     Test_Simple_Test_i *simple_impl;
     ACE_NEW_RETURN (simple_impl,
                     Test_Simple_Test_i (),
                     1);

     PortableServer::ServantBase_var owner_transfer_simple(simple_impl);

     id = root_poa->activate_object (simple_impl);

     object = root_poa->id_to_reference (id.in ());

     Test::Simple_Test_var simple_test =
       Test::Simple_Test::_narrow (object.in ());

     CORBA::String_var simple_test_ior =
       this->sorb_->object_to_string (simple_test.in ());

     // Output the IOR to the <this->output_>
     FILE *simple_test_output_file= ACE_OS::fopen (this->simple_test_output_,
                                       "w");
     if (simple_test_output_file == 0)
       ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file for writing Simple_Test IOR: %s",
                          this->simple_test_output_),
                         1);

     ACE_OS::fprintf (simple_test_output_file, "%s", simple_test_ior.in ());
     ACE_OS::fclose (simple_test_output_file);

     poa_manager->activate ();

     // Signal the main thread before we call orb->run ();
     this->me_.signal ();

     this->sorb_->run ();

     ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

     ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - verifing results\n"));

     CORBA::ULong errors = hello_impl->error_count ();

     error_count_ += errors;
   }
 catch (const CORBA::Exception& ex)
   {
     error_count_ ++;
     ex._tao_print_exception ("Exception caught:");
     return 1;
   }
 catch (...)
   {
     error_count_ ++;
     ACE_ERROR ((LM_ERROR, "(%P|%t)Server_Task::svc - caught unknown exception \n"));
     return 1;
   }

 return 0;
}

CORBA::ULong
Server_Task::error_count () const
{
  return error_count_;
}