Clean up sertopic_default definition

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2020-02-04 15:34:34 +01:00 committed by eboasson
parent ad19f571ae
commit ab7c95e02f
22 changed files with 454 additions and 380 deletions

View file

@ -30,7 +30,6 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds_topic.c
dds_listener.c
dds_read.c
dds_stream.c
dds_waitset.c
dds_readcond.c
dds_guardcond.c
@ -70,7 +69,6 @@ PREPEND(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src"
dds__guardcond.h
dds__reader.h
dds__rhc_default.h
dds__stream.h
dds__subscriber.h
dds__topic.h
dds__types.h

View file

@ -18,8 +18,6 @@
extern "C" {
#endif
void dds_sample_free_contents (char * data, const uint32_t * ops);
#if defined (__cplusplus)
}
#endif

View file

@ -9,9 +9,10 @@
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSI_SERDATA_BUILTINTOPIC_H
#define DDSI_SERDATA_BUILTINTOPIC_H
#ifndef DDS__SERDATA_BUILTINTOPIC_H
#define DDS__SERDATA_BUILTINTOPIC_H
#include "dds/dds.h"
#include "dds/ddsi/ddsi_xqos.h"
#include "dds/ddsi/ddsi_serdata.h"
#include "dds/ddsi/ddsi_sertopic.h"
@ -33,7 +34,6 @@ enum ddsi_sertopic_builtintopic_type {
DSBT_WRITER
};
struct ddsi_domaingv;
struct ddsi_sertopic_builtintopic {
struct ddsi_sertopic c;
enum ddsi_sertopic_builtintopic_type type;

View file

@ -1,88 +0,0 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef _DDS_STREAM_H_
#define _DDS_STREAM_H_
#include "dds/ddsi/ddsi_serdata.h"
#include "dds/ddsi/ddsi_serdata_default.h"
#if defined (__cplusplus)
extern "C" {
#endif
typedef struct dds_istream {
const unsigned char *m_buffer;
uint32_t m_size; /* Buffer size */
uint32_t m_index; /* Read/write offset from start of buffer */
} dds_istream_t;
typedef struct dds_ostream {
unsigned char *m_buffer;
uint32_t m_size; /* Buffer size */
uint32_t m_index; /* Read/write offset from start of buffer */
} dds_ostream_t;
typedef struct dds_ostreamBE {
dds_ostream_t x;
} dds_ostreamBE_t;
DDS_EXPORT void dds_ostream_init (dds_ostream_t * __restrict st, uint32_t size);
DDS_EXPORT void dds_ostream_fini (dds_ostream_t * __restrict st);
DDS_EXPORT void dds_ostreamBE_init (dds_ostreamBE_t * __restrict st, uint32_t size);
DDS_EXPORT void dds_ostreamBE_fini (dds_ostreamBE_t * __restrict st);
bool dds_stream_normalize (void * __restrict data, uint32_t size, bool bswap, const struct ddsi_sertopic_default * __restrict topic, bool just_key);
void dds_stream_write_sample (dds_ostream_t * __restrict os, const void * __restrict data, const struct ddsi_sertopic_default * __restrict topic);
void dds_stream_read_sample (dds_istream_t * __restrict is, void * __restrict data, const struct ddsi_sertopic_default * __restrict topic);
size_t dds_stream_check_optimize (const dds_topic_descriptor_t * __restrict desc);
void dds_istream_from_serdata_default (dds_istream_t * __restrict s, const struct ddsi_serdata_default * __restrict d);
void dds_ostream_from_serdata_default (dds_ostream_t * __restrict s, struct ddsi_serdata_default * __restrict d);
void dds_ostream_add_to_serdata_default (dds_ostream_t * __restrict s, struct ddsi_serdata_default ** __restrict d);
void dds_ostreamBE_from_serdata_default (dds_ostreamBE_t * __restrict s, struct ddsi_serdata_default * __restrict d);
void dds_ostreamBE_add_to_serdata_default (dds_ostreamBE_t * __restrict s, struct ddsi_serdata_default ** __restrict d);
void dds_stream_write_key (dds_ostream_t * __restrict os, const char * __restrict sample, const struct ddsi_sertopic_default * __restrict topic);
void dds_stream_write_keyBE (dds_ostreamBE_t * __restrict os, const char * __restrict sample, const struct ddsi_sertopic_default * __restrict topic);
void dds_stream_extract_key_from_data (dds_istream_t * __restrict is, dds_ostream_t * __restrict os, const struct ddsi_sertopic_default * __restrict topic);
void dds_stream_extract_keyBE_from_data (dds_istream_t * __restrict is, dds_ostreamBE_t * __restrict os, const struct ddsi_sertopic_default * __restrict topic);
void dds_stream_extract_keyhash (dds_istream_t * __restrict is, dds_keyhash_t * __restrict kh, const struct ddsi_sertopic_default * __restrict topic, const bool just_key);
void dds_stream_read_key (dds_istream_t * __restrict is, char * __restrict sample, const struct ddsi_sertopic_default * __restrict topic);
size_t dds_stream_print_key (dds_istream_t * __restrict is, const struct ddsi_sertopic_default * __restrict topic, char * __restrict buf, size_t size);
size_t dds_stream_print_sample (dds_istream_t * __restrict is, const struct ddsi_sertopic_default * __restrict topic, char * __restrict buf, size_t size);
/* For marshalling op code handling */
#define DDS_OP_MASK 0xff000000
#define DDS_OP_TYPE_MASK 0x00ff0000
#define DDS_OP_SUBTYPE_MASK 0x0000ff00
#define DDS_OP_JMP_MASK 0x0000ffff
#define DDS_OP_FLAGS_MASK 0x000000ff
#define DDS_JEQ_TYPE_MASK 0x00ff0000
#define DDS_OP(o) ((enum dds_stream_opcode) ((o) & DDS_OP_MASK))
#define DDS_OP_TYPE(o) ((enum dds_stream_typecode) (((o) & DDS_OP_TYPE_MASK) >> 16))
#define DDS_OP_SUBTYPE(o) ((enum dds_stream_typecode) (((o) & DDS_OP_SUBTYPE_MASK) >> 8))
#define DDS_OP_FLAGS(o) ((o) & DDS_OP_FLAGS_MASK)
#define DDS_OP_ADR_JSR(o) ((o) & DDS_OP_JMP_MASK)
#define DDS_OP_JUMP(o) ((int16_t) ((o) & DDS_OP_JMP_MASK))
#define DDS_OP_ADR_JMP(o) ((o) >> 16)
#define DDS_JEQ_TYPE(o) ((enum dds_stream_typecode) (((o) & DDS_JEQ_TYPE_MASK) >> 16))
#if defined (__cplusplus)
}
#endif
#endif

View file

@ -13,21 +13,9 @@
#include <string.h>
#include "dds__alloc.h"
#include "dds__stream.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsi/q_config.h"
/*
#define OP_DEBUG_FREE 1
*/
#if defined OP_DEBUG_FREE
static const char * stream_op_type[11] =
{
NULL, "1Byte", "2Byte", "4Byte", "8Byte", "String",
"BString", "Sequence", "Array", "Union", "Struct"
};
#endif
#include "dds/ddsi/ddsi_cdrstream.h"
static dds_allocator_t dds_allocator_fns = { ddsrt_malloc, ddsrt_realloc, ddsrt_free };
@ -87,287 +75,30 @@ void dds_string_free (char * str)
dds_free (str);
}
void dds_sample_free_contents (char *data, const uint32_t * ops)
static void dds_sample_free_key (void *vsample, const struct dds_topic_descriptor * desc)
{
uint32_t op;
uint32_t type;
uint32_t num;
uint32_t subtype;
char * addr;
while ((op = *ops) != DDS_OP_RTS)
char *sample = vsample;
for (uint32_t i = 0; i < desc->m_nkeys; i++)
{
switch (DDS_OP_MASK & op)
{
case DDS_OP_ADR:
{
type = DDS_OP_TYPE (op);
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-ADR: %s offset %d\n", stream_op_type[type], ops[1]);
#endif
addr = data + ops[1];
ops += 2;
switch (type)
{
case DDS_OP_VAL_1BY:
case DDS_OP_VAL_2BY:
case DDS_OP_VAL_4BY:
case DDS_OP_VAL_8BY:
{
break;
}
case DDS_OP_VAL_STR:
{
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-STR: @ %p %s\n", addr, *((char**) addr));
#endif
dds_free (*((char**) addr));
*((char**) addr) = NULL;
break;
}
case DDS_OP_VAL_SEQ:
{
dds_sequence_t * seq = (dds_sequence_t*) addr;
subtype = DDS_OP_SUBTYPE (op);
num = (seq->_maximum > seq->_length) ? seq->_maximum : seq->_length;
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-SEQ: of %s\n", stream_op_type[subtype]);
#endif
if ((seq->_release && num) || (subtype > DDS_OP_VAL_STR))
{
switch (subtype)
{
case DDS_OP_VAL_1BY:
case DDS_OP_VAL_2BY:
case DDS_OP_VAL_4BY:
case DDS_OP_VAL_8BY:
{
break;
}
case DDS_OP_VAL_BST:
{
ops++;
break;
}
case DDS_OP_VAL_STR:
{
char ** ptr = (char**) seq->_buffer;
while (num--)
{
dds_free (*ptr++);
}
break;
}
default:
{
const uint32_t elem_size = *ops++;
const uint32_t * jsr_ops = ops + DDS_OP_ADR_JSR (*ops) - 3;
const uint32_t jmp = DDS_OP_ADR_JMP (*ops);
char * ptr = (char*) seq->_buffer;
while (num--)
{
dds_sample_free_contents (ptr, jsr_ops);
ptr += elem_size;
}
ops += jmp ? (jmp - 3) : 1;
break;
}
}
}
if (seq->_release)
{
dds_free (seq->_buffer);
seq->_maximum = 0;
seq->_length = 0;
seq->_buffer = NULL;
}
break;
}
case DDS_OP_VAL_ARR:
{
subtype = DDS_OP_SUBTYPE (op);
num = *ops++;
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-ARR: of %s size %d\n", stream_op_type[subtype], num);
#endif
switch (subtype)
{
case DDS_OP_VAL_1BY:
case DDS_OP_VAL_2BY:
case DDS_OP_VAL_4BY:
case DDS_OP_VAL_8BY:
{
break;
}
case DDS_OP_VAL_STR:
{
char ** ptr = (char**) addr;
while (num--)
{
dds_free (*ptr++);
}
break;
}
case DDS_OP_VAL_BST:
{
ops += 2;
break;
}
default:
{
const uint32_t * jsr_ops = ops + DDS_OP_ADR_JSR (*ops) - 3;
const uint32_t jmp = DDS_OP_ADR_JMP (*ops);
const uint32_t elem_size = ops[1];
while (num--)
{
dds_sample_free_contents (addr, jsr_ops);
addr += elem_size;
}
ops += jmp ? (jmp - 3) : 2;
break;
}
}
break;
}
case DDS_OP_VAL_UNI:
{
const bool has_default = op & DDS_OP_FLAG_DEF;
subtype = DDS_OP_SUBTYPE (op);
num = ops[0];
const uint32_t * jeq_op = ops + DDS_OP_ADR_JSR (ops[1]) - 2;
uint32_t disc = 0;
assert (subtype <= DDS_OP_VAL_4BY);
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-UNI: switch %s cases %d\n", stream_op_type[subtype], num);
#endif
/* Get discriminant */
switch (subtype)
{
case DDS_OP_VAL_1BY:
{
disc = *((uint8_t*) addr);
break;
}
case DDS_OP_VAL_2BY:
{
disc = *((uint16_t*) addr);
break;
}
case DDS_OP_VAL_4BY:
{
disc = *((uint32_t*) addr);
break;
}
default: assert (0);
}
/* Free case matching discriminant */
while (num--)
{
assert ((DDS_OP_MASK & jeq_op[0]) == DDS_OP_JEQ);
if ((jeq_op[1] == disc) || (has_default && (num == 0)))
{
subtype = DDS_JEQ_TYPE (jeq_op[0]);
addr = data + jeq_op[2];
switch (subtype)
{
case DDS_OP_VAL_1BY:
case DDS_OP_VAL_2BY:
case DDS_OP_VAL_4BY:
case DDS_OP_VAL_8BY:
case DDS_OP_VAL_BST:
{
break;
}
case DDS_OP_VAL_STR:
{
dds_free (*((char**) addr));
*((char**) addr) = NULL;
break;
}
default:
{
dds_sample_free_contents (addr, jeq_op + DDS_OP_ADR_JSR (jeq_op[0]));
break;
}
}
break;
}
jeq_op += 3;
}
/* Jump to next instruction */
ops += DDS_OP_ADR_JMP (ops[1]) - 2;
break;
}
case DDS_OP_VAL_BST:
{
ops++;
break;
}
default: assert (0);
}
break;
}
case DDS_OP_JSR: /* Implies nested type */
{
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-JSR: %d\n", DDS_OP_JUMP (op));
#endif
dds_sample_free_contents (data, ops + DDS_OP_JUMP (op));
ops++;
break;
}
default: assert (0);
}
}
#ifdef OP_DEBUG_FREE
DDS_TRACE("F-RTS:\n");
#endif
}
static void dds_sample_free_key (char * sample, const struct dds_topic_descriptor * desc)
{
uint32_t i;
const uint32_t * op;
for (i = 0; i < desc->m_nkeys; i++)
{
op = desc->m_ops + desc->m_keys[i].m_index;
const uint32_t *op = desc->m_ops + desc->m_keys[i].m_index;
if (DDS_OP_TYPE (*op) == DDS_OP_VAL_STR)
{
dds_free (*(char**)(sample + op[1]));
}
dds_free (*(char **) (sample + op[1]));
}
}
void dds_sample_free (void * sample, const struct dds_topic_descriptor * desc, dds_free_op_t op)
{
/* external API, so can't replace the dds_topic_decsriptor type ... */
assert (desc);
if (sample)
{
if (op & DDS_FREE_CONTENTS_BIT)
{
dds_sample_free_contents ((char*) sample, desc->m_ops);
}
dds_stream_free_sample (sample, desc->m_ops);
else if (op & DDS_FREE_KEY_BIT)
{
dds_sample_free_key ((char*) sample, desc);
}
dds_sample_free_key (sample, desc);
if (op & DDS_FREE_ALL_BIT)
{
dds_free (sample);
}
}
}

View file

@ -20,7 +20,6 @@
#include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h"
#include "dds/ddsi/ddsi_plist.h"
#include "dds__stream.h"
#include "dds__serdata_builtintopic.h"
#include "dds/ddsi/ddsi_tkmap.h"
#include "dds/ddsi/q_entity.h"

View file

@ -49,7 +49,7 @@ static bool sertopic_builtin_equal (const struct ddsi_sertopic *acmn, const stru
static uint32_t sertopic_builtin_hash (const struct ddsi_sertopic *tpcmn)
{
const struct ddsi_sertopic_builtintopic *tp = (struct ddsi_sertopic_builtintopic *) tpcmn;
return tp->type;
return (uint32_t) tp->type;
}
static void free_pp (void *vsample)

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,6 @@
#include "dds__topic.h"
#include "dds__listener.h"
#include "dds__participant.h"
#include "dds__stream.h"
#include "dds__init.h"
#include "dds__domain.h"
#include "dds__get_status.h"
@ -32,6 +31,7 @@
#include "dds/ddsi/ddsi_iid.h"
#include "dds/ddsi/ddsi_plist.h"
#include "dds/ddsi/ddsi_domaingv.h"
#include "dds/ddsi/ddsi_cdrstream.h"
#include "dds__serdata_builtintopic.h"
DECL_ENTITY_LOCK_UNLOCK (extern inline, dds_topic)
@ -399,13 +399,19 @@ dds_entity_t dds_create_topic (dds_entity_t participant, const dds_topic_descrip
ddsi_sertopic_init (&st->c, name, desc->m_typename, &ddsi_sertopic_ops_default, desc->m_nkeys ? &ddsi_serdata_ops_cdr : &ddsi_serdata_ops_cdr_nokey, (desc->m_nkeys == 0));
st->native_encoding_identifier = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? CDR_LE : CDR_BE);
st->serpool = ppent->m_domain->gv.serpool;
st->type = (void*) desc;
st->nkeys = desc->m_nkeys;
st->keys = desc->m_keys;
st->type.m_size = desc->m_size;
st->type.m_align = desc->m_align;
st->type.m_flagset = desc->m_flagset;
st->type.m_nkeys = desc->m_nkeys;
st->type.m_keys = ddsrt_malloc (st->type.m_nkeys * sizeof (*st->type.m_keys));
for (uint32_t i = 0; i < st->type.m_nkeys; i++)
st->type.m_keys[i] = desc->m_keys[i].m_index;
st->type.m_nops = dds_stream_countops (desc->m_ops);
st->type.m_ops = ddsrt_memdup (desc->m_ops, st->type.m_nops * sizeof (*st->type.m_ops));
/* Check if topic cannot be optimised (memcpy marshal) */
if (!(desc->m_flagset & DDS_TOPIC_NO_OPTIMIZE)) {
st->opt_size = dds_stream_check_optimize (desc);
if (!(st->type.m_flagset & DDS_TOPIC_NO_OPTIMIZE)) {
st->opt_size = dds_stream_check_optimize (&st->type);
DDS_CTRACE (&ppent->m_domain->gv.logconfig, "Marshalling for type: %s is %soptimised\n", desc->m_typename, st->opt_size ? "" : "not ");
}

View file

@ -18,7 +18,7 @@
#include "dds/ddsi/q_xmsg.h"
#include "dds/ddsi/ddsi_rhc.h"
#include "dds/ddsi/ddsi_serdata.h"
#include "dds__stream.h"
#include "dds/ddsi/ddsi_cdrstream.h"
#include "dds/ddsi/q_transmit.h"
#include "dds/ddsi/ddsi_entity_index.h"
#include "dds/ddsi/q_config.h"

View file

@ -125,7 +125,6 @@ static const dds_topic_descriptor_t type_uni_desc =
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_4BY, 0u, 4,
DDS_OP_RTS,
DDS_OP_RTS
},
.m_meta = "" /* this is on its way out anyway */
};