本文整理汇总了C++中DataReader_var类的典型用法代码示例。如果您正苦于以下问题:C++ DataReader_var类的具体用法?C++ DataReader_var怎么用?C++ DataReader_var使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataReader_var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wait_match
void wait_match(const DataReader_var& dr, int n)
{
StatusCondition_var condition = dr->get_statuscondition();
condition->set_enabled_statuses(SUBSCRIPTION_MATCHED_STATUS);
WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
ConditionSeq conditions;
SubscriptionMatchedStatus ms = {0, 0, 0, 0, 0};
const Duration_t timeout = {1, 0};
while (dr->get_subscription_matched_status(ms) == RETCODE_OK
&& ms.current_count != n) {
ws->wait(conditions, timeout);
}
ws->detach_condition(condition);
}
示例2: waitForSample
bool waitForSample(const DataReader_var& dr)
{
ReadCondition_var dr_rc = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, ALIVE_INSTANCE_STATE);
WaitSet_var ws = new WaitSet;
ws->attach_condition(dr_rc);
Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
ConditionSeq active;
ReturnCode_t ret = ws->wait(active, infinite);
ws->detach_condition(dr_rc);
dr->delete_readcondition(dr_rc);
if (ret != RETCODE_OK) {
cout << "ERROR: wait(rc) failed" << endl;
return false;
}
return true;
}
示例3: getReader
bool DDSBroker::setListener(std::string topicName, DDS::DataReaderListener_var listener)
{
DataReader_var reader = getReader(topicName);
if (!reader.in())
{
ROS_ERROR("[DDS] Failed to get reader on topic %s.", topicName.c_str());
return false;
}
// set a callback listener
DDS::ReturnCode_t status;
DDS::StatusMask mask = DDS::DATA_AVAILABLE_STATUS;
status = reader->set_listener(listener, mask);
if (status != DDS::RETCODE_OK)
{
ROS_ERROR("[DDS] Failed to set a listener on topic %s (%s).", topicName.c_str(), RETCODE_DESC(status));
return false;
}
ROS_INFO("[DDS] DDSListener on %s is ready...", topicName.c_str());
return true;
}
示例4: run_filtering_test
bool run_filtering_test(const DomainParticipant_var& dp,
const MessageTypeSupport_var& ts, const Publisher_var& pub,
const Subscriber_var& sub)
{
DataWriter_var dw;
DataReader_var dr;
test_setup(dp, ts, pub, sub, "MyTopic2", dw, dr);
MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
Message sample;
sample.key = 1;
ReturnCode_t ret = mdw->write(sample, HANDLE_NIL);
if (ret != RETCODE_OK) return false;
if (!waitForSample(dr)) return false;
ReadCondition_var dr_qc = dr->create_querycondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, ALIVE_INSTANCE_STATE, "key > 1", DDS::StringSeq());
if (!dr_qc.in()) {
cout << "ERROR: failed to create QueryCondition" << endl;
return false;
}
WaitSet_var ws = new WaitSet;
ws->attach_condition(dr_qc);
ConditionSeq active;
Duration_t three_sec = {3, 0};
ret = ws->wait(active, three_sec);
// expect a timeout because the sample doesn't match the query string
if (ret != RETCODE_TIMEOUT) {
cout << "ERROR: wait(qc) should have timed out" << endl;
return false;
}
ws->detach_condition(dr_qc);
MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
MessageSeq data;
SampleInfoSeq infoseq;
ret = mdr->take_w_condition(data, infoseq, LENGTH_UNLIMITED, dr_qc);
if (ret != RETCODE_NO_DATA) {
cout << "ERROR: take_w_condition(qc) shouldn't have returned data" << endl;
return false;
}
SampleInfo info;
if (mdr->take_next_sample(sample, info) != RETCODE_OK) {
cout << "ERROR: take_next_sample() should have returned data" << endl;
return false;
}
sample.key = 2;
if (mdw->write(sample, HANDLE_NIL) != RETCODE_OK) return false;
if (!waitForSample(dr)) return false;
ws->attach_condition(dr_qc);
ret = ws->wait(active, three_sec);
if (ret != RETCODE_OK) {
cout << "ERROR: wait(qc) should not time out" << endl;
return false;
}
ws->detach_condition(dr_qc);
ret = mdr->take_w_condition(data, infoseq, LENGTH_UNLIMITED, dr_qc);
if (ret != RETCODE_OK) {
cout << "ERROR: take_w_condition(qc) should have returned data" << endl;
return false;
}
dr->delete_readcondition(dr_qc);
return true;
}
示例5: run_sorting_test
bool run_sorting_test(const DomainParticipant_var& dp,
const MessageTypeSupport_var& ts, const Publisher_var& pub,
const Subscriber_var& sub)
{
DataWriter_var dw;
DataReader_var dr;
test_setup(dp, ts, pub, sub, "MyTopic", dw, dr);
ReturnCode_t ret = RETCODE_OK;
MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
Message sample;
sample.key = 0;
sample.name = "data_X";
sample.nest.value = B;
for (int i(0); i < 20; ++i, ++sample.key) {
//replace the 'X' with a random letter
sample.name.inout()[5] = static_cast<char>((rand() % 26) + 'A');
ret = mdw->write(sample, HANDLE_NIL);
if (ret != RETCODE_OK) return false;
if (!(i % 4)) { //once in a while write more than 1 sample per instance
Message sample2(sample);
sample2.nest.value = A;
sample2.name.inout()[5] = static_cast<char>((rand() % 26) + 'A');
ret = mdw->write(sample2, HANDLE_NIL);
if (ret != RETCODE_OK) return false;
sample2.nest.value = C;
ret = mdw->write(sample2, HANDLE_NIL);
if (ret != RETCODE_OK) return false;
}
}
DDS::StringSeq empty_query_params;
ReadCondition_var dr_qc = dr->create_querycondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, ALIVE_INSTANCE_STATE, "ORDER BY name, nest.value",
empty_query_params);
WaitSet_var ws = new WaitSet;
ws->attach_condition(dr_qc);
MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
Duration_t five_seconds = {5, 0};
bool passed = true, done = false;
while (!done) {
ConditionSeq active;
ret = ws->wait(active, five_seconds);
if (ret == RETCODE_TIMEOUT) {
cout << "timeout ";
done = true; //continue to try and read
} else if (ret != RETCODE_OK) {
passed = false;
break;
}
cout << "wait returned" << endl;
MessageSeq data;
SampleInfoSeq info;
ret = mdr->take_w_condition(data, info, LENGTH_UNLIMITED, dr_qc);
if (ret == RETCODE_NO_DATA) {
// fall-through
} else if (ret != RETCODE_OK) {
cout << "ERROR: take_w_condition returned " << ret << endl;
passed = false;
done = true;
} else {
char largest = 0;
for (CORBA::ULong i(0); i < data.length(); ++i) {
cout << "Info:\tinstance_handle = " << info[i].instance_handle <<
"\tsample_rank = " << info[i].sample_rank << '\n';
if (info[i].valid_data) {
cout << "Data:\tkey = " << data[i].key <<
" \tname = " << data[i].name <<
"\tnest.value = " << data[i].nest.value <<
'\n';
if (data[i].name[5] >= largest) {
largest = data[i].name[5];
} else {
cout << "ERROR: data is not sorted for key: " <<
data[i].key << endl;
passed = false;
}
}
cout << endl;
}
}
}
MessageSeq data;
SampleInfoSeq info;
ret = mdr->take_w_condition(data, info, LENGTH_UNLIMITED, dr_qc);
if (ret != RETCODE_NO_DATA) {
cout << "WARNING: there is still data in the reader\n";
}
ws->detach_condition(dr_qc);
dr->delete_readcondition(dr_qc);
return passed;
}
示例6: OSPL_MAIN
int
OSPL_MAIN (
int argc,
char *argv[])
{
/* Generic DDS entities */
DomainParticipantFactory_var dpf;
DomainParticipant_var parentDP;
ExtDomainParticipant_var participant;
Topic_var chatMessageTopic;
Topic_var nameServiceTopic;
TopicDescription_var namedMessageTopic;
Subscriber_var chatSubscriber;
DataReader_var parentReader;
/* Type-specific DDS entities */
ChatMessageTypeSupport_var chatMessageTS;
NameServiceTypeSupport_var nameServiceTS;
NamedMessageTypeSupport_var namedMessageTS;
NamedMessageDataReader_var chatAdmin;
NamedMessageSeq_var msgSeq = new NamedMessageSeq();
SampleInfoSeq_var infoSeq = new SampleInfoSeq();
/* QosPolicy holders */
TopicQos reliable_topic_qos;
TopicQos setting_topic_qos;
SubscriberQos sub_qos;
DDS::StringSeq parameterList;
/* DDS Identifiers */
DomainId_t domain = DOMAIN_ID_DEFAULT;
ReturnCode_t status;
/* Others */
bool terminated = false;
const char * partitionName = "ChatRoom";
char * chatMessageTypeName = NULL;
char * nameServiceTypeName = NULL;
char * namedMessageTypeName = NULL;
#ifdef USE_NANOSLEEP
struct timespec sleeptime;
struct timespec remtime;
#endif
/* Options: MessageBoard [ownID] */
/* Messages having owner ownID will be ignored */
parameterList.length(1);
if (argc > 1) {
parameterList[0] = DDS::string_dup(argv[1]);
}
else
{
parameterList[0] = "0";
}
/* Create a DomainParticipantFactory and a DomainParticipant (using Default QoS settings. */
dpf = DomainParticipantFactory::get_instance();
checkHandle(dpf.in(), "DDS::DomainParticipantFactory::get_instance");
parentDP = dpf->create_participant (
domain,
PARTICIPANT_QOS_DEFAULT,
NULL,
STATUS_MASK_NONE);
checkHandle(parentDP.in(), "DDS::DomainParticipantFactory::create_participant");
/* Narrow the normal participant to its extended representative */
participant = ExtDomainParticipantImpl::_narrow(parentDP.in());
checkHandle(participant.in(), "DDS::ExtDomainParticipant::_narrow");
/* Register the required datatype for ChatMessage. */
chatMessageTS = new ChatMessageTypeSupport();
checkHandle(chatMessageTS.in(), "new ChatMessageTypeSupport");
chatMessageTypeName = chatMessageTS->get_type_name();
status = chatMessageTS->register_type(
participant.in(),
chatMessageTypeName);
checkStatus(status, "Chat::ChatMessageTypeSupport::register_type");
/* Register the required datatype for NameService. */
nameServiceTS = new NameServiceTypeSupport();
checkHandle(nameServiceTS.in(), "new NameServiceTypeSupport");
nameServiceTypeName = nameServiceTS->get_type_name();
status = nameServiceTS->register_type(
participant.in(),
nameServiceTypeName);
checkStatus(status, "Chat::NameServiceTypeSupport::register_type");
/* Register the required datatype for NamedMessage. */
namedMessageTS = new NamedMessageTypeSupport();
checkHandle(namedMessageTS.in(), "new NamedMessageTypeSupport");
namedMessageTypeName = namedMessageTS->get_type_name();
status = namedMessageTS->register_type(
participant.in(),
namedMessageTypeName);
checkStatus(status, "Chat::NamedMessageTypeSupport::register_type");
/* Set the ReliabilityQosPolicy to RELIABLE. */
status = participant->get_default_topic_qos(reliable_topic_qos);
//.........这里部分代码省略.........
示例7: run_test_instance
int run_test_instance(DDS::DomainParticipant_ptr dp)
{
using namespace DDS;
using namespace OpenDDS::DCPS;
using namespace Messenger;
WaitSet_var ws = new WaitSet;
MessageTypeSupport_var ts = new MessageTypeSupportImpl;
ts->register_type(dp, "");
CORBA::String_var type_name = ts->get_type_name();
Topic_var topic = dp->create_topic("MyTopic", type_name,
TOPIC_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DataReader_var dr = sub->create_datareader(topic, DATAREADER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
StatusCondition_var dw_sc = dw->get_statuscondition();
dw_sc->set_enabled_statuses(PUBLICATION_MATCHED_STATUS);
ws->attach_condition(dw_sc);
Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
ConditionSeq active;
ReturnCode_t ret = ws->wait(active, infinite);
if (ret != RETCODE_OK) return ret;
ret = ws->detach_condition(dw_sc);
if (ret != RETCODE_OK) return ret;
MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
Message msg = {0};
for (int i(0); i < 12; ++i) {
++msg.subject_id;
ret = mdw->write(msg, HANDLE_NIL);
if (ret != RETCODE_OK) return ret;
}
ReadCondition_var dr_rc = dr->create_readcondition(NOT_READ_SAMPLE_STATE,
NEW_VIEW_STATE, ALIVE_INSTANCE_STATE);
ReadCondition_var dr_rc2 = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, NOT_ALIVE_DISPOSED_INSTANCE_STATE);
ws->attach_condition(dr_rc);
ws->attach_condition(dr_rc2);
MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
bool passed = true, done = false;
while (!done) {
ret = ws->wait(active, infinite);
if (ret != RETCODE_OK) {
passed = false;
break;
}
cout << "wait returned" << endl;
for (CORBA::ULong i(0); i < active.length(); ++i) {
if (active[i] == dr_rc) {
// To test both take_w_condition and
// take_next_instance_w_condition, we'll limit the "take" to 3
// samples and then use take_next_instance_w_condition.
MessageSeq data;
SampleInfoSeq info;
ret = mdr->take_w_condition(data, info, 3, dr_rc);
if (ret == RETCODE_NO_DATA) break;
if (ret != RETCODE_OK) {
cout << "ERROR: take_w_condition returned " << ret << endl;
passed = false;
done = true;
}
InstanceHandle_t handle = HANDLE_NIL;
received_data(data, mdw, msg);
handle = info[info.length() - 1].instance_handle;
if (handle == HANDLE_NIL) {
cout << "ERROR: instance handle is nil" << endl;
passed = false;
done = true;
break;
}
cout << "testing take_instance_w_condition" << endl;
while (true) {
ret = mdr->take_instance_w_condition(data, info, 1,
handle, dr_rc);
if (ret == RETCODE_NO_DATA) break;
if (ret != RETCODE_OK) {
cout << "ERROR: take_instance_w_condition returned "
<< ret << endl;
passed = false;
done = true;
break;
}
received_data(data, mdw, msg);
}
} else if (active[i] == dr_rc2) {
cout << "an instance has been disposed, exiting" << endl;
done = true;
}
}
}
//.........这里部分代码省略.........
示例8: OSPL_MAIN
int OSPL_MAIN (int argc, char *argv[])
{
os_time delay_20ms = { 0, 20000000 };
os_time delay_200ms = { 0, 200000000 };
MsgSeq msgList;
SampleInfoSeq infoSeq;
// create domain participant
char partition_name[] = "Lifecycle example";
//------------------ Msg topic --------------------//
DDSEntityManager mgr;
// create domain participant
mgr.createParticipant(partition_name);
//create type
MsgTypeSupport_var mt = new MsgTypeSupport();
mgr.registerType(mt.in());
//create Topic
char topic_name[] = "Lifecycle_Msg";
mgr.createTopic(topic_name);
//create Subscriber
mgr.createSubscriber();
// create DataReader
mgr.createReader();
DataReader_var dreader = mgr.getReader();
MsgDataReader_var LifecycleReader = MsgDataReader::_narrow(dreader.in());
checkHandle(LifecycleReader.in(), "MsgDataReader::_narrow");
cout << "=== [Subscriber] Ready ..." << endl;
bool closed = false;
ReturnCode_t status;
int nbIter = 1;
int nbIterMax = 100;
while ((closed == false) && (nbIter < nbIterMax))
{
status = LifecycleReader->read(msgList, infoSeq, LENGTH_UNLIMITED,
ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
checkStatus(status, "msgDataReader::read");
for (DDS::ULong j = 0; j < msgList.length(); j++)
{
cout << endl << " Message : " << msgList[j].message.in() << endl;
cout << " writerStates : " << msgList[j].writerStates.in() << endl;
cout << " valid_data : " << (int)infoSeq[j].valid_data << endl;
cout << "sample_state:" << sSampleState[index(infoSeq[j].sample_state)] << "-view_state:" << sViewState[index(infoSeq[j].view_state)] << "-instance_state:" << sInstanceState[index(infoSeq[j].instance_state)] << endl;
os_nanoSleep(delay_200ms);
closed = (strcmp(msgList[j].writerStates.in(), "STOPPING_SUBSCRIBER") == 0);
}
status = LifecycleReader->return_loan(msgList, infoSeq);
checkStatus(status, "MsgDataReader::return_loan");
os_nanoSleep(delay_20ms);
nbIter++;
}
cout << "=== [Subscriber] stopping after "<< nbIter << " iterations - closed=" << closed << endl;
if (nbIter == nbIterMax) cout << "*** Error : max " << nbIterMax << "iterations reached" << endl;
//cleanup
// Lifecycle topic
mgr.deleteReader(LifecycleReader.in ());
mgr.deleteSubscriber();
mgr.deleteTopic();
mgr.deleteParticipant();
return 0;
}
示例9: OSPL_MAIN
int OSPL_MAIN (int argc, char *argv[])
{
// usage : ContentFilteredTopicDataSubscriber <subscription_string>
const char *ContentFilteredTopicDataToSubscribe;
os_time delay_200ms = { 0, 200000000 };
char buf[MAX_MSG_LEN];
if (argc > 1)
{
ContentFilteredTopicDataToSubscribe = argv[1];
}
else
{
cerr <<
"*** [ContentFilteredTopicDataSubscriber] Subscription string not specified" <<
endl;
cerr << "*** usage : ContentFilteredTopicDataSubscriber <subscription_string>" <<
endl;
return - 1;
}
StockSeq msgList;
SampleInfoSeq infoSeq;
DDSEntityManager mgr;
// create domain participant
char partition_name[] = "ContentFilteredTopic example";
mgr.createParticipant(partition_name);
//create type
StockTypeSupport_var st = new StockTypeSupport();
mgr.registerType(st.in());
//create Topic
char topic_name[] = "StockTrackerExclusive";
mgr.createTopic(topic_name);
//create Subscriber
mgr.createSubscriber();
char sTopicName[] = "MyStockTopic";
// create subscription filter
snprintf(buf, MAX_MSG_LEN, "ticker = '%s'", ContentFilteredTopicDataToSubscribe);
DDS::String_var sFilter = DDS::string_dup(buf);
// Filter expr
StringSeq sSeqExpr;
sSeqExpr.length(0);
// create topic
mgr.createContentFilteredTopic(sTopicName, sFilter.in(), sSeqExpr);
// create Filtered DataReader
cout << "=== [ContentFilteredTopicDataSubscriber] Subscription filter : " << sFilter
<< endl;
mgr.createReader(true);
DataReader_var dreader = mgr.getReader();
StockDataReader_var ContentFilteredTopicDataReader = StockDataReader::_narrow(dreader.in());
checkHandle(ContentFilteredTopicDataReader.in(), "StockDataReader::_narrow");
cout << "=== [ContentFilteredTopicDataSubscriber] Ready ..." << endl;
bool closed = false;
ReturnCode_t status = - 1;
int count = 0;
while (!closed && count < 1500) // We dont want the example to run indefinitely
{
status = ContentFilteredTopicDataReader->take(msgList, infoSeq, LENGTH_UNLIMITED,
ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
checkStatus(status, "ContentFilteredTopicDataDataReader::take");
for (DDS::ULong i = 0; i < msgList.length(); i++)
{
if(infoSeq[i].valid_data)
{
if (msgList[i].price == - 1.0f)
{
closed = true;
break;
}
}
cout << "=== [ContentFilteredTopicDataSubscriber] receives stockQuote : ("<< msgList[i].ticker << ", " << msgList[i].price << ')'<< endl;
}
status = ContentFilteredTopicDataReader->return_loan(msgList, infoSeq);
checkStatus(status, "StockDataReader::return_loan");
os_nanoSleep(delay_200ms);
++count;
}
cout << "=== [ContentFilteredTopicDataSubscriber] Market Closed" << endl;
//cleanup
mgr.deleteReader(ContentFilteredTopicDataReader.in ());
mgr.deleteSubscriber();
mgr.deleteFilteredTopic();
mgr.deleteTopic();
mgr.deleteParticipant();
return 0;
}
示例10: run_test
bool run_test(DomainParticipant_var& dp_sub,
DomainParticipant_var& dp_pub)
{
OpenDDS::DCPS::RepoId sub_repo_id, pub_repo_id;
{
OpenDDS::DCPS::DomainParticipantImpl* dp_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(dp_sub.in());
sub_repo_id = dp_impl->get_id ();
OpenDDS::DCPS::GuidConverter converter(sub_repo_id);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("%P ")
ACE_TEXT("Sub Domain Participant GUID=%C\n"),
std::string(converter).c_str()));
}
{
OpenDDS::DCPS::DomainParticipantImpl* dp_impl =
dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(dp_pub.in());
pub_repo_id = dp_impl->get_id ();
OpenDDS::DCPS::GuidConverter converter(pub_repo_id);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("%P ")
ACE_TEXT("Pub Domain Participant GUID=%C\n"),
std::string(converter).c_str()));
}
// If we are running with an rtps_udp transport, it can't be shared between
// participants.
TransportConfig_rch cfg = TheTransportRegistry->get_config("dp1");
if (!cfg.is_nil()) {
TheTransportRegistry->bind_config(cfg, dp_sub);
}
cfg = TheTransportRegistry->get_config("dp2");
if (!cfg.is_nil()) {
TheTransportRegistry->bind_config(cfg, dp_pub);
}
Subscriber_var bit_sub = dp_sub->get_builtin_subscriber();
if (!read_participant_bit(bit_sub, dp_sub, pub_repo_id, TestConfig::PARTICIPANT_USER_DATA())) {
return false;
}
// Each domain participant's handle to the other
InstanceHandle_t dp_sub_ih, dp_pub_ih;
InstanceHandle_t pub_ih, sub_ih, ig_ih;
if (!(check_discovered_participants(dp_sub, dp_pub_ih) &&
check_discovered_participants(dp_pub, dp_sub_ih)))
{
return false;
}
DataWriter_var dw = create_data_writer(dp_pub);
if (!dw) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not create Data Writer (participant 2)\n"));
return false;
}
if (!read_publication_bit(bit_sub, dp_sub, pub_repo_id, pub_ih, TestConfig::DATA_WRITER_USER_DATA(), TestConfig::TOPIC_DATA(), 1, 1)) {
return false;
}
DataReader_var dr = create_data_reader(dp_sub);
if (!dr) {
ACE_DEBUG((LM_ERROR, "ERROR: %P could not create Data Reader (participant 1)\n"));
return false;
}
if (!read_subscription_bit(dp_pub->get_builtin_subscriber(), dp_pub, sub_repo_id, sub_ih, TestConfig::DATA_READER_USER_DATA(), TestConfig::TOPIC_DATA())) {
return false;
}
// Wait for the reader to associate with the writer.
WriterSync::wait_match(dw);
// Remove the writer and its topic, then re-create them. The writer's
// participant should still have discovery info about the reader so that
// the association between the new writer and old reader can be established.
recreate_data_writer_and_topic(dw, dr);
// Wait for the reader to associate with the writer.
WriterSync::wait_match(dw);
// The new writer is associated with the reader, but the reader may still
// also be associated with the old writer.
wait_match(dr, 1);
// Get the new instance handle as pub_ih
if (!read_publication_bit(bit_sub, dp_sub, pub_repo_id, pub_ih, TestConfig::DATA_WRITER_USER_DATA(), TestConfig::TOPIC_DATA(), 1, 2)) {
return false;
}
TestMsgDataWriter_var tmdw = TestMsgDataWriter::_narrow(dw);
const TestMsg msg = {42};
tmdw->write(msg, HANDLE_NIL);
ReadCondition_var rc = dr->create_readcondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE,
ALIVE_INSTANCE_STATE);
//.........这里部分代码省略.........
示例11: 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 "
//.........这里部分代码省略.........
示例12: 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;
}
示例13: NodeBtHandler
int NodeBtHandler (int argc, char *argv[])
{
// DDS değişkenleri
DDSEntityManager mgrBtPub;
DDSEntityManager mgrReqSub;
ReturnCode_t status;
SampleInfoSeq_var infoSeq = new SampleInfoSeq();
BtSeq* btSeqInstance = new BtSeq();
ServerReqSeq serverReqSeq;
// Zaman ile alakalı değişkenler
long int messageIDCount = 0;
Time_t tsBeforeTheScan = { 0, 0 };
Time_t tsAfterTheScan = { 0, 0 };
//Time_t tsWifiPub = { 0, 0 };
struct timeval tsConverter;
DDS::Duration_t waitAckTime = { 0, 800000000 }; //800ms
int refreshRate = 60;
// Veri tutucular (data structures)
vector<string> btMacHolder;
vector<int> btRssiHolder;
string btFileContenHolder;
// Bluetooth tarama sonuçlarının yazdırıldığı dosyadan okuma yapacak
// olan değişken
boost::filesystem::ifstream fIn;
// Bluetooth tarama sıklığı ayarlayan değişken
int refreshRateCounter = -1;
char hostName[1024];
gethostname(hostName, 1024);
// !!! Bluetooth tarama mesajlarını Publish edecek Topic yaratılıyor
// ve o Topic'e ait konfigürasyon ayarları yapılıyor.
// Domain participant yaratılıyor
mgrBtPub.createParticipant ("KonSens_BtSeq_Participant");
// BtSeq tipi yaratılıyor
BtSeqTypeSupport_var btSeqTs = new BtSeqTypeSupport();
mgrBtPub.registerType(btSeqTs.in());
// Topic yaratılıyor
char btPubTopicName[] = "KonSensData_BtSeq_Topic";
mgrBtPub.createTopic(btPubTopicName);
// Publisher yaratılıyor
mgrBtPub.createPublisher();
// DataWriter yaratılıyor
bool autodispose_unregistered_instances = false;
mgrBtPub.createWriter(autodispose_unregistered_instances,
KEEP_ALL_HISTORY_QOS,
BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS);
// Yaratılan DataWriter, BtSeq tipi için özelleştiriliyor
DataWriter_var dWriter = mgrBtPub.getWriter ();
BtSeqDataWriter_var btSeqWriter = BtSeqDataWriter::_narrow(dWriter.in());
// Düğüm numarasını atanıyor
btSeqInstance->userID = 13;
// Publish edilecek olan mesajlara zaman etiketi takabilmek için
// btSeqInstance değişkeni register ediliyor
//userHandle = btSeqWriter->register_instance_w_timestamp(*btSeqInstance,
// tsWifiPub);
cout << "=== [Publisher of KonSensData_BtSeq_Topic] Ready ..." << endl;
// !!! Sunucudan gelen komutlara Subscribe olacak olan Topic yaratılıyor
// ve o Topic için gerekli konfigürasyon ayarları yapılıyor
// Domain participant yaratılıyor
mgrReqSub.createParticipant(
"KonSensData_ServerReq_Participant_Server_to_Node");
// ServerReq tipi yaratılıyor.
ServerReqTypeSupport_var mgrSubscriberTS = new ServerReqTypeSupport();
mgrReqSub.registerType(mgrSubscriberTS.in());
// Topic yaratılıyor
char reqSubTopicName[] = "KonSensData_ServerReq_Topic_Server_to_Node";
mgrReqSub.createTopic(reqSubTopicName, RELIABLE_RELIABILITY_QOS,
VOLATILE_DURABILITY_QOS);
// Subscriber yaratılıyor
mgrReqSub.createSubscriber();
// DataReader yaratılıyor
mgrReqSub.createReader(KEEP_LAST_HISTORY_QOS, 1);
// Yaratılan DataReader, ServerReq tipi için özelleştiriliyor.
DataReader_var dReaderSub = mgrReqSub.getReader();
ServerReqDataReader_var serverReqReader =
ServerReqDataReader::_narrow(dReaderSub.in());
checkHandle(serverReqReader.in(), "ServerReqDataReader::_narrow");
//.........这里部分代码省略.........
示例14: run_change_parameter_test
bool run_change_parameter_test(const DomainParticipant_var& dp,
const MessageTypeSupport_var& ts, const Publisher_var& pub,
const Subscriber_var& sub)
{
DataWriter_var dw;
DataReader_var dr;
test_setup(dp, ts, pub, sub, "MyTopic3", dw, dr);
MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
Message sample;
sample.key = 3;
ReturnCode_t ret = mdw->write(sample, HANDLE_NIL);
if (ret != RETCODE_OK) return false;
if (!waitForSample(dr)) return false;
DDS::StringSeq params(1);
params.length(1);
params[0] = "2";
ReadCondition_var dr_qc = dr->create_querycondition(ANY_SAMPLE_STATE,
ANY_VIEW_STATE, ALIVE_INSTANCE_STATE, "key = %0", params);
if (!dr_qc.in()) {
cout << "ERROR: failed to create QueryCondition" << endl;
return false;
}
QueryCondition_var query_cond = QueryCondition::_narrow(dr_qc);
CORBA::String_var expr = query_cond->get_query_expression();
if (std::string("key = %0") != expr.in()) {
cout << "ERROR: get_query_expression() query expression should match " << endl;
return false;
}
params = DDS::StringSeq();
ret = query_cond->get_query_parameters(params);
if (ret != RETCODE_OK) {
cout << "ERROR: get_query_parameters() failed " << endl;
return false;
} else if (params.length() != 1 || std::string(params[0]) != "2") {
cout << "ERROR: get_query_parameters() query parameters doesn't match " << endl;
return false;
}
WaitSet_var ws = new WaitSet;
ws->attach_condition(dr_qc);
ConditionSeq active;
Duration_t three_sec = {3, 0};
ret = ws->wait(active, three_sec);
// expect a timeout because the sample doesn't match the query string
if (ret != RETCODE_TIMEOUT) {
cout << "ERROR: wait(qc) should have timed out" << endl;
return false;
}
ws->detach_condition(dr_qc);
MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
MessageSeq data;
SampleInfoSeq infoseq;
ret = mdr->take_w_condition(data, infoseq, LENGTH_UNLIMITED, dr_qc);
if (ret != RETCODE_NO_DATA) {
cout << "ERROR: take_w_condition(qc) shouldn't have returned data" << endl;
return false;
}
params = DDS::StringSeq(1);
params.length(1);
params[0] = "3";
ret = query_cond->set_query_parameters(params);
params = DDS::StringSeq();
ret = query_cond->get_query_parameters(params);
if (ret != RETCODE_OK) {
cout << "ERROR: get_query_parameters() failed " << endl;
return false;
} else if (params.length() != 1 || std::string(params[0]) != "3") {
cout << "ERROR: get_query_parameters() query parameters doesn't match " << endl;
return false;
}
ws->attach_condition(dr_qc);
ret = ws->wait(active, three_sec);
if (ret != RETCODE_OK) {
cout << "ERROR: wait(qc) should not time out" << endl;
return false;
}
ws->detach_condition(dr_qc);
ret = mdr->take_w_condition(data, infoseq, LENGTH_UNLIMITED, dr_qc);
if (ret != RETCODE_OK) {
cout << "ERROR: take_w_condition(qc) should have returned data" << endl;
return false;
}
dr->delete_readcondition(dr_qc);
return true;
}
示例15: OSPL_MAIN
int OSPL_MAIN (int argc, char *argv[])
{
MsgSeq msgList;
SampleInfoSeq infoSeq;
Duration_t timeout = { 0, 200000000 };
int count = 0;
DDSEntityManager mgr;
// create domain participant
char partition_name[] = "Listener example";
mgr.createParticipant(partition_name);
//create type
MsgTypeSupport_var st = new MsgTypeSupport();
mgr.registerType(st.in());
//create Topic
char topic_name[] = "ListenerData_Msg";
mgr.createTopic(topic_name);
//create Subscriber
mgr.createSubscriber();
// create DataReader
mgr.createReader();
DataReader_var dreader = mgr.getReader();
ListenerDataListener *myListener = new ListenerDataListener();
myListener->m_MsgReader = MsgDataReader::_narrow(dreader.in());
checkHandle(myListener->m_MsgReader.in(), "MsgDataReader::_narrow");
cout << "=== [ListenerDataSubscriber] set_listener" << endl;
DDS::StatusMask mask =
DDS::DATA_AVAILABLE_STATUS | DDS::REQUESTED_DEADLINE_MISSED_STATUS;
myListener->m_MsgReader->set_listener(myListener, mask);
cout << "=== [ListenerDataSubscriber] Ready ..." << endl;
myListener->m_closed = false;
// waitset used to avoid spinning in the loop below
DDS::WaitSet_var ws = new DDS::WaitSet();
ws->attach_condition(myListener->m_guardCond);
DDS::ConditionSeq condSeq;
while (!myListener->m_closed && count < 1500 ){
// To avoid spinning here. We can either use a sleep or better a WaitSet.
ws->wait(condSeq, timeout);
myListener->m_guardCond->set_trigger_value(false);
++count;
}
cout << "===[ListenerDataSubscriber] Market Closed" << endl;
//cleanup
mgr.deleteReader(myListener->m_MsgReader.in ());
mgr.deleteSubscriber();
mgr.deleteTopic();
mgr.deleteParticipant();
delete myListener;
cout << "Completed Listener example." << endl;
return 0;
}