Beispiel #1
0
DDS_ReturnCode_t DDS_StringDataWriter_write (DDS_DataWriter dw,
					     const char *data,
					     const DDS_InstanceHandle_t h)
{
	DDS_String	s;

	s.value = (char *) data;
	return (DDS_DataWriter_write (dw, &s, h));
}
Beispiel #2
0
void DDS_Security_log (unsigned   log_level,
		       const char *message,
		       const char *category)
{
	struct timeval	tv;
	FILE		*f;
	struct tm	tm_data, *tm;
	char		tmbuf [40];
	DDS_LogInfo	log_info;

	if (!log_options_set || log_level < log_options.log_level)
		return;

	if (!log_options.log_file && !log_options.distribute) {
		log_printf (SEC_ID, log_level, "%s: %s\r\n", category, message);
		return;
	}
	if (log_options.log_file) {
		if (openf (f, logname, "a")) {
			gettimeofday (&tv, NULL);
#ifdef _WIN32
			_localtime32_s (&tm_data, &tv.tv_sec);
			tm = &tm_data;
#else
			tm = localtime_r (&tv.tv_sec, &tm_data);
			if (!tm) {
#ifdef LOG_DATE
				fprintf (f, "\?\?\?\?-\?\?\?-\?\? ");
#endif
				fprintf (f, "\?\?:\?\?:\?\?.\?\?\? ");
			}
			else
#endif
			{
				tmbuf [0] = '\0';
#ifdef LOG_DATE
				strftime (tmbuf, sizeof (tmbuf), "%Y-%m-%d ", tm);
#endif
				strftime (&tmbuf [strlen (tmbuf)],
						sizeof (tmbuf) - strlen (tmbuf),
						"%H:%M:%S.", tm);
				snprintf (&tmbuf [strlen (tmbuf)],
					  sizeof (tmbuf) - strlen (tmbuf),
					  "%03lu ", (unsigned long) tv.tv_usec / 1000);
				fprintf (f, "%s", tmbuf);
			}
			fprintf (f, "%s: %s\r\n", category, message);
			fclose (f);
		}
	}
	if (log_options.distribute && log_writer) {
		log_info.log_level = log_level;
		log_info.message = (char *) message;
		log_info.category = (char *) category;
		DDS_DataWriter_write (log_writer, &log_info, 0);
	}
}
Beispiel #3
0
DDS_ReturnCode_t DDS_KeyedStringDataWriter_write_string_w_key(DDS_DataWriter dw,
							      const char *key,
							      const char *str,
							      const DDS_InstanceHandle_t h)
{
	DDS_KeyedString	ks;

	ks.key = (char *) key;
	ks.value = (char *) str;
	return (DDS_DataWriter_write (dw, &ks, h));
}
Beispiel #4
0
DDS_ReturnCode_t DDS_BytesDataWriter_write_w_bytes (DDS_DataWriter dw,
						    const unsigned char *bytes,
						    int offset,
						    int length,
						    const DDS_InstanceHandle_t h)
{
	DDS_Bytes	bs;

	bs.value._maximum = bs.value._length = length;
	bs.value._esize = 1;
	bs.value._own = 1;
	bs.value._buffer = (unsigned char *) bytes + offset;
	return (DDS_DataWriter_write (dw, &bs, h));
}
Beispiel #5
0
int
dds_write (
    dds_entity_t wr,
    const void *data)
{
    DDS_ReturnCode_t result;

    DDS_REPORT_STACK();

    result = DDS_DataWriter_write(wr, (const DDS_Sample)data, DDS_HANDLE_NIL);

    DDS_REPORT_FLUSH(wr, result != DDS_RETCODE_OK);

    return DDS_ERRNO(result, DDS_MOD_WRITER, DDS_ERR_Mx);
}
Beispiel #6
0
DDS_ReturnCode_t DDS_KeyedBytesDataWriter_write_bytes_w_key (DDS_DataWriter dw,
							     const char *key,
							     const unsigned char *bytes,
							     int offset,
							     int length,
							     const DDS_InstanceHandle_t h)
{
	DDS_KeyedBytes	kb;

	kb.key = (char *) key;
	kb.value._length = kb.value._maximum = length;
	kb.value._esize = 1;
	kb.value._own = 1;
	kb.value._buffer = (unsigned char *) bytes + offset;
	return (DDS_DataWriter_write (dw, &kb, h));
}
Beispiel #7
0
static void make_state_writer (int id)
{
	DDS_DataWriterQos wr_qos;
	DDS_ReturnCode_t error;
	static DDS_InstanceHandle_t handle;
	MsgData_t data;
	

	printf ("Create Writer\r\n");

	/* === create publisher === */

	pub = DDS_DomainParticipant_create_publisher (part, NULL, NULL, 0);
	if (!pub) {
		fatal ("DDS_DomainParticipant_create_publisher () failed!");
		DDS_DomainParticipantFactory_delete_participant (part);
	}

	/* Test get_qos() fynctionality. */
	if ((error = DDS_Publisher_get_qos (pub, &pqos)) != DDS_RETCODE_OK)
		fatal ("DDS_Publisher_get_qos () failed (%s)!", DDS_error (error));

	/* Setup writer QoS parameters. */
	DDS_Publisher_get_default_datawriter_qos (pub, &wr_qos);

	/* === create the writer === */

	wr_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
        wr_qos.history.depth = 1;
        wr_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
        wr_qos.durability.kind  = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
        wr_qos.ownership.kind   = DDS_EXCLUSIVE_OWNERSHIP_QOS;

	dw = DDS_Publisher_create_datawriter (pub, topic, &wr_qos, NULL, sm);
	if (!dw) {
		fatal ("Unable to create a writer \r\n");
		DDS_DomainParticipantFactory_delete_participant (part);
	}

	/* === While true, add sample, remove sample === */
	if (tsm_type == 0) {
		data.key = id;
		data.counter = 100 + id;
		strcpy (data.message, "Hi folks!");
		
		if (test == 3) {
			printf ("Register instance\r\n");
			DDS_DataWriter_register_instance (dw, &data);
			printf ("Write data\r\n");
			if ((error = DDS_DataWriter_write (dw, &data, DDS_HANDLE_NIL)))
				printf ("Error writing data\r\n");
			
			sleep (5);
			
			sem_wait (&_sync);
			sem_wait (&_sync);
			
			printf ("Unregister instance\r\n");
			if ((error = DDS_DataWriter_unregister_instance(dw, &data, DDS_HANDLE_NIL)))
				printf ("Error unregistering instance\r\n");
			
			sleep (5);
			
			sem_wait (&_sync);
			sem_wait (&_sync);
			
			return;
		}
	} else {
		if (test == 3) {
			_types1.i8 = key;
			printf ("Register instance\r\n");
			DDS_DataWriter_register_instance (dw, &_types1);
			printf ("Write data\r\n");
			if ((error = DDS_DataWriter_write (dw, &_types1, DDS_HANDLE_NIL)))
				printf ("Error writing data\r\n");
			
			sleep (5);
			
			sem_wait (&_sync);
			sem_wait (&_sync);
			
			printf ("Unregister instance\r\n");
			if ((error = DDS_DataWriter_unregister_instance(dw, &_types1, DDS_HANDLE_NIL)))
				printf ("Error unregistering instance\r\n");
			
			sleep (5);
			
			sem_wait (&_sync);
			sem_wait (&_sync);
			
			return;
		}
	}

	if (test == 0) {
		printf ("Register instance\r\n");
		DDS_DataWriter_register_instance (dw, &data);
		printf ("Write data\r\n");
		if ((error = DDS_DataWriter_write (dw, &data, DDS_HANDLE_NIL)))
			printf ("Error writing data\r\n");
		
		sleep (2);
		printf ("Unregister instance\r\n");
		if ((error = DDS_DataWriter_unregister_instance(dw, &data, DDS_HANDLE_NIL)))
			printf ("Error unregistering instance\r\n");
		
		sleep (2);
		if (reader)
			remove_state_reader ();
	} else if (test >= 1) {
		while (1) {
			printf ("Register instance\r\n");
			handle = DDS_DataWriter_register_instance (dw, &data);
			printf ("Write data\r\n");
			if ((error = DDS_DataWriter_write (dw, &data, handle)))
				printf ("Error writing data\r\n");
			sleep (1);
			if (test == 1) {
				printf ("Unregister instance\r\n");
				if ((error = DDS_DataWriter_unregister_instance(dw, &data, handle)))
					printf ("Error unregistering instance\r\n");
			} else {
				printf ("Dispose instance\r\n");
				if ((error = DDS_DataWriter_dispose (dw, &data, handle)))
					printf ("Error disposing instance\r\n");
			}
			sleep (1);
		}
	}
}
Beispiel #8
0
DDS_ReturnCode_t DDS_BytesDataWriter_write (DDS_DataWriter dw,
					    const DDS_Bytes *data,
					    const DDS_InstanceHandle_t h)
{
	return (DDS_DataWriter_write (dw, data, h));
}
Beispiel #9
0
DDS_ReturnCode_t DDS_KeyedStringDataWriter_write (DDS_DataWriter dw,
						  const DDS_KeyedString *data,
						  const DDS_InstanceHandle_t h)
{
	return (DDS_DataWriter_write (dw, data, h));
}
Beispiel #10
0
int main(int argc, char* argv[])
{
	int startTime = mstime();
	DDS_PoolConstraints reqs;
	DDS_DomainParticipant    domainParticipant;
	DDS_Publisher    publisher;
	DDS_Subscriber    subscriber;
	DDS_ReturnCode_t retCode;
	char *configTopicName[nofConfigTopics];
	DDS_Topic configTopic[nofConfigTopics];
	DDS_Topic stateTopic[nofStateTopics];
	DDS_Topic statisticTopic[nofStatisticTopics];
	DDS_DataWriterQos dataWriterQos;
	DDS_DataWriter    configDataWriter[nofConfigTopics];
	DDS_DataWriter    stateDataWriter[nofStateTopics];
	DDS_DataWriter    statisticDataWriter[nofStatisticTopics];
	DDS_DataReaderQos dataReaderQos;
	DDS_DataReader    configDataReader[nofConfigTopics];
	acceptance_high_end_Config config;
	acceptance_high_end_State state;
	acceptance_high_end_Statistic statistic;
	DDS_InstanceHandle_t configInstance[nofConfigTopics][nofConfigInstances];
	DDS_InstanceHandle_t stateInstance[nofStateTopics][nofStateInstances];
	DDS_InstanceHandle_t statisticInstance[nofStatisticTopics][nofStatisticInstances];
	int i = 0;
	int j = 0;

	int firstConfigTopic = (argc > 1) ? atoi(argv[1]) : 0;
	int firstStateTopic = (argc > 2) ? atoi(argv[2]) : 0;
	int firstStatisticTopic = (argc > 3) ? atoi(argv[3]) : 0;
	int stagedLoading = (argc > 4) ? atoi(argv[4]) : 0;
	printf("[0] Config topics start at %d...\r\n", firstConfigTopic);
	printf("[0] State topics start at %d...\r\n", firstStateTopic);
	printf("[0] Statistic topics start at %d...\r\n", firstStatisticTopic);
	printf("[0] Staged loading %s.\r\n", stagedLoading ? "on" : "off");

	if (stagedLoading) {
		char file_name[24];
		sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic);
		struct stat buf;
		if (stat(file_name, &buf)) {
			printf ("[%d] Waiting for %s\r\n", mstime() - startTime, file_name);
			do {
				sleep(1);
			}
			while (stat(file_name, &buf));
			printf ("[%d] Got %s!\r\n", mstime() - startTime, file_name);
		}
	}

        DDS_program_name (&argc, argv);
	DDS_entity_name ("Technicolor Limits Component");
	DDS_get_default_pool_constraints(&reqs, ~0, 100);
#ifdef MINIMAL_POOLS
	configure_minimal_pool_constraints (&reqs);
#else
	configure_optimal_pool_constraints (&reqs);
#endif
	DDS_set_pool_constraints(&reqs);

#ifdef DDS_DEBUG
	DDS_Debug_start ();
#endif

	/* Create domain participant... */
	domainParticipant = DDS_DomainParticipantFactory_create_participant(0, NULL, NULL, 0);
	if (!domainParticipant) {
		fprintf(stderr, "Error creating domain participant.\r\n");
		return -1;
	}
	printf("[%d] Created domain participant.\r\n", mstime() - startTime);
	sleep(1);

	/* Create publisher... */
	publisher = DDS_DomainParticipant_create_publisher(domainParticipant, NULL, NULL, 0);
	if (!publisher) {
		fprintf(stderr, "Error creating publisher.\r\n");
		return -1;
	}
	printf("[%d] Created publisher.\r\n", mstime() - startTime);
	sleep(1);

	/* Create subscriber... */
	subscriber = DDS_DomainParticipant_create_subscriber(domainParticipant, NULL, NULL, 0);
	if (!subscriber) {
		fprintf(stderr, "Error creating subscriber.\r\n");
		return -1;
	}
	printf("[%d] Created subscriber.\r\n", mstime() - startTime);
	sleep(1);

	/* Register types... */
	retCode = acceptance_high_end_ConfigTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered config type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StateTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered state type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StatisticTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered statistic type.\r\n", mstime() - startTime);
	sleep(1);

	/* Create topics... */
	for (i = 0; i < nofConfigTopics; i++) {
		char topicName[32];
		sprintf(topicName, "ConfigTopic%d", firstConfigTopic + i);
		configTopicName[i] = strdup (topicName);
		configTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_ConfigTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!configTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config topics.\r\n", mstime() - startTime, nofConfigTopics);
	for (i = 0; i < nofStateTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StateTopic%d", firstStateTopic + i);
		stateTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StateTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!stateTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state topics.\r\n", mstime() - startTime, nofStateTopics);
	for (i = 0; i < nofStatisticTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StatisticTopic%d", firstStatisticTopic + i);
		statisticTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StatisticTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!statisticTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic topics.\r\n", mstime() - startTime, nofStatisticTopics);
	sleep(1);

	/* Create data writers... */
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataWriter[i] = DDS_Publisher_create_datawriter(publisher, configTopic[i], &dataWriterQos, NULL, 0);

		if (!configDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data writers.\r\n", mstime() - startTime, nofConfigTopics);
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofStateTopics; i++) {
		stateDataWriter[i] = DDS_Publisher_create_datawriter(publisher, stateTopic[i], &dataWriterQos, NULL, 0);
		if (!stateDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state data writers.\r\n", mstime() - startTime, nofStateTopics);
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	for (i = 0; i < nofStatisticTopics; i++) {
		statisticDataWriter[i] = DDS_Publisher_create_datawriter(publisher, statisticTopic[i], &dataWriterQos, NULL, 0);
		if (!statisticDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic data writers.\r\n", mstime() - startTime, nofStatisticTopics);
	sleep(1);

	/* Create data readers... */
	DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos);
	dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, configTopicName[i]), &dataReaderQos, NULL, 0);
		if (!configDataReader[i]) {
			fprintf(stderr, "Error creating data reader.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data readers.\r\n", mstime() - startTime, nofConfigTopics);
	sleep(1);

	/* Register instances... */
	for (i = 0; i < nofConfigTopics; i++) {
		for (j = 0; j < nofConfigInstances; j++) {
			config.key = j;
			configInstance[i][j] = DDS_DataWriter_register_instance(configDataWriter[i], &config);
			if (!configInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d config instances.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances);
	for (i = 0; i < nofStateTopics; i++) {
		for (j = 0; j < nofStateInstances; j++) {
			state.key = j;
			stateInstance[i][j] = DDS_DataWriter_register_instance(stateDataWriter[i], &state);
			if (!stateInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d state instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	for (i = 0; i < nofStatisticTopics; i++) {
		for (j = 0; j < nofStatisticInstances; j++) {
			statistic.key = j;
			statisticInstance[i][j] = DDS_DataWriter_register_instance(statisticDataWriter[i], &statistic);
			if (!statisticInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d statistic instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	sleep(1);

	/* Publish samples... */
	for (i = 0; i < nofConfigTopics; i++) {
		for (j = 0; j < nofConfigInstances; j++) {
			config.key = j;
			retCode = DDS_DataWriter_write(configDataWriter[i], &config, configInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d config samples.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances);
	for (i = 0; i < nofStateTopics; i++) {
		for (j = 0; j < nofStateInstances; j++) {
			state.key = j;
			retCode = DDS_DataWriter_write(stateDataWriter[i], &state, stateInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d state samples.\r\n", mstime() - startTime, nofStateTopics * nofStateInstances);
	for (i = 0; i < nofStatisticTopics; i++) {
		for (j = 0; j < nofStatisticInstances; j++) {
			statistic.key = j;
			retCode = DDS_DataWriter_write(statisticDataWriter[i], &statistic, statisticInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d statistic samples.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	sleep(1);

	if (stagedLoading) {
		char file_name[24];
		sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic + nofConfigTopics);
		FILE *f = fopen(file_name, "w");
		fclose(f);
	}

//	dbg_printf ("Zzzzzzz ... \r\n");
	sleep(TEST_TIME);
//	dbg_printf ("... o?\r\n");

	/* Delete contained entities... */
//	printf (" -- deleting contained entities.\r\n");
	retCode = DDS_DomainParticipant_delete_contained_entities(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting contained entities.\r\n");
		return -1;
	}

	for (i = 0; i < nofConfigTopics; i++)
		free (configTopicName[i]);

//	printf (" -- contained entities deleted!\r\n");
//	sleep(TEST_TIME);

	/* Delete domain participants... */
	retCode = DDS_DomainParticipantFactory_delete_participant(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting domain participant.\r\n");
		return -1;
	}

	printf ("[%d] comp completed successfully.\r\n", mstime() - startTime); 
	return 0;
}