void MeChart:: init(ECString path) { Feat::Usage = PARSE; addEdgeSubFeatureFns(); addSubFeatureFns(); ECString tmpA[MAXNUMCALCS] = {"r","h","u","m","l","lm","ru","rm","tt", "s","t","ww","dummy","dummy","dummy"}; for(int which = 0 ; which < Feature::numCalcs ; which++) { ECString tmp = tmpA[which]; Feature::init(path, tmp); if(tmp == "s" || tmp == "t") continue; ECString ftstr(path); ftstr += tmp; ftstr += ".g"; ifstream fts(ftstr.c_str()); if(!fts) cerr << "could not find " << ftstr << endl; assert(fts); FeatureTree* ft = new FeatureTree(fts); //puts it in root; if(tmp == "ww") continue; Feature::readLam(which, tmp, path); } int cntxSzReq = Feature::total[TCALC]; int scSz = Feature::total[SCALC]; if(scSz > cntxSzReq) cntxSzReq = scSz; //assert(CntxArray::sz == cntxSzReq); //assert(CntxArray::sz == (Feature::total[UCALC] -1)); }
void Feature:: readLam(int which, ECString tmp, ECString path) { ECString ftstr(path); ftstr += tmp; ftstr += ".lambdas"; ifstream fts(ftstr.c_str()); assert(fts); int b,f; // wul: lambdas文件有14行,每行的格式如下(第一列为序号): // wul: 2 0 0.329 0.336 0.00178 0.353 0.00129 0.158 0.417 for(b = 1; b < 15 ; b++) { int bb; assert(fts); fts >> bb ; //cerr << bb << endl; assert(bb == b); // wul: 读取后面的各列(不同的Which,如ru, u...)有不同的列。根据它们的Feature数目 // 而定 for(f = 2; f <= Feature::total[which] ; f++) { float lam; assert(fts); fts >> lam; //cerr << which << " " << f << " " << b << " " << lam << endl; // wul: Lambda Table有点数据库。在此记录下。b表示一个实例(行号) Feature::setLambda(which,f,b,lam); } } }
void SubDriver::init(int& argc, ACE_TCHAR* argv[]) { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); parse_args(argc, argv); participant_ = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (participant_.in ())); ::Xyz::SampleTypeTypeSupport_var fts (new ::Xyz::SampleTypeTypeSupportImpl); if (::DDS::RETCODE_OK != fts->register_type(participant_.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the SampleTypeTypeSupport."))); } ::DDS::TopicQos default_topic_qos; participant_->get_default_topic_qos(default_topic_qos); ::DDS::TopicQos new_topic_qos = default_topic_qos; new_topic_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; participant_->set_default_topic_qos(new_topic_qos); topic_ = participant_->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (topic_.in ())); subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT, ::DDS::SubscriberListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (subscriber_.in ())); std::cout << std::hex << "0x" << subscriber_->get_instance_handle() << std::endl; // Create datareader to test copy_from_topic_qos. listener_ = new DataReaderListenerImpl; ::DDS::DataReaderListener_var drl (listener_); datareader_ = subscriber_->create_datareader(topic_.in (), DATAREADER_QOS_USE_TOPIC_QOS, drl.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (datareader_.in ())); // And we are done with the init(). }
bool chmod(const std::string &path, mode_t perms, int flags) { if (flags & CHMOD_RECURSIVE) { RecursiveChmod fts(path, perms); return fts.run(); } else { return ::chmod(path.c_str(), perms) == 0; } }
void Feature:: readLam(int which, ECString tmp, ECString path) { ECString ftstr(path); ftstr += tmp; ftstr += ".lambdas"; ifstream fts(ftstr.c_str()); assert(fts); int b,f; int tot = Feature::total[which]; /* The standard training programs never read in lambdas. Only getProbs does, and it uses the new bucketing, which uses the next for loop */ for(f = 2 ; f <= tot ; f++) { float logBase; fts >> logBase; /*JT: this used to be logFacs[f][which] = 1.0/log(logBase), but that occurs in bucket */ logFacs[which][f] = logBase; } for(b = 1; b < 15 ; b++) { int bb; if(!fts) { cerr << "Trouble reading lambs for " << which << " in " << ftstr << endl; assert(fts); } fts >> bb ; //cerr << bb << endl; if(bb != b) { cerr << tmp << " " << b << " " << bb << endl; assert(bb == b); } for(f = 2; f <= tot ; f++) { float lam; assert(fts); fts >> lam; //cerr << which << " " << f << " " << b << " " << lam << endl; Feature::setLambda(which,f,b,lam); } } }
vector<int> Project::serialSGSCore(const vector<int>& order, Matrix<int>& resRem, bool robust) const { vector<int> sts(numJobs, UNSCHEDULED), fts(numJobs, UNSCHEDULED); for (int i = 0; i < numJobs; i++) { int job = robust ? chooseEligibleWithLowestIndex(sts, order) : order[i]; int lastPredFinished = computeLastPredFinishingTime(fts, job); int t; for (t = lastPredFinished; !enoughCapacityForJob(job, t, resRem); t++); scheduleJobAt(job, t, sts, fts, resRem); } return sts; }
void Feature:: createLam(int which, ECString tmp, ECString path) { ECString npath("/ltmp/discrim/FOLDS/"); int b,f; int tot = Feature::total[which]; for(int i = 0 ; i < 20 ; i++) { ECString ftstr(npath); ftstr += intToString(i) + "/"; ftstr += tmp; ftstr += ".lambdas"; ifstream fts(ftstr.c_str()); assert(fts); for(b = 1; b < 15 ; b++) { int bb; if(!fts) { cerr << "Trouble reading lambs for " << which << " in " << ftstr << endl; assert(fts); } fts >> bb ; //cerr << bb << endl; if(bb != b) { cerr << tmp << " " << b << " " << bb << endl; assert(bb == b); } for(f = 2; f <= tot ; f++) { float lam; assert(fts); fts >> lam; //cerr << which << " " << f << " " << b << " " << lam << endl; if(i == 0) Feature::setLambda(which,f,b,lam); else lamVal(which,f,b) += lam; } } } for(b = 1; b < 15 ; b++) for(f = 2; f <= tot ; f++) lamVal(which,f,b) /= 20.0; ECString ftstr(path); ftstr += tmp; ftstr += ".lambdas"; ofstream res(ftstr.c_str()); assert(res); res.precision(3); printLambdas(res); }
bool chown(const std::string &path, uid_t uid, gid_t gid, int flags) { if (flags & CHOWN_RECURSIVE) { RecursiveChown fts(path, uid, gid, flags & CHOWN_FOLLOW_SYMLINKS); return fts.run(); } else { return chown_internal(path, uid, gid, flags & CHOWN_FOLLOW_SYMLINKS); } }
bool chown(const std::string &path, uid_t uid, gid_t gid, ChownFlags flags) { if (flags & ChownFlag::Recursive) { RecursiveChown fts(path, uid, gid, flags & ChownFlag::FollowSymlinks); return fts.run(); } else { return chown_internal(path, uid, gid, flags & ChownFlag::FollowSymlinks); } }
pair<vector<int>, Matrix<int>> Project::serialSGSForPartial(const vector<int>& sts, const vector<int>& order, Matrix<int>& resRem) const { vector<int> fts(numJobs, UNSCHEDULED), nsts = sts; transferAlreadyScheduledToFts(fts, sts); for(int job : order) { if (sts[job] == UNSCHEDULED) { int lastPredFinished = computeLastPredFinishingTimeForPartial(fts, job); int t; for (t = lastPredFinished; !enoughCapacityForJob(job, t, resRem); t++); scheduleJobAt(job, t, nsts, fts, resRem); } } return make_pair(nsts, resRem); }
void Feature:: readLam(int which, ECString tmp, ECString path) { ECString ftstr(path); ftstr += tmp; ftstr += ".lambdas"; ifstream fts(ftstr.c_str()); assert(fts); int b,f; int tot = Feature::total[which]; if(Feature::isLM or Feature::useExtraConditioning) { /* This for loop is removed for old bucketing; */ for(f = 2 ; f <= tot ; f++) { float logBase; fts >> logBase; logFacs[which][f] = 1.0/log(logBase); } } for(b = 1; b < 15 ; b++) { int bb; if(!fts) { cerr << "Trouble reading lambs for " << which << " in " << ftstr << endl; assert(fts); } fts >> bb ; //cerr << bb << endl; if(bb != b) { cerr << tmp << " " << b << " " << bb << endl; assert(bb == b); } for(f = 2; f <= tot ; f++) { float lam; assert(fts); fts >> lam; //cerr << which << " " << f << " " << b << " " << lam << endl; Feature::setLambda(which,f,b,lam); } } }
int main (int argc, char *argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil()); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil()); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(MY_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, ::DDS::SubscriberListener::_nil()); if (CORBA::is_nil (sub.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_subscriber failed.\n")), 1); } // Initialize the transport OpenDDS::DCPS::TransportImpl_rch reader_transport_impl; if (0 != ::init_reader_tranport(reader_transport_impl) ) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) init_transport failed!\n")), 1); } // Attach the subscriber to the transport. OpenDDS::DCPS::SubscriberImpl* sub_impl = dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ()); if (0 == sub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain servant ::OpenDDS::DCPS::SubscriberImpl\n")), 1); } OpenDDS::DCPS::AttachStatus attach_status = sub_impl->attach_transport(reader_transport_impl.in()); if (attach_status != OpenDDS::DCPS::ATTACH_OK) { // We failed to attach to the transport for some reason. ACE_TString status_str; switch (attach_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; } ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str.c_str()), 1); } // Create the Datareaders ::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; ::DDS::DataReaderListener_var drl (new DataReaderListenerImpl); DataReaderListenerImpl* drl_servant = dynamic_cast<DataReaderListenerImpl*>(drl.in()); ::DDS::DataReader_var dr ; dr = sub->create_datareader(description.in (), dr_qos, drl.in ()); ACE_OS::sleep(test_duration); // clean up subscriber objects sub->delete_contained_entities() ; dp->delete_subscriber(sub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheTransportFactory->release(); TheServiceParticipant->shutdown (); if (drl_servant->deadline_missed() < threshold_liveliness_lost) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) The liviness deadline wasn't missed as many times as it should have." "threashold=%d, num missed=%d\n"), threshold_liveliness_lost, drl_servant->deadline_missed())); return 1; } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
/*! * \brief Copy /system directory excluding multiboot files * * \param source Source directory * \param target Target directory */ bool copy_system(const std::string &source, const std::string &target) { CopySystem fts(source, target); return fts.run(); }
int main(int argc, char *argv[]) { struct rlimit core_limits; core_limits.rlim_cur = 0; core_limits.rlim_max = 0; setrlimit( RLIMIT_CORE, &core_limits ); ECArgs args( argc, argv ); assert(args.nargs() == 2); conditionedType = args.arg(0); cerr << "start trainRs: " << conditionedType << endl; ECString path( args.arg( 1 ) ); if(args.isset('L')) Feature::setLM(); Term::init(path); readHeadInfo(path); Pst pst(path); if(Feature::isLM) ClassRule::readCRules(path); addSubFeatureFns(); Feature::init(path, conditionedType); whichInt = Feature::whichInt; int ceFunInt = Feature::conditionedFeatureInt[Feature::whichInt]; Feature::conditionedEvent = SubFeature::Funs[ceFunInt]; Feat::Usage = PARSE; ECString ftstr(path); ftstr += conditionedType; ftstr += ".g"; ifstream fts(ftstr.c_str()); if(!fts) { cerr << "Could not find " << ftstr << endl; assert(fts); } tRoot = new FeatureTree(fts); //puts it in root; cout.precision(3); cerr.precision(3); lamInit(); InputTree* trainingData[1001]; int usedCount = 0; sentenceCount = 0; for( ; ; sentenceCount++) { if(sentenceCount%10000 == 1) { // cerr << conditionedType << ".tr " //<< sentenceCount << endl; } if(usedCount >= 1000) break; InputTree* correct = new InputTree; cin >> (*correct); if(correct->length() == 0) break; if(!cin) break; EcSPairs wtList; correct->make(wtList); InputTree* par; par = correct; trainingData[usedCount++] = par; } if(Feature::isLM) pickLogBases(trainingData,sentenceCount); procGSwitch = true; for(pass = 0 ; pass < 10 ; pass++) { if(pass%2 == 1) cout << "Pass " << pass << endl; goThroughSents(trainingData, sentenceCount); updateLambdas(); //printLambdas(cout); zeroData(); } ECString resS(path); resS += conditionedType; resS += ".lambdas"; ofstream res(resS.c_str()); res.precision(3); printLambdas(res); printLambdas(cout); cout << "Total params = " << FeatureTree::totParams << endl; cout << "Done: " << (int)sbrk(0) << endl; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; topic_qos.history.depth = history_depth; ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } Reader* reader ; Writer* writer ; SampleInfoMap si_map ; ::DDS::SampleInfo si ={::DDS::NOT_READ_SAMPLE_STATE, ::DDS::NOT_NEW_VIEW_STATE , ::DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE , {0, 0}, ::DDS::HANDLE_NIL , 0, 0, 0, 0, 0, ::DDS::HANDLE_NIL, false}; reader = new Reader(dp.in (), history_depth, max_samples_per_instance) ; ACE_OS::sleep(5) ; // why??? writer = new Writer(dp.in (), topic.in (), history_depth, max_samples_per_instance) ; ACE_OS::sleep(5) ; // why??? si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 0 ; si.sample_rank = 0 ; si.generation_rank = 0; si.absolute_generation_rank = 0; si_map['A'] = si ; // Test1: write I1 A, reg I2 writer->test1 (); reader->read (si_map); ACE_OS::sleep(1) ; // why??? si_map['A'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['A'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['A'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['A'].disposed_generation_count = 0 ; si_map['A'].no_writers_generation_count = 0 ; si_map['A'].sample_rank = 1 ; si_map['A'].generation_rank = 0 ; si_map['A'].absolute_generation_rank = 0 ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NOT_NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 0 ; si.sample_rank = 0 ; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['B'] = si ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 0 ; si.sample_rank = 0 ; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['X'] = si ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0; si.no_writers_generation_count = 0; si.sample_rank = 0; si.generation_rank = 0; si.absolute_generation_rank = 0; si_map['Q'] = si ; // Test2: write I2 X, write I1 B, reg I3, write I3 Q writer->test2 (); ACE_OS::sleep(1) ; reader->read (si_map); ACE_OS::sleep(1) ; // why??? si_map['A'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['A'].view_state = ::DDS::NEW_VIEW_STATE ; si_map['A'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['A'].disposed_generation_count = 2; si_map['A'].no_writers_generation_count = 0; // two addition dispose "sample" after 'A'. si_map['A'].sample_rank = 3 + 2; si_map['A'].generation_rank = 2; si_map['A'].absolute_generation_rank = 2; si_map['B'].sample_state = ::DDS::READ_SAMPLE_STATE ; // The samples of the same instance returned by // a single read() should have same view state // so samples 'B','C','D' should have same view // state as 'A'. si_map['B'].view_state = ::DDS::NEW_VIEW_STATE ; si_map['B'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['B'].disposed_generation_count = 2 ; si_map['B'].no_writers_generation_count = 0 ; // two addition dispose "sample" after 'B'. si_map['B'].sample_rank = 2 + 2; si_map['B'].generation_rank = 2 ; si_map['B'].absolute_generation_rank = 2 ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 2 ; si.no_writers_generation_count = 0 ; // one addition dispose "sample" after. si.sample_rank = 1 + 1; // disposed_generation_count = 1 when receiving "C" // while disposed_generation_count = 0 when receiving "A" and "B" // so // S.disposed_generation_count = 1 // MRSIC.disposed_generation_count = 2 // MRSIC.no_writers_generation_count = S.no_writers_generation_count = 0 // // // si.generation_rank = // (MRSIC.disposed_generation_count + MRSIC.no_writers_generation_count) // - (S.disposed_generation_count + S.no_writers_generation_count) si.generation_rank = 1 ; si.absolute_generation_rank = 1 ; si_map['C'] = si ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 2 ; si.no_writers_generation_count = 0 ; // no addition dispose "sample" si.sample_rank = 0; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['D'] = si ; si_map['X'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['X'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['X'].instance_state = ::DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE ; // The disposed_generation_count will not be changed if the datareader // has not received any new samples after dispose. si_map['X'].disposed_generation_count = 0 ; si_map['X'].no_writers_generation_count = 0 ; // one addition dispose "sample" si_map['X'].sample_rank = 1 + 1; si_map['X'].generation_rank = 0 ; si_map['X'].absolute_generation_rank = 0 ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NOT_NEW_VIEW_STATE ; si.instance_state = ::DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 0 ; // one addition dispose "sample" si.sample_rank = 0 + 1; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['Y'] = si ; si_map['Q'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['Q'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['Q'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['Q'].disposed_generation_count = 0 ; si_map['Q'].no_writers_generation_count = 0 ; si_map['Q'].sample_rank = 0 ; si_map['Q'].generation_rank = 0 ; si_map['Q'].absolute_generation_rank = 0 ; //Test3: Dispose I1, write I1 C, dispose I1, write I1 D, write I2 Y, dispose I2. writer->test3 (); ACE_OS::sleep(5) ; reader->read (si_map); delete writer; delete reader; //--------------------------------------------------------------------- reader = new Reader(dp.in (), history_depth, max_samples_per_instance) ; ACE_OS::sleep(5) ; // why??? writer = new Writer(dp.in (), topic.in (), history_depth, max_samples_per_instance) ; ACE_OS::sleep(5) ; // why??? si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 0 ; si.sample_rank = 0; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['c'] = si ; //Test4: write I1 c. writer->test4 (); ACE_OS::sleep(1) ; reader->read (si_map); // Sleep to make no writer so the next read will get the instance // with NOT_ALIVE_NO_WRITERS instance state. ACE_OS::sleep(20) ; si_map['c'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['c'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['c'].instance_state = ::DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE ; si_map['c'].disposed_generation_count = 0 ; si_map['c'].no_writers_generation_count = 0 ; si_map['c'].sample_rank = 0 ; si_map['c'].generation_rank = 0 ; si_map['c'].absolute_generation_rank = 0 ; reader->read (si_map); si_map['c'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['c'].view_state = ::DDS::NEW_VIEW_STATE ; si_map['c'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['c'].disposed_generation_count = 0 ; si_map['c'].no_writers_generation_count = 1 ; si_map['c'].sample_rank = 1 ; si_map['c'].generation_rank = 1 ; si_map['c'].absolute_generation_rank = 1 ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; // The samples of the same instance returned by // a single read() should have same view state // so sample 'd' should have same view state as // sample 'c'. si.view_state = ::DDS::NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 1 ; si.sample_rank = 0 ; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['d'] = si ; //Test5: write I1 d writer->test5 (); ACE_OS::sleep(1) ; reader->read (si_map); ACE_OS::sleep(1) ; // why??? si_map['c'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['c'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['c'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['c'].disposed_generation_count = 0 ; si_map['c'].no_writers_generation_count = 1 ; si_map['c'].sample_rank = 2 ; si_map['c'].generation_rank = 1 ; si_map['c'].absolute_generation_rank = 1 ; si_map['d'].sample_state = ::DDS::READ_SAMPLE_STATE ; si_map['d'].view_state = ::DDS::NOT_NEW_VIEW_STATE ; si_map['d'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['d'].disposed_generation_count = 0 ; si_map['d'].no_writers_generation_count = 1 ; si_map['d'].sample_rank = 1 ; si_map['d'].generation_rank = 0 ; si_map['d'].absolute_generation_rank = 0 ; si.sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si.view_state = ::DDS::NOT_NEW_VIEW_STATE ; si.instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si.disposed_generation_count = 0 ; si.no_writers_generation_count = 1 ; si.sample_rank = 0 ; si.generation_rank = 0 ; si.absolute_generation_rank = 0 ; si_map['e'] = si ; //Test6: write I1 e. writer->test6 (); ACE_OS::sleep(1) ; reader->read (si_map); delete writer; delete reader; //--------------------------------------------------------------------- reader = new Reader(dp.in (), 1, 1) ; ACE_OS::sleep(5) ; // why??? writer = new Writer(dp.in (), topic.in (), history_depth, max_samples_per_instance) ; ACE_OS::sleep(5) ; // why??? writer->test5 (); writer->test6 (); ACE_OS::sleep(1) ; si_map['d'].sample_state = ::DDS::NOT_READ_SAMPLE_STATE ; si_map['d'].view_state = ::DDS::NEW_VIEW_STATE ; si_map['d'].instance_state = ::DDS::ALIVE_INSTANCE_STATE ; si_map['d'].disposed_generation_count = 0 ; si_map['d'].no_writers_generation_count = 0 ; si_map['d'].sample_rank = 0 ; si_map['d'].generation_rank = 0 ; si_map['d'].absolute_generation_rank = 0 ; reader->read (si_map); delete writer; delete reader; //--------------------------------------------------------------------- dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); writer_transport_impl = 0; reader_transport_impl = 0; TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return 0; }
void PubDriver::init(int& argc, ACE_TCHAR *argv[]) { // Create DomainParticipant and then publisher, topic and datawriter. ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); datawriters_ = new ::DDS::DataWriter_var[num_datawriters_]; writers_ = new Writer* [num_datawriters_]; ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); participant_ = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (participant_.in ())); if (::DDS::RETCODE_OK != fts->register_type(participant_.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); } ::DDS::TopicQos topic_qos; participant_->get_default_topic_qos(topic_qos); if (block_on_write_) { topic_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance_; topic_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; } else { topic_qos.history.depth = history_depth_; } topic_ = participant_->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (topic_.in ())); publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (publisher_.in ())); ::DDS::DataWriterQos datawriter_qos; publisher_->get_default_datawriter_qos (datawriter_qos); if (block_on_write_) { datawriter_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; datawriter_qos.resource_limits.max_samples_per_instance = max_samples_per_instance_; datawriter_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; } else { datawriter_qos.history.depth = history_depth_; } // Create one datawriter or multiple datawriters belong to the same // publisher. for (int i = 0; i < num_datawriters_; i ++) { datawriters_[i] = publisher_->create_datawriter(topic_.in (), datawriter_qos, ::DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_CHECK (! CORBA::is_nil (datawriters_[i].in ())); } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_topic failed!\n")), 1); } OpenDDS::DCPS::TransportImpl_rch writer_transport_impl; // Create the publisher ::DDS::Publisher_var pub = dp->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("(%P|%t) create_publisher failed.\n")), 1); } // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.durability.kind = durability_kind; dw_qos.liveliness.kind = liveliness_kind; dw_qos.liveliness.lease_duration = LEASE_DURATION; dw_qos.reliability.kind = reliability_kind; ::DDS::DataWriterListener_var dwl (new DataWriterListenerImpl); ::DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, dwl.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // Writer writer(dw.in ()); // ACE_Time_Value duration(10); // writer.run_test(duration); ACE_OS::sleep(test_duration); // Clean up publisher objects dp->delete_contained_entities(); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown(); { DataWriterListenerImpl* dwl_servant = dynamic_cast<DataWriterListenerImpl*>(dwl.ptr()); // check to see if the publisher worked if(dwl_servant->publication_matched() != compatible) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Expected publication_matched to be %C, but it wasn't. ") ACE_TEXT("durability_kind=%s,liveliness_kind=%s,liveliness_duration=%s,") ACE_TEXT("reliability_kind=%s\n"), (compatible) ? "true" : "false", durability_kind_str.c_str(), liveliness_kind_str.c_str(), LEASE_DURATION_STR.c_str(), reliability_kind_str.c_str())); return 1 ; } } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } catch (std::runtime_error& err) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: main() - %C\n"), err.what()), -1); } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) %T publisher main\n")); ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts(new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; topic_qos.history.depth = history_depth; ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } // Create the publisher ::DDS::Publisher_var pub = dp->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("(%P|%t) create_publisher failed.\n")), 1); } // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.history.depth = history_depth ; dw_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; dw_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC ; dw_qos.liveliness.lease_duration.nanosec = 0 ; ::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 ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // ensure that the connection and association has been fully established ACE_OS::sleep(2); //TBD remove this kludge when the transport is fixed. // Indicate that the publisher is ready FILE* writers_ready = ACE_OS::fopen (pub_ready_filename.c_str (), ACE_TEXT("w")); if (writers_ready == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Unable to create publisher ready file\n"))); } // Wait for the subscriber to be ready. FILE* readers_ready = 0; do { ACE_Time_Value small_time(0,250000); ACE_OS::sleep (small_time); readers_ready = ACE_OS::fopen (sub_ready_filename.c_str (), ACE_TEXT("r")); } while (0 == readers_ready); ACE_OS::fclose(writers_ready); ACE_OS::fclose(readers_ready); ReactorCtrl rc ; // stop the Service_Participant reactor so LIVELINESS.kind=AUTOMATIC does not // send out an automatic liveliness control message when sleeping in the loop // below. rc.pause() ; Writer* writer = new Writer(dw.in (), 1, num_ops_per_thread); for (int i = 0 ; i < num_unlively_periods ; i++) { writer->run_test (i); // 3 ensures that we will detect when an DataReader detects // liveliness lost on an already unliveliy DataReader. ACE_OS::sleep (3 * LEASE_DURATION_SEC); } writer->run_test (num_unlively_periods); rc.resume() ; bool writers_finished = false; ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for writers to finish\n") )); while ( !writers_finished ) { ACE_OS::sleep(ACE_Time_Value(0,250000)); writers_finished = true; writers_finished = writers_finished && writer->is_finished(); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T Writers are finished\n") )); // Indicate that the publisher is done FILE* writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("w")); if (writers_completed == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Unable to create publisher completed file\n"))); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for readers to finish\n") )); // Wait for the subscriber to finish. FILE* readers_completed = 0; do { ACE_Time_Value small_time(0,250000); ACE_OS::sleep (small_time); readers_completed = ACE_OS::fopen (sub_finished_filename.c_str (), ACE_TEXT("r")); } while (0 == readers_completed); ACE_OS::fclose(writers_completed); ACE_OS::fclose(readers_completed); ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T Readers are finished\n") )); // Clean up publisher objects pub->delete_contained_entities() ; delete writer; dp->delete_publisher(pub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
void GradFragment::initRnd(InstInfo& t) { const vector<int>& fTypes = PointRep::_brInstance->_featureTypes; int numWts = _RandOf(PointRep::_brInstance->_atomSymbols) + 1; _indexes.resize(numWts); _values.resize(numWts); _operations.resize(numWts); _weightVal.resize(numWts); _biasParam._val = _gRand(SMRNDSD); const vector<FValue>& vec = static_cast<PtInstInfo&>(t)._features; vector<double> fts(numWts); for (int n=0; n<numWts; ++n) { int idx = _RandOf(fTypes.size()); _indexes[n] = idx; if (fTypes[idx] == iClass) { _operations[n] = eq; if (! vec.empty()) _values[n] = vec.at(idx); else { const vector<int>& fClasses = PointRep::_brInstance->_featureClasses; _values[n].iVal = _RandOf(fClasses[idx]); } continue; } else { // grab from state to match feature // define sigmoid activation _operations[n] = other; double val; if (! vec.empty()) { if (fTypes[idx] == iSeq) val = vec.at(idx).iVal; else if (fTypes[idx] == fSeq) val = vec.at(idx).fVal; } else { vector<pair<FValue, FValue> >& fRanges = PointRep::_brInstance->_featureRanges; double min, max; if (fTypes[idx] == iSeq) { min = fRanges[idx].first.iVal; max = fRanges[idx].second.iVal; } else { min = fRanges[idx].first.fVal; max = fRanges[idx].second.fVal; } val = _fRand() * (max - min) + min; } fts[n] = val; // initialise random _weightVal[n]._val = _gRand(SMRNDSD); } } // adjust so gives positive response int ttl = MAXADJITER; double act, sum = 0.0; for (int n=0; n<numWts; ++n) { if (_operations[n] == eq) sum += 1.0; sum += _weightVal[n]._val * fts[n]; } act = NeurFn(sum + _biasParam._val); //double margin = 0.1 * (Params::_MAXTARGET - Params::_MINTARGET); double target = (Params::_MAXTARGET - PointRep::_brInstance->_matchThreshold) / 2.0; double margin = (target - PointRep::_brInstance->_matchThreshold) / 2.0; double delta = act - target; while (fabs(delta) > margin && ttl--) { //double delta = act - Params::_MAXTARGET; double grad = delta * NeurDelta(act); updateWts(grad, _biasParam, FASTLR); for (int n=0; n<numWts; ++n) { if (_operations[n] != other) continue; updateWts(grad * fts[n], _weightVal[n], FASTLR); } // find output again sum = 0.0; for (int n=0; n<numWts; ++n) { if (_operations[n] == eq) sum += 1.0; sum += _weightVal[n]._val * fts[n]; } act = NeurFn(sum + _biasParam._val); delta = act - target; } }
int main (int argc, char *argv[]) { int status = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) %T publisher main\n")); ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts(new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil()); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; topic_qos.history.depth = history_depth; ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil()); if (CORBA::is_nil (topic.in ())) { return 1 ; } // Create the publisher ::DDS::Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil()); if (CORBA::is_nil (pub.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_publisher failed.\n")), 1); } // Initialize the transport if (0 != ::init_writer_tranport() ) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) init_transport failed!\n")), 1); } // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast<OpenDDS::DCPS::PublisherImpl*> (pub.in ()); if (0 == pub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain servant ::OpenDDS::DCPS::PublisherImpl\n")), 1); } OpenDDS::DCPS::AttachStatus attach_status = pub_impl->attach_transport(writer_transport_impl.in()); if (attach_status != OpenDDS::DCPS::ATTACH_OK) { // We failed to attach to the transport for some reason. ACE_TString status_str; switch (attach_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; } ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str.c_str()), 1); } // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.history.depth = history_depth ; dw_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; dw_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC ; dw_qos.liveliness.lease_duration.nanosec = 0 ; ::DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, ::DDS::DataWriterListener::_nil()); if (CORBA::is_nil (dw.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // ensure that the connection and association has been fully established ACE_OS::sleep(2); //TBD remove this kludge when the transport is fixed. // Indicate that the publisher is ready FILE* writers_ready = ACE_OS::fopen (pub_ready_filename.c_str (), ACE_LIB_TEXT("w")); if (writers_ready == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR Unable to create publisher ready file\n"))); } // Wait for the subscriber to be ready. FILE* readers_ready = 0; do { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); readers_ready = ACE_OS::fopen (sub_ready_filename.c_str (), ACE_LIB_TEXT("r")); } while (0 == readers_ready); ACE_OS::fclose(writers_ready); ACE_OS::fclose(readers_ready); ReactorCtrl rc ; // stop the Service_Participant reactor so LIVELINESS.kind=AUTOMATIC does not // send out an automatic liveliness control message when sleeping in the loop // below. rc.pause() ; Writer* writer = new Writer(dw.in (), 1, num_ops_per_thread); for (int i = 0 ; i < num_unlively_periods ; i++) { writer->run_test (i); // 3 ensures that we will detect when an DataReader detects // liveliness lost on an already unliveliy DataReader. ACE_OS::sleep (3 * LEASE_DURATION_SEC); } writer->run_test (num_unlively_periods); rc.resume() ; bool writers_finished = false; ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for writers to finish\n") )); while ( !writers_finished ) { ACE_OS::sleep(ACE_Time_Value(0,250000)); writers_finished = true; writers_finished = writers_finished && writer->is_finished(); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T Writers are finished\n") )); // Indicate that the publisher is done FILE* writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_LIB_TEXT("w")); if (writers_completed == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR Unable to create publisher completed file\n"))); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for readers to finish\n") )); // Wait for the subscriber to finish. FILE* readers_completed = 0; do { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); readers_completed = ACE_OS::fopen (sub_finished_filename.c_str (), ACE_LIB_TEXT("r")); } while (0 == readers_completed); ACE_OS::fclose(writers_completed); ACE_OS::fclose(readers_completed); ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T Readers are finished\n") )); // Clean up publisher objects pub->delete_contained_entities() ; delete writer; dp->delete_publisher(pub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); // Moved TransportImpl reference release from just before exit from main // to here. This intended to fix the access violation in some optimize // build on linux during shutdown. I think TransportImpl object cleanup // may reference some resouces that already released. writer_transport_impl = 0; TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args(argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(MY_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->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("(%P|%t) create_subscriber failed.\n")), 1); } // Create the Datareaders ::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; ::DDS::DataReaderListener_var drl (new DataReaderListenerImpl); DataReaderListenerImpl* drl_servant = dynamic_cast<DataReaderListenerImpl*>(drl.in()); ::DDS::DataReader_var dr ; dr = sub->create_datareader(description.in (), dr_qos, drl.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); ACE_OS::sleep(test_duration); // clean up subscriber objects sub->delete_contained_entities() ; dp->delete_subscriber(sub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); if( drl_servant->deadline_missed() < threshold_liveliness_lost) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) subscriber: ") ACE_TEXT("liviness deadline not violated enough for test. ") ACE_TEXT("threshold( %d) < num missed( %d).\n"), threshold_liveliness_lost, drl_servant->deadline_missed() )); return 1; } else { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) subscriber: ") ACE_TEXT("liviness deadline violated enough to pass test. ") ACE_TEXT("threshold( %d) < num missed( %d).\n"), threshold_liveliness_lost, drl_servant->deadline_missed() )); } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int test_failed = 0; u_long mask = ACE_LOG_MSG->priority_mask(ACE_Log_Msg::PROCESS) ; ACE_LOG_MSG->priority_mask(mask | LM_TRACE | LM_DEBUG, ACE_Log_Msg::PROCESS) ; ACE_DEBUG((LM_DEBUG,"(%P|%t) FooTest5_0 main\n")); try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if (CORBA::is_nil (dpf.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) creating the DomainParticipantFactory failed.\n"))); return 1 ; } // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; topic_qos.history.depth = history_depth; ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(MY_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->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("(%P|%t) create_subscriber failed.\n")), 1); } // Create the publisher ::DDS::Publisher_var pub = dp->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("(%P|%t) create_publisher failed.\n")), 1); } // Initialize the transport if (0 != ::init_tranport() ) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) init_transport failed!\n")), 1); } // Attach the subscriber to the transport. OpenDDS::DCPS::SubscriberImpl* sub_impl = dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ()); if (0 == sub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain servant ::OpenDDS::DCPS::SubscriberImpl\n")), 1); } sub_impl->attach_transport(reader_transport_impl.in()); // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast<OpenDDS::DCPS::PublisherImpl*> (pub.in ()); if (0 == pub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain servant ::OpenDDS::DCPS::PublisherImpl\n")), 1); } pub_impl->attach_transport(writer_transport_impl.in()); // Create the datawriter ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.history.depth = history_depth ; dw_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; ::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 ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // Create the Datareader ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); dr_qos.history.depth = history_depth ; dr_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; ::DDS::DataReader_var dr = sub->create_datareader(description.in (), dr_qos, ::DDS::DataReaderListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dr.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_datareader failed.\n")), 1); } ::Xyz::FooDataWriter_var foo_dw = ::Xyz::FooDataWriter::_narrow(dw.in ()); if (CORBA::is_nil (foo_dw.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ::Xyz::FooDataWriter::_narrow failed.\n"))); return 1; // failure } ::Xyz::FooDataWriterImpl* fast_dw = dynamic_cast<Xyz::FooDataWriterImpl*>(foo_dw.in()); ::Xyz::FooDataReader_var foo_dr = ::Xyz::FooDataReader::_narrow(dr.in ()); if (CORBA::is_nil (foo_dr.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ::Xyz::FooDataReader::_narrow failed.\n"))); return 1; // failure } ::Xyz::FooDataReaderImpl* fast_dr = dynamic_cast<Xyz::FooDataReaderImpl*>(foo_dr.in()); // wait for association establishement before writing. ACE_OS::sleep(5); //REMOVE if not needed // =============== do the test ==== ::DDS::OfferedIncompatibleQosStatus incomp; if (foo_dw->get_offered_incompatible_qos_status (incomp) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("ERROR: failed to get offered incompatible qos status\n")), 1); } int incompatible_transport_found = 0; for (CORBA::ULong ii =0; ii < incomp.policies.length (); ii++) { if (incomp.policies[ii].policy_id == ::OpenDDS::TRANSPORTTYPE_QOS_POLICY_ID) incompatible_transport_found = 1; } ::DDS::SubscriptionMatchedStatus matched; if (foo_dr->get_subscription_matched_status (matched) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("ERROR: failed to get subscription matched status\n")), 1); } ::DDS::InstanceHandle_t handle; if (pub_using_udp != sub_using_udp) { if (!incompatible_transport_found) ACE_ERROR_RETURN((LM_ERROR, "TEST ERROR: Expected offered_incompatible_qos" " with TRANSPORTTYPE_QOS_POLICY_ID" " but did not get it. %d incompatible_qos values.\n", incomp.policies.length ()), 7); else { ACE_DEBUG((LM_DEBUG, "Got expected offered_incompatible_qos" " with TRANSPORTTYPE_QOS_POLICY_ID" " existing with success.\n")); goto cleanup; } } else { if (incompatible_transport_found) ACE_ERROR_RETURN((LM_ERROR, "TEST ERROR: Did not expect offered_incompatible_qos" " with TRANSPORTTYPE_QOS_POLICY_ID" " but got it. %d incompatible_qos values.\n", incomp.policies.length ()), 8); if (matched.total_count != 1) ACE_ERROR_RETURN((LM_ERROR, "TEST ERROR: expected subscription_match" " with count 1 but got %d\n", matched.total_count), 9); } ::Xyz::Foo foo; foo.key = 10101; foo.x = -1; foo.y = -1; handle = fast_dw->register_instance(foo); foo.x = 7; fast_dw->write(foo, handle); ::Xyz::Foo sample; ::DDS::SampleInfo info ; // wait for new data for upto 10 seconds if (!wait_for_data(sub.in (), 5)) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: timeout waiting for data.\n")), 1); DDS::ReturnCode_t status ; status = fast_dr->read_next_sample(sample, info) ; if (status == ::DDS::RETCODE_OK) { ACE_DEBUG((LM_DEBUG, "read foo.x = %f foo.y = %f, foo.key = %d\n", sample.x, sample.y, sample.key)); ACE_DEBUG((LM_DEBUG, "read SampleInfo.sample_rank = %d\n", info.sample_rank)); if (foo.x != sample.x) { ACE_ERROR((LM_ERROR, "ERROR: unexpected foo value wrote %f got %f\n", foo.x, sample.x)); test_failed = 1; } } else if (status == ::DDS::RETCODE_NO_DATA) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: reader received ::DDS::RETCODE_NO_DATA!\n") )); test_failed = 1; } else { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: unexpected status %d!\n"), status )); test_failed = 1; } //======== clean up ============ cleanup: // Clean up publisher objects // pub->delete_contained_entities() ; pub->delete_datawriter(dw.in ()); dp->delete_publisher(pub.in ()); //clean up subscriber objects // sub->delete_contained_entities() ; sub->delete_datareader(dr.in ()); dp->delete_subscriber(sub.in ()); // clean up common objects dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); reader_transport_impl = 0; writer_transport_impl = 0; TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return test_failed; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(MY_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->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("(%P|%t) create_subscriber failed.\n")), 1); } // Create the Datareaders ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); dr_qos.durability.kind = durability_kind; dr_qos.liveliness.kind = liveliness_kind; dr_qos.liveliness.lease_duration = LEASE_DURATION; dr_qos.reliability.kind = reliability_kind; ::DDS::DataReaderListener_var drl (new DataReaderListenerImpl); DataReaderListenerImpl* drl_servant = dynamic_cast<DataReaderListenerImpl*>(drl.in()); if (!drl_servant) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: drl_servant is nil (dynamic_cast failed)!\n")), -1); } ::DDS::DataReader_var dr(sub->create_datareader(description.in (), dr_qos, drl.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK)); ACE_OS::sleep(test_duration); // clean up subscriber objects dp->delete_contained_entities() ; dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); // there is an error if we matched when not compatible (or vice-versa) if (drl_servant->subscription_matched() != compatible) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Expected subscription_matched to be %C, but it wasn't.") ACE_TEXT("durability_kind=%s,liveliness_kind=%s,liveliness_duration=%s,") ACE_TEXT("reliability_kind=%s\n"), (compatible) ? "true" : "false", durability_kind_str.c_str(), liveliness_kind_str.c_str(), LEASE_DURATION_STR.c_str(), reliability_kind_str.c_str())); return 1; } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } catch (const std::exception& ex) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) std::exception caught in main.cpp: %C\n"), ex.what())); return 1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_topic failed!\n")), 1); } OpenDDS::DCPS::TransportImpl_rch writer_transport_impl; // Initialize the transport if (0 != ::init_writer_tranport(writer_transport_impl) ) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) init_transport failed!\n")), 1); } // Create the publisher ::DDS::Publisher_var pub = dp->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("(%P|%t) create_publisher failed.\n")), 1); } // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast<OpenDDS::DCPS::PublisherImpl*> (pub.in ()); if (0 == pub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain servant ::OpenDDS::DCPS::PublisherImpl\n")), 1); } OpenDDS::DCPS::AttachStatus attach_status = pub_impl->attach_transport(writer_transport_impl.in()); if (attach_status != OpenDDS::DCPS::ATTACH_OK) { // We failed to attach to the transport for some reason. ACE_TString status_str; switch (attach_status) { case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT: status_str = ACE_TEXT("ATTACH_BAD_TRANSPORT"); break; case OpenDDS::DCPS::ATTACH_ERROR: status_str = ACE_TEXT("ATTACH_ERROR"); break; case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS: status_str = ACE_TEXT("ATTACH_INCOMPATIBLE_QOS"); break; default: status_str = ACE_TEXT("Unknown Status"); break; } ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str.c_str()), 1); } // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.durability.kind = durability_kind; dw_qos.liveliness.kind = liveliness_kind; dw_qos.liveliness.lease_duration = LEASE_DURATION; dw_qos.reliability.kind = reliability_kind; ::DDS::DataWriterListener_var dwl (new DataWriterListenerImpl); ::DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, dwl.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // Writer writer(dw.in ()); // ACE_Time_Value duration(10); // writer.run_test(duration); ACE_OS::sleep(test_duration); // Clean up publisher objects pub->delete_contained_entities() ; dp->delete_publisher(pub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheTransportFactory->release(); TheServiceParticipant->shutdown (); { DataWriterListenerImpl* dwl_servant = dynamic_cast<DataWriterListenerImpl*>(dwl.in()); // check to see if the publisher worked if(dwl_servant->publication_matched() != compatible) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Expected publication_matched to be %C, but it wasn't.") ACE_TEXT("durability_kind=%s,liveliness_kind=%s,liveliness_duration=%s,") ACE_TEXT("reliability_kind=%s\n"), (compatible) ? "true" : "false", durability_kind_str.c_str(), liveliness_kind_str.c_str(), LEASE_DURATION_STR.c_str(), reliability_kind_str.c_str())); return 1 ; } } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) create_topic failed!\n")), 1); } // Create the publisher ::DDS::Publisher_var pub = dp->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("(%P|%t) create_publisher failed.\n")), 1); } // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC; dw_qos.liveliness.lease_duration.nanosec = 0; ::DDS::DataWriterListener_var dwl (new DataWriterListenerImpl); ::DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, dwl.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); return 1 ; } // Writer writer(dw.in ()); // ACE_Time_Value duration(10); // writer.run_test(duration); ACE_OS::sleep(test_duration); // Clean up publisher objects pub->delete_contained_entities() ; dp->delete_publisher(pub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); // check to see if the publisher worked { DataWriterListenerImpl* dwl_servant = dynamic_cast<DataWriterListenerImpl*>(dwl.in()); if(!dwl_servant->valid()) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) publisher didn't connect with subscriber. test_duration=%d\n"), test_duration)); return 1 ; } } } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) %T subscriber main\n")); ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // TheServiceParticipant->liveliness_factor(100) ; // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::Xyz::FooTypeSupport_var fts (new ::Xyz::FooTypeSupportImpl); ::DDS::DomainParticipant_var dp = dpf->create_participant(MY_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); return 1 ; } if (::DDS::RETCODE_OK != fts->register_type(dp.in (), MY_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooTypeSupport."))); return 1; } ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; topic_qos.history.depth = history_depth; ::DDS::Topic_var topic = dp->create_topic (MY_TOPIC, MY_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(MY_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->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("(%P|%t) create_subscriber failed.\n")), 1); } // Create the Datareaders ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); dr_qos.history.depth = history_depth ; dr_qos.resource_limits.max_samples_per_instance = max_samples_per_instance ; dr_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC ; dr_qos.liveliness.lease_duration.nanosec = 0 ; ::DDS::DataReaderListener_var drl (new DataReaderListenerImpl); DataReaderListenerImpl* drl_servant = dynamic_cast<DataReaderListenerImpl*>(drl.in()); ::DDS::DataReader_var dr ; dr = sub->create_datareader(description.in (), dr_qos, drl.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); // Indicate that the subscriber is ready FILE* readers_ready = ACE_OS::fopen (sub_ready_filename.c_str (), ACE_TEXT("w")); if (readers_ready == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Unable to create subscriber completed file\n"))); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for publisher to be ready\n") )); // 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.c_str (), ACE_TEXT("r")); } while (0 == writers_ready); ACE_OS::fclose(readers_ready); ACE_OS::fclose(writers_ready); ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T Publisher is ready\n") )); // Indicate that the subscriber is done // (((it is done when ever the publisher is done))) FILE* readers_completed = ACE_OS::fopen (sub_finished_filename.c_str (), ACE_TEXT("w")); if (readers_completed == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Unable to create subscriber completed file\n"))); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T waiting for publisher to finish\n") )); // Wait for the publisher to finish FILE* writers_completed = 0; do { ACE_Time_Value small_time(0,250000); ACE_OS::sleep (small_time); writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("r")); } while (0 == writers_completed); ACE_OS::fclose(readers_completed); ACE_OS::fclose(writers_completed); // // We need to wait for liveliness to go away here. // ACE_OS::sleep( 5); // // Determine the test status at this point. // ACE_OS::fprintf (stderr, "**********\n") ; ACE_OS::fprintf (stderr, "drl_servant->liveliness_changed_count() = %d\n", drl_servant->liveliness_changed_count()) ; ACE_OS::fprintf (stderr, "drl_servant->no_writers_generation_count() = %d\n", drl_servant->no_writers_generation_count()) ; ACE_OS::fprintf (stderr, "********** use_take=%d\n", use_take) ; if( drl_servant->liveliness_changed_count() < 2 + 2 * num_unlively_periods) { status = 1; // Some error condition. ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: subscriber - ") ACE_TEXT("test failed first condition.\n") )); } else if( drl_servant->verify_last_liveliness_status () == false) { status = 1; // Some other error condition. ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: subscriber - ") ACE_TEXT("test failed second condition.\n") )); } else if( drl_servant->no_writers_generation_count() != num_unlively_periods) { status = 1; // Yet another error condition. // Using take will remove the instance and instance state will be // reset for any subsequent samples sent. Since there are no // more samples sent, the information available from the listener // retains that from the last read sample rather than the reset // value for an (as yet unreceived) next sample. ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: subscriber - ") ACE_TEXT("test failed third condition.\n") )); } ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) %T publisher is finish - cleanup subscriber\n") )); // clean up subscriber objects sub->delete_contained_entities() ; dp->delete_subscriber(sub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }