summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2084_Regression/Client_Task.cpp
blob: 0219846bc87a686a3dfe3fc82ca98de26b74e72d (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
//
// $Id$
//

#include "Client_Task.h"
#include "TestC.h"
#include "Hello.h"
#include "tao/ORB_Core.h"
#include "tao/PortableServer/PortableServer.h"

ACE_RCSID(Bug_2084_Regression,
          Client_Task,
          "$Id$")

Client_Task::Client_Task (const char *ior,
			  CORBA::ORB_ptr corb,
			  ACE_Thread_Manager *thr_mgr)
  : ACE_Task_Base (thr_mgr)
    , input_ (ior)
    , corb_ (CORBA::ORB::_duplicate (corb))

{
}

int
Client_Task::svc (void)
{
  try
    {
      CORBA::Object_var poa_object =
        this->corb_->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 = 0;
      ACE_NEW_RETURN (hello_impl,
                      Hello (this->corb_.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_servant = Test::Hello::_narrow (object.in ());
      poa_manager->activate ();

      ACE_DEBUG((LM_DEBUG,"Client (%t) optimize_collocation_objects=%d use_global_collocation=%d\n",
                           corb_->orb_core()->optimize_collocation_objects(),
                           corb_->orb_core()->use_global_collocation ()));

      CORBA::Object_var tmp =
        this->corb_->string_to_object (input_);

      Test::EventNode_var evNode=
        Test::EventNode::_narrow(tmp.in ());

      if (CORBA::is_nil (evNode.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::EventNode reference <%s>\n",
                             input_),
                            1);
        }

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Client starting\n"));

      evNode->registerHello( hello_servant.in() );

      evNode->shutdown ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;

}