本文整理汇总了C++中dds::DataReader_var::in方法的典型用法代码示例。如果您正苦于以下问题:C++ DataReader_var::in方法的具体用法?C++ DataReader_var::in怎么用?C++ DataReader_var::in使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataReader_var
的用法示例。
在下文中一共展示了DataReader_var::in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
// Default DomainParticipantFactory qos is to auto enable.
::DDS::DomainParticipantFactoryQos fqos;
if (dpf->get_qos (fqos) != ::DDS::RETCODE_OK)
{
cerr << "DomainParticipantFactory get_qos failed." << endl;
return 1;
}
if (fqos.entity_factory.autoenable_created_entities == 0)
{
cerr << "The DomainParticipantFactory defaults to autoenable upon entities creation." << endl;
return 1;
}
// Now disable DomainParticipantFactory autoenable
fqos.entity_factory.autoenable_created_entities = 0;
if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK)
{
cerr << "DomainParticipantFactory set_qos failed." << endl;
return 1;
}
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 (participant->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
{
cerr << "DomainParticipant can not be enabled because factory autoenable is off." << endl;
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 << "Failed to create_topic." << endl;
exit(1);
}
if (topic->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
{
cerr << "Topic can not be enabled because DomainParticipant is not enabled." << endl;
return 1;
}
// Initialize the transport
OpenDDS::DCPS::TransportImpl_rch transport_impl =
TheTransportFactory->create_transport_impl (transport_impl_id,
::OpenDDS::DCPS::AUTO_CONFIG);
// 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);
}
if (sub->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
{
cerr << "Publisher can not be enabled because DomainParticipant is not enabled." << endl;
return 1;
}
// Attach the subscriber to the transport.
OpenDDS::DCPS::SubscriberImpl* sub_impl =
dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ());
if (0 == sub_impl) {
cerr << "Failed to obtain subscriber servant\n" << endl;
exit(1);
}
//.........这里部分代码省略.........
示例2: listener
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 ;
}
MessageTypeSupportImpl* mts_servant = new 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);
}
// 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());
// 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);
}
while ( ! listener_servant->received_all ()) {
ACE_OS::sleep (1);
}
if (! listener_servant->passed ()) {
cerr << "test failed - see errors." << endl;
return 1;
}
if (!CORBA::is_nil (participant.in ())) {
participant->delete_contained_entities();
}
if (!CORBA::is_nil (dpf.in ())) {
dpf->delete_participant(participant.in ());
}
::DDS::InstanceHandleSeq handles;
while (1)
{
ACE_OS::sleep(1);
dr->get_matched_publications(handles);
if (handles.length() == 0)
break;
}
//.........这里部分代码省略.........
示例3: 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,
//.........这里部分代码省略.........
示例4: MessageTypeSupportImpl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int status = EXIT_SUCCESS;
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
// handle test performance issue on one platform
#if defined (sun)
const char* udpTransName = "udp";
OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst(udpTransName);
if (inst != 0) {
OpenDDS::DCPS::UdpInst_rch udp_inst = OpenDDS::DCPS::dynamic_rchandle_cast<OpenDDS::DCPS::UdpInst>(inst);
if (udp_inst == 0) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: retrieving transport config for: %C failed!\n"),
udpTransName), -1);
}
udp_inst->rcv_buffer_size_ = 0x40000;
}
#endif
// Create DomainParticipant
DDS::DomainParticipant_var 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)
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* listener_svt = new DataReaderListenerImpl;
DDS::DataReaderListener_var listener(listener_svt);
DDS::DataReaderQos qos;
sub->get_default_datareader_qos(qos);
qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
qos.liveliness.lease_duration.sec = 10;
qos.liveliness.lease_duration.nanosec = 0;
qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
bool reliable = true;
parse_args(argc, argv, reliable);
if (reliable) {
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
}
DDS::DataReader_var reader =
sub->create_datareader(topic.in(),
qos,
listener.in(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
//.........这里部分代码省略.........
示例5: 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);
//.........这里部分代码省略.........
示例6: init
bool ExampleSubscriber::init()
{
this->msgs_count = 0;
domain = DDS::DOMAIN_ID_DEFAULT;
partition_name = "Default";
topic_name = "big_chatter";
/* Create Domain Participant Factory */
this->dpf = DDS::DomainParticipantFactory::get_instance();
checkHandle(dpf.in(), "DDS::DomainParticipantFactory::get_instance");
/* Create Domain Participant */
std::cout << "Creating domain participant in subscriber" << std::endl;
this->participant = dpf->create_participant(
domain,
PARTICIPANT_QOS_DEFAULT,
NULL,
DDS::STATUS_MASK_NONE
);
checkHandle(participant.in(), "DDS::DomainParticipantFactory::create_participant");
/* Create a default QoS for Topics */
status = participant->get_default_topic_qos(default_topic_qos);
checkStatus(status, "DDS::DomainParticipant::get_default_topic_qos");
// default_topic_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
default_topic_qos.reliability.kind = DDS::BEST_EFFORT_RELIABILITY_QOS;
/* Register the LargeMessage Type */
large_message_ts = new LargeMsg::LargeMessageTypeSupport();
checkHandle(large_message_ts.in(), "new LargeMessageTypeSupport");
this->large_message_type_name = large_message_ts->get_type_name();
status = large_message_ts->register_type(participant.in(), large_message_type_name);
checkStatus(status, "LargeMsg::LargeMessageTypeSupport::register_type");
/* Setup the Subscribers's QoS */
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] = partition_name;
/* Create the subscriber */
this->subscriber = participant->create_subscriber(
sub_qos,
NULL,
DDS::STATUS_MASK_NONE
);
checkHandle(subscriber.in(), "DDS::DomainParticipant::create_subscriber");
/* Create the Topic */
this->large_message_topic = participant->create_topic(
topic_name,
large_message_type_name,
default_topic_qos,
NULL,
DDS::STATUS_MASK_NONE
);
checkHandle(large_message_topic.in(), "DDS::DomainParticipant::create_topic(LargeMessage)");
/* Create Topic specific DataReader */
topic_reader = subscriber->create_datareader(
large_message_topic.in(),
DATAREADER_QOS_USE_TOPIC_QOS,
NULL,
DDS::STATUS_MASK_NONE
);
checkHandle(topic_reader.in(), "DDS::Subscriber::create_datareader");
/* Narrow topic_reader down to LargeMessage specific DataReader */
this->data_reader = LargeMsg::LargeMessageDataReader::_narrow(topic_reader.in());
checkHandle(data_reader.in(), "LargeMsg::LargeMessageDataReader::_narrow");
this->large_msg_seq = new LargeMsg::LargeMessageSeq();
this->sample_info_seq = new DDS::SampleInfoSeq();
std::cout << "Polling DataReader..." << std::endl;
return true;
}
示例7: main
int main (int argc, char *argv[])
{
const int domainId = 411;
const char *topicName = "Stock Quotes";
try {
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
// To Do: Create the participant
participant =
dpf->create_participant(domainId,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil());
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
// End: Create the participant
QuoterTypeSupportImpl* servant = new QuoterTypeSupportImpl();
PortableServer::ServantBase_var safe_servant = servant;
// To Do: Register the type
if (DDS::RETCODE_OK != servant->register_type(participant.in (),
"")) {
cerr << "Failed to register the QuoterTypeTypeSupport." << endl;
exit(1);
}
// End: Register the type
CORBA::String_var type_name = servant->get_type_name ();
// To Do: Get the (default) topic QoS and create the topic
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic(topicName,
type_name.in (),
topic_qos,
DDS::TopicListener::_nil());
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// End: Get the (default) topic QoS and create the topic
// To Do: Create the subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil());
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// End: Create the subscriber
// jhoffert
// There seem to be problems using auto configurations with an application
// distributed across different nodes. Take this out for now.
// Initialize the transport
TAO::DCPS::TransportImpl_rch tcp_impl =
TheTransportFactory->create_transport_impl (TCP_IMPL_ID,
//::TAO::DCPS::AUTO_CONFIG);
::TAO::DCPS::DONT_AUTO_CONFIG);
TAO::DCPS::TransportConfiguration_rch reader_config =
//TheTransportFactory->get_configuration (SUB_TRAFFIC);
TheTransportFactory->get_configuration (TCP_IMPL_ID);
TAO::DCPS::SimpleTcpConfiguration* reader_tcp_config =
static_cast <TAO::DCPS::SimpleTcpConfiguration*> (reader_config.in ());
if (0 != ACE_OS::strcmp ("default", reader_address_str)) {
ACE_INET_Addr reader_address (reader_address_str);
reader_tcp_config->local_address_ = reader_address;
}
if (0 != tcp_impl->configure (reader_config.in ())) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) ::main: ")
ACE_TEXT("Failed to configure the transport.\n")));
exit(1);
}
// jhoffert - End of transport configuration changes
// Attach the subscriber to the transport.
TAO::DCPS::SubscriberImpl* sub_impl =
::TAO::DCPS::reference_to_servant< TAO::DCPS::SubscriberImpl,
DDS::Subscriber_ptr> (sub.in ());
if (0 == sub_impl) {
cerr << "Failed to obtain subscriber servant\n" << endl;
exit(1);
}
TAO::DCPS::AttachStatus status = sub_impl->attach_transport(tcp_impl.in());
if (status != TAO::DCPS::ATTACH_OK) {
std::string status_str;
//.........这里部分代码省略.........
示例8: 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);
//.........这里部分代码省略.........
示例9: 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(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 ;
}
Messenger::MessageTypeSupport_var 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);
topic_qos.lifespan.duration.sec = 10;
topic_qos.lifespan.duration.nanosec = 0;
topic_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_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);
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::DataReader_var dr = sub->create_datareader(topic.in (),
DATAREADER_QOS_USE_TOPIC_QOS,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
ACE_OS::sleep (10);
if (listener_servant->num_reads () != 1)
{
cerr << "ERROR: Incorrect number of samples received." << endl
<< " Expired data was probably read." << endl;
exit (1);
}
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 ();
//.........这里部分代码省略.........
示例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 };
//.........这里部分代码省略.........
示例11: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("initialization starting.\n")
));
}
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( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("participant created.\n")
));
}
MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl;
Messenger::MessageTypeSupport_var mts = mts_servant;
if (DDS::RETCODE_OK != mts_servant->register_type(participant, "")) {
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name();
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("type support installed.\n")
));
}
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);
}
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("topic created.\n")
));
}
// 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);
}
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("subscriber created.\n")
));
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("listener created.\n")
));
//.........这里部分代码省略.........
示例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);
//.........这里部分代码省略.........
示例13: init
void MultiTopicDataReaderBase::init(const DDS::DataReaderQos& dr_qos,
DDS::DataReaderListener_ptr a_listener, DDS::StatusMask mask,
SubscriberImpl* parent, MultiTopicImpl* multitopic)
{
using namespace std;
DDS::DataReader_var dr = multitopic->get_type_support()->create_datareader();
resulting_reader_ = DataReaderEx::_narrow(dr);
DataReaderImpl* resulting_impl =
dynamic_cast<DataReaderImpl*>(resulting_reader_.in());
resulting_impl->raw_latency_buffer_size() = parent->raw_latency_buffer_size();
resulting_impl->raw_latency_buffer_type() = parent->raw_latency_buffer_type();
DDS::DomainParticipant_var participant = parent->get_participant();
resulting_impl->init(multitopic, dr_qos, a_listener, mask,
dynamic_cast<DomainParticipantImpl*>(participant.in()), parent,
resulting_reader_);
init_typed(resulting_reader_);
listener_ = new Listener(this);
std::map<string, string> fieldToTopic;
// key: name of field that's a key for the 'join'
// mapped: set of topicNames that have this key in common
std::map<string, set<string> > joinKeys;
const vector<string>& selection = multitopic->get_selection();
for (size_t i = 0; i < selection.size(); ++i) {
const DDS::Duration_t no_wait = {0, 0};
DDS::Topic_var t = participant->find_topic(selection[i].c_str(), no_wait);
if (!t.in()) {
throw runtime_error("Topic: " + selection[i] + " not found.");
}
DDS::DataReader_var incoming =
parent->create_datareader(t, dr_qos, listener_, ALL_STATUS_MASK);
if (!incoming.in()) {
throw runtime_error("Could not create incoming DataReader "
+ selection[i]);
}
QueryPlan& qp = query_plans_[selection[i]];
qp.data_reader_ = incoming;
const MetaStruct& meta = metaStructFor(incoming);
for (const char** names = meta.getFieldNames(); *names; ++names) {
if (fieldToTopic.count(*names)) { // already seen this field name
set<string>& topics = joinKeys[*names];
topics.insert(fieldToTopic[*names]);
topics.insert(selection[i]);
} else {
fieldToTopic[*names] = selection[i];
}
}
}
const vector<SubjectFieldSpec>& aggregation = multitopic->get_aggregation();
if (aggregation.size() == 0) { // "SELECT * FROM ..."
const MetaStruct& meta = getResultingMeta();
for (const char** names = meta.getFieldNames(); *names; ++names) {
std::map<string, string>::const_iterator found =
fieldToTopic.find(*names);
if (found == fieldToTopic.end()) {
if (DCPS_debug_level > 1) {
ACE_DEBUG((LM_WARNING,
ACE_TEXT("(%P|%t) WARNING: ")
ACE_TEXT("MultiTopicDataReaderBase::init(), in SELECT * ")
ACE_TEXT("resulting field %C has no corresponding ")
ACE_TEXT("incoming field.\n"), *names));
}
} else {
query_plans_[found->second].projection_.push_back(
SubjectFieldSpec(*names));
}
}
} else { // "SELECT A, B FROM ..."
for (size_t i = 0; i < aggregation.size(); ++i) {
std::map<string, string>::const_iterator found =
fieldToTopic.find(aggregation[i].incoming_name_);
if (found == fieldToTopic.end()) {
throw std::runtime_error("Projected field " +
aggregation[i].incoming_name_ + " has no incoming field.");
} else {
query_plans_[found->second].projection_.push_back(aggregation[i]);
}
}
}
typedef std::map<string, set<string> >::const_iterator iter_t;
for (iter_t iter = joinKeys.begin(); iter != joinKeys.end(); ++iter) {
const string& field = iter->first;
const set<string>& topics = iter->second;
for (set<string>::const_iterator iter2 = topics.begin();
iter2 != topics.end(); ++iter2) {
const string& topic = *iter2;
QueryPlan& qp = query_plans_[topic];
if (find_if(qp.projection_.begin(), qp.projection_.end(),
MatchesIncomingName(field)) == qp.projection_.end()) {
//.........这里部分代码省略.........
示例14: 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 ();
//.........这里部分代码省略.........
示例15: main
int main (int argc, char *argv[])
{
try {
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
if( parse_args(argc, argv) != 0)
return 1;
participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil());
if (CORBA::is_nil (participant.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) create_participant failed.\n")
, -1);
}
MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl();
PortableServer::ServantBase_var safe_servant = mts_servant;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
"")) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to register the MessageTypeTypeSupport.\n")
, -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());
if (CORBA::is_nil (topic.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to create_topic.\n")
, -1);
}
// Initialize the transport
TAO::DCPS::TransportImpl_rch tcp_impl =
TheTransportFactory->create_transport_impl (TCP_IMPL_ID, ::TAO::DCPS::AUTO_CONFIG);
// Indicate that the subscriber is about to become ready
FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, "w");
if (readers_ready == 0) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) ERROR Unable to create subscriber ready file.\n")
, -1);
}
ACE_OS::fclose(readers_ready);
// Check if the publisher is up and running
ACE_stat stats;
while (ACE_OS::stat (pub_ready_filename, &stats) == -1)
{
ACE_Time_Value small(0,250000);
ACE_OS::sleep (small);
}
for (int count = 1; count <= sub_reinit_itr; count++)
{
if (verbose) {
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Reinitializing subscriber.\n"));
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil());
if (CORBA::is_nil (sub.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to create_subscriber.\n")
, -1);
}
// Attach the subscriber to the transport.
TAO::DCPS::SubscriberImpl* sub_impl =
::TAO::DCPS::reference_to_servant
< TAO::DCPS::SubscriberImpl, DDS::Subscriber_ptr> (sub.in ());
if (0 == sub_impl) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to obtain subscriber servant.\n")
, -1);
}
TAO::DCPS::AttachStatus status = sub_impl->attach_transport(tcp_impl.in());
if (status != TAO::DCPS::ATTACH_OK)
{
std::string status_str;
switch (status)
{
case TAO::DCPS::ATTACH_BAD_TRANSPORT:
//.........这里部分代码省略.........