summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/Strategized_Object_Proxy_Broker.cpp
blob: 131922817370c250986ff8ac983afd2a3d2f7aca (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
// $Id$

#include "Strategized_Object_Proxy_Broker.h"
#include "Direct_Object_Proxy_Impl.h"
#include "ThruPOA_Object_Proxy_Impl.h"

#include "tao/Remote_Object_Proxy_Impl.h"


ACE_RCSID (tao, TAO_Strategized_Object_Proxy_Broker, "$Id$")



TAO_Strategized_Object_Proxy_Broker *
the_tao_strategized_object_proxy_broker (void)
{
  static TAO_Strategized_Object_Proxy_Broker the_broker;
  return &the_broker;
}

TAO_Strategized_Object_Proxy_Broker::TAO_Strategized_Object_Proxy_Broker (void)
{
  for (int i = 0;
       i < TAO_Collocation_Strategies::CS_LAST;
       ++i)
    this->proxy_cache_[i] = 0;
}

TAO_Strategized_Object_Proxy_Broker::~TAO_Strategized_Object_Proxy_Broker (void)
{
  for (int i = 0;
       i < TAO_Collocation_Strategies::CS_LAST;
       ++i)
    delete this->proxy_cache_[i];
}

TAO_Object_Proxy_Impl &
TAO_Strategized_Object_Proxy_Broker::select_proxy (CORBA::Object_ptr object,
                                                   CORBA::Environment &ACE_TRY_ENV)
{
  int strategy =
    TAO_ORB_Core::collocation_strategy (object, ACE_TRY_ENV);
  ACE_CHECK_RETURN (*this->proxy_cache_[strategy]);

  if (this->proxy_cache_[strategy] != 0)
    return *this->proxy_cache_[strategy];

  this->create_proxy (strategy, ACE_TRY_ENV);
  ACE_CHECK_RETURN (*this->proxy_cache_[strategy]);

  return *this->proxy_cache_[strategy];
}

void
TAO_Strategized_Object_Proxy_Broker::create_proxy (int strategy,
                                                   CORBA::Environment &ACE_TRY_ENV)
{
  ACE_GUARD (TAO_SYNCH_MUTEX,
             guard,
             this->mutex_);

  if (this->proxy_cache_[strategy] == 0)
    {
      switch (strategy)
        {
        case TAO_Collocation_Strategies::CS_THRU_POA_STRATEGY:
          {
            ACE_NEW_THROW_EX (this->proxy_cache_[strategy],
                              TAO_ThruPOA_Object_Proxy_Impl,
                              CORBA::NO_MEMORY ());
            ACE_CHECK;
            break;
          }
        case TAO_Collocation_Strategies::CS_DIRECT_STRATEGY:
          {
            ACE_NEW_THROW_EX (this->proxy_cache_[strategy],
                              TAO_Direct_Object_Proxy_Impl,
                              CORBA::NO_MEMORY ());
            ACE_CHECK;
            break;
          }
        default:
        case TAO_Collocation_Strategies::CS_REMOTE_STRATEGY:
          {
            ACE_NEW_THROW_EX (this->proxy_cache_[strategy],
                              TAO_Remote_Object_Proxy_Impl,
                              CORBA::NO_MEMORY ());
            ACE_CHECK;
            break;
          }

        }
    }
}

TAO_Object_Proxy_Broker * _TAO_collocation_Object_Proxy_Broker_Factory (
                                                         CORBA::Object_ptr obj
                                                         )
{
  ACE_UNUSED_ARG (obj);
  return the_tao_strategized_object_proxy_broker ();
}

int _TAO_collocation_Object_Proxy_Broker_Factory_Initializer (long dummy)
{
  ACE_UNUSED_ARG (dummy);

  _TAO_collocation_Object_Proxy_Broker_Factory_function_pointer =
    _TAO_collocation_Object_Proxy_Broker_Factory;

  return 0;
}

static int
_TAO_collocation_Object_Proxy_Broker_Factory_Initializer_Scarecrow =
_TAO_collocation_Object_Proxy_Broker_Factory_Initializer (ACE_reinterpret_cast (long,
                                                                                _TAO_collocation_Object_Proxy_Broker_Factory_Initializer));