Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tao / ZIOP / ZIOP_Stub.cpp
bloba0d819ae2e8307b5eec937fc56c6a5314d5bc5a1
1 #include "tao/ZIOP/ZIOP_Stub.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/ZIOP/ZIOP_Policy_i.h"
6 #include "tao/ZIOP/ZIOP.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/Policy_Set.h"
9 #include "tao/Policy_Manager.h"
10 #include "tao/SystemException.h"
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO_ZIOP_Stub::TAO_ZIOP_Stub (const char *repository_id,
15 const TAO_MProfile &profiles,
16 TAO_ORB_Core *orb_core)
17 : TAO_Stub (repository_id,
18 profiles,
19 orb_core),
20 are_policies_parsed_ (false)
24 TAO_ZIOP_Stub::~TAO_ZIOP_Stub ()
26 if (!CORBA::is_nil (this->compression_enabling_policy_.in ()))
27 this->compression_enabling_policy_->destroy ();
29 if (!CORBA::is_nil (this->compression_id_list_policy_.in ()))
30 this->compression_id_list_policy_->destroy ();
33 void
34 TAO_ZIOP_Stub::parse_policies ()
36 CORBA::PolicyList_var policy_list
37 = this->base_profiles_.policy_list ();
39 CORBA::ULong const length = policy_list->length ();
41 // Cache away the policies that we'll need later.
42 for (CORBA::ULong i = 0; i < length; ++i)
44 switch (policy_list[i]->policy_type ())
46 case ZIOP::COMPRESSION_ENABLING_POLICY_ID:
48 this->exposed_compression_enabling_policy (policy_list[i]);
50 break;
51 case ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID:
53 this->exposed_compression_id_list_policy (policy_list[i]);
55 break;
60 this->are_policies_parsed_ = true;
63 CORBA::Policy *
64 TAO_ZIOP_Stub::exposed_compression_id_list_policy ()
66 if (!this->are_policies_parsed_)
68 this->parse_policies ();
71 return CORBA::Policy::_duplicate (this->compression_id_list_policy_.in ());
74 void
75 TAO_ZIOP_Stub::exposed_compression_id_list_policy (CORBA::Policy_ptr policy)
77 this->compression_id_list_policy_ = CORBA::Policy::_duplicate (policy);
80 CORBA::Policy *
81 TAO_ZIOP_Stub::exposed_compression_enabling_policy ()
83 if (!this->are_policies_parsed_)
85 this->parse_policies ();
88 return CORBA::Policy::_duplicate (this->compression_enabling_policy_.in ());
91 void
92 TAO_ZIOP_Stub::exposed_compression_enabling_policy (CORBA::Policy_ptr policy)
94 this->compression_enabling_policy_ = CORBA::Policy::_duplicate (policy);
97 CORBA::Policy_ptr
98 TAO_ZIOP_Stub::get_policy (CORBA::PolicyType type)
100 // If we are dealing with a client exposed policy, check if any
101 // value came in the IOR/reconcile IOR value and overrides.
102 switch (type)
104 case ZIOP::COMPRESSION_ENABLING_POLICY_ID :
106 return this->effective_compression_enabling_policy ();
108 case ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID :
110 return this->effective_compression_id_list_policy ();
114 return this->TAO_Stub::get_policy (type);
117 CORBA::Policy_ptr
118 TAO_ZIOP_Stub::get_cached_policy (TAO_Cached_Policy_Type type)
120 // If we are dealing with a client exposed policy, check if any
121 // value came in the IOR/reconcile IOR value and overrides.
122 switch (type)
124 case TAO_CACHED_COMPRESSION_ENABLING_POLICY:
126 return this->effective_compression_enabling_policy ();
128 case TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY:
130 return this->effective_compression_id_list_policy ();
132 default:
133 break;
136 return this->TAO_Stub::get_cached_policy (type);
139 CORBA::Policy *
140 TAO_ZIOP_Stub::effective_compression_enabling_policy ()
142 // Get effective override.
143 CORBA::Policy_var override =
144 this->TAO_Stub::get_cached_policy (
145 TAO_CACHED_COMPRESSION_ENABLING_POLICY);
147 // Get the value from the ior.
148 CORBA::Policy_var exposed = this->exposed_compression_enabling_policy ();
150 // Reconcile client-exposed and locally set values.
151 if (CORBA::is_nil (exposed.in ()))
152 return override._retn ();
154 if (CORBA::is_nil (override.in ()))
155 return exposed._retn ();
157 ZIOP::CompressionEnablingPolicy_var override_policy_var =
158 ZIOP::CompressionEnablingPolicy::_narrow (override.in ());
160 ZIOP::CompressionEnablingPolicy_var exposed_policy_var =
161 ZIOP::CompressionEnablingPolicy::_narrow (exposed.in ());
163 // Both override and exposed have been set.
164 // See if either of them has empty priority bands.
165 if (override_policy_var->compression_enabled () && exposed_policy_var->compression_enabled ())
166 return override._retn ();
168 if (!override_policy_var->compression_enabled ())
169 return override._retn ();
171 return exposed._retn ();
174 CORBA::Policy *
175 TAO_ZIOP_Stub::effective_compression_id_list_policy ()
177 // Get effective override (This is the CLIENTS compressor's priority ordered list).
178 CORBA::Policy_var policy (
179 this->TAO_Stub::get_cached_policy (TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY));
180 ZIOP::CompressorIdLevelListPolicy_var clientCompressors (
181 ZIOP::CompressorIdLevelListPolicy::_narrow (policy.in ()));
182 // If CLIENT does not have an available compressor's list, compression can't go ahead.
183 if (CORBA::is_nil (clientCompressors.in ()))
185 if (6 < TAO_debug_level)
187 TAOLIB_DEBUG ((LM_DEBUG,
188 ACE_TEXT ("ZIOP (%P|%t) ")
189 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
190 ACE_TEXT ("no clientCompressorIdLevelListPolicy (did not compress).\n")));
192 return 0;
194 ::Compression::CompressorIdLevelList &clientList =
195 *clientCompressors->compressor_ids ();
197 // Get the value from the IOR (This is the SERVERS available compressor's list).
198 policy = this->exposed_compression_id_list_policy ();
199 ZIOP::CompressorIdLevelListPolicy_var serverCompressors (
200 ZIOP::CompressorIdLevelListPolicy::_narrow (policy.in ()));
201 // Likewise if SERVER does not have an available compressor's list, compression can't go ahead.
202 if (CORBA::is_nil (serverCompressors.in ()))
204 // OK if we are allowing the client to ZIOP compress without having any server
205 // ZIOP available compressor's list policies, then we simply return the copy of
206 // the client's compressors here and we will go on to use the first compressor
207 // configured. THIS IS GOING DIRECTLY AGAINST THE CORBA Compressed GIOP (ZIOP)
208 // V1.0 specification, but allows us to use ZIOP with MIOP and/or CORBALOCs.
209 // We have to trust the end user knows what his system is configured to allow;
210 // Any servers that cannot decompress the client's used ZIOP compressor will
211 // reject the request as they simply cannot decode or handle it (comms will
212 // simply timeout or lock-up at the client for any such incorrect two-way requests).
213 if (this->orb_core()->orb_params()->allow_ziop_no_server_policies ())
215 if (6 < TAO_debug_level)
217 TAOLIB_DEBUG ((LM_DEBUG,
218 ACE_TEXT ("ZIOP (%P|%t) ")
219 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
220 ACE_TEXT ("no serverCompressorIdLevelListPolicy (but allow_ziop_no_server_policies in force).\n")));
222 return clientCompressors._retn ();
224 else if (6 < TAO_debug_level)
226 TAOLIB_DEBUG ((LM_DEBUG,
227 ACE_TEXT ("ZIOP (%P|%t) ")
228 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
229 ACE_TEXT ("no serverCompressorIdLevelListPolicy (did not compress).\n")));
231 return 0;
233 ::Compression::CompressorIdLevelList &serverList =
234 *serverCompressors->compressor_ids ();
236 // For each CLIENT compressor (in priority order) check...
237 for (CORBA::ULong client = 0u; client < clientList.length (); ++client)
239 ::Compression::CompressorIdLevel_var clientEntry (clientList[client]);
241 // ... which each SERVER compressor id if it is available to use.
242 for (CORBA::ULong server = 0u; server < serverList.length (); ++server)
244 ::Compression::CompressorIdLevel_var serverEntry (serverList[server]);
246 if (clientEntry->compressor_id == serverEntry->compressor_id)
248 // OK we found a match, however we need to make the highest priority
249 // compressor (the one we are going to employ) use slot 0 in the
250 // list we are returning. Since we can't modify the original list
251 // we have to make a copy and modify that.
252 policy= clientCompressors->copy ();
253 ZIOP::CompressorIdLevelListPolicy_var returningCompressors (
254 ZIOP::CompressorIdLevelListPolicy::_narrow (policy.in ()));
255 if (CORBA::is_nil (returningCompressors.in ()))
257 // This shouldn't happen, it's basically an internal error.
258 if (6 < TAO_debug_level)
260 TAOLIB_DEBUG ((LM_DEBUG,
261 ACE_TEXT ("ZIOP (%P|%t) ")
262 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
263 ACE_TEXT ("could not copy clientCompressorIdLevelListPolicy (did not compress).\n")));
265 return 0;
267 ::Compression::CompressorIdLevelList &returningList =
268 *returningCompressors->compressor_ids ();
270 // We must ensure the other compressors are not lost, as they tell the server
271 // which compressors are available for it to use with the reply message.
272 for (CORBA::ULong shuffle = client; 0u < shuffle; --shuffle)
274 returningList[shuffle].compressor_id= returningList[shuffle-1u].compressor_id;
275 returningList[shuffle].compression_level= returningList[shuffle-1u].compression_level;
278 // The one we found is the one we are going to use (now the highest priority)
279 // but with the correct (minimized) compression level of the client and server.
280 returningList[0].compressor_id= clientEntry->compressor_id;
281 returningList[0].compression_level= ACE_MIN (clientEntry->compression_level,
282 serverEntry->compression_level);
283 if (6 < TAO_debug_level)
285 TAOLIB_DEBUG ((LM_DEBUG,
286 ACE_TEXT ("ZIOP (%P|%t) ")
287 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
288 ACE_TEXT ("found (Client %d: %C@%d == Server %d: %C@%d) using @%d.\n"),
289 client,
290 TAO_ZIOP_Loader::ziop_compressorid_name (clientEntry->compressor_id),
291 static_cast<int> (clientEntry->compression_level),
292 server,
293 TAO_ZIOP_Loader::ziop_compressorid_name (serverEntry->compressor_id),
294 static_cast<int> (serverEntry->compression_level),
295 static_cast<int> (returningList[0].compression_level)));
298 return returningCompressors._retn ();
301 if (7 < TAO_debug_level)
303 TAOLIB_DEBUG ((LM_DEBUG,
304 ACE_TEXT ("ZIOP (%P|%t) ")
305 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
306 ACE_TEXT ("checking (Client %d: %C@%d != Server %d: %C@%d).\n"),
307 client,
308 TAO_ZIOP_Loader::ziop_compressorid_name (clientEntry->compressor_id),
309 static_cast<int> (clientEntry->compression_level),
310 server,
311 TAO_ZIOP_Loader::ziop_compressorid_name (serverEntry->compressor_id),
312 static_cast<int> (serverEntry->compression_level)));
314 } // next serverEntry
315 } // next clientEntry
317 if (6 < TAO_debug_level)
319 TAOLIB_DEBUG ((LM_DEBUG,
320 ACE_TEXT("ZIOP (%P|%t) ")
321 ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ")
322 ACE_TEXT("no matching CompressorIdLevelListPolicy (did not compress).\n")));
324 return 0;
327 TAO_END_VERSIONED_NAMESPACE_DECL
328 #endif