本文整理汇总了C++中Subscriber_var::lookup_datareader方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber_var::lookup_datareader方法的具体用法?C++ Subscriber_var::lookup_datareader怎么用?C++ Subscriber_var::lookup_datareader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscriber_var
的用法示例。
在下文中一共展示了Subscriber_var::lookup_datareader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_subscription_bit
bool read_subscription_bit(const Subscriber_var& bit_sub,
const DomainParticipant_var& publisher,
const OpenDDS::DCPS::RepoId& subscriber_repo_id,
InstanceHandle_t& handle,
int user_data,
int topic_data,
bool ignored_subscription = false)
{
OpenDDS::DCPS::Discovery_rch disc =
TheServiceParticipant->get_discovery(publisher->get_domain_id());
OpenDDS::DCPS::DomainParticipantImpl* publisher_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(publisher.in());
DataReader_var dr = bit_sub->lookup_datareader(BUILT_IN_SUBSCRIPTION_TOPIC);
if (!ignored_subscription) {
ReadCondition_var rc = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE,
ALIVE_INSTANCE_STATE);
WaitSet_var waiter = new WaitSet;
waiter->attach_condition(rc);
ConditionSeq activeConditions;
Duration_t forever = { DURATION_INFINITE_SEC,
DURATION_INFINITE_NSEC };
ReturnCode_t result = waiter->wait(activeConditions, forever);
waiter->detach_condition(rc);
if (result != RETCODE_OK) {
ACE_DEBUG((LM_ERROR,
"ERROR: %P (subscription BIT) could not wait for condition: %d\n", result));
return false;
}
} else {
ACE_OS::sleep(1);
}
SubscriptionBuiltinTopicDataDataReader_var pub_bit =
SubscriptionBuiltinTopicDataDataReader::_narrow(dr);
SubscriptionBuiltinTopicDataSeq data;
SampleInfoSeq infos;
ReturnCode_t ret =
pub_bit->read(data, infos, LENGTH_UNLIMITED,
ANY_SAMPLE_STATE, ANY_VIEW_STATE, ALIVE_INSTANCE_STATE);
if (ignored_subscription && (ret != RETCODE_NO_DATA)) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not read ignored subscription BIT: %d\n",
ret));
return false;
} else if (ret != RETCODE_OK && ret != RETCODE_NO_DATA) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not read subscription BIT: %d\n", ret));
return false;
}
int num_valid = 0;
bool found_subscriber = false;
for (CORBA::ULong i = 0; i < data.length(); ++i) {
if (infos[i].valid_data) {
++num_valid;
OpenDDS::DCPS::RepoId repo_id =
disc->bit_key_to_repo_id(publisher_impl,
OpenDDS::DCPS::BUILT_IN_PARTICIPANT_TOPIC,
data[i].participant_key);
OpenDDS::DCPS::GuidConverter converter(repo_id);
ACE_DEBUG((LM_DEBUG,
"%P Read Subscription BIT with key: %x %x %x and handle %d\n"
"\tParticipant's GUID=%C\n\tTopic: %C\tType: %C\n",
data[i].key.value[0], data[i].key.value[1],
data[i].key.value[2], infos[i].instance_handle,
std::string(converter).c_str (), data[i].topic_name.in(),
data[i].type_name.in()));
if (repo_id == subscriber_repo_id) {
found_subscriber = true;
if (data[i].user_data.value.length() != 1) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P subscription [%d] user data length %d "
"not expected length of 1\n",
i,
data[i].user_data.value.length()),
false);
}
if (data[i].topic_data.value.length() != 1) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P subscription [%d] topic data length %d "
"not expected length of 1\n",
i,
data[i].topic_data.value.length()),
false);
}
if (data[i].user_data.value[0] != user_data) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P subscription [%d] user data value %d "
"not expected value %d\n",
i,
data[i].user_data.value[0],
user_data),
false);
}
if (data[i].topic_data.value[0] != topic_data) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P subscription [%d] topic data value %d "
//.........这里部分代码省略.........
示例2: read_participant_bit
bool read_participant_bit(const Subscriber_var& bit_sub,
const DomainParticipant_var& dp,
const OpenDDS::DCPS::RepoId& other_dp_repo_id,
int user_data)
{
OpenDDS::DCPS::Discovery_rch disc =
TheServiceParticipant->get_discovery(dp->get_domain_id());
OpenDDS::DCPS::DomainParticipantImpl* dp_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(dp.in());
DataReader_var dr = bit_sub->lookup_datareader(BUILT_IN_PARTICIPANT_TOPIC);
ReadCondition_var rc = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE,
ALIVE_INSTANCE_STATE);
WaitSet_var waiter = new WaitSet;
waiter->attach_condition(rc);
ConditionSeq activeConditions;
Duration_t forever = { DURATION_INFINITE_SEC,
DURATION_INFINITE_NSEC };
ReturnCode_t result = waiter->wait(activeConditions, forever);
waiter->detach_condition(rc);
if (result != RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR, "ERROR: %P could not wait for condition: %d\n", result), false);
}
ParticipantBuiltinTopicDataDataReader_var part_bit =
ParticipantBuiltinTopicDataDataReader::_narrow(dr);
ParticipantBuiltinTopicDataSeq data;
SampleInfoSeq infos;
ReturnCode_t ret =
part_bit->read_w_condition(data, infos, LENGTH_UNLIMITED, rc);
if (ret != RETCODE_OK) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not read participant BIT: %d\n", ret));
return false;
}
bool found_other_dp = false;
int num_valid = 0;
for (CORBA::ULong i = 0; i < data.length(); ++i) {
if (infos[i].valid_data) {
++num_valid;
OpenDDS::DCPS::RepoId repo_id =
disc->bit_key_to_repo_id(dp_impl,
OpenDDS::DCPS::BUILT_IN_PARTICIPANT_TOPIC,
data[i].key);
OpenDDS::DCPS::GuidConverter converter(repo_id);
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("%P ")
ACE_TEXT("Read Participant BIT GUID=%C handle=%d\n"),
std::string(converter).c_str(), infos[i].instance_handle));
if (repo_id == other_dp_repo_id) {
if (data[i].user_data.value.length() != 1) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P participant[%d] user data length %d "
"not expected length of 1\n",
i,
data[i].user_data.value.length()),
false);
}
if (data[i].user_data.value[0] != user_data) {
ACE_ERROR_RETURN((LM_ERROR,
"ERROR: %P participant[%d] user data value %d "
"not expected value %d\n",
i,
data[i].user_data.value[0],
user_data),
false);
}
found_other_dp = true;
}
}
}
if (num_valid != 1) {
ACE_DEBUG((LM_ERROR, "ERROR: %P expected to discover 1 other participant, found %d\n", data.length ()));
}
part_bit->return_loan(data, infos);
if (!found_other_dp) {
ACE_ERROR_RETURN((LM_ERROR, "ERROR: %P did not find expected participant\n"), false);
}
return true;
}