本文整理汇总了C++中DomainParticipant_var::create_subscriber方法的典型用法代码示例。如果您正苦于以下问题:C++ DomainParticipant_var::create_subscriber方法的具体用法?C++ DomainParticipant_var::create_subscriber怎么用?C++ DomainParticipant_var::create_subscriber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomainParticipant_var
的用法示例。
在下文中一共展示了DomainParticipant_var::create_subscriber方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_test
int run_test(int argc, ACE_TCHAR *argv[])
{
DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv);
DomainParticipant_var dp =
dpf->create_participant(23, PARTICIPANT_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
MessageTypeSupport_var ts = new MessageTypeSupportImpl;
ts->register_type(dp, "");
Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
TransportImpl_rch pub_tport =
TheTransportFactory->create_transport_impl(1, AUTO_CONFIG);
PublisherImpl* pub_impl = dynamic_cast<PublisherImpl*>(pub.in());
pub_impl->attach_transport(pub_tport.in());
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
TransportImpl_rch sub_tport =
TheTransportFactory->create_transport_impl(2, AUTO_CONFIG);
SubscriberImpl* sub_impl = dynamic_cast<SubscriberImpl*>(sub.in());
sub_impl->attach_transport(sub_tport.in());
bool passed = run_sorting_test(dp, ts, pub, sub);
passed &= run_filtering_test(dp, ts, pub, sub);
dp->delete_contained_entities();
dpf->delete_participant(dp);
return passed ? 0 : 1;
}
示例2: create_data_reader
DataReader_var create_data_reader(const DomainParticipant_var& dp)
{
TypeSupport_var ts = new TestMsgTypeSupportImpl;
if (ts->register_type(dp, "") != RETCODE_OK) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to register type support\n"));
return 0;
}
TopicQos topic_qos;
dp->get_default_topic_qos(topic_qos);
set_qos(topic_qos.topic_data.value, TestConfig::TOPIC_DATA());
CORBA::String_var type_name = ts->get_type_name();
Topic_var topic = dp->create_topic("Movie Discussion List",
type_name,
topic_qos,
0,
DEFAULT_STATUS_MASK);
if (!topic) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to create topic\n"));
return 0;
}
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
0,
DEFAULT_STATUS_MASK);
if (!sub) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to create subscriber\n"));
return 0;
}
DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.reliability.kind = RELIABLE_RELIABILITY_QOS;
set_qos(dr_qos.user_data.value, TestConfig::DATA_READER_USER_DATA());
DataReader_var dr = sub->create_datareader(topic,
dr_qos,
0,
DEFAULT_STATUS_MASK);
if (!dr) {
ACE_DEBUG((LM_ERROR, "ERROR: %P failed to create data reader\n"));
return 0;
}
return dr;
}
示例3: run_test
int run_test(int argc, ACE_TCHAR *argv[])
{
using namespace DDS;
using namespace OpenDDS::DCPS;
WaitSet_var ws = new WaitSet;
DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv);
DomainParticipant_var dp = dpf->create_participant(23,
PARTICIPANT_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl;
ts->register_type(dp, ts->get_type_name());
Topic_var topic = dp->create_topic("MyTopic", ts->get_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);
TransportImpl_rch pub_tport =
TheTransportFactory->create_transport_impl(1, AUTO_CONFIG);
PublisherImpl* pub_impl = dynamic_cast<PublisherImpl*> (pub.in());
pub_impl->attach_transport(pub_tport.in());
DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
StatusCondition_var cond = dw->get_statuscondition();
cond->set_enabled_statuses(OFFERED_INCOMPATIBLE_QOS_STATUS);
ws->attach_condition(cond);
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
TransportImpl_rch sub_tport =
TheTransportFactory->create_transport_impl(2, AUTO_CONFIG);
SubscriberImpl* sub_impl = dynamic_cast<SubscriberImpl*> (sub.in());
sub_impl->attach_transport(sub_tport.in());
DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = PERSISTENT_DURABILITY_QOS;
Waiter w(ws);
w.activate();
DataReader_var dr = sub->create_datareader(topic, dr_qos, 0,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
w.wait();
bool passed = (w.result() == RETCODE_OK);
ws->detach_condition(cond);
dp->delete_contained_entities();
dpf->delete_participant(dp);
return passed ? 0 : 1;
}
示例4: run_test
int run_test(int argc, ACE_TCHAR *argv[])
{
DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv);
DomainParticipant_var dp =
dpf->create_participant(23, PARTICIPANT_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
MessageTypeSupport_var ts = new MessageTypeSupportImpl;
ts->register_type(dp, "");
Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
DEFAULT_STATUS_MASK);
bool passed = run_sorting_test(dp, ts, pub, sub);
passed &= run_filtering_test(dp, ts, pub, sub);
passed &= run_change_parameter_test(dp, ts, pub, sub);
dp->delete_contained_entities();
dpf->delete_participant(dp);
return passed ? 0 : 1;
}
示例5: checkHandle
//.........这里部分代码省略.........
status = participant->set_default_topic_qos(reliable_topic_qos);
checkStatus(status, "DDS::DomainParticipant::set_default_topic_qos");
/* Use the changed policy when defining the ChatMessage topic */
chatMessageTopic = participant->create_topic(
"Chat_ChatMessage",
chatMessageTypeName,
reliable_topic_qos,
NULL,
STATUS_MASK_NONE);
checkHandle(chatMessageTopic.in(), "DDS::DomainParticipant::create_topic (ChatMessage)");
/* Set the DurabilityQosPolicy to TRANSIENT. */
status = participant->get_default_topic_qos(setting_topic_qos);
checkStatus(status, "DDS::DomainParticipant::get_default_topic_qos");
setting_topic_qos.durability.kind = TRANSIENT_DURABILITY_QOS;
/* Create the NameService Topic. */
nameServiceTopic = participant->create_topic(
"Chat_NameService",
nameServiceTypeName,
setting_topic_qos,
NULL,
STATUS_MASK_NONE);
checkHandle(nameServiceTopic.in(), "DDS::DomainParticipant::create_topic");
/* Adapt the default SubscriberQos to read from the "ChatRoom" Partition. */
status = participant->get_default_subscriber_qos (sub_qos);
checkStatus(status, "DDS::DomainParticipant::get_default_subscriber_qos");
sub_qos.partition.name.length(1);
sub_qos.partition.name[0UL] = "ChatRoom";
/* Create a Subscriber for the UserLoad application. */
chatSubscriber = participant->create_subscriber(sub_qos, NULL, STATUS_MASK_NONE);
checkHandle(chatSubscriber.in(), "DDS::DomainParticipant::create_subscriber");
/* Create a DataReader for the NameService Topic (using the appropriate QoS). */
parentReader = chatSubscriber->create_datareader(
nameServiceTopic.in(),
DATAREADER_QOS_USE_TOPIC_QOS,
NULL,
STATUS_MASK_NONE);
checkHandle(parentReader, "DDS::Subscriber::create_datareader (NameService)");
/* Narrow the abstract parent into its typed representative. */
nameServer = NameServiceDataReader::_narrow(parentReader);
checkHandle(nameServer.in(), "Chat::NameServiceDataReader::_narrow");
/* Adapt the DataReaderQos for the ChatMessageDataReader to keep track of all messages. */
status = chatSubscriber->get_default_datareader_qos(message_qos);
checkStatus(status, "DDS::Subscriber::get_default_datareader_qos");
status = chatSubscriber->copy_from_topic_qos(message_qos, reliable_topic_qos);
checkStatus(status, "DDS::Subscriber::copy_from_topic_qos");
message_qos.history.kind = KEEP_ALL_HISTORY_QOS;
/* Create a DataReader for the ChatMessage Topic (using the appropriate QoS). */
parentReader = chatSubscriber->create_datareader(
chatMessageTopic.in(),
message_qos,
NULL,
STATUS_MASK_NONE);
checkHandle(parentReader, "DDS::Subscriber::create_datareader (ChatMessage)");
/* Narrow the abstract parent into its typed representative. */
loadAdmin = ChatMessageDataReader::_narrow(parentReader);
checkHandle(loadAdmin.in(), "Chat::ChatMessageDataReader::_narrow");
示例6: run_test
int run_test(int argc, ACE_TCHAR *argv[])
{
using namespace DDS;
using namespace OpenDDS::DCPS;
using namespace Messenger;
WaitSet_var ws = new WaitSet;
DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv);
DomainParticipant_var dp = dpf->create_participant(23,
PARTICIPANT_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
MessageTypeSupport_var ts = new MessageTypeSupportImpl;
// leave type name not speficied would register it with _interface_repository_id
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;
ws->wait(active, infinite);
ws->detach_condition(dw_sc);
ReturnCode_t ret = RETCODE_OK;
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_OK && ret != RETCODE_NO_DATA) {
cout << "ERROR: take_w_condition returned " << ret << endl;
passed = false;
done = true;
}
if (ret == RETCODE_OK) {
received_data(data, mdw, msg);
}
cout << "testing take_next_instance_w_condition" << endl;
InstanceHandle_t handle = HANDLE_NIL;
while (true) {
ret = mdr->take_next_instance_w_condition(data, info, 1,
handle, dr_rc);
if (ret == RETCODE_NO_DATA) break;
if (ret != RETCODE_OK) {
cout << "ERROR: take_next_instance_w_condition returned "
<< ret << endl;
passed = false;
done = true;
}
received_data(data, mdw, msg);
handle = info[info.length() - 1].instance_handle;
}
} else if (active[i] == dr_rc2) {
cout << "an instance has been disposed, exiting" << endl;
done = true;
}
}
}
ws->detach_condition(dr_rc);
dr->delete_readcondition(dr_rc);
ws->detach_condition(dr_rc2);
// Instead of: dr->delete_readcondition(dr_rc2);
//.........这里部分代码省略.........
示例7: ChatMessageSeq
int
OSPL_MAIN (
int argc,
char *argv[])
{
/* Generic DDS entities */
DomainParticipantFactory_var dpf;
DomainParticipant_var participant;
Topic_var chatMessageTopic;
Subscriber_var chatSubscriber;
DataReader_ptr parentReader;
/* Type-specific DDS entities */
ChatMessageTypeSupport_var chatMessageTS;
ChatMessageDataReader_var chatAdmin;
ChatMessageSeq_var msgSeq = new ChatMessageSeq();
SampleInfoSeq_var infoSeq = new SampleInfoSeq();
/* QosPolicy holders */
TopicQos reliable_topic_qos;
SubscriberQos sub_qos;
DDS::StringSeq parameterList;
/* DDS Identifiers */
DomainId_t domain = 0;
ReturnCode_t status;
/* Others */
bool terminated = false;
const char * partitionName = "ChatRoom1";
char * chatMessageTypeName = NULL;
/* Options: MessageBoard [ownID] */
/* Messages having owner ownID will be ignored */
parameterList.length(1);
if (argc > 1) {
parameterList[0] = 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");
participant = dpf->create_participant (
domain,
PARTICIPANT_QOS_DEFAULT,
NULL,
STATUS_MASK_NONE);
checkHandle(participant, "DDS::DomainParticipantFactory::create_participant");
/* 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, "NetworkPartitionsData::ChatMessageTypeSupport::register_type");
/* Set the ReliabilityQosPolicy to RELIABLE. */
status = participant->get_default_topic_qos(reliable_topic_qos);
checkStatus(status, "DDS::DomainParticipant::get_default_topic_qos");
reliable_topic_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
/* Make the tailored QoS the new default. */
status = participant->set_default_topic_qos(reliable_topic_qos);
checkStatus(status, "DDS::DomainParticipant::set_default_topic_qos");
/* Use the changed policy when defining the ChatMessage topic */
chatMessageTopic = participant->create_topic(
"Chat_ChatMessage",
chatMessageTypeName,
reliable_topic_qos,
NULL,
STATUS_MASK_NONE);
checkHandle(chatMessageTopic.in(), "DDS::DomainParticipant::create_topic (ChatMessage)");
/* Adapt the default SubscriberQos to read from the "ChatRoom1" Partition. */
status = participant->get_default_subscriber_qos (sub_qos);
checkStatus(status, "DDS::DomainParticipant::get_default_subscriber_qos");
sub_qos.partition.name.length(1);
sub_qos.partition.name[0] = partitionName;
/* Create a Subscriber for the MessageBoard application. */
chatSubscriber = participant->create_subscriber(sub_qos, NULL, STATUS_MASK_NONE);
checkHandle(chatSubscriber.in(), "DDS::DomainParticipant::create_subscriber");
/* Create a DataReader for the NamedMessage Topic (using the appropriate QoS). */
parentReader = chatSubscriber->create_datareader(
chatMessageTopic.in(),
DATAREADER_QOS_USE_TOPIC_QOS,
NULL,
STATUS_MASK_NONE);
checkHandle(parentReader, "DDS::Subscriber::create_datareader");
/* Narrow the abstract parent into its typed representative. */
//.........这里部分代码省略.........