📄 trader_utils.cpp
字号:
if (this->policies_[LINK_FOLLOW_RULE] != 0)
{
CosTrading::FollowOption max_follow_policy =
this->trader_.import_attributes ().max_follow_policy ();
CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE];
CosTrading::PolicyValue& value = policy->value;
CORBA::TypeCode_var type = value.type ();
// Extract the link follow rule
CORBA::Boolean type_equal =
type->equal (CosTrading::_tc_FollowOption ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (return_value);
if (!type_equal)
ACE_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy),
return_value);
else
value >>= return_value;
if (return_value > max_follow_policy)
return_value = max_follow_policy;
}
return return_value;
}
CosTrading::FollowOption
TAO_Policies::link_follow_rule (const CosTrading::Link::LinkInfo& link_info
ACE_ENV_ARG_DECL) const
ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch,
CosTrading::Lookup::InvalidPolicyValue,
CosTrading::Link::IllegalLinkName,
CosTrading::Link::UnknownLinkName))
{
CosTrading::FollowOption return_value = CosTrading::local_only;
CosTrading::FollowOption trader_max_follow_policy =
this->trader_.import_attributes ().max_follow_policy ();
CosTrading::FollowOption link_limiting_follow_rule =
link_info.limiting_follow_rule;
// If not defined defaults to trader.def_link_follow_rule
CosTrading::FollowOption query_link_follow_rule =
this->link_follow_rule (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (return_value);
return_value = (query_link_follow_rule < trader_max_follow_policy)
? query_link_follow_rule : trader_max_follow_policy;
return_value = (return_value < link_limiting_follow_rule)
? return_value : link_limiting_follow_rule;
return return_value;
}
CORBA::ULong
TAO_Policies::hop_count (ACE_ENV_SINGLE_ARG_DECL) const
ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch))
{
return this->ulong_prop (HOP_COUNT ACE_ENV_ARG_PARAMETER);
}
CosTrading::Admin::OctetSeq*
TAO_Policies::request_id (ACE_ENV_SINGLE_ARG_DECL) const
ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch))
{
CosTrading::Admin::OctetSeq* request_id = 0;
if (this->policies_[REQUEST_ID] != 0)
{
CosTrading::Policy* policy = this->policies_[REQUEST_ID];
CosTrading::PolicyValue& value = policy->value;
CORBA::TypeCode_var type = value.type ();
CORBA::Boolean equal_octetseq =
type->equal (CosTrading::Admin::_tc_OctetSeq ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (request_id);
if (!equal_octetseq)
ACE_THROW_RETURN (CosTrading::Lookup::PolicyTypeMismatch (*policy),
request_id);
else
value >>= request_id;
}
return request_id;
}
void
TAO_Policies::
copy_in_follow_option (CosTrading::PolicySeq& policy_seq,
const CosTrading::Link::LinkInfo& link_info
ACE_ENV_ARG_DECL) const
ACE_THROW_SPEC ((CosTrading::Lookup::PolicyTypeMismatch,
CosTrading::Lookup::InvalidPolicyValue))
{
CosTrading::FollowOption follow_option = CosTrading::local_only;
CosTrading::FollowOption trader_max_follow_policy =
this->trader_.import_attributes ().max_follow_policy ();
if (this->policies_[LINK_FOLLOW_RULE] != 0)
{
CosTrading::FollowOption query_link_follow_rule =
this->link_follow_rule (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
follow_option = (CosTrading::FollowOption)
(link_info.limiting_follow_rule < trader_max_follow_policy
? (link_info.limiting_follow_rule < query_link_follow_rule
? link_info.limiting_follow_rule
: query_link_follow_rule)
: (trader_max_follow_policy < query_link_follow_rule
? trader_max_follow_policy
: query_link_follow_rule));
}
else
follow_option = (CosTrading::FollowOption)
(link_info.def_pass_on_follow_rule < trader_max_follow_policy
? link_info.def_pass_on_follow_rule
: trader_max_follow_policy);
CORBA::ULong i = 0;
for (i = 0; i < policy_seq.length (); i++)
if (ACE_OS::strcmp (policy_seq[i].name,
POLICY_NAMES[LINK_FOLLOW_RULE]) == 0)
{
policy_seq[i].value <<= follow_option;
break;
}
if (i == policy_seq.length ())
{
policy_seq.length (i + 1);
policy_seq[i].name = POLICY_NAMES[LINK_FOLLOW_RULE];
policy_seq[i].value <<= follow_option;
}
}
void
TAO_Policies::
copy_to_pass (CosTrading::PolicySeq& policy_seq,
const CosTrading::Admin::OctetSeq& request_id) const
{
CORBA::ULong counter = 0;
CosTrading::Policy* policy_buffer =
CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1);
if (policy_buffer == 0)
return;
for (int i = 0; i <= REQUEST_ID; i++)
{
CosTrading::Policy& new_policy = policy_buffer[counter];
if (i == REQUEST_ID)
{
// Set the new request id.
new_policy.name = POLICY_NAMES[REQUEST_ID];
new_policy.value <<= request_id;
counter++;
}
else if (this->policies_[i] != 0)
{
// Copy in the existing policies.
new_policy.name = POLICY_NAMES[i];
new_policy.value = this->policies_[i]->value;
counter++;
}
// We always require a hop count.
if (i == HOP_COUNT)
{
// @@ Seth, Same thing here, are you trying to catch the exception??? (and forget about it?)
ACE_DECLARE_NEW_CORBA_ENV;
new_policy.name = POLICY_NAMES[HOP_COUNT];
new_policy.value <<= this->hop_count (ACE_ENV_SINGLE_ARG_PARAMETER) - 1;
// Don't count hop count twice.
if (this->policies_[i] == 0)
counter++;
}
}
policy_seq.replace (REQUEST_ID + 1,
counter,
policy_buffer,
1);
}
void
TAO_Policies::copy_to_forward (CosTrading::PolicySeq& policy_seq,
const CosTrading::TraderName& trader_name) const
{
// Create a new policy sequence, shortening the starting trader
// policy by one link.
CORBA::ULong counter = 0;
CosTrading::Policy* policy_buffer =
CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1);
if (policy_buffer == 0)
return;
for (int i = 0; i <= REQUEST_ID; i++)
{
CosTrading::Policy& new_policy = policy_buffer[counter];
if (this->policies_[i] != 0)
{
// Copy in the existing policies.
if (i == STARTING_TRADER && trader_name.length () > 1)
{
// Eliminate the first link of the trader name.
// Only pass on the property if the sequence
// contains more links after us.
// The any will sieze control of this memory.
// Allocating here avoids copying in the policy
// any.
CORBA::ULong length = trader_name.length ();
CosTrading::LinkName* buf =
CosTrading::TraderName::allocbuf (length - 1);
if (buf != 0)
{
for (CORBA::ULong j = 1; j < length; j++)
buf[j - 1] = CORBA::string_dup (trader_name[j]);
new_policy.name = this->policies_[i]->name;
CosTrading::TraderName new_name (length - 1,
length - 1,
buf,
1);
new_policy.value <<= new_name;
counter++;
}
}
else if (i != STARTING_TRADER)
{
new_policy.name = this->policies_[i]->name;
new_policy.value = this->policies_[i]->value;
counter++;
}
}
}
// Create the new sequence
policy_seq.replace (REQUEST_ID + 1,
counter,
policy_buffer, 1);
}
TAO_Offer_Modifier::
TAO_Offer_Modifier (const char* type_name,
const CosTradingRepos::ServiceTypeRepository::TypeStruct& type_struct,
CosTrading::Offer* offer)
: type_ (type_name),
offer_ (offer)
{
const CosTradingRepos::ServiceTypeRepository::PropStructSeq&
pstructs = type_struct.props;
CosTrading::PropertySeq& prop_seq = this->offer_->properties;
CORBA::ULong pstructs_length = pstructs.length (),
props_length = prop_seq.length (),
i = 0;
// Create a mapping of property names to their types.
for (i = 0; i < pstructs_length; i++)
{
TAO_String_Hash_Key prop_name = pstructs[i].name.in ();
CORBA::TypeCode_ptr type_code =
CORBA::TypeCode::_duplicate (pstructs[i].value_type.in ());
this->prop_types_.bind (prop_name, type_code);
}
// Separate the type defined properties into mandatory and readonly
for (i = 0; i < pstructs_length; i++)
{
const char* pname = pstructs[i].name;
if (pstructs[i].mode ==
CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY)
{
TAO_String_Hash_Key prop_name (pname);
this->mandatory_.insert (prop_name);
}
else if (pstructs[i].mode ==
CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
{
TAO_String_Hash_Key prop_name (pname);
this->readonly_.insert (prop_name);
}
}
// Insert the indices of the offer properties into a map.
for (i = 0; i < props_length; i++)
{
TAO_String_Hash_Key prop_name =
ACE_static_cast (const char*, prop_seq[i].name);
this->props_.bind (prop_name, &prop_seq[i]);
}
}
TAO_Offer_Modifier::~TAO_Offer_Modifier (void)
{
for (TAO_Typecode_Table::iterator type_iter (this->prop_types_);
! type_iter.done ();
type_iter++)
{
CORBA::TypeCode_ptr corba_type = (*type_iter).int_id_;
CORBA::release (corba_type);
}
}
void
TAO_Offer_Modifier::
delete_properties (const CosTrading::PropertyNameSeq& deletes
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CosTrading::Register::UnknownPropertyName,
CosTrading::Register::MandatoryProperty,
CosTrading::IllegalPropertyName,
CosTrading::DuplicatePropertyName))
{
// Validate that the listed property names can be deleted
CORBA::ULong i = 0,
length = deletes.length ();
TAO_String_Set delete_me;
for (i = 0; i < length; i++)
{
const char* dname = ACE_static_cast (const char*, deletes[i]);
if (! TAO_Trader_Base::is_valid_identifier_name (dname))
ACE_THROW (CosTrading::IllegalPropertyName (dname));
else
{
TAO_String_Hash_Key prop_name (dname);
if (this->mandatory_.find (prop_name) == 0)
ACE_THROW (CosTrading::Register::MandatoryProperty (this->type_, dname));
else if (delete_me.insert (prop_name) == 1)
ACE_THROW (CosTrading::DuplicatePropertyName (dname));
else if (this->props_.find (prop_name) == -1)
ACE_THROW (CosTrading::Register::UnknownPropertyName (dname));
}
}
// Delete those properties from the offer.
for (i = 0; i < length; i++)
{
TAO_String_Hash_Key prop_name =
ACE_static_cast (const char *, deletes[i]);
this->props_.unbind (prop_name);
}
}
void
TAO_Offer_Modifier::
merge_properties (const CosTrading::PropertySeq& modifies
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CosTrading::IllegalPropertyName,
CosTrading::DuplicatePropertyName,
CosTrading::PropertyTypeMismatch,
CosTrading::ReadonlyDynamicProperty,
CosTrading::Register::ReadonlyProperty))
{
int i = 0, length = 0;
TAO_String_Set modify_me;
// Ensure that the proposed changes aren't to readonly properties or
// otherwise invalid.
TAO_Property_Evaluator prop_eval (modifies);
for (i = 0, length = modifies.length (); i < length; i++)
{
const char* mname = modifies[i].name;
if (TAO_Trader_Base::is_valid_identifier_name (mname))
{
TAO_String_Hash_Key prop_name (mname);
if (this->readonly_.find (prop_name) == 0)
{
// Can't assign a dynamic property to a property with
// readonly mode, and can't reassign a readonly property.
if (prop_eval.is_dynamic_property (i))
ACE_THROW (CosTrading::ReadonlyDynamicProperty (this->type_, mname));
else if (this->props_.find (prop_name) == 0)
ACE_THROW (CosTrading::Register::ReadonlyProperty (this->type_, mname));
}
// Validate the property type if the property is defined in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -