void TAO_ConstantDef_i::value_i (const CORBA::Any &value) { CORBA::TypeCode_var my_tc = this->type_i (); CORBA::TypeCode_var val_tc = value.type (); CORBA::Boolean const equal_tc = my_tc.in ()->equal (val_tc.in ()); if (!equal_tc) { return; } ACE_Message_Block *mb = 0; TAO::Any_Impl *impl = value.impl (); if (impl->encoded ()) { TAO::Unknown_IDL_Type *unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); mb = unk->_tao_get_cdr ().steal_contents (); } else { TAO_OutputCDR out; impl->marshal_value (out); TAO_InputCDR in (out); mb = in.steal_contents (); } ACE_Auto_Ptr<ACE_Message_Block> safe (mb); CORBA::TCKind kind = val_tc->kind (); switch (kind) { // The data for these types will be aligned to an 8-byte // boundary, while the rd_ptr may not. case CORBA::tk_double: case CORBA::tk_ulonglong: case CORBA::tk_longlong: case CORBA::tk_longdouble: mb->rd_ptr (ACE_ptr_align_binary (mb->rd_ptr (), ACE_CDR::MAX_ALIGNMENT)); break; default: break; } mb->crunch (); this->repo_->config ()->set_binary_value (this->section_key_, "value", mb->base (), mb->length ()); }
CORBA::Boolean operator<< (TAO_OutputCDR &cdr, const CORBA::Any &any) { TAO::Any_Impl *impl = any.impl (); if (impl != 0) { return impl->marshal (cdr); } return (cdr << CORBA::_tc_null); }
int TAO_Log_Constraint_Visitor::visit_identifier (ETCL_Identifier *ident) { int return_value = -1; const char *name = ident->value (); ACE_CString key (name, 0, false); CORBA::Any any; if (this->property_lookup_.find (key, any) == 0) { if (any.impl() != 0) { this->queue_.enqueue_head (TAO_ETCL_Literal_Constraint (&any)); return_value = 0; } } return return_value; }
int TAO_Log_Constraint_Visitor::visit_component_assoc ( ETCL_Component_Assoc *assoc) { // @@@ (JP) The spec reserves this type of constraint for NVLists. // Since NVLists don't have type codes or Any operators, there's // no way that TAO can put one into the event's filterable data. // However, from the looks of the ETCL grammar, I believe that a // contruct like 'exist $(foo)' is legal, and is in effect using // the event's filterable data as one big NVList. It is // equivalent to '$.foo'. I've implemented this method on that // basis, while keeping in mind that a clearer interpretation of // the spec may come along someday. CORBA::Any any; ACE_CString key (assoc->identifier ()->value (), 0, false); if (this->property_lookup_.find (key, any) != 0 || any.impl () == 0) { return -1; } ETCL_Constraint *comp = assoc->component (); if (comp == 0) { TAO_ETCL_Literal_Constraint result (&any); this->queue_.enqueue_head (result); return 0; } CORBA::Any *any_ptr = 0; ACE_NEW_RETURN (any_ptr, CORBA::Any (any), -1); this->current_member_ = any_ptr; return comp->accept (this); }
void TAO_DynEnum_i::init (const CORBA::Any &any) { CORBA::TypeCode_var tc = any.type (); CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()); if (kind != CORBA::tk_enum) { throw DynamicAny::DynAnyFactory::InconsistentTypeCode (); } this->type_ = tc; TAO::Any_Impl *impl = any.impl (); if (impl->encoded ()) { TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) throw CORBA::INTERNAL (); // We don't want unk's rd_ptr to move, in case we are shared by // another Any, so we use this to copy the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); for_reading.read_ulong (this->value_); } else { TAO_OutputCDR out; impl->marshal_value (out); TAO_InputCDR in (out); in.read_ulong (this->value_); } this->init_common (); }
CORBA::Boolean TAO::Any_Array_Impl_T<T_slice, T_forany>::extract (const CORBA::Any & any, _tao_destructor destructor, CORBA::TypeCode_ptr tc, T_slice *& _tao_elem) { _tao_elem = 0; try { CORBA::TypeCode_ptr any_tc = any._tao_get_typecode (); CORBA::Boolean const _tao_equiv = any_tc->equivalent (tc); if (_tao_equiv == false) { return false; } TAO::Any_Impl *impl = any.impl (); if (!impl->encoded ()) { TAO::Any_Array_Impl_T<T_slice, T_forany> *narrow_impl = dynamic_cast <TAO::Any_Array_Impl_T <T_slice, T_forany> *> (impl); if (narrow_impl == 0) { return false; } _tao_elem = reinterpret_cast <T_slice*> (narrow_impl->value_); return true; } TAO::Any_Array_Impl_T<T_slice, T_forany> *replacement = 0; typedef TAO::Any_Array_Impl_T<T_slice, T_forany> ARRAY_ANY_IMPL; ACE_NEW_RETURN (replacement, ARRAY_ANY_IMPL (destructor, any_tc, T_forany::tao_alloc ()), false); #if defined (ACE_HAS_CPP11) std::unique_ptr<TAO::Any_Array_Impl_T<T_slice, T_forany> > replacement_safety (replacement); #else auto_ptr<TAO::Any_Array_Impl_T<T_slice, T_forany> > replacement_safety (replacement); #endif /* ACE_HAS_CPP11 */ // We know this will work since the unencoded case is covered above. TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) return false; // We don't want the rd_ptr of unk to move, in case it is // shared by another Any. This copies the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); CORBA::Boolean const good_decode = replacement->demarshal_value (for_reading); if (good_decode) { _tao_elem = reinterpret_cast <T_slice*> (replacement->value_); const_cast<CORBA::Any &> (any).replace (replacement); replacement_safety.release (); return true; } // Duplicated by Any_Impl base class constructor. ::CORBA::release (any_tc); } catch (const ::CORBA::Exception&) { } return false; }
void TAO_DynSequence_i::from_any (const CORBA::Any & any) { if (this->destroyed_) { throw ::CORBA::OBJECT_NOT_EXIST (); } CORBA::TypeCode_var tc = any.type (); CORBA::Boolean equivalent = this->type_.in ()->equivalent (tc.in ()); if (equivalent) { // Get the CDR stream of the Any, if there isn't one, make one. TAO::Any_Impl *impl = any.impl (); TAO_OutputCDR out; TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0)); if (impl->encoded ()) { TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) throw CORBA::INTERNAL (); cdr = unk->_tao_get_cdr (); } else { impl->marshal_value (out); TAO_InputCDR tmp_in (out); cdr = tmp_in; } CORBA::ULong arg_length; // If the any is a sequence, first 4 bytes of cdr hold the // length. cdr.read_ulong (arg_length); // If the array grows, we must do it now. if (arg_length > this->component_count_) { this->da_members_.size (arg_length); } CORBA::TypeCode_var field_tc = this->get_element_type (); for (CORBA::ULong i = 0; i < arg_length; ++i) { CORBA::Any field_any; TAO_InputCDR unk_in (cdr); TAO::Unknown_IDL_Type *field_unk = 0; ACE_NEW (field_unk, TAO::Unknown_IDL_Type (field_tc.in (), unk_in)); field_any.replace (field_unk); if (i < this->component_count_) { this->da_members_[i]->destroy (); } this->da_members_[i] = TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> ( field_any._tao_get_typecode (), field_any, this->allow_truncation_ ); // Move to the next field in the CDR stream. (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr); } // Destroy any dangling members. for (CORBA::ULong j = arg_length; j < this->component_count_; ++j) { this->da_members_[j]->destroy (); } // If the array shrinks, we must wait until now to do it. if (arg_length < this->component_count_) { this->da_members_.size (arg_length); } // Now we can update component_count_. this->component_count_ = arg_length; this->current_position_ = arg_length ? 0 : -1; } else { throw DynamicAny::DynAny::TypeMismatch (); } }
void TAO_DynSequence_i::init (const CORBA::Any& any) { CORBA::TypeCode_var tc = any.type (); CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ()); if (kind != CORBA::tk_sequence) { throw DynamicAny::DynAnyFactory::InconsistentTypeCode (); } this->type_ = tc; // Get the CDR stream of the Any, if there isn't one, make one. TAO::Any_Impl *impl = any.impl (); CORBA::ULong length; TAO_OutputCDR out; TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0)); if (impl->encoded ()) { TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) throw CORBA::INTERNAL (); cdr = unk->_tao_get_cdr (); } else { impl->marshal_value (out); TAO_InputCDR tmp_in (out); cdr = tmp_in; } // If the any is a sequence, first 4 bytes of cdr hold the // length. cdr.read_ulong (length); // Resize the array. this->da_members_.size (length); this->init_common (); // Get the type of the sequence elments. CORBA::TypeCode_var field_tc = this->get_element_type (); for (CORBA::ULong i = 0; i < length; ++i) { CORBA::Any field_any; TAO_InputCDR unk_in (cdr); TAO::Unknown_IDL_Type *field_unk = 0; ACE_NEW (field_unk, TAO::Unknown_IDL_Type (field_tc.in (), unk_in)); field_any.replace (field_unk); // This recursive step will call the correct constructor // based on the type of field_any. this->da_members_[i] = TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> ( field_any._tao_get_typecode (), field_any, this->allow_truncation_ ); // Move to the next field in the CDR stream. (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr); } }
CORBA::Boolean Any_Basic_Impl::extract (const CORBA::Any &any, CORBA::TypeCode_ptr tc, void *_tao_elem) { try { CORBA::TypeCode_ptr any_tc = any._tao_get_typecode (); CORBA::Boolean const _tao_equiv = any_tc->equivalent (tc); if (!_tao_equiv) { return false; } TAO::Any_Impl * const impl = any.impl (); if (impl && !impl->encoded ()) { TAO::Any_Basic_Impl * const narrow_impl = dynamic_cast<TAO::Any_Basic_Impl *> (impl); if (narrow_impl == 0) { return false; } Any_Basic_Impl::assign_value (_tao_elem, narrow_impl); return true; } TAO::Any_Basic_Impl *replacement = TAO::Any_Basic_Impl::create_empty (any_tc); auto_ptr<TAO::Any_Basic_Impl> replacement_safety (replacement); // We know this will work since the unencoded case is covered above. TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) return false; // Get the kind of the type where we are extracting in ie. the // aliased type if there are any. Passing the aliased kind // will not help. CORBA::TCKind const tck = tc->kind (); // We don't want the rd_ptr of unk to move, in case it is // shared by another Any. This copies the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); CORBA::Boolean const good_decode = replacement->demarshal_value (for_reading, static_cast<CORBA::Long> (tck)); if (good_decode) { Any_Basic_Impl::assign_value (_tao_elem, replacement, tck); const_cast<CORBA::Any &> (any).replace (replacement); replacement_safety.release (); return true; } // Duplicated by Any_Impl base class constructor. ::CORBA::release (any_tc); } catch (const ::CORBA::Exception&) { } return false; }
void TAO_DynArray_i::from_any (const CORBA::Any& any) { if (this->destroyed_) { throw ::CORBA::OBJECT_NOT_EXIST (); } CORBA::TypeCode_var tc = any.type (); CORBA::Boolean equivalent = this->type_.in ()->equivalent (tc.in ()); if (equivalent) { // Get the CDR stream of the Any,if there isn't one, make one. TAO::Any_Impl *impl = any.impl (); TAO_OutputCDR out; TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0)); if (impl->encoded ()) { TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) throw CORBA::INTERNAL (); cdr = unk->_tao_get_cdr (); } else { impl->marshal_value (out); TAO_InputCDR tmp_in (out); cdr = tmp_in; } CORBA::ULong length = static_cast<CORBA::ULong> (this->da_members_.size ()); CORBA::ULong arg_length = this->get_tc_length (tc.in ()); if (length != arg_length) { throw DynamicAny::DynAny::TypeMismatch (); } CORBA::TypeCode_var field_tc = this->get_element_type (); for (CORBA::ULong i = 0; i < arg_length; ++i) { CORBA::Any field_any; TAO_InputCDR unk_in (cdr); TAO::Unknown_IDL_Type *field_unk = 0; ACE_NEW (field_unk, TAO::Unknown_IDL_Type (field_tc.in (), unk_in)); field_any.replace (field_unk); this->da_members_[i]->destroy (); this->da_members_[i] = TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> ( field_any._tao_get_typecode (), field_any, this->allow_truncation_ ); // Move to the next field in the CDR stream. (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr); } this->current_position_ = arg_length ? 0 : -1; } else { throw DynamicAny::DynAny::TypeMismatch (); } }
CORBA::Boolean TAO::Any_Impl_T<T>::extract (const CORBA::Any & any, _tao_destructor destructor, CORBA::TypeCode_ptr tc, T *& _tao_elem) { _tao_elem = 0; try { CORBA::TypeCode_ptr any_tc = any._tao_get_typecode (); CORBA::Boolean const _tao_equiv = any_tc->equivalent (tc); if (_tao_equiv == false) { return false; } TAO::Any_Impl * const impl = any.impl (); if (impl && !impl->encoded ()) { TAO::Any_Impl_T<T> * const narrow_impl = dynamic_cast <TAO::Any_Impl_T<T> *> (impl); if (narrow_impl == 0) { return false; } _tao_elem = (T *) narrow_impl->value_; return true; } TAO::Any_Impl_T<T> *replacement = 0; ACE_NEW_RETURN (replacement, TAO::Any_Impl_T<T> (destructor, any_tc, 0), false); auto_ptr<TAO::Any_Impl_T<T> > replacement_safety (replacement); // We know this will work since the unencoded case is covered above. TAO::Unknown_IDL_Type * const unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); if (!unk) return false; // We don't want the rd_ptr of unk to move, in case it is // shared by another Any. This copies the state, not the buffer. TAO_InputCDR for_reading (unk->_tao_get_cdr ()); CORBA::Boolean const good_decode = replacement->demarshal_value (for_reading); if (good_decode) { _tao_elem = const_cast<T *> (replacement->value_); const_cast<CORBA::Any &> (any).replace (replacement); replacement_safety.release (); return true; } // Duplicated by Any_Impl base class constructor. ::CORBA::release (any_tc); } catch (const ::CORBA::Exception&) { } return false; }