本文整理汇总了C++中dds::DomainParticipantFactory_var::create_participant方法的典型用法代码示例。如果您正苦于以下问题:C++ DomainParticipantFactory_var::create_participant方法的具体用法?C++ DomainParticipantFactory_var::create_participant怎么用?C++ DomainParticipantFactory_var::create_participant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DomainParticipantFactory_var
的用法示例。
在下文中一共展示了DomainParticipantFactory_var::create_participant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
DDS::DomainParticipant_var
Factory::participant(const DDS::DomainParticipantFactory_var& dpf) const
{
DDS::DomainParticipant_var dp =
dpf->create_participant(MY_DOMAIN,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
TEST_CHECK(!CORBA::is_nil(dp.in()));
// If there is a ini file-based configuration name initialize
// the transport configuration for the corresponding Entity
if (opts_.configuration_str != "none" && opts_.entity_str == "participant")
{
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str, dp.in());
}
// Register TypeSupport (Messenger::Message)
CORBA::String_var tn = typsup_->get_type_name();
TEST_CHECK(DDS::RETCODE_OK == typsup_->register_type(dp.in(), tn)); // Use the default name for the type
return dp;
}
示例2: catch
DDS::DomainParticipant*
OpenDDS::Model::Delegate::createParticipant(
unsigned long domain,
const DDS::DomainParticipantQos& participantQos,
DDS::StatusMask mask,
const OPENDDS_STRING& transportConfig
)
{
DDS::DomainParticipantFactory_var pfact = TheParticipantFactory;
DDS::DomainParticipant_var participant
= pfact->create_participant(
domain,
participantQos,
DDS::DomainParticipantListener::_nil(),
mask
);
// If the modeler specified a transport config, bind to it
if (!transportConfig.empty()) {
try {
TheTransportRegistry->bind_config(transportConfig, participant);
} catch (OpenDDS::DCPS::Transport::Exception&) {
pfact->delete_participant(participant);
return 0;
}
}
return participant;
}
示例3: Manager_Exception
OpenDDS_Domain_Manager::OpenDDS_Domain_Manager (int & argc,
ACE_TCHAR* argv[],
DDS::DomainId_t domain_id,
const DDS::DomainParticipantQos & qos)
: dp_ (DDS::DomainParticipant::_nil ()),
shutdown_lock_ (0),
exit_handler_ (shutdown_lock_)
{
// get the domain participant factory from the singleton
DDS::DomainParticipantFactory_var dpf =
OpenDDS::DCPS::Service_Participant::instance ()->
get_domain_participant_factory (argc, argv);
this->parse_args (argc, argv);
// create the participant named 'participant'.
dp_ = dpf->create_participant (domain_id,
qos,
DDS::DomainParticipantListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
// check for successful creation
if (CORBA::is_nil (dp_.in ()))
throw Manager_Exception ("Failed to create domain participant.");
// add a the handler for the SIGINT signal here
ACE_Sig_Handler sig_handler;
sig_handler.register_handler (SIGINT, &exit_handler_);
}
示例4: string
DDS::DomainParticipant_var
createParticipant(DDS::DomainParticipantFactory_var dpf)
{
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(42, // made-up domain ID
PARTICIPANT_QOS_DEFAULT,
0, // no listener
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
// Check for failure
if (!participant) {
throw std::string("failed to create domain participant");
}
return participant;
}
示例5:
DDS::DomainParticipant_var
TestBase::create_participant()
{
DDS::DomainId_t domain = DEFAULT_DOMAIN;
DDS::DomainParticipantQos qos;
DDS::DomainParticipantFactory_var dpf = TheParticipantFactory;
if (dpf->get_default_participant_qos(qos) != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: create_participant() -")
ACE_TEXT(" get_default_participant_qos failed!\n")));
ACE_OS::exit(-1);
}
DDS::DomainParticipantListener_ptr listener =
DDS::DomainParticipantListener::_nil();
DDS::StatusMask status = OpenDDS::DCPS::DEFAULT_STATUS_MASK;
if (init_participant(domain, qos, listener, status) != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: create_participant() -")
ACE_TEXT(" init_participant failed!\n")));
ACE_OS::exit(-1);
}
DDS::DomainParticipant_var participant =
dpf->create_participant(domain, qos, listener, status);
if (CORBA::is_nil(participant.in())) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: create_participant() -")
ACE_TEXT(" create_participant failed!\n")));
ACE_OS::exit(-1);
}
return participant;
}
示例6: listener
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(42,
PARTICIPANT_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!participant) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_participant failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl;
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 (Movie Discussion List)
CORBA::String_var type_name = ts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
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);
}
// Create DataReader
DDS::DataReaderListener_var listener(new DataReaderListenerImpl);
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
DATAREADER_QOS_DEFAULT,
listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!reader) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_datareader failed!\n")), -1);
}
Messenger::MessageDataReader_var reader_i =
Messenger::MessageDataReader::_narrow(reader);
if (!reader_i) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow 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);
while (true) {
DDS::SubscriptionMatchedStatus matches;
if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" get_subscription_matched_status failed!\n")), -1);
}
if (matches.current_count == 0 && matches.total_count > 0) {
break;
//.........这里部分代码省略.........
示例7: options
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
bool ok = true;
bool generated_config = false;
try {
//Look to see if the config file (.ini) was generated
//for rtps participant processing
for(int i = 0; i < argc; ++i) {
if(ACE_OS::strstr(argv[i], ACE_TEXT("generated"))) {
generated_config = true;
}
}
// 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
const Options options(argc, argv);
// Create DomainParticipant
typedef std::vector<DDS::DomainParticipant_var> Participants;
Participants participants(options.num_sub_participants);
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl();
CORBA::String_var type_name = ts->get_type_name();
typedef std::vector<DataReaderListenerImpl*> ListenerServants;
ListenerServants listener_servants;
std::vector<DDS::DataReaderListener_var> listeners;
std::stringstream ss;
ss << std::setw(5) << ACE_OS::getpid();
const std::string pid = ss.str();
ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Created dpf\n")));
unsigned int part_index = 0;
for (Participants::iterator part = participants.begin();
part != participants.end();
++part, ++part_index) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Creating participant\n")));
*part =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(part->in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
}
if (generated_config) {
std::stringstream domain_config_stream;
std::string config_name = "domain_part_";
domain_config_stream << config_name << part_index;
std::string config;
config = domain_config_stream.str();
TheTransportRegistry->bind_config(config, *part);
}
if (ts->register_type(part->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 =
(*part)->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 =
(*part)->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
//.........这里部分代码省略.........
示例8: ACE_TMAIN
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;
}
MessageTypeSupportImpl* servant = new MessageTypeSupportImpl;
if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
cerr << "register_type failed." << endl;
exit(1);
}
CORBA::String_var type_name = 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 << "create_topic failed." << endl;
exit(1);
}
DDS::Publisher_var pub =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (pub.in ())) {
cerr << "create_publisher failed." << endl;
exit(1);
}
// Create the datawriter
DDS::DataWriterQos dw_qos;
pub->get_default_datawriter_qos (dw_qos);
DDS::DataWriter_var dw =
pub->create_datawriter(topic.in (),
dw_qos,
DDS::DataWriterListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dw.in ())) {
cerr << "create_datawriter failed." << endl;
exit(1);
}
Writer* writer = new Writer(dw.in());
writer->start ();
while ( !writer->is_finished()) {
ACE_Time_Value small_time(0,250000);
ACE_OS::sleep (small_time);
}
// Cleanup
writer->end();
delete writer;
participant->delete_contained_entities();
dpf->delete_participant(participant);
TheServiceParticipant->shutdown();
} catch (CORBA::Exception& e) {
cerr << "Exception caught in main.cpp:" << endl
<< e << endl;
exit(1);
}
return 0;
}
示例9: ACE_TMAIN
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;
}
if (parse_args (argc, argv) == -1) {
return -1;
}
{
// At this point we are connected to the Info Repo.
// Trigger the driver
std::ofstream ior_stream (driver_trigger.c_str());
if (!ior_stream) {
std::cerr << "Unable to open internal trigger file: "
<< driver_trigger << std::endl;
return -1;
}
ior_stream << "junk";
}
int max_wait_time = 30; //seconds
int count = 0;
while (true)
{
if (count > max_wait_time) {
std::cerr << "Timed out waiting for external file: "
<< publisher_trigger << std::endl;
return -1;
}
// check for file
ACE_stat my_stat;
if (ACE_OS::stat (publisher_trigger.c_str(), &my_stat) == 0) {
// found the trigger file.
break;
}
ACE_OS::sleep (1);
}
MessageTypeSupportImpl* servant = new MessageTypeSupportImpl();
OpenDDS::DCPS::LocalObject_var safe_servant = servant;
if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
cerr << "register_type failed." << endl;
exit(1);
}
CORBA::String_var type_name = 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 << "create_topic failed." << endl;
exit(1);
}
DDS::Publisher_var pub =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (pub.in ())) {
cerr << "create_publisher failed." << endl;
exit(1);
}
// Create the datawriter
DDS::DataWriterQos dw_qos;
pub->get_default_datawriter_qos (dw_qos);
DDS::DataWriter_var dw =
pub->create_datawriter(topic.in (),
dw_qos,
DDS::DataWriterListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dw.in ())) {
cerr << "create_datawriter failed." << endl;
exit(1);
}
Writer* writer = new Writer(dw.in());
writer->start ();
while ( !writer->is_finished()) {
ACE_Time_Value small_time(0,250000);
//.........这里部分代码省略.........
示例10: 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);
//.........这里部分代码省略.........
示例11: sp_drl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(OpenDDS::DCPS::MONITOR_DOMAIN_ID,
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 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);
}
// Initialize Transport
OpenDDS::DCPS::TransportImpl_rch transport_impl =
TheTransportFactory->create_transport_impl(transport_impl_id,
OpenDDS::DCPS::AUTO_CONFIG);
OpenDDS::DCPS::AttachStatus status = transport_impl->attach(sub.in());
if (status != OpenDDS::DCPS::ATTACH_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: attach() failed!\n")), -1);
}
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;
DDS::DataReader_var reader;
// Register for OpenDDS::DCPS::ServiceParticipantReport
OpenDDS::DCPS::ServiceParticipantReportTypeSupport_var sp_ts =
new OpenDDS::DCPS::ServiceParticipantReportTypeSupportImpl();
if (sp_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);
}
CORBA::String_var sp_type_name = sp_ts->get_type_name();
DDS::DataReaderListener_var sp_drl(new SPMDataReaderListenerImpl);
reader = create_data_reader(participant.in(),
sub.in(),
sp_type_name.in(),
OpenDDS::DCPS::SERVICE_PARTICIPANT_MONITOR_TOPIC,
dr_qos,
sp_drl);
if (CORBA::is_nil(reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
}
// Register for OpenDDS::DCPS::DomainParticipantReport
OpenDDS::DCPS::DomainParticipantReportTypeSupport_var dp_ts =
new OpenDDS::DCPS::DomainParticipantReportTypeSupportImpl();
if (dp_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);
}
CORBA::String_var dp_type_name = dp_ts->get_type_name();
DDS::DataReaderListener_var dp_drl(new DPMDataReaderListenerImpl);
reader = create_data_reader(participant.in(),
sub.in(),
dp_type_name.in(),
OpenDDS::DCPS::DOMAIN_PARTICIPANT_MONITOR_TOPIC,
dr_qos,
dp_drl);
if (CORBA::is_nil(reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
}
// Register for OpenDDS::DCPS::TopicReport
OpenDDS::DCPS::TopicReportTypeSupport_var topic_ts =
new OpenDDS::DCPS::TopicReportTypeSupportImpl();
if (topic_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
//.........这里部分代码省略.........
示例12: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int status = 0;
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
bool reliable = true;
int num_msgs = 10;
int my_pid = ACE_OS::getpid();
parse_args(argc, argv, reliable, num_msgs, my_pid);
// 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 TypeSupport (Messenger::Message)
Messenger::MessageTypeSupport_var mts =
new Messenger::MessageTypeSupportImpl();
if (mts->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
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())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_topic failed!\n")),
-1);
}
// Create Publisher
DDS::Publisher_var pub =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(pub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_publisher failed!\n")),
-1);
}
DDS::DataWriterQos qos;
pub->get_default_datawriter_qos(qos);
qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
qos.liveliness.lease_duration.sec = 5;
qos.liveliness.lease_duration.nanosec = 0;
qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;
// Create DataWriter
DDS::DataWriter_var dw =
pub->create_datawriter(topic.in(),
qos,
DDS::DataWriterListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(dw.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_datawriter failed!\n")),
-1);
}
DDS::DataWriter_var dw2 =
pub->create_datawriter(topic.in(),
qos,
DDS::DataWriterListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(dw2.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
//.........这里部分代码省略.........
示例13: init_dcps_objects
void init_dcps_objects (int i)
{
participant[i] =
dpf->create_participant(domain_id,
PARTICIPANT_QOS_DEFAULT,
::DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant[i].in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) create_participant failed.\n")));
throw TestException ();
}
::Xyz::FooTypeSupportImpl* fts_servant
= new ::Xyz::FooTypeSupportImpl();
::Xyz::FooTypeSupportImpl* another_fts_servant
= new ::Xyz::FooTypeSupportImpl();
if (::DDS::RETCODE_OK != fts_servant->register_type(participant[i].in (), type_name))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to register the FooNoTypeTypeSupport.")));
throw TestException ();
}
// Test if different TypeSupport instances of the same TypeSupport type can register
// with the same type name within the same domain participant.
if (::DDS::RETCODE_OK != another_fts_servant->register_type(participant[i].in (), type_name))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to register the FooNoTypeTypeSupport.")));
throw TestException ();
}
::DDS::TopicQos topic_qos;
participant[i]->get_default_topic_qos(topic_qos);
topic[i]
= participant[i]->create_topic(topic_name[i],
type_name,
topic_qos,
::DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic[i].in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to create_topic.")));
throw TestException ();
}
subscriber[i] = participant[i]->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
::DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (subscriber[i].in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Failed to create_subscriber.")));
throw TestException ();
}
// Create the Datareaders
::DDS::DataReaderQos dr_qos;
subscriber[i]->get_default_datareader_qos (dr_qos);
::DDS::TopicDescription_var description
= participant[i]->lookup_topicdescription(topic_name[i]);
// create the datareader.
datareader[i] = subscriber[i]->create_datareader(description.in (),
dr_qos,
listener[i].in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (datareader[i].in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) create_datareader failed.\n")));
throw TestException ();
}
}
示例14: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){
try
{
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
DDS::DomainParticipant_var participant =
dpf->create_participant(311,
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* servant = new MessageTypeSupportImpl();
if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
cerr << "register_type failed." << endl;
exit(1);
}
CORBA::String_var type_name = 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 << "create_topic failed." << endl;
exit(1);
}
DDS::PublisherQos pub_qos;
participant->get_default_publisher_qos (pub_qos);
pub_qos.partition.name.length (1);
pub_qos.partition.name[0] = PARTITION_A;
DDS::Publisher_var pub =
participant->create_publisher(pub_qos, DDS::PublisherListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (pub.in ())) {
cerr << "create_publisher failed." << endl;
exit(1);
}
// ----------------------------------------------
// Create DataWriter which is belongs to PARTITION_A
DDS::DataWriter_var dw =
pub->create_datawriter (topic.in (),
DATAWRITER_QOS_DEFAULT,
DDS::DataWriterListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
int const max_attempts = 15;
int attempts = 1;
// ----------------------------------------------
// Wait for first DataReader that belongs to PARTITION_A too,
// then write samples.
// cache handle for first reader.
::DDS::InstanceHandle_t handle = -1;
{
std::auto_ptr<Writer> writer (new Writer (dw.in ()));
cout << "Pub waiting for match on A partition." << std::endl;
if (OpenDDS::Model::WriterSync::wait_match(dw)) {
cerr << "Error waiting for match on A partition" << std::endl;
return 1;
}
while (attempts != max_attempts)
{
::DDS::InstanceHandleSeq handles;
dw->get_matched_subscriptions(handles);
cout << "Pub matched " << handles.length() << " A subs." << std::endl;
if (handles.length() == 1)
{
handle = handles[0];
break;
}
else
ACE_OS::sleep(1);
++attempts;
}
if (attempts == max_attempts)
{
cerr << "ERROR: failed to wait for first DataReader." << endl;
exit (1);
}
writer->start ();
//.........这里部分代码省略.........
示例15: BadParticipantException
Subscriber::Subscriber( const Options& options)
: options_( options),
listener_( 0),
waiter_( new DDS::WaitSet)
{
DDS::DomainParticipantFactory_var dpf = TheParticipantFactory;
// Create the DomainParticipant
this->participant_
= dpf->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 the listener.
this->listener_ = new DataReaderListener( this->options_.verbose());
this->safe_listener_ = this->listener_;
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created reader listener.\n")
));
// Create and register the type support.
DataTypeSupportImpl::_var_type testData = new DataTypeSupportImpl();
CORBA::String_var type_name = testData->get_type_name();
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"),
type_name.in()
));
throw BadTypeSupportException ();
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created type %C support.\n"),
type_name.in()
));
// Create the topic.
this->topic_ = this->participant_->create_topic(
this->options_.topicName().c_str(),
type_name,
TOPIC_QOS_DEFAULT,
::DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK
);
if( CORBA::is_nil( this->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();
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created topic %C.\n"),
this->options_.topicName().c_str()
));
// Create the subscriber.
this->subscriber_ = this->participant_->create_subscriber(
SUBSCRIBER_QOS_DEFAULT,
::DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK
);
if( CORBA::is_nil( this->subscriber_.in())) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ")
ACE_TEXT("failed to create subscriber.\n")
));
throw BadSubscriberException();
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ")
ACE_TEXT("created subscriber.\n")
));
//.........这里部分代码省略.........