From 030802aa7960bead3694b4890a170056dde77f67 Mon Sep 17 00:00:00 2001 From: Dennis Potman Date: Mon, 18 Sep 2023 15:51:35 +0200 Subject: [PATCH] Move loaned sample meta-data initialization to generic PSMX implementation Signed-off-by: Dennis Potman --- src/core/ddsc/src/dds_psmx.c | 7 ++++++- src/core/ddsc/tests/psmx_cdds_impl.c | 4 ---- src/psmx_iox/src/psmx_iox_impl.cpp | 13 ++++--------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/core/ddsc/src/dds_psmx.c b/src/core/ddsc/src/dds_psmx.c index 94049c6940..0953c04b8c 100644 --- a/src/core/ddsc/src/dds_psmx.c +++ b/src/core/ddsc/src/dds_psmx.c @@ -194,7 +194,12 @@ dds_return_t dds_psmx_topic_cleanup_generic (struct dds_psmx_topic *psmx_topic) dds_loaned_sample_t * dds_psmx_endpoint_request_loan (struct dds_psmx_endpoint *psmx_endpoint, uint32_t sz) { assert (psmx_endpoint->ops.request_loan); - return psmx_endpoint->ops.request_loan (psmx_endpoint, sz); + dds_loaned_sample_t *loaned_sample = psmx_endpoint->ops.request_loan (psmx_endpoint, sz); + loaned_sample->metadata->sample_state = DDS_LOANED_SAMPLE_STATE_UNITIALIZED; + loaned_sample->metadata->sample_size = sz; + loaned_sample->metadata->instance_id = psmx_endpoint->psmx_topic->psmx_instance->instance_id; + loaned_sample->metadata->data_type = psmx_endpoint->psmx_topic->data_type; + return loaned_sample; } static dds_psmx_instance_id_t get_psmx_instance_id (const struct ddsi_domaingv * gv, const char *config_name) diff --git a/src/core/ddsc/tests/psmx_cdds_impl.c b/src/core/ddsc/tests/psmx_cdds_impl.c index 4bbca5410f..6a74346f9f 100644 --- a/src/core/ddsc/tests/psmx_cdds_impl.c +++ b/src/core/ddsc/tests/psmx_cdds_impl.c @@ -303,10 +303,6 @@ static dds_loaned_sample_t * cdds_psmx_ep_request_loan (struct dds_psmx_endpoint ls->loan_origin.origin_kind = DDS_LOAN_ORIGIN_KIND_PSMX; ls->loan_origin.psmx_endpoint = (struct dds_psmx_endpoint *) cep; ls->metadata = dds_alloc (sizeof (*ls->metadata)); - ls->metadata->sample_state = DDS_LOANED_SAMPLE_STATE_UNITIALIZED; - ls->metadata->sample_size = size_requested; - ls->metadata->instance_id = cep->c.psmx_topic->psmx_instance->instance_id; - ls->metadata->data_type = cep->c.psmx_topic->data_type; ls->sample_ptr = dds_alloc (sz); memset (ls->sample_ptr, 0, sz); ddsrt_atomic_st32 (&ls->refc, 1); diff --git a/src/psmx_iox/src/psmx_iox_impl.cpp b/src/psmx_iox/src/psmx_iox_impl.cpp index bffab365d6..1d87dc938a 100644 --- a/src/psmx_iox/src/psmx_iox_impl.cpp +++ b/src/psmx_iox/src/psmx_iox_impl.cpp @@ -357,11 +357,11 @@ iox_psmx_endpoint::~iox_psmx_endpoint() struct iox_loaned_sample : public dds_loaned_sample_t { - iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t sz, const void * ptr, dds_loaned_sample_state_t st); + iox_loaned_sample(struct dds_psmx_endpoint * origin, const void * iox_payload); ~iox_loaned_sample(); }; -iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t sz, const void * iox_payload, dds_loaned_sample_state_t st): +iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, const void * iox_payload): dds_loaned_sample_t { .ops = ls_ops, .loan_origin = { .origin_kind = DDS_LOAN_ORIGIN_KIND_PSMX, .psmx_endpoint = origin }, @@ -370,10 +370,6 @@ iox_loaned_sample::iox_loaned_sample(struct dds_psmx_endpoint * origin, uint32_t .refc = { .v = 1 } } { - metadata->sample_state = st; - metadata->data_type = origin->psmx_topic->data_type; - metadata->instance_id = origin->psmx_topic->psmx_instance->instance_id; - metadata->sample_size = sz; } iox_loaned_sample::~iox_loaned_sample() @@ -519,7 +515,7 @@ static dds_loaned_sample_t * iox_req_loan(struct dds_psmx_endpoint *psmx_endpoin const std::lock_guard lock(cpp_ep_ptr->lock); publisher->loan(size_requested, iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT, sizeof(dds_psmx_metadata_t), alignof(dds_psmx_metadata_t)) .and_then([&](const void* iox_payload) { - loaned_sample = new iox_loaned_sample(psmx_endpoint, size_requested, iox_payload, DDS_LOANED_SAMPLE_STATE_UNITIALIZED); + loaned_sample = new iox_loaned_sample(psmx_endpoint, iox_payload); }) .or_else([&](auto& error) { std::cerr << ERROR_PREFIX "failure getting loan" << iox::popo::asStringLiteral(error) << std::endl; @@ -570,8 +566,7 @@ static dds_return_t iox_write(struct dds_psmx_endpoint * psmx_endpoint, dds_loan static dds_loaned_sample_t * incoming_sample_to_loan(iox_psmx_endpoint *psmx_endpoint, const void *iox_payload) { - auto metadata = static_cast(iox::mepoo::ChunkHeader::fromUserPayload(iox_payload)->userHeader()); - return new iox_loaned_sample(psmx_endpoint, metadata->sample_size, iox_payload, metadata->sample_state); + return new iox_loaned_sample(psmx_endpoint, iox_payload); } static dds_loaned_sample_t * iox_take(struct dds_psmx_endpoint * psmx_endpoint)