1 #include "tao/ZIOP/ZIOP_Service_Context_Handler.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/Transport.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/GIOP_Message_Base.h"
8 #include "tao/operation_details.h"
10 #include "tao/ZIOP/ZIOP_Policy_i.h"
11 #include "tao/Messaging_PolicyValueC.h"
13 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 TAO_ZIOP_Service_Context_Handler::process_service_context (
18 const IOP::ServiceContext
&ctx
,
19 TAO_ServerRequest
*req
)
21 // Ensure this context is actually for us to decode.
22 if (!req
|| ctx
.context_id
!= IOP::INVOCATION_POLICIES
)
27 #if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP == 1
28 // Create an input CDR from the context buffer
29 TAO_InputCDR
cdr (reinterpret_cast<const char*> (ctx
.context_data
.get_buffer ()),
30 ctx
.context_data
.length () );
31 CORBA::Boolean byte_order
;
32 if (!(cdr
>> TAO_InputCDR::to_boolean (byte_order
)))
36 cdr
.reset_byte_order (static_cast<int> (byte_order
));
38 // Extract the sequence of policy values that was sent.
39 Messaging::PolicyValueSeq policy_value_seq
;
40 if (!(cdr
>> policy_value_seq
))
45 // Extract each policy from the slots we received.
46 for (CORBA::ULong i
= 0u; i
< static_cast<CORBA::ULong
> (policy_value_seq
.length ()); ++i
)
48 TAO_InputCDR
policy_cdr (
49 reinterpret_cast<const char*> (policy_value_seq
[i
].pvalue
.get_buffer ()),
50 policy_value_seq
[i
].pvalue
.length ());
52 if (policy_cdr
>> TAO_InputCDR::to_boolean (byte_order
))
54 policy_cdr
.reset_byte_order (static_cast<int> (byte_order
));
55 switch (policy_value_seq
[i
].ptype
)
57 case ::ZIOP::COMPRESSION_ENABLING_POLICY_ID
:
59 TAO::CompressionEnablingPolicy
*enabled
= 0;
60 ACE_NEW_RETURN (enabled
, TAO::CompressionEnablingPolicy (), 0);
61 std::unique_ptr
<TAO::CompressionEnablingPolicy
> guard (enabled
);
62 if (enabled
->_tao_decode (policy_cdr
))
64 req
->clientCompressionEnablingPolicy (guard
.release ());
69 case ::ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID
:
71 TAO::CompressorIdLevelListPolicy
*id_list
= 0;
72 ACE_NEW_RETURN (id_list
, TAO::CompressorIdLevelListPolicy (), 0);
73 std::unique_ptr
<TAO::CompressorIdLevelListPolicy
> guard (id_list
);
74 if (id_list
->_tao_decode (policy_cdr
))
76 req
->clientCompressorIdLevelListPolicy (guard
.release ());
86 #endif /* TAO_HAS_ZIOP */
92 TAO_ZIOP_Service_Context_Handler::generate_service_context (
95 TAO_Operation_Details
&opdetails
,
96 TAO_Target_Specification
&,
101 // Obtain the two policies we are interested in sending to the server.
102 CORBA::Policy_var idpolicy
=
103 stub
->get_cached_policy (TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY
);
104 CORBA::Policy_var enabledpolicy
=
105 stub
->get_cached_policy (TAO_CACHED_COMPRESSION_ENABLING_POLICY
);
107 // upcast to the actual policy types.
108 ::ZIOP::CompressorIdLevelListPolicy_var idpolicyp
=
109 ::ZIOP::CompressorIdLevelListPolicy::_narrow (idpolicy
.in ());
110 ::ZIOP::CompressionEnablingPolicy_var enabledpolicyp
=
111 ::ZIOP::CompressionEnablingPolicy::_narrow (enabledpolicy
.in ());
113 // Put these into a sequence of policy values.
114 Messaging::PolicyValueSeq policy_value_seq
;
115 policy_value_seq
.length (0);
119 // If we do have an COMPRESSION_ID_LEVEL_LIST_POLICY, place it in a slot
120 if (!CORBA::is_nil (idpolicyp
.in ()))
122 policy_value_seq
.length (i
+ 1);
123 policy_value_seq
[i
].ptype
= idpolicyp
->policy_type ();
125 TAO_OutputCDR out_CDR
;
126 if (!(out_CDR
<< ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER
)))
129 if (!(idpolicyp
->_tao_encode (out_CDR
)))
132 length
= out_CDR
.total_length ();
133 policy_value_seq
[i
].pvalue
.length (static_cast <CORBA::ULong
>(length
));
134 CORBA::Octet
*buf
= policy_value_seq
[i
].pvalue
.get_buffer ();
136 // Copy the CDR buffer data into the octet sequence buffer.
137 for (const ACE_Message_Block
*iterator
= out_CDR
.begin ();
139 iterator
= iterator
->cont ())
141 ACE_OS::memcpy (buf
, iterator
->rd_ptr (), iterator
->length ());
142 buf
+= iterator
->length ();
147 // If we do have an COMPRESSION_ENABLING_POLICY, place it in a slot
148 if (!CORBA::is_nil (enabledpolicyp
.in ()))
150 policy_value_seq
.length (i
+ 1);
151 policy_value_seq
[i
].ptype
= enabledpolicyp
->policy_type ();
153 TAO_OutputCDR out_CDR
;
154 if (!(out_CDR
<< ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER
)))
157 if (!(enabledpolicyp
->_tao_encode (out_CDR
)))
160 length
= out_CDR
.total_length ();
161 policy_value_seq
[i
].pvalue
.length (static_cast <CORBA::ULong
>(length
));
162 CORBA::Octet
*buf
= policy_value_seq
[i
].pvalue
.get_buffer ();
164 // Copy the CDR buffer data into the octet sequence buffer.
165 for (const ACE_Message_Block
*iterator
= out_CDR
.begin ();
167 iterator
= iterator
->cont ())
169 ACE_OS::memcpy (buf
, iterator
->rd_ptr (), iterator
->length ());
170 buf
+= iterator
->length ();
175 // If we actually have any policies to send, encode them into the context.
176 if (0 < policy_value_seq
.length ())
178 TAO_OutputCDR out_cdr
;
179 if (!(out_cdr
<< ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER
)))
184 if (!(out_cdr
<< policy_value_seq
))
189 opdetails
.request_service_context ().set_context (IOP::INVOCATION_POLICIES
, out_cdr
);
196 TAO_END_VERSIONED_NAMESPACE_DECL