summaryrefslogtreecommitdiff
path: root/TAO/tao/CSD_Framework/CSD_Strategy_Base.cpp
blob: aa641fe9bc76838ab44ee1534a7cc3c4ecd51587 (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
// $Id$

#include "tao/CSD_Framework/CSD_Strategy_Base.h"
#include "tao/CSD_Framework/CSD_POA.h"
#include "tao/CSD_Framework/CSD_Strategy_Proxy.h"
#include "tao/PortableServer/Root_POA.h"
#include "tao/PortableServer/POAManager.h"
#include "tao/PortableServer/Servant_Base.h"
#include "tao/TAO_Server_Request.h"

ACE_RCSID (CSD_Framework,
           CSD_Strategy_Base,
           "$Id$")

#if !defined (__ACE_INLINE__)
# include "tao/CSD_Framework/CSD_Strategy_Base.inl"
#endif /* ! __ACE_INLINE__ */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO::CSD::Strategy_Base::~Strategy_Base()
{
}

CORBA::Boolean
TAO::CSD::Strategy_Base::apply_to (PortableServer::POA_ptr poa
                                   ACE_ENV_ARG_DECL_WITH_DEFAULTS)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (CORBA::is_nil(poa))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy cannot ")
                   ACE_TEXT("be applied to a nil POA.\n")));
      return false;
    }

  if (!CORBA::is_nil(this->poa_.in()))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy already ")
                   ACE_TEXT("applied to a POA.\n")));
      return false;
    }

  // The POA is a local interface (IDL terminology), and thus we know that
  // we can downcast the POA_ptr to its (TAO) implementation type.
  TAO_CSD_POA* poa_impl = dynamic_cast<TAO_CSD_POA*>(poa);

  if (poa_impl == 0)
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy cannot ")
                   ACE_TEXT("be applied to a non CSD POA.\n")));
      return false;
    }

  // We need to check to see if the POA is already "active".  If this is
  // the case, then we need to handle the poa_activated_event() right now.
  // If the POA is not already "active", then we can just wait until it
  // does get activated, and we (the strategy) will be informed of the
  // poa_activated_event() at that time.
  if (poa_impl->tao_poa_manager().get_state() ==
                                       PortableServer::POAManager::ACTIVE)
    {
      // The POA is already "active" (since its POAManager is active).
      // We need to "raise" the poa_activated_event() now.  Otherwise,
      // the event will be raised when the POAManager does become active.
      if (!this->poa_activated_event())
        {
          // An error has been already been reported to the log with
          // the detailed reason for the failure to handle the event.
          return false;
        }
    }

  // Set the CSD Strategy_Base on the strategy proxy object owned by the POA.
  bool strategy_set = false;
  ACE_TRY_NEW_ENV
    {
      poa_impl->set_csd_strategy (this ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      strategy_set = true;
    }
  ACE_CATCHANY
    {
    }
  ACE_ENDTRY;

  if (! strategy_set)
    {
      // We need to make sure that we raise a poa_deactivated_event() if
      // we earlier raised a poa_activated_event().
      this->poa_deactivated_event();

      // An error has been already been reported to the log with
      // the detailed reason why the proxy will not accept the
      // custom strategy.
      return false;
    }

  // Save a duplicate of the poa into our data member.
  this->poa_ = PortableServer::POA::_duplicate (poa);

  // Success
  return true;
}


void
TAO::CSD::Strategy_Base::servant_activated_event_i
                                (PortableServer::Servant ,
                                 const PortableServer::ObjectId& 
                                 ACE_ENV_ARG_DECL)
{
  // do nothing.
}


void
TAO::CSD::Strategy_Base::servant_deactivated_event_i
                                (PortableServer::Servant,
                                 const PortableServer::ObjectId&
                                 ACE_ENV_ARG_DECL)
{
  // do nothing.
}

TAO_END_VERSIONED_NAMESPACE_DECL