本文整理汇总了C++中dds::Subscriber_var类的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber_var类的具体用法?C++ Subscriber_var怎么用?C++ Subscriber_var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subscriber_var类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil();
DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil();
try {
// Initialize, and create a DomainParticipant
// (same as publishe
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant = dpf->create_participant(
QUOTER_DOMAIN_ID,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
ACE_OS::exit(1);
}
// Create a subscriber for the two topics
// (SUBSCRIBER_QOS_DEFAULT is defined in Marked_Default_Qos.h)
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "create_subscriber failed." << endl;
ACE_OS::exit(1);
}
// Initialize the transport; the TRANSPORT_IMPL_ID must match the
// value in the configuration file.
OpenDDS::DCPS::TransportImpl_rch trans_impl =
TheTransportFactory->create_transport_impl (TRANSPORT_IMPL_ID,
OpenDDS::DCPS::AUTO_CONFIG);
// Attach the subscriber to the TCP transport.
// (almost identical to the publisher)
OpenDDS::DCPS::SubscriberImpl* sub_impl =
dynamic_cast< OpenDDS::DCPS::SubscriberImpl* >(sub.in ());
if (0 == sub_impl) {
cerr << "Failed to obtain subscriber servant" << endl;
ACE_OS::exit(1);
}
OpenDDS::DCPS::AttachStatus status = sub_impl->attach_transport(trans_impl.in());
if (status != OpenDDS::DCPS::ATTACH_OK) {
std::string status_str;
switch (status) {
case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT:
status_str = "ATTACH_BAD_TRANSPORT";
break;
case OpenDDS::DCPS::ATTACH_ERROR:
status_str = "ATTACH_ERROR";
break;
case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS:
status_str = "ATTACH_INCOMPATIBLE_QOS";
break;
default:
status_str = "Unknown Status";
break;
}
cerr << "Failed to attach to the transport. Status == "
<< status_str.c_str() << endl;
ACE_OS::exit(1);
}
// Register the Quote type
// (same as publisher)
StockQuoter::QuoteTypeSupport_var quote_servant
= new StockQuoter::QuoteTypeSupportImpl();
if (DDS::RETCODE_OK != quote_servant->register_type(participant.in (),
QUOTER_QUOTE_TYPE)) {
cerr << "register_type for " << QUOTER_QUOTE_TYPE << " failed." << endl;
ACE_OS::exit(1);
}
// Register the ExchangeEvent type
// (same as publisher)
StockQuoter::ExchangeEventTypeSupport_var exchange_evt_servant
= new StockQuoter::ExchangeEventTypeSupportImpl();
if (DDS::RETCODE_OK != exchange_evt_servant->register_type(participant.in (),
QUOTER_EXCHANGE_EVENT_TYPE)) {
cerr << "register_type for " << QUOTER_EXCHANGE_EVENT_TYPE
<< " failed." << endl;
ACE_OS::exit(1);
}
// Get QoS to use for our two topics
// (same as publisher)
DDS::TopicQos default_topic_qos;
participant->get_default_topic_qos(default_topic_qos);
// Create a topic for the Quote type...
// Could also use TOPIC_QOS_DEFAULT instead
// (same as publisher)
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例2: shifter
//.........这里部分代码省略.........
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_participant failed!\n")),
-1);
}
// Register TypeSupport
TestMsgTypeSupport_var ts =
new TestMsgTypeSupportImpl;
if (ts->register_type(participant, "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" register_type failed!\n")),
-1);
}
// Create Topic
CORBA::String_var type_name = ts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("TheTopic",
type_name,
TOPIC_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!topic) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_topic failed!\n")),
-1);
}
// Create Subscriber
DDS::Subscriber_var subscriber =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!subscriber) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_subscriber failed!\n")), -1);
}
const int n_msgs = reliable ? MSGS_PER_WRITER * total_writers : 0;
// Create DataReaders
for (std::vector<std::string>::iterator pos = readers.begin(), limit = readers.end();
pos != limit;
++pos) {
pos->resize(6);
DDS::DataReaderListener_var listener(new DataReaderListenerImpl(*pos, n_msgs, reader_done_callback));
DDS::DataReaderQos qos;
subscriber->get_default_datareader_qos(qos);
qos.user_data.value.length(3);
qos.user_data.value[0] = fromhex(*pos, 0);
qos.user_data.value[1] = fromhex(*pos, 1);
qos.user_data.value[2] = fromhex(*pos, 2);
qos.reliability.kind = reliable ? DDS::RELIABLE_RELIABILITY_QOS : DDS::BEST_EFFORT_RELIABILITY_QOS;
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
qos,
listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
开发者ID:tempbottle,项目名称:OpenDDS,代码行数:67,代码来源:StaticDiscoveryTest.cpp
示例3: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant = dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
if (parse_args (argc, argv) == -1) {
return -1;
}
MessageTypeSupport_var mts = new MessageTypeSupportImpl();
if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) {
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts->get_type_name ();
DDS::Topic_var topic = participant->create_topic("Movie Discussion List",
type_name.in (),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "ERROR Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "ERROR Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener = new DataReaderListenerImpl;
DataReaderListenerImpl &listener_servant =
*dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "ERROR listener is nil." << endl;
exit(1);
}
::DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
dr_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC ;
dr_qos.liveliness.lease_duration.nanosec = 0 ;
// Create the Datareaders
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "ERROR create_datareader failed." << endl;
exit(1);
}
int count = 0;
while ((++count < 60) && ((listener_servant.num_reads() < total_num_messages)))
{
ACE_OS::sleep (1);
}
ACE_OS::sleep(2);
ACE_DEBUG((LM_INFO,
"Subscriber got %d of %d messages, "
"and %d of %d callbacks, deleting entities\n",
(int) listener_servant.num_reads(), total_num_messages,
listener_servant.num_liveliness_change_callbacks(), num_liveliness_change_callbacks));
if (!CORBA::is_nil (participant.in ())) {
participant->delete_contained_entities();
}
if (!CORBA::is_nil (dpf.in ())) {
dpf->delete_participant(participant.in ());
}
ACE_OS::sleep(2);
TheServiceParticipant->shutdown ();
//.........这里部分代码省略.........
开发者ID:Fantasticer,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例4: ACE_TMAIN
//.........这里部分代码省略.........
::DDS::Topic_var topic1;
::DDS::TopicDescription_var description1;
if (mixed_trans)
{
topic1 = participant->create_topic (MY_TOPIC_FOR_UDP,
MY_TYPE_FOR_UDP,
topic_qos,
::DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic1.in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) create_topic failed.\n")));
throw TestException ();
}
description1
= participant->lookup_topicdescription(MY_TOPIC_FOR_UDP);
if (CORBA::is_nil (description1.in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to lookup_topicdescription.")));
throw TestException ();
}
}
int attach_to_udp = using_udp;
int attach_to_multicast = using_multicast;
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
create_subscriber(participant, attach_to_udp, attach_to_multicast,
using_rtps_transport, using_shmem);
if (CORBA::is_nil (sub.in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to create_subscriber.")));
throw TestException ();
}
::DDS::Subscriber_var sub1;
if (mixed_trans)
{
// Create the subscriber with a different transport from previous
// subscriber.
sub1 = create_subscriber(participant, !attach_to_udp,
attach_to_multicast, false /*rtps*/, false);
if (CORBA::is_nil (sub1.in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to create_subscriber.")));
throw TestException ();
}
}
// Create the Datareaders
::DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
// Make it KEEP_ALL history so we can verify the received
// data without dropping.
dr_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
dr_qos.reliability.kind =
开发者ID:examyes,项目名称:OpenDDS,代码行数:67,代码来源:subscriber.cpp
示例5: SubscriberListenerImpl
int
ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
parse_args(argc, argv);
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> SUBSCRIBER STARTED\n")));
::CORBA::Long sec = deadline_msec / 1000;
::CORBA::ULong remainder_msec = (deadline_msec - 1000*sec);
::CORBA::ULong nanosec = remainder_msec * 1000000;
DDS::Duration_t const DEADLINE_PERIOD =
{
sec,
nanosec
};
bool deadline_used = DEADLINE_PERIOD.sec > 0 || DEADLINE_PERIOD.nanosec > 0;
try
{
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
SubscriberListenerImpl * subscriberListener =
new SubscriberListenerImpl(received_samples, missed_samples);
DDS::SubscriberListener_var subscriberListener_var = subscriberListener;
// Create Participant
DDS::DomainParticipant_var participant =
dpf->create_participant(42,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_participant failed!\n")), 1);
ACE_Time_Value delay_between_cycles(0, delay_between_cycles_msec * 1000);
bool expected_samples_received = false;
int i = 0;
do
{
++i;
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> Subscriber cycle %d\n"), i));
// Create Subscriber
DDS::Subscriber_var subscriber =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
subscriberListener,
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(subscriber.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_subscriber failed!\n")), 2);
// Register Type (FooType)
FooTypeSupport_var ts = new FooTypeSupportImpl;
if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" register_type failed!\n")), 5);
// Create Topic (FooTopic)
DDS::Topic_var topic =
participant->create_topic("FooTopic",
ts->get_type_name(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DDS::TopicDescription_ptr topic_used = topic.in();
DDS::ContentFilteredTopic_ptr cft = 0;
if (use_cft)
{
// Topic name must be unique.
ACE_CString topic_name = "FooTopic-Filtered-" + toStr(i);
cft =
participant->create_contentfilteredtopic(topic_name.c_str(),
topic,
"key > 0",
DDS::StringSeq());
if (CORBA::is_nil(cft))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_contentfilteredtopic failed!\n")), 8);
topic_used = cft;
}
if (CORBA::is_nil(topic.in()))
ACE_ERROR_RETURN((LM_ERROR,
//.........这里部分代码省略.........
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:101,代码来源:Subscriber.cpp
示例6: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
int return_result = 0;
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant =
dpf->create_participant(11,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Messenger::MessageTypeSupportImpl* mts_servant =
new Messenger::MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
""))
{
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// Create the listener.
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ()))
{
cerr << "ERROR: listener is nil." << endl;
exit(1);
}
DDS::DataReaderQos dr_qos; // Good QoS.
sub->get_default_datareader_qos (dr_qos);
dr_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCES;
dr_qos.resource_limits.max_samples = MAX_SAMPLES;
dr_qos.resource_limits.max_instances = MAX_INSTANCES;
#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
dr_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
dr_qos.history.depth = MAX_SAMPLES_PER_INSTANCES;
#endif
DDS::DataReader_var dr1 =
sub->create_datareader (topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr1.in ()) )
{
cerr << "ERROR: create_datareader failed." << endl;
exit(1);
}
DDS::DataReader_var dr2 =
sub->create_datareader (topic.in (),
dr_qos,
DDS::DataReaderListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr2.in ()) )
{
cerr << "ERROR: create_datareader failed." << endl;
exit(1);
}
//.........这里部分代码省略.........
开发者ID:shaominghaoo,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例7: test
int
ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
try
{
TheParticipantFactoryWithArgs(argc, argv);
// Create Participant
DDS::DomainParticipant_var participant =
TheParticipantFactory->create_participant(42,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_participant failed!\n")), 1);
// Create Subscriber
DDS::Subscriber_var subscriber =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(subscriber.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_subscriber failed!\n")), 2);
// Create Publisher
DDS::Publisher_var publisher =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(publisher.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_publisher failed!\n")), 1);
OpenDDS::DCPS::TransportIdType transportId(0);
// Attach Subscriber Transport
++transportId;
OpenDDS::DCPS::TransportConfiguration_rch sub_config =
TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp"));
OpenDDS::DCPS::TransportImpl_rch sub_transport =
TheTransportFactory->create_transport_impl(transportId);
OpenDDS::DCPS::SubscriberImpl* subscriber_i =
dynamic_cast<OpenDDS::DCPS::SubscriberImpl*>(subscriber.in());
if (subscriber_i == 0)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1);
OpenDDS::DCPS::AttachStatus sub_status =
subscriber_i->attach_transport(sub_transport.in());
if (sub_status != OpenDDS::DCPS::ATTACH_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: attach_transport failed!\n")), 1);
// Attach Publisher Transport
++transportId;
OpenDDS::DCPS::TransportConfiguration_rch pub_config =
TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp"));
OpenDDS::DCPS::TransportImpl_rch pub_transport =
TheTransportFactory->create_transport_impl(transportId);
OpenDDS::DCPS::PublisherImpl* publisher_i =
dynamic_cast<OpenDDS::DCPS::PublisherImpl*>(publisher.in());
if (publisher_i == 0)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1);
OpenDDS::DCPS::AttachStatus pub_status =
publisher_i->attach_transport(pub_transport.in());
if (pub_status != OpenDDS::DCPS::ATTACH_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: attach_transport failed!\n")), 1);
// Register Type (FooType)
FooTypeSupport_var ts = new FooTypeSupportImpl;
if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: register_type failed!\n")), 1);
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:OpenDDS,代码行数:101,代码来源:main.cpp
示例8: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
if( parse_args(argc, argv) != 0)
return 1;
ACE_DEBUG((LM_DEBUG, "(%P|%t) subscriber.cpp main()\n"));
participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Messenger::MessageTypeSupportImpl* mts_servant = new Messenger::MessageTypeSupportImpl();
OpenDDS::DCPS::LocalObject_var safe_servant = mts_servant;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
"")) {
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (!listener_servant) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: listener_servant is nil (dynamic_cast failed)!\n")), -1);
}
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
// Indicate that the subscriber is ready
FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, ACE_TEXT ("w"));
if (readers_ready == 0) {
cerr << "ERROR Unable to create subscriber ready file." << endl;
exit(1);
}
ACE_OS::fclose(readers_ready);
// Wait for the publisher to be ready
FILE* writers_ready = 0;
do {
ACE_Time_Value small_time(0,250000);
ACE_OS::sleep (small_time);
writers_ready = ACE_OS::fopen (pub_ready_filename, ACE_TEXT ("r"));
} while (0 == writers_ready);
ACE_OS::fclose(writers_ready);
//.........这里部分代码省略.........
开发者ID:stonejiang208,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例9: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
long expected_late = 0;
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant = dpf->create_participant(111,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("l:"));
int c;
while ((c = get_opts ()) != -1)
{
switch(c)
{
case 'l':
expected_late = ACE_OS::atoi (get_opts.opt_arg ());
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-l expected late samples "
"\n",
argv [0]),
-1);
}
}
Messenger::MessageTypeSupportImpl::_var_type mts_servant =
new Messenger::MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type (participant.in (),
""))
{
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic ("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ()))
{
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ()))
{
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* const listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
if (!listener_servant) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: listener_servant is nil (dynamic_cast failed)!\n")), -1);
}
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
dr_qos.latency_budget.duration.sec = 1;
dr_qos.latency_budget.duration.nanosec = 0;
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
dr_qos,
//.........这里部分代码省略.........
开发者ID:oschwaldp-oci,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例10: MessageTypeSupportImpl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int status = 0;
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
int error;
if ((error = parse_args(argc, argv)) != 0) {
return error;
}
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(4,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl();
if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
}
// Create Topic (Movie Discussion List)
CORBA::String_var type_name = ts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(topic.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_topic() failed!\n")), -1);
}
// Create Subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(sub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
}
// Create DataReader
DataReaderListenerImpl* const listener_servant = new DataReaderListenerImpl;
DDS::DataReaderListener_var listener(listener_servant);
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
if (DataReaderListenerImpl::is_reliable()) {
std::cout << "Reliable DataReader" << std::endl;
dr_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
}
DDS::DataReader_var reader =
sub->create_datareader(topic.in(),
dr_qos,
listener.in(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
}
// Block until Publisher completes
DDS::StatusCondition_var condition = reader->get_statuscondition();
condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
DDS::Duration_t timeout =
{ DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };
DDS::ConditionSeq conditions;
DDS::SubscriptionMatchedStatus matches = { 0, 0, 0, 0, 0 };
//.........这里部分代码省略.........
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:101,代码来源:subscriber.cpp
示例11: BadParticipantException
Subscriber::Subscriber( const Options& options)
: options_( options),
waiter_( new DDS::WaitSet)
{
// Create the DomainParticipant
this->participant_
= TheParticipantFactory->create_participant(
this->options_.domain(),
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK
);
if( CORBA::is_nil( this->participant_.in())) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
ACE_TEXT("failed to create a participant.\n")
));
throw BadParticipantException();
} else if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created participant in domain %d.\n"),
this->options_.domain()
));
}
// Create and register the type support.
DataTypeSupportImpl* testData = new DataTypeSupportImpl();
if( ::DDS::RETCODE_OK
!= testData->register_type( this->participant_.in(), 0)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
ACE_TEXT("unable to install type %C support.\n"),
testData->get_type_name()
));
throw BadTypeSupportException ();
} else if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created type %C support.\n"),
testData->get_type_name()
));
}
// Create the topic.
DDS::Topic_var topic = this->participant_->create_topic(
this->options_.topicName().c_str(),
testData->get_type_name(),
TOPIC_QOS_DEFAULT,
::DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK
);
if( CORBA::is_nil( topic.in())) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
ACE_TEXT("failed to create topic %C.\n"),
this->options_.topicName().c_str()
));
throw BadTopicException();
} else if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created topic %C.\n"),
this->options_.topicName().c_str()
));
}
// Create the subscriber.
DDS::Subscriber_var subscriber
= this->participant_->create_subscriber(
SUBSCRIBER_QOS_DEFAULT,
::DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK
);
if( CORBA::is_nil( subscriber.in())) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
ACE_TEXT("failed to create subscriber.\n")
));
throw BadSubscriberException();
} else if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created subscriber.\n")
));
}
// Create the transport.
OpenDDS::DCPS::TransportImpl_rch transport
= TheTransportFactory->create_transport_impl(
this->options_.transportKey(),
OpenDDS::DCPS::AUTO_CONFIG
);
if( transport.is_nil()) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:OpenDDS,代码行数:101,代码来源:Subscriber.cpp
示例12: DataReaderListenerImpl
int
ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
parse_args(argc, argv);
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> SUBSCRIBER STARTED\n")));
try
{
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
// Create Participant
DDS::DomainParticipant_var participant =
dpf->create_participant(42,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_participant failed!\n")), 1);
// Create Subscriber
DDS::Subscriber_var subscriber =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(subscriber.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_subscriber failed!\n")), 2);
// Attach Transport
OpenDDS::DCPS::TransportImpl_rch transport =
TheTransportFactory->create_transport_impl(
OpenDDS::DCPS::DEFAULT_SIMPLE_TCP_ID,
"SimpleTcp");
OpenDDS::DCPS::SubscriberImpl* subscriber_i =
dynamic_cast<OpenDDS::DCPS::SubscriberImpl*>(subscriber.in());
if (subscriber_i == 0)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" dynamic_cast failed!\n")), 3);
OpenDDS::DCPS::AttachStatus status =
subscriber_i->attach_transport(transport.in());
if (status != OpenDDS::DCPS::ATTACH_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" attach_transport failed!\n")), 4);
// Register Type (FooType)
FooTypeSupport_var ts = new FooTypeSupportImpl;
if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" register_type failed!\n")), 5);
// Create Topic (FooTopic)
DDS::Topic_var topic =
participant->create_topic("FooTopic",
ts->get_type_name(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(topic.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_topic failed!\n")), 6);
// Create DataReader
ProgressIndicator progress =
ProgressIndicator("(%P|%t) SUBSCRIBER %d%% (%d samples received)\n",
expected_samples);
DDS::DataReaderListener_var listener =
new DataReaderListenerImpl(received_samples, progress);
DDS::DataReaderQos reader_qos;
subscriber->get_default_datareader_qos(reader_qos);
reader_qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
DDS::DataReader_var reader =
subscriber->create_datareader(topic.in(),
reader_qos,
listener.in(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(reader.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_datareader failed!\n")), 7);
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:OpenDDS,代码行数:101,代码来源:Subscriber.cpp
示例13: MessageTypeSupportImpl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
DDS::DomainParticipant_var participant;
bool result1, result2;
int error;
if ((error = parse_args(argc, argv)) != 0) {
ACE_DEBUG((LM_ERROR, "(%P|%t) Parsing error, returning %d\n", error));
return error;
}
{ // Scope of entities
// Create DomainParticipant
participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl();
if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
}
// Create Topic (Movie Discussion List)
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
ts->get_type_name(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(topic.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_topic() failed!\n")), -1);
}
// Create Subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(sub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
|
请发表评论