bool StartLineProcessConnector::createReader() { DDSSubscriber *subscriber = RTIConnector::getSubscriber(); if(FAILURE==CControllerThread::getInstance()->CommandWriter("Monitoring_Library","psl_profile")) { g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> StartLineProcessConnector::CreateWriter Failure\n ", LOG_LOCATION); } if (NULL == m_read_topic) { g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> StartLineProcessConnector::CreateReader() m_read_topic is NULL for RTC! \n ", LOG_LOCATION); return false; } if (NULL != m_reader_cache) { g_cSystemLogger.LogMessage("(%s:%s:%d):: Error ---> RTCConnector::CreateReader() m_reader_cache exists for RTC!\n \n ", LOG_LOCATION); return false; } /* Create a data reader listener for cache */ LineProcessStatusListener *m_reader_listener_cache = new LineProcessStatusListener(); /* To customize the data reader QoS, use the configuration file USER_QOS_PROFILES.xml */ m_reader_cache = subscriber->create_datareader_with_profile(m_read_topic, "Monitoring_Library", "Monitoring_Profile", m_reader_listener_cache, DDS_STATUS_MASK_ALL); if (m_reader_cache == NULL) { g_cSystemLogger.LogMessage("(%s:%s:%d)::CreateReader() error for RTC\n \n ", LOG_LOCATION); delete m_reader_listener_cache; m_reader_listener_cache = NULL; return false; } g_cSystemLogger.LogMessage("(%s:%s:%d):: Create Reader sucess", LOG_LOCATION); return true; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { DDSTopic* topic = 0; DDSDataReader* data_reader = 0; DDSSubscriber* sub = 0; DDS_ReturnCode_t retcode = DDS_RETCODE_OK; QueryConditionTestDataReader* typed_dr = 0; DDSQueryCondition* qc = 0; DDSReadCondition* rc = 0; int run = 0; // NDDS_Config_LogVerbosity n_verbosity = // static_cast <NDDS_Config_LogVerbosity> (3); // NDDSConfigLogger::get_instance()->set_verbosity (n_verbosity); const ACE_TCHAR * env_domain_id = 0; if (argc > 1) { env_domain_id = argv[1]; } if (!env_domain_id) { printf ("Environment variable DEFAULT_DOMAIN_ID not set " "=> setting it to 2\n"); env_domain_id = "2"; } else printf ("Domain ID set to %s\n", env_domain_id); const int domain_id = ACE_OS::atoi (env_domain_id); DDSDomainParticipant *participant = DDSDomainParticipantFactory::get_instance()-> create_participant_with_profile (domain_id, /* Domain ID */ LIBRARY_NAME, /* QoS */ PROFILE_NAME, 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!participant) { cerr << "RECEIVER: Error creating participant" << endl; return 1; } retcode = QueryConditionTestTypeSupport::register_type( participant, QueryConditionTestTypeSupport::get_type_name ()); if (retcode != DDS_RETCODE_OK) { cerr << "RECEIVER: Error registering type" << endl; return clean_up (participant); } topic = participant->create_topic_with_profile ( "QC", /* Topic name*/ QueryConditionTestTypeSupport::get_type_name (), /* Type name */ LIBRARY_NAME, /* QoS */ PROFILE_NAME, 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!topic) { cerr << "RECEIVER: Error creating topic" << endl; return clean_up (participant); } sub = participant->create_subscriber_with_profile (LIBRARY_NAME, PROFILE_NAME, 0, 0); if (!sub) { cerr << "RECEIVER: Error creating subscriber" << endl; return clean_up (participant); } data_reader = sub->create_datareader_with_profile ( topic, LIBRARY_NAME, /* QoS */ PROFILE_NAME, 0, /* Listener */ DDS_STATUS_MASK_NONE); if (!data_reader) { cerr << "RECEIVER: Error creating data reader" << endl; return clean_up (participant); } typed_dr = QueryConditionTestDataReader::narrow (data_reader); if (!typed_dr) { cerr << "RECEIVER: Unable to cast to a type specific data reader" << endl; return clean_up (participant); } const char* PARAMS_RUN_1[] = {"1", "3"}; DDS_StringSeq parameters_run_1; parameters_run_1.from_array (PARAMS_RUN_1, 2); qc = typed_dr->create_querycondition ( DDS_NOT_READ_SAMPLE_STATE, DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE, DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE, "iteration > %0 AND iteration < %1", parameters_run_1); if (!qc) { cerr << "RECEIVER: Error creating query condition" << endl; return clean_up (participant); } else cout << "RECEIVER: query condition created : iteration > 1 AND iteration < 3" << endl; ws_->attach_condition (qc); cout << "RECEIVER: Expecting two samples (key_1 and key_2) with iteration 2." <<endl; read (data_reader, qc, rc, ++run); //Second run: change the parameters if (qc) { const char* PARAMS_RUN_2[] = {"4", "6"}; DDS_StringSeq parameters_run_2; parameters_run_2.from_array (PARAMS_RUN_2, 2); if (qc->set_query_parameters (parameters_run_2) != DDS_RETCODE_OK) { cerr << "RECEIVER: Unable the set the new query parameters!!!" << endl; return clean_up (participant); } } cout << "RECEIVER: query condition changed : iteration > 4 AND iteration < 6" << endl; cout << "RECEIVER: Expecting two samples (key_1 and key_2) with iterations 5" <<endl; read (data_reader, qc, rc, ++run); // Third run: Detach querycondition and create read condition instead. // Remove the qc from the waitset and create a readcondition and start receiving // samples if (ws_->detach_condition (qc) != DDS_RETCODE_OK) { cerr << "RECEIVER: Error detaching query condition" << endl; return clean_up (participant); } // Delete the query condition from the data reader typed_dr->delete_readcondition (qc); cout << "RECEIVER: query condition deleted" << endl; cout << "RECEIVER: create read condition : DDS_NOT_READ_SAMPLE_STATE," << "DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE," << "DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE" << endl; sleep_now(10); rc = typed_dr->create_readcondition ( DDS_NOT_READ_SAMPLE_STATE, DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE, DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE); if (!rc) { cerr << "RECEIVER: Error creating read condition" << endl; return clean_up (participant); } if (ws_->attach_condition (rc) != DDS_RETCODE_OK) { cerr << "RECEIVER: Error attaching read condition" << endl; return clean_up (participant); } cout << "RECEIVER: Expecting ALL UNREAD samples (key_1 and key_2) with iterations between 1 and 9, except 2 and 5" <<endl; read (data_reader, qc, rc, ++run); return clean_up (participant); }