|
15 | 15 | package com.eprosima.fastdds.idl.grammar;
|
16 | 16 |
|
17 | 17 | import com.eprosima.fastdds.idl.grammar.Operation;
|
| 18 | +import com.eprosima.fastdds.idl.parser.typecode.EnumTypeCode; |
| 19 | +import com.eprosima.fastdds.idl.parser.typecode.StructTypeCode; |
| 20 | +import com.eprosima.idl.parser.typecode.Member; |
| 21 | +import com.eprosima.idl.parser.typecode.EnumMember; |
| 22 | +import com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind; |
18 | 23 | import org.antlr.v4.runtime.Token;
|
19 | 24 |
|
20 | 25 | public class Interface extends com.eprosima.idl.parser.tree.Interface
|
@@ -44,5 +49,100 @@ public void add(com.eprosima.idl.parser.tree.Export exp)
|
44 | 49 | super.add(exp);
|
45 | 50 | }
|
46 | 51 |
|
47 |
| - private Context m_context; |
| 52 | + /*! |
| 53 | + * @brief This function is used in stringtemplates to generate the typesupport code for the interface. |
| 54 | + * |
| 55 | + * @return The typecode of the request type. |
| 56 | + */ |
| 57 | + public StructTypeCode getRequestTypeCode() |
| 58 | + { |
| 59 | + if (m_request_type == null) |
| 60 | + { |
| 61 | + String scope = getHasScope() ? getScope() + "::detail" : "detail"; |
| 62 | + StructTypeCode request_type = new StructTypeCode(scope, getName() + "_Request"); |
| 63 | + |
| 64 | + // The request type should be a `@choice`, which means that it should have MUTABLE extensibility, |
| 65 | + // and also treat all fields as optional. |
| 66 | + request_type.get_extensibility(ExtensibilityKind.MUTABLE); |
| 67 | + |
| 68 | + getAll_operations().forEach(operation -> { |
| 69 | + Operation op = (Operation)operation; |
| 70 | + Member member = new Member(op.getInTypeCode(), op.getName()); |
| 71 | + // Add `@optional` and `@hashid` annotations |
| 72 | + member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional"))); |
| 73 | + member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid"))); |
| 74 | + request_type.addMember(member); |
| 75 | + // Add input feed parameters |
| 76 | + op.getParameters().forEach(param -> { |
| 77 | + Param p = (Param)param; |
| 78 | + if (p.isInput() && p.isAnnotationFeed()) |
| 79 | + { |
| 80 | + Member feed_member = new Member(p.getFeedTypeCode(), op.getName() + "_" + p.getName()); |
| 81 | + feed_member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional"))); |
| 82 | + feed_member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid"))); |
| 83 | + request_type.addMember(feed_member); |
| 84 | + } |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + m_request_type = request_type; |
| 89 | + } |
| 90 | + return m_request_type; |
| 91 | + } |
| 92 | + |
| 93 | + /*! |
| 94 | + * @brief This function is used in stringtemplates to generate the typesupport code for the interface. |
| 95 | + * |
| 96 | + * @return The typecode of the reply type. |
| 97 | + */ |
| 98 | + public StructTypeCode getReplyTypeCode() |
| 99 | + { |
| 100 | + if (m_reply_type == null) |
| 101 | + { |
| 102 | + String scope = getHasScope() ? getScope() + "::detail" : "detail"; |
| 103 | + StructTypeCode reply_type = new StructTypeCode(scope, getName() + "_Reply"); |
| 104 | + |
| 105 | + // The reply type should be a `@choice`, which means that it should have MUTABLE extensibility, |
| 106 | + // and also treat all fields as optional. |
| 107 | + reply_type.get_extensibility(ExtensibilityKind.MUTABLE); |
| 108 | + |
| 109 | + getAll_operations().forEach(operation -> { |
| 110 | + Operation op = (Operation)operation; |
| 111 | + Member member = new Member(op.getResultTypeCode(), op.getName()); |
| 112 | + // Add `@optional` and `@hashid` annotations |
| 113 | + member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional"))); |
| 114 | + member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid"))); |
| 115 | + reply_type.addMember(member); |
| 116 | + }); |
| 117 | + |
| 118 | + Member remoteEx = new Member(get_remoteExceptionCode_t_type(), "remoteEx"); |
| 119 | + remoteEx.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional"))); |
| 120 | + remoteEx.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid"))); |
| 121 | + reply_type.addMember(remoteEx); |
| 122 | + |
| 123 | + m_reply_type = reply_type; |
| 124 | + } |
| 125 | + return m_reply_type; |
| 126 | + } |
| 127 | + |
| 128 | + private EnumTypeCode get_remoteExceptionCode_t_type() |
| 129 | + { |
| 130 | + if (m_remoteExceptionCode_t_type == null) |
| 131 | + { |
| 132 | + EnumTypeCode type = new EnumTypeCode("eprosima::fastdds::dds::rpc", "RemoteExceptionCode_t"); |
| 133 | + type.addMember(new EnumMember("REMOTE_EX_OK")); |
| 134 | + type.addMember(new EnumMember("REMOTE_EX_UNSUPPORTED")); |
| 135 | + type.addMember(new EnumMember("REMOTE_EX_INVALID_ARGUMENT")); |
| 136 | + type.addMember(new EnumMember("REMOTE_EX_OUT_OF_RESOURCES")); |
| 137 | + type.addMember(new EnumMember("REMOTE_EX_UNKNOWN_OPERATION")); |
| 138 | + type.addMember(new EnumMember("REMOTE_EX_UNKNOWN_EXCEPTION")); |
| 139 | + m_remoteExceptionCode_t_type = type; |
| 140 | + } |
| 141 | + return m_remoteExceptionCode_t_type; |
| 142 | + } |
| 143 | + |
| 144 | + private Context m_context = null; |
| 145 | + private StructTypeCode m_request_type = null; |
| 146 | + private StructTypeCode m_reply_type = null; |
| 147 | + static private EnumTypeCode m_remoteExceptionCode_t_type = null; |
48 | 148 | }
|
0 commit comments