summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciao/Containers/Servant_Activator.cpp
blob: eb7efa2a98de050b6c2149428bd3d2bb755a7e0a (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "Servant_Activator.h"

#include "tao/PortableServer/PortableServer_Functions.h"
#include "ciao/Logger/Log_Macros.h"

ACE_RCSID (ciao,
           Servant_Activator_i,
           "$Id$")

namespace CIAO
{
  Servant_Activator_i::Servant_Activator_i (CORBA::ORB_ptr o)
    : orb_ (CORBA::ORB::_duplicate (o)),
      slot_index_ (0)
  {
  }

  Servant_Activator_i::~Servant_Activator_i (void)
  {
    CIAO_TRACE ("Servant_Activator_i::~Servant_Activator_i");
  }

  bool
  Servant_Activator_i::update_port_activator (
    const PortableServer::ObjectId &oid)
  {
    CIAO_TRACE ("Servant_Activator_i::update_port_activator");

    CORBA::String_var str =
      PortableServer::ObjectId_to_string (oid);
    {
      ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
                          guard,
                          this->mutex_,
                          CORBA::NO_RESOURCES ());

      Port_Activators::iterator pa_iter = this->pa_.find (str.in ());
      
      if (pa_iter != this->pa_.end ())
        {
          this->pa_.erase (pa_iter);
        }
      else return false;
    }

    return true;
  }

  PortableServer::Servant
  Servant_Activator_i::incarnate (const PortableServer::ObjectId &oid,
                                  PortableServer::POA_ptr)
  {
    CIAO_TRACE ("Servant_Activator_i::incarnate");

    CORBA::String_var str =
      PortableServer::ObjectId_to_string (oid);

    CIAO_DEBUG ((LM_INFO, CLINFO
                "Servant_Activator_i::incarnate, "
                "Attempting to activate port name [%C]\n",
                str.in ()));
    
    Port_Activators::iterator pa_iter;
    
    {
      ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
                          guard,
                          this->mutex_,
                          CORBA::NO_RESOURCES ());
      
      pa_iter = this->pa_.find (str.in ());
    }
    
    if (pa_iter == this->pa_.end ())
      {
        CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Activator_i::incarnate - "
                     "Unable to find sutible port activator for ObjectID %C\n",
                     str.in ()));
        throw CORBA::OBJECT_NOT_EXIST ();
      }
    
    if (CORBA::is_nil (pa_iter->second))
      {
        CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Activator_i::incarnate - "
                     "Port Activator for ObjectId %C was nil!\n",
                     str.in ()));
        throw CORBA::OBJECT_NOT_EXIST ();
      }
    
    CIAO_DEBUG ((LM_INFO, CLINFO
                 "Servant_Activator_i::incarnate - Activating Port %C\n",
                 str.in ()));
    
    return pa_iter->second->activate (oid);
  }

  void
  Servant_Activator_i::etherealize (const PortableServer::ObjectId &oid,
                                  PortableServer::POA_ptr ,
                                  PortableServer::Servant servant,
                                  CORBA::Boolean ,
                                  CORBA::Boolean)
  {
    CORBA::String_var str =
      PortableServer::ObjectId_to_string (oid);
    
    CIAO_DEBUG ((LM_TRACE, CLINFO "Servant_Activator_i::etherealize - "
                 "Attempting to etherealize servant with object ID %C\n",
                 str.in ()));
    
    Port_Activators::iterator pa_iter;
    
    {
      ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX,
                          guard,
                          this->mutex_,
                          CORBA::NO_RESOURCES ());
      
      pa_iter = this->pa_.find (str.in ());
    }
    
    if (pa_iter == this->pa_.end ())
      {
        CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Activator_i::etherealize - "
                     "Unable to find sutible port activator for ObjectID %C\n",
                     str.in ()));
        throw CORBA::OBJECT_NOT_EXIST ();
      }
    
    if (CORBA::is_nil (pa_iter->second))
      {
        CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Activator_i::etherealize - "
                     "Port Activator for ObjectId %C was nil!\n",
                     str.in ()));
        throw CORBA::OBJECT_NOT_EXIST ();
      }
    
    pa_iter->second->deactivate (servant);
  }
  
  bool
  Servant_Activator_i::register_port_activator (Port_Activator_ptr pa)
  {
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                      guard,
                      this->mutex_,
                      false);
    
    CIAO_DEBUG ((LM_INFO, CLINFO "Servant_Activator_i::register_port_activator - "
                 "Registering a port activator for port [%C] with ObjectID [%C]\n",
                 pa->name (), pa->oid ()));

    try
      {
        this->pa_ [pa->oid ()] = Port_Activator::_duplicate (pa);
      }
    catch (...)
      {
        CIAO_ERROR ((LM_ERROR, CLINFO "Servant_Activator_i::register_port_activator - "
                     "Unable to register a port activator for port [%C] with ObjectID [%C]\n",
                     pa->name (), pa->oid ()));
        return false;
      }
    
    return true;
  }
}