本文整理汇总了C++中dds::DataReaderListener_var::in方法的典型用法代码示例。如果您正苦于以下问题:C++ DataReaderListener_var::in方法的具体用法?C++ DataReaderListener_var::in怎么用?C++ DataReaderListener_var::in使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataReaderListener_var
的用法示例。
在下文中一共展示了DataReaderListener_var::in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
assert_subscription_matched(const Options& opts, const DDS::DataReaderListener_var& drl)
{
// Assert if pub/sub made a match ...
DataReaderListenerImpl* drl_servant =
dynamic_cast<DataReaderListenerImpl*> (drl.in());
// there is an error if we matched when not compatible (or vice-versa)
if (opts.compatible != drl_servant->subscription_matched() && opts.reliability_kind == DDS::RELIABLE_RELIABILITY_QOS)
{
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) Expected publication_matched to be %C, but it was %C [")
ACE_TEXT(" durability_kind=%C, liveliness_kind=%C, liveliness_duration=%C, ")
ACE_TEXT("reliability_kind=%C]\n"),
(opts.compatible) ? "true" : "false",
(drl_servant->subscription_matched()) ? "true" : "false",
opts.durability_kind_str.c_str(),
opts.liveliness_kind_str.c_str(),
opts.LEASE_DURATION_STR.c_str(),
opts.reliability_kind_str.c_str()),
false);
}
return true;
}
示例2: rd
DDS::DataReader_var
Factory::reader(const DDS::Subscriber_var& sub, const DDS::Topic_var& topic, const DDS::DataReaderListener_var& drl) const
{
// Create the data readers
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = opts_.durability_kind;
dr_qos.liveliness.kind = opts_.liveliness_kind;
dr_qos.liveliness.lease_duration = opts_.LEASE_DURATION;
dr_qos.reliability.kind = opts_.reliability_kind;
DDS::DomainParticipant_var dp = sub->get_participant();
CORBA::String_var tn = topic->get_name();
DDS::TopicDescription_var description = dp->lookup_topicdescription(tn);
TEST_ASSERT(!CORBA::is_nil(description.in()));
DDS::DataReader_var rd(sub->create_datareader(description.in(),
dr_qos,
drl.in(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK));
// Initialize the transport configuration for the appropriate entity
TEST_ASSERT(!opts_.configuration_str.empty());
if (opts_.configuration_str != "none" && opts_.entity_str == "rw")
{
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str,
rd.in());
if (!opts_.entity_autoenable)
{
TEST_ASSERT(DDS::RETCODE_OK == rd->enable());
}
}
return rd;
}
示例3: 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")
));
}
if (parse_args (argc, argv) == -1) {
return -1;
}
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("command line parsed.\n")
));
}
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 ();
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")
));
}
// Initialize the transport
OpenDDS::DCPS::TransportImpl_rch tcp_impl =
TheTransportFactory->create_transport_impl (transport_impl_id,
::OpenDDS::DCPS::AUTO_CONFIG);
if( OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) subscriber: ")
ACE_TEXT("transport 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);
}
//.........这里部分代码省略.........
示例4: 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(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);
}
// ----------------------------------------------
{
// Attempt to create a DataReader with intentionally
// incompatible QoS.
DDS::DataReaderQos bogus_qos;
sub->get_default_datareader_qos (bogus_qos);
// Set up a 2 second recurring deadline. DataReader creation
// should fail with this QoS since the requested deadline period
// will be less than the test configured offered deadline
// period.
bogus_qos.deadline.period.sec = 2;
bogus_qos.deadline.period.nanosec = 0;
DDS::DataReader_var tmp_dr =
sub->create_datareader (topic.in (),
bogus_qos,
DDS::DataReaderListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (tmp_dr.in ()))
{
cerr << "ERROR: DataReader creation with bogus QoS failed."
<< endl;
exit (1);
}
DDS::StatusCondition_var cond = tmp_dr->get_statuscondition();
cond->set_enabled_statuses(DDS::REQUESTED_INCOMPATIBLE_QOS_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(cond);
DDS::Duration_t four_sec = {4, 0};
DDS::ConditionSeq active;
ws->wait(active, four_sec);
// Check if the incompatible deadline was correctly flagged.
if ((active.length() == 0) || (active[0] != cond)) {
cerr << "ERROR: Failed to get requested incompatible qos status" << endl;
exit (1);
}
DDS::RequestedIncompatibleQosStatus incompatible_status;
if (tmp_dr->get_requested_incompatible_qos_status (incompatible_status) != ::DDS::RETCODE_OK)
{
cerr << "ERROR: Failed to get requested incompatible qos status" << endl;
//.........这里部分代码省略.........
示例5: 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());
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());
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Initialize the transport
OpenDDS::DCPS::TransportImpl_rch tcp_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());
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(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);
}
OpenDDS::DCPS::AttachStatus const status =
sub_impl->attach_transport(tcp_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;
exit(1);
}
// ----------------------------------------------
{
// Attempt to create a DataReader with intentionally
// incompatible QoS.
DDS::DataReaderQos bogus_qos;
sub->get_default_datareader_qos (bogus_qos);
// Set up a 1 second recurring deadline. DataReader creation
// should fail with this QoS since the requested deadline period
// will be less than the test configured offered deadline
//.........这里部分代码省略.........
示例6: 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 ;
}
Test::DataTypeSupportImpl * const dts_servant =
new Test::DataTypeSupportImpl;
if (DDS::RETCODE_OK != dts_servant->register_type(participant.in (),
""))
{
cerr << "Failed to register the DataTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = dts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Data",
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);
}
size_t const num_partitions =
sizeof (Test::Requested::PartitionConfigs)
/ sizeof (Test::Requested::PartitionConfigs[0]);
Test::PartitionConfig const * const begin =
Test::Requested::PartitionConfigs;
Test::PartitionConfig const * const end =
begin + num_partitions;
// Keep the readers around long enough for the publications and
// subscriptions to match.
std::vector<DDS::DataReader_var> readers (num_partitions);
for (Test::PartitionConfig const * i = begin; i != end; ++i)
{
DDS::SubscriberQos sub_qos;
participant->get_default_subscriber_qos (sub_qos);
// Specify partitions we're requesting.
CORBA::ULong n = 0;
DDS::StringSeq & names = sub_qos.partition.name;
for (char const * const * s = (*i).partitions;
s != 0 && *s != 0;
++s, ++n)
{
CORBA::ULong const new_len = names.length () + 1;
names.length (new_len);
names[n] = *s;
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber (sub_qos,
DDS::SubscriberListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ()))
{
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
DDS::DataReaderListener_var listener (
new Test::DataReaderListener ((*i).expected_matches));
// 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);
}
readers.push_back (dr);
//.........这里部分代码省略.........
示例7: 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 ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Messenger::MessageTypeSupportImpl* mts_servant = new Messenger::MessageTypeSupportImpl();
TAO::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());
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Initialize the transport
TAO::DCPS::TransportImpl_rch tcp_impl =
TheTransportFactory->create_transport_impl (TCP_IMPL_ID, ::TAO::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());
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// Attach the subscriber to the transport.
TAO::DCPS::SubscriberImpl* sub_impl =
TAO::DCPS::reference_to_servant<TAO::DCPS::SubscriberImpl> (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;
switch (status) {
case TAO::DCPS::ATTACH_BAD_TRANSPORT:
status_str = "ATTACH_BAD_TRANSPORT";
break;
case TAO::DCPS::ATTACH_ERROR:
status_str = "ATTACH_ERROR";
break;
case TAO::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;
exit(1);
}
// activate the listener
DataReaderListenerImpl listener_servant;
DDS::DataReaderListener_var listener =
::TAO::DCPS::servant_to_reference (&listener_servant);
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(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,
//.........这里部分代码省略.........
示例8: 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,
//.........这里部分代码省略.........
示例9: listener
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
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 ()))
{
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);
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);
}
// Create the Datareader
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = DDS::PERSISTENT_DURABILITY_QOS;
DDS::DataReader_var dr =
sub->create_datareader(topic, dr_qos, listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
int const expected = 10;
while (listener_servant->num_reads() < expected)
{
ACE_OS::sleep (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 ();
}
catch (CORBA::Exception& e)
{
cerr << "SUB: Exception caught in main ():" << endl << e << endl;
//.........这里部分代码省略.........
示例10: 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);
}
//.........这里部分代码省略.........
示例11: 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;
}
//.........这里部分代码省略.........
示例12: 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;
//.........这里部分代码省略.........
示例13: 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 ();
//.........这里部分代码省略.........
示例14: 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());
// 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);
// Since the publisher continue sending while the subscriber crashes,
// some messages may be lost, we lower the num_expected_reads by 2.
num_expected_reads -= num_reads_deviation;
FILE* writers_completed = 0;
//.........这里部分代码省略.........
示例15: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int result = 0;
ACE_DEBUG ((LM_DEBUG, "(%P|%t) subscriber main\n"));
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
if (parse_args (argc, argv) == -1) {
return -1;
}
DDS::DomainParticipantQos partQos;
dpf->get_default_participant_qos(partQos);
// set up user data in DP qos
CORBA::ULong part_user_data_len
= static_cast<CORBA::ULong>(ACE_OS::strlen (PART_USER_DATA));
partQos.user_data.value.length (part_user_data_len);
partQos.user_data.value.replace (part_user_data_len,
part_user_data_len,
reinterpret_cast<CORBA::Octet*>(PART_USER_DATA));
participant = dpf->create_participant(411,
partQos,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "subscriber: create_participant failed." << endl;
return 1 ;
}
::Messenger::MessageTypeSupport_var mts = new ::Messenger::MessageTypeSupportImpl();
if (DDS::RETCODE_OK != mts->register_type(participant.in (), "Messenger")) {
cerr << "subscriber: Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
// set up topic data in topic qos
CORBA::ULong topic_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (TOPIC_DATA));
topic_qos.topic_data.value.length (topic_data_len);
topic_qos.topic_data.value.replace (topic_data_len, topic_data_len, reinterpret_cast<CORBA::Octet*>(TOPIC_DATA));
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 << "subscriber: Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber
DDS::SubscriberQos sub_qos;
participant->get_default_subscriber_qos (sub_qos);
// set up group data in subscriber qos
CORBA::ULong group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (GROUP_DATA));
sub_qos.group_data.value.length (group_data_len);
sub_qos.group_data.value.replace (group_data_len, group_data_len, reinterpret_cast<CORBA::Octet*>(GROUP_DATA));
DDS::Subscriber_var sub =
participant->create_subscriber(sub_qos,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "subscriber: Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
DDS::Subscriber_var builtin = participant->get_builtin_subscriber();
DDS::DataReader_var bitdr =
builtin->lookup_datareader(OpenDDS::DCPS::BUILT_IN_PUBLICATION_TOPIC);
listener_servant->set_builtin_datareader(bitdr.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "subscriber: listener is nil." << endl;
exit(1);
}
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
//.........这里部分代码省略.........