Allow readconditions and queryconditions as valid entities for dds_instance_get_key Signed-off-by: TheFixer <thefixer@iteazz.com>
This commit is contained in:
parent
0dd2155f99
commit
1f5083aa44
3 changed files with 110 additions and 12 deletions
|
@ -2939,7 +2939,7 @@ dds_instance_lookup(dds_entity_t entity, const void *data);
|
|||
/**
|
||||
* @brief This operation takes an instance handle and return a key-value corresponding to it.
|
||||
*
|
||||
* @param[in] entity Reader or writer entity.
|
||||
* @param[in] entity Reader, writer, readcondition or querycondition entity.
|
||||
* @param[in] inst Instance handle.
|
||||
* @param[out] data pointer to an instance, to which the key ID corresponding to the instance handle will be
|
||||
* returned, the sample in the instance should be ignored.
|
||||
|
|
|
@ -284,23 +284,27 @@ dds_return_t dds_instance_get_key (dds_entity_t entity, dds_instance_handle_t ih
|
|||
dds_return_t ret;
|
||||
const dds_topic *topic;
|
||||
struct ddsi_tkmap_instance *tk;
|
||||
dds_entity *w_or_r;
|
||||
dds_entity *e;
|
||||
|
||||
if (data == NULL)
|
||||
return DDS_RETCODE_BAD_PARAMETER;
|
||||
|
||||
if ((ret = dds_entity_lock (entity, DDS_KIND_DONTCARE, &w_or_r)) < 0)
|
||||
if ((ret = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) < 0)
|
||||
return ret;
|
||||
switch (dds_entity_kind (w_or_r))
|
||||
switch (dds_entity_kind (e))
|
||||
{
|
||||
case DDS_KIND_WRITER:
|
||||
topic = ((dds_writer *) w_or_r)->m_topic;
|
||||
topic = ((dds_writer *) e)->m_topic;
|
||||
break;
|
||||
case DDS_KIND_READER:
|
||||
topic = ((dds_reader *) w_or_r)->m_topic;
|
||||
topic = ((dds_reader *) e)->m_topic;
|
||||
break;
|
||||
case DDS_KIND_COND_READ:
|
||||
case DDS_KIND_COND_QUERY:
|
||||
topic = ((dds_reader *) e->m_parent)->m_topic;
|
||||
break;
|
||||
default:
|
||||
dds_entity_unlock (w_or_r);
|
||||
dds_entity_unlock (e);
|
||||
return DDS_RETCODE_ILLEGAL_OPERATION;
|
||||
}
|
||||
|
||||
|
@ -315,6 +319,6 @@ dds_return_t dds_instance_get_key (dds_entity_t entity, dds_instance_handle_t ih
|
|||
ret = DDS_RETCODE_OK;
|
||||
}
|
||||
thread_state_asleep (ts1);
|
||||
dds_entity_unlock (w_or_r);
|
||||
dds_entity_unlock (e);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -18,20 +18,40 @@
|
|||
#include "dds/ddsrt/string.h"
|
||||
#include "RoundTrip.h"
|
||||
|
||||
#define MAX_SAMPLES 10
|
||||
|
||||
static dds_entity_t participant = DDS_ENTITY_NIL;
|
||||
static dds_entity_t waitset = DDS_ENTITY_NIL;
|
||||
static dds_entity_t topic = DDS_ENTITY_NIL;
|
||||
static dds_entity_t publisher = DDS_ENTITY_NIL;
|
||||
static dds_entity_t subscriber = DDS_ENTITY_NIL;
|
||||
static dds_entity_t writer = DDS_ENTITY_NIL;
|
||||
|
||||
static dds_entity_t reader = DDS_ENTITY_NIL;
|
||||
static dds_entity_t readcondition = DDS_ENTITY_NIL;
|
||||
static dds_entity_t querycondition = DDS_ENTITY_NIL;
|
||||
static dds_instance_handle_t handle = DDS_HANDLE_NIL;
|
||||
|
||||
static bool
|
||||
filter(const void * sample)
|
||||
{
|
||||
const RoundTripModule_Address *s = sample;
|
||||
return (s->port == 1);
|
||||
}
|
||||
|
||||
static RoundTripModule_Address data;
|
||||
|
||||
/* Fixture to create prerequisite entity */
|
||||
static void setup(void)
|
||||
{
|
||||
uint32_t mask = DDS_ANY_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE;
|
||||
dds_return_t ret;
|
||||
|
||||
participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
|
||||
CU_ASSERT_FATAL(participant > 0);
|
||||
|
||||
waitset = dds_create_waitset(participant);
|
||||
CU_ASSERT_FATAL(waitset > 0);
|
||||
|
||||
topic = dds_create_topic(participant, &RoundTripModule_Address_desc, "ddsc_instance_get_key", NULL, NULL);
|
||||
CU_ASSERT_FATAL(topic > 0);
|
||||
|
||||
|
@ -41,6 +61,24 @@ static void setup(void)
|
|||
writer = dds_create_writer(publisher, topic, NULL, NULL);
|
||||
CU_ASSERT_FATAL(writer > 0);
|
||||
|
||||
subscriber = dds_create_subscriber(participant, NULL, NULL);
|
||||
CU_ASSERT_FATAL(subscriber > 0);
|
||||
|
||||
reader = dds_create_reader(subscriber, topic, NULL, NULL);
|
||||
CU_ASSERT_FATAL(reader > 0);
|
||||
|
||||
readcondition = dds_create_readcondition(reader, mask);
|
||||
CU_ASSERT_FATAL(readcondition > 0);
|
||||
|
||||
ret = dds_waitset_attach(waitset, readcondition, readcondition);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
querycondition = dds_create_querycondition(reader, mask, filter);
|
||||
CU_ASSERT_FATAL(querycondition > 0);
|
||||
|
||||
ret = dds_waitset_attach(waitset, querycondition, querycondition);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ip = ddsrt_strdup("some data");
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(data.ip);
|
||||
|
@ -52,9 +90,6 @@ static void teardown(void)
|
|||
{
|
||||
RoundTripModule_Address_free(&data, DDS_FREE_CONTENTS);
|
||||
|
||||
dds_delete(writer);
|
||||
dds_delete(publisher);
|
||||
dds_delete(topic);
|
||||
dds_delete(participant);
|
||||
}
|
||||
|
||||
|
@ -104,3 +139,62 @@ CU_Test(ddsc_instance_get_key, registered_instance, .init=setup, .fini=teardown)
|
|||
RoundTripModule_Address_free(&key_data, DDS_FREE_CONTENTS);
|
||||
}
|
||||
|
||||
CU_Test(ddsc_instance_get_key, readcondition, .init=setup, .fini=teardown)
|
||||
{
|
||||
dds_return_t ret;
|
||||
RoundTripModule_Address key_data;
|
||||
|
||||
/* The instance handle of a successful write is by
|
||||
* design the same as the instance handle for the
|
||||
* readers,readconditions and queryconditions.
|
||||
* For that reason there is no need to actually read
|
||||
* the data. It is sufficient to do a successful write
|
||||
* and use the instance handle to obtain the key_data
|
||||
* for the readcondition. */
|
||||
ret = dds_write(writer, &data);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
handle = dds_lookup_instance (writer, &data);
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(handle);
|
||||
|
||||
memset(&key_data, 0, sizeof(key_data));
|
||||
|
||||
ret = dds_instance_get_key(readcondition, handle, &key_data);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip);
|
||||
CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip);
|
||||
CU_ASSERT_EQUAL_FATAL(key_data.port, data.port);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
RoundTripModule_Address_free(&key_data, DDS_FREE_CONTENTS);
|
||||
}
|
||||
|
||||
CU_Test(ddsc_instance_get_key, querycondition, .init=setup, .fini=teardown)
|
||||
{
|
||||
dds_return_t ret;
|
||||
RoundTripModule_Address key_data;
|
||||
|
||||
/* The instance handle of a successful write is by
|
||||
* design the same as the instance handle for the
|
||||
* readers,readconditions and queryconditions.
|
||||
* For that reason there is no need to actually read
|
||||
* the data. It is sufficient to do a successful write
|
||||
* and use the instance handle to obtain the key_data
|
||||
* for the querycondition. */
|
||||
ret = dds_write(writer, &data);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
handle = dds_lookup_instance (writer, &data);
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(handle);
|
||||
|
||||
memset(&key_data, 0, sizeof(key_data));
|
||||
|
||||
ret = dds_instance_get_key(querycondition, handle, &key_data);
|
||||
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip);
|
||||
CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip);
|
||||
CU_ASSERT_EQUAL_FATAL(key_data.port, data.port);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
|
||||
RoundTripModule_Address_free(&key_data, DDS_FREE_CONTENTS);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue