StartLineProcessConnector::StartLineProcessConnector(const char* rd_topic) {
    DDS_ReturnCode_t retcode_cache;
    DDSDomainParticipant *participant = RTIConnector::getParticipant();
    m_read_topic = NULL;
    pt_rtc = NULL;
    m_reader_cache = NULL;

    if (rd_topic == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->rd_topic is NULL \n", LOG_LOCATION);
        return;
    }
    if (participant == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Participant is NULL \n", LOG_LOCATION);
        return;
    }

    /* Register the type before creating the topic for RTC */
    m_type_name_cache = MONITORING::leaseProcessStartTypeSupport::get_type_name();
    retcode_cache = MONITORING::leaseProcessStartTypeSupport::register_type(participant, m_type_name_cache);
    if (retcode_cache != DDS_RETCODE_OK) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Register Type RTC ERROR \n", LOG_LOCATION);
        m_type_name_cache = NULL;
        return;
    }
    if (NULL == m_read_topic) {
        /* To customize the topic QoS, use the configuration file USER_QOS_PROFILES.xml */
        m_read_topic = participant->create_topic(rd_topic, m_type_name_cache, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */
                , DDS_STATUS_MASK_NONE);
        if (m_read_topic == NULL) {
            g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->create topic success is NULL \n", LOG_LOCATION);
            return;
        }
    }
    g_cSystemLogger.LogMessage("(%s:%s:%d)::  --->create topic success \n", LOG_LOCATION);

}
Beispiel #2
0
	void MyPublisher::publish(unsigned short *image, const std::string& qosProfileName, 
		uint32_t domainId, const std::string& topic)
	{
		DDSDomainParticipant *participant = DDSDomainParticipantFactory::get_instance()->
			create_participant_with_profile(
											domainId,
											"DataExchangeProfile",
											qosProfileName.c_str(),
											NULL,
											DDS_STATUS_MASK_NONE);

		if(participant == NULL) {
			std::cout << "Error while creating participant" << std::endl;
		}

		DataExchangeTypeSupport::register_type(participant, DataExchangeTypeSupport::get_type_name());

		DDSTopic *ddstopic = participant->create_topic(
			topic.c_str(),
			DataExchangeTypeSupport::get_type_name(),
			DDS_TOPIC_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(ddstopic == NULL) {
			std::cout << "Publisher: Error while creating topic: " << topic << std::endl;
			std::cout << "With typename: " << DataExchangeTypeSupport::get_type_name() << std::endl;
		}

		DDSPublisher *publisher = participant->create_publisher(
			DDS_PUBLISHER_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(publisher == NULL) {
			std::cout << "Error while creating publisher" << std::endl;
		}

		DDSDataWriter *dataWriter = publisher->create_datawriter(
			ddstopic,
			DDS_DATAWRITER_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(dataWriter == NULL) {
			std::cout << "Error while creating dataWriter" << std::endl;
		}

		DataExchangeDataWriter *dataExchangeWriter    = NULL;
		dataExchangeWriter = DataExchangeDataWriter::narrow(dataWriter);

		DDS_Duration_t disc_period = {1,0};
		NDDSUtility::sleep(disc_period);

		DataExchange *instance                 = NULL;

		instance = DataExchangeTypeSupport::create_data_ex(DDS_BOOLEAN_FALSE);
		int rows = 1024;
		int cols = 1024;
		DDS_UnsignedShortSeq_ensure_length(&instance->pixels, rows*cols, MAX_PIXELS_SEQUENCE_LENGTH);

		for (int i = 0; i < rows*cols; ++i) {
			instance->pixels[i] = i;
		}

		std::cout << "Sending dataaa...";
		instance->rows = rows;
		instance->cols = cols;
		dataExchangeWriter->write(*instance, DDS_HANDLE_NIL);
		std::cout << " DONE!" << std::endl;
	}