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
178180static 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
363377err :
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 );
0 commit comments