Skip to content

Commit 4aed1b6

Browse files
Generate TypeObject support code for RPC generated types (#486)
* Refs #23268. Add register methods for request and reply. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Add methods for internal types. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Exceptions and types inside interfaces Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Add include for new methods in Fast DDS. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Generate `register_type_object_representation` method. Signed-off-by: Miguel Company <[email protected]> * Refs #23268.Add parameter name in generated doxydoc. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Refactor generation of namespaces. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Fixed declarations inside interface. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Fixed build with exceptions without interfaces. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. More fixes for declarations inside interface. Signed-off-by: Miguel Company <[email protected]> * Refs #23268. Update IDL parser submodule. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]>
1 parent 7bd08c6 commit 4aed1b6

File tree

5 files changed

+108
-48
lines changed

5 files changed

+108
-48
lines changed

src/main/java/com/eprosima/fastdds/idl/grammar/Exception.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public StructTypeCode getTypeCode()
4444
getMembers().forEach(member -> m_typecode.addMember(member));
4545
// Default to final extensibility
4646
m_typecode.get_extensibility(ExtensibilityKind.FINAL);
47+
m_typecode.setParent(this);
4748
}
4849

4950
return m_typecode;

src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,16 @@ public:
406406
delete pData;
407407
}
408408

409+
eProsima_user_DllExport void register_type_object_representation() override
410+
{
411+
$if (ctx.generateTypeObjectSupport)$
412+
register_$interface.name$_$suffix$_type_identifier(type_identifiers_);
413+
$else$
414+
EPROSIMA_LOG_WARNING(XTYPES_TYPE_REPRESENTATION,
415+
"TypeObject type representation support disabled in generated code");
416+
$endif$
417+
}
418+
409419
};
410420
>>
411421

src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectHeader.stg

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,43 +68,41 @@ namespace $annotation.name$ {
6868

6969
} // namespace $annotation.name$
7070

71-
$register_type_identifier(typename=annotation.name)$
71+
$register_type_identifier(typename=annotation.nameForTypeObjectRegistration)$
7272
>>
7373

7474
bitmask_type(ctx, parent, bitmask) ::= <<
75-
$if(!bitmask.declaredInsideInterface)$
76-
$register_type_identifier(typename=bitmask.name)$
77-
$endif$
75+
$register_type_identifier(typename=bitmask.nameForTypeObjectRegistration)$
7876
>>
7977

8078
bitset_type(ctx, parent, bitset) ::= <<
81-
$if(!bitset.declaredInsideInterface)$
82-
$register_type_identifier(typename=bitset.name)$
83-
$endif$
79+
$register_type_identifier(typename=bitset.nameForTypeObjectRegistration)$
8480
>>
8581

8682
enum_type(ctx, parent, enum) ::= <<
87-
$if(!enum.declaredInsideInterface)$
88-
$register_type_identifier(typename=enum.name)$
89-
$endif$
83+
$register_type_identifier(typename=enum.nameForTypeObjectRegistration)$
9084
>>
9185

9286
struct_type(ctx, parent, struct, member_list) ::= <<
93-
$if(!struct.declaredInsideInterface)$
94-
$register_type_identifier(typename=struct.name)$
95-
$endif$
87+
$register_type_identifier(typename=struct.nameForTypeObjectRegistration)$
9688
>>
9789

9890
typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= <<
9991
$typedefs : { typedef |
100-
$register_type_identifier(typename=typedef.name)$
92+
$register_type_identifier(typename=typedef.nameForTypeObjectRegistration)$
10193

10294
}; separator="\n"$
10395
>>
10496

10597
union_type(ctx, parent, union, extensions, switch_type) ::= <<
106-
$if(!union.declaredInsideInterface)$
107-
$register_type_identifier(typename=union.name)$
98+
$register_type_identifier(typename=union.nameForTypeObjectRegistration)$
99+
>>
100+
101+
interface(ctx, parent, interface, export_list) ::= <<
102+
$export_list$
103+
$if(!interface.annotatedAsNested)$
104+
$register_type_identifier(typename=interface.requestTypeCode.nameForTypeObjectRegistration)$
105+
$register_type_identifier(typename=interface.replyTypeCode.nameForTypeObjectRegistration)$
108106
$endif$
109107
>>
110108

@@ -116,7 +114,7 @@ register_type_identifier(typename) ::= <<
116114
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
117115
* indirectly registered as well.
118116
*
119-
* @param[out] TypeIdentifier of the registered type.
117+
* @param[out] type_ids TypeIdentifier of the registered type.
120118
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
121119
* Invalid TypeIdentifier is returned in case of error.
122120
*/

src/main/java/com/eprosima/fastdds/idl/templates/XTypesTypeObjectSource.stg

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "TypeObjectSupport.cxx"], description=[
3232
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
3333
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
3434
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
35+
$if(ctx.thereIsInterface || ctx.thereIsException)$
36+
#include <fastdds/dds/rpc/RPCTypeObjectSupport.hpp>
37+
$endif$
3538

3639
#include "$ctx.filename$.hpp"
3740

@@ -65,7 +68,7 @@ namespace $annotation.name$ {
6568

6669
} // namespace $annotation.name$
6770

68-
void register_$annotation.name$_type_identifier(
71+
void register_$annotation.nameForTypeObjectRegistration$_type_identifier(
6972
TypeIdentifierPair& type_ids_$annotation.name$)
7073
{
7174
ReturnCode_t return_code_$annotation.name$ {eprosima::fastdds::dds::RETCODE_OK};
@@ -94,8 +97,7 @@ void register_$annotation.name$_type_identifier(
9497
>>
9598

9699
bitmask_type(ctx, parent, bitmask) ::= <<
97-
$if(!bitmask.declaredInsideInterface)$
98-
void register_$bitmask.name$_type_identifier(
100+
void register_$bitmask.nameForTypeObjectRegistration$_type_identifier(
99101
TypeIdentifierPair& type_ids_$bitmask.name$)
100102
{
101103
ReturnCode_t return_code_$bitmask.name$ {eprosima::fastdds::dds::RETCODE_OK};
@@ -119,13 +121,11 @@ void register_$bitmask.name$_type_identifier(
119121
}
120122
}
121123
}
122-
$endif$
123124
>>
124125

125126

126127
bitset_type(ctx, parent, bitset, extensions) ::= <<
127-
$if(!bitset.declaredInsideInterface)$
128-
void register_$bitset.name$_type_identifier(
128+
void register_$bitset.nameForTypeObjectRegistration$_type_identifier(
129129
TypeIdentifierPair& type_ids_$bitset.name$)
130130
{
131131
ReturnCode_t return_code_$bitset.name$ {eprosima::fastdds::dds::RETCODE_OK};
@@ -147,13 +147,11 @@ void register_$bitset.name$_type_identifier(
147147
}
148148
}
149149
}
150-
$endif$
151150
>>
152151

153152

154153
enum_type(ctx, parent, enum) ::= <<
155-
$if(!enum.declaredInsideInterface)$
156-
void register_$enum.name$_type_identifier(
154+
void register_$enum.nameForTypeObjectRegistration$_type_identifier(
157155
TypeIdentifierPair& type_ids_$enum.name$)
158156
{
159157
ReturnCode_t return_code_$enum.name$ {eprosima::fastdds::dds::RETCODE_OK};
@@ -177,13 +175,15 @@ void register_$enum.name$_type_identifier(
177175
}
178176
}
179177
}
180-
$endif$
181178
>>
182179

183180
struct_type(ctx, parent, struct, member_list) ::= <<
184-
$if(!struct.declaredInsideInterface)$
181+
$content_for_struct_type(ctx, struct)$
182+
>>
183+
184+
content_for_struct_type(ctx, struct) ::= <<
185185
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
186-
void register_$struct.name$_type_identifier(
186+
void register_$struct.nameForTypeObjectRegistration$_type_identifier(
187187
TypeIdentifierPair& type_ids_$struct.name$)
188188
{
189189
$if (struct.nonForwardedContent)$
@@ -202,7 +202,7 @@ void register_$struct.name$_type_identifier(
202202
$get_type_identifier(type=struct.inheritance, name=struct.name)$
203203
if (return_code_$struct.name$ != eprosima::fastdds::dds::RETCODE_OK)
204204
{
205-
$struct.inheritance.scope$::register_$struct.inheritance.name$_type_identifier(type_ids_$struct.name$);
205+
$add_namespace(struct.inheritance)$::register_$struct.inheritance.nameForTypeObjectRegistration$_type_identifier(type_ids_$struct.name$);
206206
}
207207
$endif$
208208
$complete_type_detail(type=struct, type_kind=" Structure", name=struct.name)$
@@ -242,12 +242,11 @@ void register_$struct.name$_type_identifier(
242242
"$struct.scopedname$ contains forward declarations (not yet supported).");
243243
$endif$
244244
}
245-
$endif$
246245
>>
247246

248247
typedef_decl(ctx, parent, typedefs, typedefs_type, declarator_type) ::= <<
249248
$typedefs : { typedef |
250-
void register_$typedef.name$_type_identifier(
249+
void register_$typedef.nameForTypeObjectRegistration$_type_identifier(
251250
TypeIdentifierPair& type_ids_$typedef.name$)
252251
{
253252
$! TODO(jlbueno): annotated collections aliases are considered non-anonymous collections.
@@ -315,9 +314,8 @@ void register_$typedef.name$_type_identifier(
315314
>>
316315

317316
union_type(ctx, parent, union, extensions, switch_type) ::= <<
318-
$if(!union.declaredInsideInterface)$
319317
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
320-
void register_$union.name$_type_identifier(
318+
void register_$union.nameForTypeObjectRegistration$_type_identifier(
321319
TypeIdentifierPair& type_ids_$union.name$)
322320
{
323321
$if (union.nonForwardedContent)$
@@ -335,9 +333,9 @@ void register_$union.name$_type_identifier(
335333
if (return_code_$union.name$ != eprosima::fastdds::dds::RETCODE_OK)
336334
{
337335
$if (union.discriminator.typecode.isAliasType)$
338-
$union.discriminator.typecode.scope$::register_$union.discriminator.typecode.name$_type_identifier(type_ids_$union.name$);
336+
$add_namespace(union.discriminator.typecode)$::register_$union.discriminator.typecode.nameForTypeObjectRegistration$_type_identifier(type_ids_$union.name$);
339337
$elseif (union.discriminator.typecode.isEnumType)$
340-
$union.discriminator.typecode.scope$::register_$union.discriminator.typecode.name$_type_identifier(type_ids_$union.name$);
338+
$add_namespace(union.discriminator.typecode)$::register_$union.discriminator.typecode.nameForTypeObjectRegistration$_type_identifier(type_ids_$union.name$);
341339
$else$
342340
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
343341
"Union discriminator TypeIdentifier unknown to TypeObjectRegistry.");
@@ -380,17 +378,66 @@ void register_$union.name$_type_identifier(
380378
"$union.scopedname$ contains forward declarations (not yet supported).");
381379
$endif$
382380
}
381+
>>
382+
383+
exception(ctx, parent, exception, extensions) ::= <<
384+
$content_for_struct_type(ctx, exception.typeCode)$
385+
>>
386+
387+
interface(ctx, parent, interface, export_list) ::= <<
388+
389+
$export_list$
390+
391+
namespace detail {
392+
393+
$interface.operations : { operation | $operation_details(interface, operation)$ }; separator="\n"$
394+
395+
} // namespace detail
396+
397+
$if(!interface.annotatedAsNested)$
398+
$content_for_struct_type(ctx, interface.requestTypeCode)$
399+
$content_for_struct_type(ctx, interface.replyTypeCode)$
383400
$endif$
384401
>>
385402

386403
/***** Utils *****/
404+
operation_details(interface, operation) ::= <<
405+
//{ $operation.name$
406+
$operation_in_struct(interface, operation)$
407+
408+
$operation.inputparam : { param | $if (param.annotationFeed)$$operation_feed_struct(interface, operation, param)$$endif$ }$
409+
410+
$operation_out_struct(interface, operation)$
411+
412+
$operation_result_struct(interface, operation)$
413+
414+
//} // $operation.name$
415+
416+
>>
417+
418+
operation_in_struct(interface, operation) ::= <<
419+
$content_for_struct_type(ctx, operation.inTypeCode)$
420+
>>
421+
422+
operation_feed_struct(interface, operation, param) ::= <<
423+
$content_for_struct_type(ctx, param.feedTypeCode)$
424+
>>
425+
426+
operation_out_struct(interface, operation) ::= <<
427+
$content_for_struct_type(ctx, operation.outTypeCode)$
428+
>>
429+
430+
operation_result_struct(interface, operation) ::= <<
431+
$content_for_struct_type(ctx, operation.resultTypeCode)$
432+
>>
433+
387434
register_type(ctx, object) ::= <<
388435
$if (object.isTypeDeclaration)$
389436
$if ((object.typeCode.isStructType || object.typeCode.isUnionType) && !object.typeCode.forwarded)$
390-
$if (!object.scope.empty)$$object.scope$::$endif$register_$object.name$_type_identifier(type_id);
437+
$add_namespace(object)$::register_$object.nameForTypeObjectRegistration$_type_identifier(type_id);
391438
$endif$
392439
$elseif (object.isAnnotation)$
393-
$if (!object.scope.empty)$$object.scope$::$endif$register_$object.name$_type_identifier(type_id);
440+
$add_namespace(object)$::register_$object.nameForTypeObjectRegistration$_type_identifier(type_id);
394441
$endif$
395442
>>
396443

@@ -444,7 +491,7 @@ $endif$
444491
$get_type_identifier_registry(typename=annotation.scopedname, name=annotation.name)$
445492
if (return_code_$annotation.name$ != eprosima::fastdds::dds::RETCODE_OK)
446493
{
447-
$annotation.annotationDeclaration.scope$::register_$annotation.annotationDeclaration.name$_type_identifier(type_ids_$annotation.annotationDeclaration.name$);
494+
$annotation.annotationDeclaration.scope$::register_$annotation.annotationDeclaration.nameForTypeObjectRegistration$_type_identifier(type_ids_$annotation.annotationDeclaration.name$);
448495
}
449496
if (!tmp_applied_annotation_parameter_seq_$member.name$.empty())
450497
{
@@ -511,9 +558,9 @@ annotation_parameter(param, parent) ::= <<
511558
if (return_code_$param.name$ != eprosima::fastdds::dds::RETCODE_OK)
512559
{
513560
$if (param.typecode.isAliasType)$
514-
$param.typecode.scope$::register_$param.typecode.name$_type_identifier(type_ids_$param.name$);
561+
$add_namespace(param.typecode)$::register_$param.typecode.nameForTypeObjectRegistration$_type_identifier(type_ids_$param.name$);
515562
$elseif (param.typecode.isEnumType)$
516-
$param.typecode.scope$::register_$param.typecode.name$_type_identifier(type_ids_$param.name$);
563+
$add_namespace(param.typecode)$::register_$param.typecode.nameForTypeObjectRegistration$_type_identifier(type_ids_$param.name$);
517564
$elseif (param.typecode.isStringType)$
518565
$register_string_type(string=param.typecode, name=param.name)$
519566
$elseif (param.typecode.isWStringType)$
@@ -902,23 +949,23 @@ check_register_type_identifier(type, message, name) ::= <<
902949
if (eprosima::fastdds::dds::RETCODE_OK != return_code_$name$)
903950
{
904951
$if (type.isAliasType)$
905-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
952+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
906953
$elseif (type.isStructType)$
907-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
954+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
908955
$elseif (type.isUnionType)$
909-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
956+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
910957
$elseif (type.isBitsetType)$
911-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
958+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
912959
$elseif (type.isSequenceType)$
913960
$register_sequence_type(sequence=type, name=name)$
914961
$elseif (type.isArrayType)$
915962
$register_array_type(array=type, name=name)$
916963
$elseif (type.isMapType)$
917964
$register_map_type(map=type, name=name)$
918965
$elseif (type.isEnumType)$
919-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
966+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
920967
$elseif (type.isBitmaskType)$
921-
$type.scope$::register_$type.name$_type_identifier(type_ids_$name$);
968+
$add_namespace(type)$::register_$type.nameForTypeObjectRegistration$_type_identifier(type_ids_$name$);
922969
$elseif (type.isStringType)$
923970
$register_string_type(string=type, name=name)$
924971
$elseif (type.isWStringType)$
@@ -973,6 +1020,10 @@ CollectionElementFlag element_flags_$collection_name$ = 0;
9731020
PlainCollectionHeader header_$collection_name$ = TypeObjectUtils::build_plain_collection_header(equiv_kind_$collection_name$, element_flags_$collection_name$);
9741021
>>
9751022

1023+
add_namespace(type) ::= <%
1024+
$if (!type.namespace.empty)$::$type.namespace$$endif$
1025+
%>
1026+
9761027
//{ Fast DDS-Gen extensions
9771028
module_conversion(ctx, parent, modules, definition_list) ::= <<
9781029
$modules : { module |

0 commit comments

Comments
 (0)