c++ - OpenDDS - Create multiple topics from single IDL structure -


in exercise opendds create multiple topics single idl structure, possible? otherwise please let me know how it.

i below, please correct me if not right way it. sample use available @ opendds-3.12/examples/dcps/introductiontoopendds

the idl follows,

stockquoter.idl --------------- module stockquoter { #pragma dcps_data_type "stockquoter::quote" #pragma dcps_data_key "stockquoter::quote ticker"    struct quote {     string ticker;     string exchange;     string full_name;     double value;     string data;     timebase::timet timestamp;   }; } 

publisher.cpp


  // create topics , types vector   std::stringstream ss;   for(unsigned int idx = 0; idx < 100; ++idx)   {       ss << (idx+1);       topics.push_back("topic" + std::string(ss.str()));       types.push_back("type" + std::string(ss.str()));       ss.clear();       ss.str(std::string());   }       // register     for( unsigned int idx = 0; idx < 100; ++idx )     {         vec_quote_servent.push_back(new stockquoter::quotetypesupportimpl());         if (dds::retcode_ok != vec_quote_servent[idx]->register_type(participant.in (), types[idx].c_str()))         {           cerr << "register_type " << types[idx] << " failed." << endl;           ace_os::exit(1);         }     }      // create topics     for( unsigned int idx = 0; idx < 100; ++idx )     {          vec_quote_topic.push_back(   participant->create_topic (topics[idx].c_str(),                                       types[idx].c_str(),                                       default_topic_qos,                                       dds::topiclistener::_nil(),                                       ::opendds::dcps::default_status_mask));           if (corba::is_nil (vec_quote_topic[idx].in ())) {              cerr << "create_topic " << topics[idx] << " failed." << endl;              ace_os::exit(1);         }      }      // create datawriters     for( unsigned int idx = 0; idx < 100; ++idx )     {          vec_quote_base_dw.push_back( pub->create_datawriter(vec_quote_topic[idx].in (),                                       dw_default_qos,                                       dds::datawriterlistener::_nil(),                                       ::opendds::dcps::default_status_mask) );          if (corba::is_nil (vec_quote_base_dw[idx].in ())) {            cerr << "create_datawriter " << topics[idx] << " failed." << endl;            ace_os::exit(1);         }          vec_quote_dw.push_back( stockquoter::quotedatawriter::_narrow(vec_quote_base_dw[idx].in()) );         if (corba::is_nil (vec_quote_dw[idx].in ())) {           cerr << topics[idx] << " not narrowed"<< endl;           ace_os::exit(1);         }     }      // create handle     for( unsigned int idx = 0; idx < 100 ; ++idx )     {         {             stockquoter::quote topic2;             topic2.ticker = corba::string_dup(topics[idx].c_str());             vec_topic_handle.push_back(vec_quote_dw[idx]->register_instance(topic2));         }     }        // publish data       stockquoter::quote vec_quote;       vec_quote.exchange = stock_exchange_name;       vec_quote.ticker = corba::string_dup("vec_topic");       vec_quote.full_name = corba::string_dup("topic receipts");       vec_quote.value = 1600.0 + 10.0*i;       vec_quote.timestamp = get_timestamp();        for(unsigned int idx = 0; idx < 100; ++idx )       {           vec_quote.value += idx + 10;           cout << "publishing " << topics[idx] << " : " << vec_quote.value <<endl;           ret = vec_quote_dw[idx]->write(vec_quote, vec_topic_handle[idx]);           if (ret != dds::retcode_ok) {              ace_error ((lm_error, ace_text("(%p|%t) error: topic2 write returned %d.\n"), ret));           }       } 

you can create many topics wish single idl file. doing line:

participant->create_topic (topics[idx].c_str(),                            types[idx].c_str(),                            default_topic_qos,                            dds::topiclistener::_nil(),                            ::opendds::dcps::default_status_mask); 

however, each topic created has same type. can create different types topics if have to.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -