Jump to content
OpenSplice DDS Forum

ljjreg

Members
  • Content count

    2
  • Joined

  • Last visited

About ljjreg

  • Rank
    Member

Profile Information

  • Company
    hust

Recent Profile Visitors

214 profile views
  1. The full code is as follows: #include<iostream> #include<stdlib.h> #include<string.h> #include"ccpp_dds_dcps.h" #include"CheckStatus.h" #include"ccpp_top.h" #ifndef _WIN32 #include <unistd.h> #else #include <Windows.h> #endif using namespace DDS; using namespace pubsub; #define TERMINATION_MESSAGE -1 int main() { DomainParticipantFactory_var dpf; DomainParticipant_var dp; Topic_var top1Topic; Subscriber_var suber; DataReader_var drer1; TopicQos top1qos; SubscriberQos subqos; top1TypeSupport_var top1TS; top1DataReader_var top1dr; top1Seq_var msg1Seq = new top1Seq(); SampleInfoSeq_var info1Seq = new SampleInfoSeq(); ReturnCode_t status; DomainId_t domain = DOMAIN_ID_DEFAULT; bool terminated = false; const char * partitionName = "Communication"; char * top1TypeName = NULL; dpf = DomainParticipantFactory::get_instance(); checkHandle(dpf.in(),"DDS::DomainParticipantFactory::get_instance"); dp = dpf->create_participant(domain,PARTICIPANT_QOS_DEFAULT,NULL,STATUS_MASK_NONE); checkHandle(dp.in(),"DDS::DomainParticipantFactory::create_participant"); top1TS = new top1TypeSupport(); checkHandle(top1TS.in(),"new top1TypeSupport"); top1TypeName = top1TS->get_type_name(); status = top1TS->register_type( dp.in(), top1TypeName); checkStatus(status,"pubsub::top1TypeSupport::register_type"); status = dp->get_default_topic_qos(top1qos); checkStatus(status,"DDS::DomainParticipant::get_default_topic_qos"); top1Topic = dp->create_topic( "pubsub_top1", top1TypeName, top1qos, NULL, STATUS_MASK_NONE); checkHandle(top1Topic.in(),"DDS::DomainParticipant::create_topic"); status = dp->get_default_subscriber_qos(subqos); checkStatus(status,"DDS::DomainParticipant::get_default_subscriber_qos"); subqos.partition.name.length(1); subqos.partition.name[0] = partitionName; suber = dp->create_subscriber( subqos, NULL, STATUS_MASK_NONE); checkHandle(suber.in(),"DDS::DomainParticipant::create_subscriber"); drer1 = suber->create_datareader( top1Topic.in(), DATAREADER_QOS_USE_TOPIC_QOS, NULL, STATUS_MASK_NONE); checkHandle(drer1.in(),"DDS::Subscriber::create_datareader"); top1dr = pubsub::top1DataReader::_narrow(drer1.in()); checkHandle(top1dr.in(),"pubsub::top1DataReader::_narrow"); cout<<"prepare to read data..."<<endl; while (!terminated) { status = top1dr->take( msg1Seq, info1Seq, LENGTH_UNLIMITED, ANY_SAMPLE_STATE, ANY_VIEW_STATE, ALIVE_INSTANCE_STATE); checkStatus(status,"pubsub::top1DataReader::take"); for (DDS::ULong i = 0;i<msg1Seq->length();i++) { top1 *msg1 = &(msg1Seq[i]); cout<<"receive data:"<<msg1->content<<endl; fflush(stdout); } status = top1dr->return_loan(msg1Seq,info1Seq); checkStatus(status,"pubsub::top1DataReader::return_loan"); #ifdef USE_NANOSLEEP sleeptime.tv_sec = 0; sleeptime.tv_nsec = 100000000; nanosleep(&sleeptime, &remtime); #elif defined _WIN32 Sleep(100); #else usleep(100000); #endif } status = suber->delete_datareader(top1dr.in()); checkStatus(status,"DDS::Subscriber::delete_datareader"); status = dp->delete_subscriber(suber.in()); checkStatus(status,"DDS::Participant::delete_subscriber"); status = dp->delete_topic(top1Topic.in()); checkStatus(status,"DDS::Participant::delete_topic"); DDS::string_free(top1TypeName); status = dpf->delete_participant(dp.in()); checkStatus(status,"DDS::DomainParticipantFactory::delete_participant"); system("pause"); return 0; }
  2. I am a beginer of DDS. This is a very simple program,just like the example 'Tutorial'. Publisher sends some messages and subscriber gets them. But subscriber can only receive one message ,after that the program could be crashed. The code is as follows: for (DDS::ULong i = 0;i<msg1Seq->length();i++) { top1 *msg1 = &(msg1Seq[i]); cout<<"receive data:"<<msg1->content<<endl; fflush(stdout); } status = top1dr->return_loan(msg1Seq,info1Seq); checkStatus(status,"pubsub::top1DataReader::return_loan"); When run to 'status = top1dr->return_loan(msg1Seq,info1Seq);', the program be crashed. It shows: Someone says it means a wild pointer,but i don't know why. Thank you.
×