Skip to content

Commit defb861

Browse files
committed
expr filtering without typelib build
Support for content filtering without typelib dependency, which allow user to use filtering via expressions on `key` fields only.
1 parent 8442316 commit defb861

File tree

10 files changed

+110
-51
lines changed

10 files changed

+110
-51
lines changed

src/core/cdr/include/dds/cdr/dds_cdrstream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct dds_cdrstream_allocator {
117117
} dds_cdrstream_allocator_t;
118118

119119
typedef struct dds_cdrstream_desc_key {
120+
char *name; /* Name of key field */
120121
uint32_t ops_offs; /* Offset for key ops */
121122
uint32_t idx; /* Key index in containing type (definition order) */
122123
} dds_cdrstream_desc_key_t;

src/core/cdr/src/dds_cdrstream.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6919,6 +6919,7 @@ static void copy_desc_keys (dds_cdrstream_desc_key_t **dst, const struct dds_cdr
69196919
*dst = allocator->malloc (nkeys * sizeof (**dst));
69206920
for (uint32_t i = 0; i < nkeys; i++)
69216921
{
6922+
(*dst)[i].name = ddsrt_strdup(keys[i].m_name);
69226923
(*dst)[i].ops_offs = keys[i].m_offset;
69236924
(*dst)[i].idx = keys[i].m_idx;
69246925
}
@@ -7036,6 +7037,12 @@ void dds_cdrstream_desc_fini (struct dds_cdrstream_desc *desc, const struct dds_
70367037
{
70377038
if (desc->keys.nkeys > 0)
70387039
{
7040+
for (size_t i = 0; i < desc->keys.nkeys; i++) {
7041+
if (desc->keys.keys != NULL)
7042+
allocator->free (desc->keys.keys[i].name);
7043+
if (desc->keys.keys_definition_order != NULL)
7044+
allocator->free (desc->keys.keys_definition_order[i].name);
7045+
}
70397046
if (desc->keys.keys != NULL)
70407047
allocator->free (desc->keys.keys);
70417048
if (desc->keys.keys_definition_order != NULL)

src/core/ddsc/src/dds__types.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
/* DDS internal type definitions */
1515

1616
#include "dds/dds.h"
17+
#include "dds/ddsrt/avl.h"
1718
#include "dds/ddsrt/sync.h"
1819
#include "dds/ddsi/ddsi_protocol.h"
1920
#include "dds/ddsi/ddsi_domaingv.h"
21+
#include "dds/ddsi/ddsi_builtin_topic_if.h"
2022
#ifdef DDS_HAS_TOPIC_DISCOVERY
21-
#include "dds/ddsi/ddsi_typewrap.h"
23+
#include "dds/ddsi/ddsi_typewrap.h"
2224
#endif
23-
#include "dds/ddsrt/avl.h"
24-
#include "dds/ddsi/ddsi_builtin_topic_if.h"
2525
#include "dds/ddsc/dds_psmx.h"
26+
#include "dds/cdr/dds_cdrstream.h"
2627
#include "dds__handles.h"
27-
#include "dds__loaned_sample.h"
2828

2929

3030
#if defined (__cplusplus)
@@ -459,7 +459,6 @@ struct dds_expression_filter {
459459
char *expression;
460460
struct dds_sql_expr *expr; // pre-build expression a.k.a full described.
461461
struct dds_sql_expr *bin_expr; // build/optimized expression with params.
462-
struct dds_topic_descriptor *desc; // newly constructed descriptor.
463462
struct ddsi_sertype *st; // newly constructed sertype.
464463
};
465464

src/core/ddsc/src/dds_filter.c

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
#include "dds/dds.h"
1414

15-
#include "dds/ddsi/ddsi_typebuilder.h"
1615
#include "dds/ddsrt/heap.h"
1716
#include "dds/ddsrt/string.h"
1817
#include "dds/ddsi/ddsi_sertype.h"
19-
#include "dds/ddsi/ddsi_typelib.h"
18+
#include "dds/ddsi/ddsi_typebuilder.h"
19+
#ifdef DDS_HAS_TYPELIB
20+
#include "dds/ddsi/ddsi_typelib.h"
21+
#endif
2022

2123
#include "dds__domain.h"
2224
#include "dds__filter.h"
@@ -178,15 +180,16 @@ static dds_return_t expr_var_set (const struct dds_expression_filter *filter, co
178180
static dds_return_t topic_expr_filter_vars_apply(const struct dds_expression_filter *filter, const void *sample)
179181
{
180182
dds_return_t ret = DDS_RETCODE_OK;
181-
const dds_topic_descriptor_t *desc = filter->desc;
183+
const struct dds_sertype_default *st = (const struct dds_sertype_default *)filter->st;
184+
const struct dds_cdrstream_desc desc = st->type;
182185

183-
for (size_t i = 0; i < desc->m_nkeys; i++)
186+
for (size_t i = 0; i < desc.keys.nkeys; i++)
184187
{
185-
dds_key_descriptor_t msg_field = desc->m_keys[i];
186-
const uint32_t *op = desc->m_ops + msg_field.m_offset;
188+
const struct dds_cdrstream_desc_key msg_field = desc.keys.keys[i];
189+
const uint32_t *op = desc.ops.ops + msg_field.ops_offs;
187190
size_t offset = 0U, op_id = 1;
188-
const uint32_t *ops = (desc->m_ops + op[op_id]);
189-
if ((ret = expr_var_set (filter, sample, (uintptr_t)msg_field.m_name, op, ops, &offset, &op_id)) != DDS_RETCODE_OK)
191+
const uint32_t *ops = (desc.ops.ops + op[op_id]);
192+
if ((ret = expr_var_set (filter, sample, (uintptr_t)msg_field.name, op, ops, &offset, &op_id)) != DDS_RETCODE_OK)
190193
goto err;
191194
}
192195

@@ -256,7 +259,6 @@ static void topic_expr_filter_free(struct dds_filter *filter)
256259
ddsrt_free(ef->expression);
257260
if (ef->bin_expr != NULL) dds_sql_expr_fini(ef->bin_expr);
258261
if (ef->expr != NULL) dds_sql_expr_fini(ef->expr);
259-
if (ef->desc != NULL) {ddsi_topic_descriptor_fini(ef->desc); ddsrt_free(ef->desc);}
260262
if (ef->st != NULL) ddsi_sertype_unref(ef->st);
261263
ddsrt_free(ef);
262264
}
@@ -306,12 +308,6 @@ static dds_return_t topic_expr_filter_param_rebind (struct dds_filter *a, const
306308
dds_sql_expr_fini(ef->bin_expr);
307309
ef->bin_expr = exp;
308310

309-
ddsi_typeid_t *id = ddsi_sertype_typeid(st, DDSI_TYPEID_KIND_COMPLETE);
310-
struct ddsi_domaingv *gv = ddsrt_atomic_ldvoidp (&st->gv);
311-
struct ddsi_type *type = ddsi_type_lookup(gv, id);
312-
ddsi_typeid_fini (id);
313-
ddsrt_free (id);
314-
315311
const char **fields = ddsrt_malloc(sizeof(*fields)*ef->bin_expr->nparams);
316312
size_t nfields = ef->bin_expr->nparams;
317313

@@ -320,14 +316,24 @@ static dds_return_t topic_expr_filter_param_rebind (struct dds_filter *a, const
320316
for (dds_sql_param_t *param = ddsrt_hh_iter_first(ef->bin_expr->param_tokens, &it); param != NULL; param = ddsrt_hh_iter_next(&it))
321317
fields[i++] = param->token.s;
322318

319+
#ifndef NDEBUG
323320
assert (i == nfields);
321+
#else
322+
(void) nfields;
323+
#endif
324+
325+
#ifdef DDS_HAS_TYPELIB
326+
ddsi_typeid_t *id = ddsi_sertype_typeid(st, DDSI_TYPEID_KIND_COMPLETE);
327+
struct ddsi_domaingv *gv = ddsrt_atomic_ldvoidp (&st->gv);
328+
struct ddsi_type *type = ddsi_type_lookup(gv, id);
329+
ddsi_typeid_fini (id);
330+
ddsrt_free (id);
324331

325332
struct ddsi_type *res_type = ddsi_type_dup_with_keys(type, fields, nfields);
326-
ddsrt_free (fields);
327-
if (ef->desc != NULL)
328-
ddsi_topic_descriptor_fini(ef->desc);
329-
ef->desc = ddsrt_malloc(sizeof(*ef->desc));
330-
ret = ddsi_topic_descriptor_from_type (gv, ef->desc, res_type);
333+
if (ef->st != NULL)
334+
ddsi_sertype_unref(ef->st);
335+
struct dds_topic_descriptor *desc = ddsrt_malloc(sizeof(*desc));
336+
ret = ddsi_topic_descriptor_from_type (gv, desc, res_type);
331337
assert (ret == DDS_RETCODE_OK);
332338

333339
/* FIXME
@@ -340,17 +346,20 @@ static dds_return_t topic_expr_filter_param_rebind (struct dds_filter *a, const
340346
* (by meaningful we mean interpretations which mentioned in initial expression)
341347
* interpretations of this "union" */
342348

343-
assert (ef->desc->m_nkeys == nfields);
349+
assert (desc->m_nkeys == nfields);
344350

345351
ddsrt_mutex_lock (&dds_global.m_mutex);
346352
struct dds_domain *dom = dds_domain_find_locked(ef->tf.domain_id);
347353
struct dds_sertype_default *st_def = ddsrt_malloc(sizeof(*st_def));
348-
uint16_t min_xcdrv = ef->desc->m_flagset & DDS_DATA_REPRESENTATION_FLAG_XCDR1? DDSI_RTPS_CDR_ENC_VERSION_1: DDSI_RTPS_CDR_ENC_VERSION_2;
354+
uint16_t min_xcdrv = desc->m_flagset & DDS_DATA_REPRESENTATION_FLAG_XCDR1? DDSI_RTPS_CDR_ENC_VERSION_1: DDSI_RTPS_CDR_ENC_VERSION_2;
349355
dds_data_representation_id_t data_representation = ((struct dds_sertype_default *)st)->write_encoding_version == DDSI_RTPS_CDR_ENC_VERSION_1? DDS_DATA_REPRESENTATION_XCDR1: DDS_DATA_REPRESENTATION_XCDR2;
350-
ret = dds_sertype_default_init (dom, st_def, ef->desc, min_xcdrv, data_representation);
356+
ret = dds_sertype_default_init (dom, st_def, desc, min_xcdrv, data_representation);
351357
assert (ret == DDS_RETCODE_OK);
352358
ddsrt_mutex_unlock (&dds_global.m_mutex);
353359

360+
ret = dds_delete_topic_descriptor (desc);
361+
assert (ret == DDS_RETCODE_OK);
362+
354363
ef->st = (struct ddsi_sertype *)st_def;
355364
/* FIXME
356365
* the next unref cause to constructed type to be destroyed. which is not so
@@ -359,6 +368,11 @@ static dds_return_t topic_expr_filter_param_rebind (struct dds_filter *a, const
359368
* type?
360369
* */
361370
ddsi_type_unref (gv, res_type);
371+
#else
372+
ef->st = ddsi_sertype_ref(st);
373+
#endif
374+
375+
ddsrt_free (fields);
362376

363377
err:
364378
return ret;
@@ -373,7 +387,6 @@ static dds_return_t expression_filter_create (dds_domainid_t domain_id, const st
373387
dds_return_t ret = DDS_RETCODE_OK;
374388
struct dds_expression_filter *ef = (struct dds_expression_filter *) ddsrt_malloc(sizeof(*ef));
375389
ef->st = NULL;
376-
ef->desc = NULL;
377390
ef->expr = NULL;
378391
ef->bin_expr = NULL;
379392
ef->expression = ddsrt_strdup(cflt->expression);

src/core/ddsc/src/dds_reader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "dds/ddsi/ddsi_tkmap.h"
2929
#include "dds/ddsc/dds_rhc.h"
3030
#include "dds/ddsc/dds_internal_api.h"
31+
#include "dds__loaned_sample.h"
3132
#include "dds__participant.h"
3233
#include "dds__subscriber.h"
3334
#include "dds__reader.h"

src/core/ddsc/src/dds_sql_expr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,8 @@ dds_return_t dds_sql_expr_bind_integer(const struct dds_sql_expr *ex, uintptr_t
18411841
if (ex->param_kind == DDS_SQL_EXPR_KIND_PARAMETER) tmpl.id.index = (uint64_t)i;
18421842
else if (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE) tmpl.id.str = ddsrt_strdup((char *)(void *)i);
18431843
else goto err;
1844+
/* FIXME: not found? no worries it's optimized or DDS_HAS_TYPELIB missing. */
1845+
retcode = (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE)? DDS_RETCODE_OK: DDS_RETCODE_BAD_PARAMETER;
18441846
struct dds_sql_param *param = ddsrt_hh_lookup(ex->param_tokens, &tmpl);
18451847
if (param == NULL) goto err_not_found;
18461848
struct dds_sql_token *t = (struct dds_sql_token *)param;
@@ -1863,6 +1865,8 @@ dds_return_t dds_sql_expr_bind_real(const struct dds_sql_expr *ex, uintptr_t i,
18631865
if (ex->param_kind == DDS_SQL_EXPR_KIND_PARAMETER) tmpl.id.index = (uint64_t)i;
18641866
else if (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE) tmpl.id.str = ddsrt_strdup((char *)(void *)i);
18651867
else goto err;
1868+
/* FIXME: not found? no worries it's optimized or DDS_HAS_TYPELIB missing. */
1869+
retcode = (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE)? DDS_RETCODE_OK: DDS_RETCODE_BAD_PARAMETER;
18661870
struct dds_sql_param *param = ddsrt_hh_lookup(ex->param_tokens, &tmpl);
18671871
if (param == NULL) goto err_not_found;
18681872
struct dds_sql_token *t = (struct dds_sql_token *)param;
@@ -1885,6 +1889,8 @@ dds_return_t dds_sql_expr_bind_string(const struct dds_sql_expr *ex, uintptr_t i
18851889
if (ex->param_kind == DDS_SQL_EXPR_KIND_PARAMETER) tmpl.id.index = (uint64_t)i;
18861890
else if (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE) tmpl.id.str = ddsrt_strdup((char *)(void *)i);
18871891
else goto err;
1892+
/* FIXME: not found? no worries it's optimized or DDS_HAS_TYPELIB missing. */
1893+
retcode = (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE)? DDS_RETCODE_OK: DDS_RETCODE_BAD_PARAMETER;
18881894
struct dds_sql_param *param = ddsrt_hh_lookup(ex->param_tokens, &tmpl);
18891895
if (param == NULL) goto err_not_found;
18901896
struct dds_sql_token *t = (struct dds_sql_token *)param;
@@ -1910,6 +1916,8 @@ dds_return_t dds_sql_expr_bind_blob(const struct dds_sql_expr *ex, uintptr_t i,
19101916
if (ex->param_kind == DDS_SQL_EXPR_KIND_PARAMETER) tmpl.id.index = (uint64_t)i;
19111917
else if (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE) tmpl.id.str = ddsrt_strdup((char *)(void *)i);
19121918
else goto err;
1919+
/* FIXME: not found? no worries it's optimized or DDS_HAS_TYPELIB missing. */
1920+
retcode = (ex->param_kind == DDS_SQL_EXPR_KIND_VARIABLE)? DDS_RETCODE_OK: DDS_RETCODE_BAD_PARAMETER;
19131921
struct dds_sql_param *param = ddsrt_hh_lookup(ex->param_tokens, &tmpl);
19141922
if (param == NULL) goto err_not_found;
19151923
struct dds_sql_token *t = (struct dds_sql_token *)param;

src/core/ddsc/src/dds_writer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "dds/cdr/dds_cdrstream.h"
3030
#include "dds/ddsc/dds_internal_api.h"
3131
#include "dds__filter.h"
32+
#include "dds__loaned_sample.h"
3233
#include "dds__writer.h"
3334
#include "dds__listener.h"
3435
#include "dds__init.h"

src/core/ddsc/tests/Space.idl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1010

1111
module Space {
12+
struct Type0 {
13+
@key
14+
long long_1;
15+
@key
16+
long long_2;
17+
long long_3;
18+
};
19+
1220
struct Type1 {
1321
@key
1422
long long_1;

0 commit comments

Comments
 (0)