Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Adapter_Registry.cpp
blob9a53767886bc8cbf433672e7f76cad617959b9ee
1 #include "tao/Object.h"
2 #include "tao/Stub.h"
3 #include "tao/Adapter_Registry.h"
4 #include "tao/Adapter.h"
5 #include "tao/SystemException.h"
6 #include "tao/debug.h"
7 #include "tao/TAO_Server_Request.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/CORBA_macros.h"
12 #include <cstring>
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 TAO_Adapter_Registry::TAO_Adapter_Registry (TAO_ORB_Core *)
17 : adapters_capacity_ (16), // @@ Make it configurable
18 adapters_count_ (0),
19 adapters_ (nullptr)
21 ACE_NEW (this->adapters_,
22 TAO_Adapter*[this->adapters_capacity_]);
25 TAO_Adapter_Registry::~TAO_Adapter_Registry ()
27 for (size_t i = 0; i != this->adapters_count_; ++i)
28 delete this->adapters_[i];
30 delete[] this->adapters_;
33 void
34 TAO_Adapter_Registry::close (int wait_for_completion)
36 try
38 for (size_t i = 0; i != this->adapters_count_; ++i)
40 this->adapters_[i]->close (wait_for_completion);
43 catch (const::CORBA::Exception &ex)
45 if (TAO_debug_level > 3)
47 ex._tao_print_exception (
48 "Exception in TAO_Adapter_Registry::close ()");
50 return;
53 return;
56 void
57 TAO_Adapter_Registry::check_close (int wait_for_completion)
59 for (size_t i = 0; i != this->adapters_count_; ++i)
61 this->adapters_[i]->check_close (wait_for_completion);
65 void
66 TAO_Adapter_Registry::insert (TAO_Adapter *adapter)
68 if (this->adapters_capacity_ == this->adapters_count_)
70 this->adapters_capacity_ *= 2;
71 TAO_Adapter **tmp = nullptr;
72 ACE_NEW_THROW_EX (tmp,
73 TAO_Adapter*[this->adapters_capacity_],
74 CORBA::NO_MEMORY ());
76 for (size_t i = 0; i != this->adapters_count_; ++i)
77 tmp[i] = this->adapters_[i];
78 delete[] this->adapters_;
79 this->adapters_ = tmp;
82 int const priority = adapter->priority ();
83 for (size_t i = 0; i != this->adapters_count_; ++i)
85 if (this->adapters_[i]->priority () >= priority)
87 for (size_t j = this->adapters_count_ + 1;
88 j > i;
89 --j)
91 this->adapters_[j] = this->adapters_[j - 1];
93 this->adapters_[i] = adapter;
94 ++this->adapters_count_;
95 return;
98 this->adapters_[this->adapters_count_++] = adapter;
101 void
102 TAO_Adapter_Registry::dispatch (TAO::ObjectKey &key,
103 TAO_ServerRequest &request,
104 CORBA::Object_out forward_to)
106 for (size_t i = 0; i != this->adapters_count_; ++i)
108 int const r = this->adapters_[i]->dispatch (key, request, forward_to);
110 if (r != TAO_Adapter::DS_MISMATCHED_KEY)
112 return;
116 if (!request.is_forwarded ())
118 throw ::CORBA::OBJECT_NOT_EXIST ();
122 CORBA::Object_ptr
123 TAO_Adapter_Registry::create_collocated_object (TAO_Stub *stub,
124 const TAO_MProfile &mprofile)
126 for (size_t i = 0; i != this->adapters_count_; ++i)
128 CORBA::Object_ptr x =
129 this->adapters_[i]->create_collocated_object (stub, mprofile);
130 if (x != nullptr)
132 if (!stub->collocated_servant ())
134 // This adapter created an object but it was not able to locate
135 // a servant so we need to give the rest of the adapters a chance to
136 // initialise the stub and find a servant or forward us or whatever.
137 for (CORBA::Long go_on = 1; go_on && i != this->adapters_count_;
138 ++i)
140 // initialize_collocated_object only returns 0 if it has completely
141 // initialised the object.
142 go_on = this->adapters_[i]->initialize_collocated_object (
143 stub);
146 return x;
149 return nullptr;
152 CORBA::Long
153 TAO_Adapter_Registry::initialize_collocated_object (TAO_Stub *stub)
155 for (size_t i = 0; i != this->adapters_count_; ++i)
157 int const retval =
158 this->adapters_[i]->initialize_collocated_object (stub);
159 if (retval == 0)
161 // initialize_collocated_object only returns 0 if it has completely
162 // initialised the object. We can return early.
163 return retval;
166 return 0;
169 TAO_Adapter *
170 TAO_Adapter_Registry::find_adapter (const char *name) const
172 for (TAO_Adapter **i = this->adapters_;
173 i != this->adapters_ + this->adapters_count_;
174 ++i)
175 if (std::strcmp ((*i)->name (), name) == 0)
176 return *i;
178 return nullptr;
181 TAO_END_VERSIONED_NAMESPACE_DECL