Rearrange and fixup abstraction layer

- Replace os_result by dds_retcode_t and move DDS return code defines down.
  Eliminates the need to convert between different return code types.

- Move dds_time_t down and remove os_time.
  Eliminates the need to convert between different time representations and
  reduces code duplication.

- Remove use of Microsoft source-code annotation language (SAL).
  SAL annotations are Microsoft specific and not very well documented. This
  makes it very difficult for contributers to write.

- Rearrange the abstraction layer to be feature-based. The previous layout
  falsely assumed that the operating system dictates which implementation is
  best suited. For general purpose operating systems this is mostly true, but
  embedded targets require a slightly different approach and may not even offer
  all features. The new layout makes it possible to mix-and-match feature
  implementations and allows for features to not be implemented at all.

- Replace the os prefix by ddsrt to avoid name collisions.

- Remove various portions of unused and unwanted code.

- Export thread names on all supported platforms.

- Return native thread identifier on POSIX compatible platforms.

- Add timed wait for condition variables that takes an absolute time.

- Remove system abstraction for errno. The os_getErrno and os_setErrno were
  incorrect. Functions that might fail now simply return a DDS return code
  instead.

- Remove thread-specific memory abstraction. os_threadMemGet and accompanying
  functions were a mess and their use has been eliminated by other changes in
  this commit.

- Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name
  collisions and problems with faulty __nonnull__ attributes.

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-01-18 14:10:19 +01:00
parent 318968f40f
commit cd6742ee12
439 changed files with 22117 additions and 28782 deletions

View file

@ -1,61 +1,66 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "HelloWorldData.h"
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char ** argv)
{
dds_entity_t participant;
dds_entity_t topic;
dds_entity_t writer;
dds_return_t ret;
HelloWorldData_Msg msg;
(void)argc;
(void)argv;
dds_entity_t participant;
dds_entity_t topic;
dds_entity_t writer;
dds_return_t rc;
HelloWorldData_Msg msg;
uint32_t status = 0;
(void)argc;
(void)argv;
/* Create a Participant. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Create a Participant. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
if (participant < 0)
DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
/* Create a Topic. */
topic = dds_create_topic (participant, &HelloWorldData_Msg_desc,
"HelloWorldData_Msg", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Create a Topic. */
topic = dds_create_topic (
participant, &HelloWorldData_Msg_desc, "HelloWorldData_Msg", NULL, NULL);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* Create a Writer. */
writer = dds_create_writer (participant, topic, NULL, NULL);
/* Create a Writer. */
writer = dds_create_writer (participant, topic, NULL, NULL);
if (writer < 0)
DDS_FATAL("dds_create_write: %s\n", dds_strretcode(-writer));
printf("=== [Publisher] Waiting for a reader to be discovered ...\n");
printf("=== [Publisher] Waiting for a reader to be discovered ...\n");
ret = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS);
if (rc != DDS_RETCODE_OK)
DDS_FATAL("dds_set_status_mask: %s\n", dds_strretcode(-rc));
while(true)
{
uint32_t status;
ret = dds_get_status_changes (writer, &status);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
while(!(status & DDS_PUBLICATION_MATCHED_STATUS))
{
rc = dds_get_status_changes (writer, &status);
if (rc != DDS_RETCODE_OK)
DDS_FATAL("dds_get_status_changes: %s\n", dds_strretcode(-rc));
if (status == DDS_PUBLICATION_MATCHED_STATUS) {
break;
}
/* Polling sleep. */
dds_sleepfor (DDS_MSECS (20));
}
/* Polling sleep. */
dds_sleepfor (DDS_MSECS (20));
}
/* Create a message to write. */
msg.userID = 1;
msg.message = "Hello World";
/* Create a message to write. */
msg.userID = 1;
msg.message = "Hello World";
printf ("=== [Publisher] Writing : ");
printf ("Message (%d, %s)\n", msg.userID, msg.message);
printf ("=== [Publisher] Writing : ");
printf ("Message (%d, %s)\n", msg.userID, msg.message);
ret = dds_write (writer, &msg);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_write (writer, &msg);
if (rc != DDS_RETCODE_OK)
DDS_FATAL("dds_write: %s\n", dds_strretcode(-rc));
/* Deleting the participant will delete all its children recursively as well. */
ret = dds_delete (participant);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Deleting the participant will delete all its children recursively as well. */
rc = dds_delete (participant);
if (rc != DDS_RETCODE_OK)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc));
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

@ -1,4 +1,4 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "HelloWorldData.h"
#include <stdio.h>
#include <string.h>
@ -9,69 +9,74 @@
int main (int argc, char ** argv)
{
dds_entity_t participant;
dds_entity_t topic;
dds_entity_t reader;
HelloWorldData_Msg *msg;
void *samples[MAX_SAMPLES];
dds_sample_info_t infos[MAX_SAMPLES];
dds_return_t ret;
dds_qos_t *qos;
(void)argc;
(void)argv;
dds_entity_t participant;
dds_entity_t topic;
dds_entity_t reader;
HelloWorldData_Msg *msg;
void *samples[MAX_SAMPLES];
dds_sample_info_t infos[MAX_SAMPLES];
dds_return_t rc;
dds_qos_t *qos;
(void)argc;
(void)argv;
/* Create a Participant. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Create a Participant. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
if (participant < 0)
DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
/* Create a Topic. */
topic = dds_create_topic (participant, &HelloWorldData_Msg_desc,
"HelloWorldData_Msg", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Create a Topic. */
topic = dds_create_topic (
participant, &HelloWorldData_Msg_desc, "HelloWorldData_Msg", NULL, NULL);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* Create a reliable Reader. */
qos = dds_create_qos ();
dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10));
reader = dds_create_reader (participant, topic, qos, NULL);
DDS_ERR_CHECK (reader, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
dds_delete_qos(qos);
/* Create a reliable Reader. */
qos = dds_create_qos ();
dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10));
reader = dds_create_reader (participant, topic, qos, NULL);
if (reader < 0)
DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-reader));
dds_delete_qos(qos);
printf ("\n=== [Subscriber] Waiting for a sample ...\n");
printf ("\n=== [Subscriber] Waiting for a sample ...\n");
/* Initialize sample buffer, by pointing the void pointer within
* the buffer array to a valid sample memory location. */
samples[0] = HelloWorldData_Msg__alloc ();
/* Initialize sample buffer, by pointing the void pointer within
* the buffer array to a valid sample memory location. */
samples[0] = HelloWorldData_Msg__alloc ();
/* Poll until data has been read. */
while (true)
/* Poll until data has been read. */
while (true)
{
/* Do the actual read.
* The return value contains the number of read samples. */
rc = dds_read (reader, samples, infos, MAX_SAMPLES, MAX_SAMPLES);
if (rc < 0)
DDS_FATAL("dds_read: %s\n", dds_strretcode(-rc));
/* Check if we read some data and it is valid. */
if ((rc > 0) && (infos[0].valid_data))
{
/* Do the actual read.
* The return value contains the number of read samples. */
ret = dds_read (reader, samples, infos, MAX_SAMPLES, MAX_SAMPLES);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Check if we read some data and it is valid. */
if ((ret > 0) && (infos[0].valid_data))
{
/* Print Message. */
msg = (HelloWorldData_Msg*) samples[0];
printf ("=== [Subscriber] Received : ");
printf ("Message (%d, %s)\n", msg->userID, msg->message);
break;
}
else
{
/* Polling sleep. */
dds_sleepfor (DDS_MSECS (20));
}
/* Print Message. */
msg = (HelloWorldData_Msg*) samples[0];
printf ("=== [Subscriber] Received : ");
printf ("Message (%d, %s)\n", msg->userID, msg->message);
break;
}
else
{
/* Polling sleep. */
dds_sleepfor (DDS_MSECS (20));
}
}
/* Free the data location. */
HelloWorldData_Msg_free (samples[0], DDS_FREE_ALL);
/* Free the data location. */
HelloWorldData_Msg_free (samples[0], DDS_FREE_ALL);
/* Deleting the participant will delete all its children recursively as well. */
ret = dds_delete (participant);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
/* Deleting the participant will delete all its children recursively as well. */
rc = dds_delete (participant);
if (rc != DDS_RETCODE_OK)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc));
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

@ -1,4 +1,4 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "RoundTrip.h"
#include <stdio.h>
#include <stdlib.h>
@ -158,7 +158,8 @@ static void data_available(dds_entity_t rd, void *arg)
/* Take sample and check that it is valid */
preTakeTime = dds_time ();
status = dds_take (rd, samples, info, MAX_SAMPLES, MAX_SAMPLES);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_take: %s\n", dds_strretcode(-status));
postTakeTime = dds_time ();
/* Update stats */
@ -203,7 +204,8 @@ static void data_available(dds_entity_t rd, void *arg)
preWriteTime = dds_time();
status = dds_write_ts (writer, &pub_data, preWriteTime);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_write_ts: %s\n", dds_strretcode(-status));
postWriteTime = dds_time();
}
@ -270,7 +272,8 @@ int main (int argc, char *argv[])
}
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (participant < 0)
DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
if (use_listener)
{
@ -292,7 +295,8 @@ int main (int argc, char *argv[])
pub_data.payload._release = true;
pub_data.payload._maximum = 0;
status = dds_writedispose (writer, &pub_data);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_writedispose: %s\n", dds_strretcode(-status));
dds_sleepfor (DDS_SECS (1));
goto done;
}
@ -337,11 +341,14 @@ int main (int argc, char *argv[])
while (!dds_triggered (waitSet) && difference < DDS_SECS(5))
{
status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status));
if (status > 0 && listener == NULL) /* data */
{
status = dds_take (reader, samples, info, MAX_SAMPLES, MAX_SAMPLES);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_take: %s\n", dds_strretcode(-status));
}
time = dds_time ();
@ -365,12 +372,14 @@ int main (int argc, char *argv[])
/* Write a sample that pong can send back */
preWriteTime = dds_time ();
status = dds_write_ts (writer, &pub_data, preWriteTime);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_write_ts: %s\n", dds_strretcode(-status));
postWriteTime = dds_time ();
for (i = 0; !dds_triggered (waitSet) && (!numSamples || i < numSamples); i++)
{
status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status));
if (status != 0 && listener == NULL) {
data_available(reader, NULL);
}
@ -439,14 +448,16 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
/* A DDS_Topic is created for our sample type on the domain participant. */
topic = dds_create_topic (participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* A DDS_Publisher is created on the domain participant. */
pubQos = dds_create_qos ();
dds_qset_partition (pubQos, 1, pubPartitions);
publisher = dds_create_publisher (participant, pubQos, NULL);
DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (publisher < 0)
DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher));
dds_delete_qos (pubQos);
/* A DDS_DataWriter is created on the Publisher & Topic with a modified Qos. */
@ -454,7 +465,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
dds_qset_reliability (dwQos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10));
dds_qset_writer_data_lifecycle (dwQos, false);
*wr = dds_create_writer (publisher, topic, dwQos, NULL);
DDS_ERR_CHECK (*wr, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*wr < 0)
DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*wr));
dds_delete_qos (dwQos);
/* A DDS_Subscriber is created on the domain participant. */
@ -463,25 +475,29 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
dds_qset_partition (subQos, 1, subPartitions);
subscriber = dds_create_subscriber (participant, subQos, NULL);
DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (subscriber < 0)
DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber));
dds_delete_qos (subQos);
/* A DDS_DataReader is created on the Subscriber & Topic with a modified QoS. */
drQos = dds_create_qos ();
dds_qset_reliability (drQos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10));
*rd = dds_create_reader (subscriber, topic, drQos, listener);
DDS_ERR_CHECK (*rd, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*rd < 0)
DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*rd));
dds_delete_qos (drQos);
waitSet = dds_create_waitset (participant);
if (listener == NULL) {
*rdcond = dds_create_readcondition (*rd, DDS_ANY_STATE);
status = dds_waitset_attach (waitSet, *rdcond, *rd);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
} else {
*rdcond = 0;
}
status = dds_waitset_attach (waitSet, waitSet, waitSet);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
return participant;
}
@ -490,5 +506,6 @@ static void finalize_dds(dds_entity_t ppant)
{
dds_return_t status;
status = dds_delete (ppant);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status));
}

View file

@ -1,4 +1,4 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "RoundTrip.h"
#include <stdio.h>
#include <stdlib.h>
@ -42,7 +42,8 @@ static void data_available(dds_entity_t rd, void *arg)
int status, samplecount;
(void)arg;
samplecount = dds_take (rd, samples, info, MAX_SAMPLES, MAX_SAMPLES);
DDS_ERR_CHECK (samplecount, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (samplecount < 0)
DDS_FATAL("dds_take: %s\n", dds_strretcode(-samplecount));
for (int j = 0; !dds_triggered (waitSet) && j < samplecount; j++)
{
/* If writer has been disposed terminate pong */
@ -58,7 +59,8 @@ static void data_available(dds_entity_t rd, void *arg)
/* If sample is valid, send it back to ping */
RoundTripModule_DataType * valid_sample = &data[j];
status = dds_write_ts (writer, valid_sample, info[j].source_timestamp);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_write_ts: %s\n", -status);
}
}
}
@ -101,7 +103,8 @@ int main (int argc, char *argv[])
}
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (participant < 0)
DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
if (use_listener)
{
@ -116,7 +119,8 @@ int main (int argc, char *argv[])
/* Wait for a sample from ping */
status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status));
/* Take samples */
if (listener == NULL) {
@ -140,7 +144,8 @@ static void finalize_dds(dds_entity_t pp, RoundTripModule_DataType xs[MAX_SAMPLE
{
dds_return_t status;
status = dds_delete (pp);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status));
for (unsigned int i = 0; i < MAX_SAMPLES; i++)
{
RoundTripModule_DataType_free (&xs[i], DDS_FREE_CONTENTS);
@ -160,7 +165,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
/* A DDS Topic is created for our sample type on the domain participant. */
topic = dds_create_topic (participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* A DDS Publisher is created on the domain participant. */
@ -168,7 +174,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
dds_qset_partition (qos, 1, pubPartitions);
publisher = dds_create_publisher (participant, qos, NULL);
DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (publisher < 0)
DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher));
dds_delete_qos (qos);
/* A DDS DataWriter is created on the Publisher & Topic with a modififed Qos. */
@ -177,7 +184,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10));
dds_qset_writer_data_lifecycle (qos, false);
*wr = dds_create_writer (publisher, topic, qos, NULL);
DDS_ERR_CHECK (*wr, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*wr < 0)
DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*wr));
dds_delete_qos (qos);
/* A DDS Subscriber is created on the domain participant. */
@ -186,7 +194,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
dds_qset_partition (qos, 1, subPartitions);
subscriber = dds_create_subscriber (participant, qos, NULL);
DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (subscriber < 0)
DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber));
dds_delete_qos (qos);
/* A DDS DataReader is created on the Subscriber & Topic with a modified QoS. */
@ -194,19 +203,22 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t
qos = dds_create_qos ();
dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10));
*rd = dds_create_reader (subscriber, topic, qos, rdlist);
DDS_ERR_CHECK (*rd, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*rd < 0)
DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*rd));
dds_delete_qos (qos);
waitSet = dds_create_waitset (participant);
if (rdlist == NULL) {
*rdcond = dds_create_readcondition (*rd, DDS_ANY_STATE);
status = dds_waitset_attach (waitSet, *rdcond, *rd);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
} else {
*rdcond = 0;
}
status = dds_waitset_attach (waitSet, waitSet, waitSet);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
printf ("Waiting for samples from ping to send back...\n");
fflush (stdout);

View file

@ -1,4 +1,4 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "Throughput.h"
#include <stdio.h>
#include <stdlib.h>
@ -44,6 +44,7 @@ int main (int argc, char **argv)
char * partitionName = "Throughput example";
dds_entity_t participant;
dds_entity_t writer;
dds_return_t rc;
ThroughputModule_DataType sample;
#if !defined(_WIN32)
@ -59,7 +60,9 @@ int main (int argc, char **argv)
/* Wait until have a reader */
if (wait_for_reader(writer, participant) == 0) {
printf ("=== [Publisher] Did not discover a reader.\n");
DDS_ERR_CHECK (dds_delete (participant), DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_delete (participant);
if (rc < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc));
return EXIT_FAILURE;
}
@ -143,18 +146,21 @@ static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName)
/* A domain participant is created for the default domain. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (participant < 0)
DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant));
/* A topic is created for our sample type on the domain participant. */
topic = dds_create_topic (participant, &ThroughputModule_DataType_desc, "Throughput", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* A publisher is created on the domain participant. */
pubQos = dds_create_qos ();
pubParts[0] = partitionName;
dds_qset_partition (pubQos, 1, pubParts);
publisher = dds_create_publisher (participant, pubQos, NULL);
DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (publisher < 0)
DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher));
dds_delete_qos (pubQos);
/* A DataWriter is created on the publisher. */
@ -163,7 +169,8 @@ static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName)
dds_qset_history (dwQos, DDS_HISTORY_KEEP_ALL, 0);
dds_qset_resource_limits (dwQos, MAX_SAMPLES, DDS_LENGTH_UNLIMITED, DDS_LENGTH_UNLIMITED);
*writer = dds_create_writer (publisher, topic, dwQos, NULL);
DDS_ERR_CHECK (*writer, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*writer < 0)
DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*writer));
dds_delete_qos (dwQos);
/* Enable write batching */
@ -176,22 +183,26 @@ static dds_return_t wait_for_reader(dds_entity_t writer, dds_entity_t participan
{
printf ("\n=== [Publisher] Waiting for a reader ...\n");
dds_return_t ret;
dds_return_t rc;
dds_entity_t waitset;
ret = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS);
if (rc < 0)
DDS_FATAL("dds_set_status_mask: %s\n", dds_strretcode(-rc));
waitset = dds_create_waitset(participant);
DDS_ERR_CHECK (waitset, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (waitset < 0)
DDS_FATAL("dds_create_waitset: %s\n", dds_strretcode(-waitset));
ret = dds_waitset_attach(waitset, writer, (dds_attach_t)NULL);
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_waitset_attach(waitset, writer, (dds_attach_t)NULL);
if (rc < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-rc));
ret = dds_waitset_wait(waitset, NULL, 0, DDS_SECS(30));
DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
rc = dds_waitset_wait(waitset, NULL, 0, DDS_SECS(30));
if (rc < 0)
DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-rc));
return ret;
return rc;
}
static void start_writing(
@ -225,9 +236,12 @@ static void start_writing(
{
timedOut = true;
}
else if (status < 0)
{
DDS_FATAL("dds_write: %s\n", dds_strretcode(-status));
}
else
{
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
sample->count++;
burstCount++;
}
@ -277,12 +291,11 @@ static void start_writing(
static void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample)
{
dds_return_t status = dds_dispose (writer, &sample);
if (dds_err_nr (status) != DDS_RETCODE_TIMEOUT)
{
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
}
if (dds_err_nr (status) != DDS_RETCODE_TIMEOUT && status < 0)
DDS_FATAL("dds_dispose: %s\n", dds_strretcode(-status));
dds_free (sample.payload._buffer);
status = dds_delete (participant);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status));
}

View file

@ -1,4 +1,4 @@
#include "ddsc/dds.h"
#include "dds/dds.h"
#include "Throughput.h"
#include <stdio.h>
#include <stdlib.h>
@ -168,7 +168,8 @@ static int do_take (dds_entity_t reader)
/* Take samples and iterate through them */
samples_received = dds_take (reader, samples, info, MAX_SAMPLES, MAX_SAMPLES);
DDS_ERR_CHECK (samples_received, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (samples_received < 0)
DDS_FATAL("dds_take: %s\n", dds_strretcode(-samples_received));
for (int i = 0; !done && i < samples_received; i++)
{
@ -256,7 +257,8 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles)
else
{
status = dds_waitset_wait (waitSet, wsresults, sizeof(wsresults)/sizeof(wsresults[0]), DDS_MSECS(100));
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status));
}
if (pollingDelay >= 0)
@ -316,19 +318,22 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
/* A Participant is created for the default domain. */
participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (participant < 0)
DDS_FATAL("dds_create_particpant: %s\n", dds_strretcode(-participant));
/* A Topic is created for our sample type on the domain participant. */
topic = dds_create_topic (participant, &ThroughputModule_DataType_desc, "Throughput", NULL, NULL);
DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (topic < 0)
DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic));
/* A Subscriber is created on the domain participant. */
subParts[0] = partitionName;
dds_qset_partition (subQos, 1, subParts);
subscriber = dds_create_subscriber (participant, subQos, NULL);
DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (subscriber < 0)
DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber));
dds_delete_qos (subQos);
/* A Reader is created on the Subscriber & Topic with a modified Qos. */
@ -342,10 +347,12 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
/* A Read Condition is created which is triggered when data is available to read */
waitSet = dds_create_waitset (participant);
DDS_ERR_CHECK (waitSet, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (waitSet < 0)
DDS_FATAL("dds_create_waitset: %s\n", dds_strretcode(-waitSet));
status = dds_waitset_attach (waitSet, waitSet, waitSet);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
imap = HandleMap__alloc ();
@ -356,12 +363,14 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
}
*reader = dds_create_reader (subscriber, topic, drQos, pollingDelay < 0 ? rd_listener : NULL);
DDS_ERR_CHECK (*reader, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (*reader < 0)
DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*reader));
if (pollingDelay == 0)
{
status = dds_waitset_attach (waitSet, *reader, *reader);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status));
}
dds_delete_qos (drQos);
@ -380,9 +389,12 @@ static void finalize_dds(dds_entity_t participant)
}
status = dds_waitset_detach (waitSet, waitSet);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_waitset_detach: %s\n", dds_strretcode(-status));
status = dds_delete (waitSet);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status));
status = dds_delete (participant);
DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT);
if (status < 0)
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status));
}