📄 trader_utils.cpp
字号:
// the service type description.
CORBA::TypeCode_ptr type_def = 0;
if (this->prop_types_.find (prop_name, type_def) == 0)
{
CORBA::TypeCode_var prop_type = prop_eval.property_type (i);
// @@ Frank: This code used to have this comment and line
// of code before I fixed the "ACE_TRY" fuzz warning here.
// @@ Seth, are we trying to ignore the exception here?
// CORBA::Environment ACE_TRY_ENV;
// @@ Frank: It seems clear that this is not going to work as
// expected. Is the purpose to ignore any exceptions from
// equal ()? For now, exceptions are returned since this
// seemed "safest".
CORBA::Boolean td_equal =
type_def->equal (prop_type.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (!td_equal)
ACE_THROW (CosTrading::PropertyTypeMismatch (mname, modifies[i]));
}
if (modify_me.insert (prop_name) == 1)
ACE_THROW (CosTrading::DuplicatePropertyName (mname));
}
else
ACE_THROW (CosTrading::IllegalPropertyName (mname));
}
}
void
TAO_Offer_Modifier::affect_change (const CosTrading::PropertySeq& modifies)
{
// Create a new property list reflecting the deletes, modifies, and
// add operations performed, and place this property list in the
// offer.
// Merge these properties with the original set.
CORBA::ULong i = 0,
merge_length = modifies.length ();
for (i = 0; i < merge_length; i++)
{
Property_Table::ENTRY* entry = 0;
TAO_String_Hash_Key prop_name = modifies[i].name.in ();
CosTrading::Property* prop =
ACE_const_cast (CosTrading::Property*, &modifies[i]);
if (this->props_.bind (prop_name, prop, entry) == 1)
// We need to rebind here.
entry->int_id_ = prop;
}
CORBA::ULong num_modified = 0,
original_length = this->offer_->properties.length (),
total_length = ACE_static_cast (CORBA::ULong,
this->props_.current_size ());
// Scrap the existing property sequence and begin a new one
CosTrading::PropertySeq prop_seq (total_length);
// this->offer_->properties.length (total_length);
// Copy in the unaffected and modified props into the offer,
// excluding those that were deleted. Let's try and retain their
// relative ordering.
for (i = 0; i < original_length; i++)
{
CosTrading::Property* prop_value = 0;
const char* name = this->offer_->properties[i].name;
TAO_String_Hash_Key prop_name (name);
if (this->props_.unbind (prop_name, prop_value) == 0)
prop_seq[num_modified++] = *prop_value;
}
for (i = 0; i < merge_length; i++)
{
CosTrading::Property* prop_value = 0;
const char* name = modifies[i].name;
TAO_String_Hash_Key prop_name (name);
if (this->props_.unbind (prop_name, prop_value) == 0)
prop_seq[num_modified++] = *prop_value;
}
this->offer_->properties.length (total_length);
for (i = 0; i < total_length; i++)
this->offer_->properties[i] = prop_seq[i];
// Free the old, orphaned sequence.
// CosTrading::PropertySeq::freebuf (prop_buf);
}
TAO_Offer_Filter::TAO_Offer_Filter (TAO_Policies& policies
ACE_ENV_ARG_DECL)
{
search_card_ = policies.search_card (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
match_card_ = policies.match_card (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
return_card_ = policies.return_card (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
dp_ = policies.use_dynamic_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
mod_ = policies.use_modifiable_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
CORBA::Boolean exact_type_match =
policies.exact_type_match (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
if (exact_type_match == 1)
{
TAO_String_Hash_Key exact_match
(TAO_Policies::POLICY_NAMES[TAO_Policies::EXACT_TYPE_MATCH]);
this->limits_.insert (exact_match);
}
}
void
TAO_Offer_Filter::
configure_type (CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct)
{
CosTradingRepos::ServiceTypeRepository::PropStructSeq&
prop_seq = type_struct->props;
// Take note of non-modifiable properties in the type_struct
this->not_mod_props_.reset ();
for (int i = prop_seq.length () - 1; i >= 0; i--)
{
CosTradingRepos::ServiceTypeRepository::PropertyMode mode = prop_seq[i].mode;
if (mode == CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY_READONLY ||
mode == CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
{
TAO_String_Hash_Key prop_name ((const char*) prop_seq[i].name);
this->not_mod_props_.insert (prop_name);
}
}
}
CORBA::Boolean
TAO_Offer_Filter::ok_to_consider (CosTrading::Offer* offer)
{
TAO_String_Hash_Key use_mods =
TAO_Policies::POLICY_NAMES[TAO_Policies::USE_MODIFIABLE_PROPERTIES];
TAO_String_Hash_Key use_dyns =
TAO_Policies::POLICY_NAMES[TAO_Policies::USE_DYNAMIC_PROPERTIES];
CORBA::Boolean return_value = 1;
TAO_Property_Evaluator prop_eval (*offer);
// If we should screen offers, determine if this offer is unworthy
// for consideration.
if (! (this->mod_ && this->dp_))
{
for (int i = offer->properties.length () - 1;
i >= 0 && return_value;
i--)
{
// Winnow away the unwanted offers with modifiable or
// dynamic properties.
if (! this->mod_)
{
// Determine if this property name is found in the set
// of modifiable properties for the type being considered.
TAO_String_Hash_Key prop_name ((const char*) offer->properties[i].name);
if (this->not_mod_props_.find (prop_name) == -1)
{
this->limits_.insert (use_mods);
return_value = 0;
}
}
if (! this->dp_ && return_value)
{
// Determine if this property is dynamic.
if (prop_eval.is_dynamic_property (i))
{
this->limits_.insert (use_dyns);
return_value = 0;
}
}
if (return_value == 0)
break;
}
}
// If we're good to go, consider this offer considered and decrement
// the search cardinality counter.
if (return_value)
{
this->search_card_--;
if (this->search_card_ == 0)
{
TAO_String_Hash_Key search_card =
TAO_Policies::POLICY_NAMES[TAO_Policies::SEARCH_CARD];
this->limits_.insert (search_card);
}
}
return return_value;
}
CORBA::Boolean
TAO_Offer_Filter::ok_to_consider_more (void)
{
return this->search_card_ > 0 && this->match_card_ > 0;
}
void
TAO_Offer_Filter::matched_offer (void)
{
this->match_card_--;
this->return_card_--;
if (this->match_card_ == 0)
{
TAO_String_Hash_Key match_card =
TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
this->limits_.insert (match_card);
}
if (this->return_card_ == 0)
{
TAO_String_Hash_Key return_card =
TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
this->limits_.insert (return_card);
}
}
CORBA::ULong
TAO_Offer_Filter::search_card_remaining (void) const
{
return this->search_card_;
}
CORBA::ULong
TAO_Offer_Filter::match_card_remaining (void) const
{
return this->match_card_;
}
CosTrading::PolicyNameSeq*
TAO_Offer_Filter::limits_applied (void)
{
int i = 0;
CORBA::ULong size = ACE_static_cast (CORBA::ULong,
this->limits_.size ());
CosTrading::PolicyName* temp =
CosTrading::PolicyNameSeq::allocbuf (size);
for (TAO_String_Set::iterator p_iter (this->limits_.begin());
! p_iter.done ();
p_iter.advance ())
{
TAO_String_Hash_Key* policy_name_ptr = 0;
p_iter.next (policy_name_ptr);
temp[i++] = CORBA::string_dup (policy_name_ptr->in ());
}
return new CosTrading::PolicyNameSeq (size, size, temp, 1);
}
TAO_Property_Filter::
TAO_Property_Filter (const SPECIFIED_PROPS& desired_props
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CosTrading::IllegalPropertyName,
CosTrading::DuplicatePropertyName))
: policy_ (desired_props._d ())
{
if (this->policy_ == CosTrading::Lookup::some)
{
const CosTrading::PropertyNameSeq&
prop_seq = desired_props.prop_names ();
int length = prop_seq.length ();
for (int i = 0; i < length; i++)
{
const char* pname = prop_seq[i];
// Check for errors or duplicates
if (TAO_Trader_Base::is_valid_identifier_name (pname))
{
TAO_String_Hash_Key prop_name (pname);
if (this->props_.insert (prop_name) == 1)
ACE_THROW (CosTrading::DuplicatePropertyName (pname));
}
else
ACE_THROW (CosTrading::IllegalPropertyName (pname));
}
}
}
TAO_Property_Filter::
TAO_Property_Filter (const TAO_Property_Filter& prop_filter)
: props_ (prop_filter.props_),
policy_ (prop_filter.policy_)
{
}
TAO_Property_Filter&
TAO_Property_Filter::operator= (const TAO_Property_Filter& other)
{
this->props_ = other.props_;
this->policy_ = other.policy_;
return *this;
}
void
TAO_Property_Filter::filter_offer (CosTrading::Offer* source,
CosTrading::Offer& destination)
{
Prop_Queue prop_queue;
CosTrading::PropertySeq& s_props = source->properties;
CosTrading::PropertySeq& d_props = destination.properties;
CORBA::ULong length = ACE_static_cast (CORBA::ULong, s_props.length ()),
elem = 0;
destination.reference = CORBA::Object::_duplicate (source->reference.in ());
if (this->policy_ == CosTrading::Lookup::some)
{
for (CORBA::ULong i = 0; i < length; i++)
{
if (this->policy_ == CosTrading::Lookup::all)
prop_queue.enqueue_tail (&s_props[i]);
else
{
const char* p_name = s_props[i].name;
TAO_String_Hash_Key prop_name (p_name);
// Save those property that match.
if (this->props_.find (prop_name) == 0)
prop_queue.enqueue_tail (&s_props[i]);
}
}
// Shove the matched properties into the destination property
// sequence.
length = ACE_static_cast (CORBA::ULong, prop_queue.size ());
d_props.length (length);
for (Prop_Queue::ITERATOR prop_iter (prop_queue);
! prop_iter.done ();
prop_iter.advance (), elem++)
{
CosTrading::Property** prop_ptr = 0;
prop_iter.next (prop_ptr);
d_props[elem] = **prop_ptr;
}
}
else if (this->policy_ == CosTrading::Lookup::all)
// CosTrading::Property* props = s_props.get_buffer (0);
// d_props.replace (length, length, props, 0);
d_props = s_props;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Hash_Map_Entry<TAO_String_Hash_Key, CosTrading::Property*>;
template class ACE_Hash_Map_Manager<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>;
template class ACE_Hash_Map_Manager_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Base_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>;
template class ACE_Node<CosTrading::Property*>;
template class ACE_Unbounded_Queue<CosTrading::Property*>;
template class ACE_Unbounded_Queue_Iterator<CosTrading::Property*>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Hash_Map_Entry<TAO_String_Hash_Key, CosTrading::Property*>
#pragma instantiate ACE_Hash_Map_Manager<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator<TAO_String_Hash_Key, CosTrading::Property*, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<TAO_String_Hash_Key, CosTrading::Property*, ACE_Hash<TAO_String_Hash_Key>, ACE_Equal_To<TAO_String_Hash_Key>, ACE_Null_Mutex>
#pragma instantiate ACE_Node<CosTrading::Property*>
#pragma instantiate ACE_Unbounded_Queue<CosTrading::Property*>
#pragma instantiate ACE_Unbounded_Queue_Iterator<CosTrading::Property*>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -