| OLD | NEW |
| (Empty) |
| 1 // NOTE: This file was generated by the Mojo bindings generator. | |
| 2 #include "{{module.path}}-common.h" | |
| 3 | |
| 4 #include <math.h> | |
| 5 #include <ostream> | |
| 6 | |
| 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | |
| 8 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" | |
| 9 #include "mojo/public/cpp/bindings/lib/bounds_checker.h" | |
| 10 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" | |
| 11 #include "mojo/public/cpp/bindings/lib/map_serialization.h" | |
| 12 #include "mojo/public/cpp/bindings/lib/message_builder.h" | |
| 13 #include "mojo/public/cpp/bindings/lib/message_validation.h" | |
| 14 #include "mojo/public/cpp/bindings/lib/string_serialization.h" | |
| 15 #include "mojo/public/cpp/bindings/lib/validate_params.h" | |
| 16 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | |
| 17 #include "mojo/public/cpp/bindings/lib/validation_util.h" | |
| 18 #include "mojo/public/cpp/environment/logging.h" | |
| 19 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" | |
| 20 | |
| 21 {%- for namespace in namespaces_as_array %} | |
| 22 namespace {{namespace}} { | |
| 23 {%- endfor %} | |
| 24 | |
| 25 // --- Constants --- | |
| 26 {%- for constant in module.constants %} | |
| 27 {%- if not constant.kind|is_integral_kind %} | |
| 28 const {{constant.kind|cpp_pod_type}} {{constant.name}} | |
| 29 = {{constant|constant_value}}; | |
| 30 {%- endif %} | |
| 31 {%- endfor %} | |
| 32 | |
| 33 namespace internal { | |
| 34 | |
| 35 // --- Struct definitions --- | |
| 36 {% for struct in structs %} | |
| 37 {%- include "struct_definition.tmpl" %} | |
| 38 {%- endfor %} | |
| 39 | |
| 40 // --- Union definitions --- | |
| 41 {% for union in unions %} | |
| 42 {%- include "union_definition.tmpl" %} | |
| 43 {%- endfor %} | |
| 44 | |
| 45 // --- Definitions of the data structs for interface methods --- | |
| 46 {%- for interface in interfaces %} | |
| 47 {%- for method in interface.methods %} | |
| 48 {% set struct = method.param_struct %} | |
| 49 {%- include "struct_definition.tmpl" %} | |
| 50 {%- if method.response_parameters != None %} | |
| 51 {%- set struct = method.response_param_struct %} | |
| 52 {%- include "struct_definition.tmpl" %} | |
| 53 {%- endif %} | |
| 54 {%- endfor %} | |
| 55 {%- endfor %} | |
| 56 | |
| 57 } // namespace internal | |
| 58 | |
| 59 // --- Request and response validator definitions for interfaces --- | |
| 60 {%- for interface in interfaces %} | |
| 61 {%- set base_name = "internal::%s_Base"|format(interface.name) %} | |
| 62 mojo::internal::ValidationError {{interface.name}}RequestValidator::Validate( | |
| 63 const mojo::Message* message, | |
| 64 std::string* err) { | |
| 65 mojo::internal::ValidationError retval; | |
| 66 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { | |
| 67 retval = mojo::internal::ValidateControlRequest(message, err); | |
| 68 if (retval != mojo::internal::ValidationError::NONE) { | |
| 69 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 70 << "request validation error for interface '{{interface.name}}', " | |
| 71 "message name '" << message->header()->name << "': " << | |
| 72 (err ? *err : ""); | |
| 73 ReportValidationError(retval, err); | |
| 74 return retval; | |
| 75 } | |
| 76 return mojo::internal::ValidationError::NONE; | |
| 77 } | |
| 78 | |
| 79 {{base_name}}::MessageOrdinals method_ordinal = | |
| 80 static_cast<{{base_name}}::MessageOrdinals>(message->header()->name); | |
| 81 switch (method_ordinal) { | |
| 82 {%- for method in interface.methods %} | |
| 83 case {{base_name}}::MessageOrdinals::{{method.name}}: { | |
| 84 {%- if method.response_parameters != None %} | |
| 85 retval = | |
| 86 mojo::internal::ValidateMessageIsRequestExpectingResponse(message, | |
| 87 err); | |
| 88 if (retval != mojo::internal::ValidationError::NONE) { | |
| 89 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 90 << "request validation error for interface '{{interface.name}}', " | |
| 91 "message name '" << message->header()->name << "': " << | |
| 92 (err ? *err : ""); | |
| 93 ReportValidationError(retval, err); | |
| 94 return retval; | |
| 95 } | |
| 96 {%- else %} | |
| 97 retval = mojo::internal::ValidateMessageIsRequestWithoutResponse(message, | |
| 98 err); | |
| 99 if (retval != mojo::internal::ValidationError::NONE) { | |
| 100 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 101 << "request validation error for interface '{{interface.name}}', " | |
| 102 "message name '" << message->header()->name << "': " << | |
| 103 (err ? *err : ""); | |
| 104 ReportValidationError(retval, err); | |
| 105 return retval; | |
| 106 } | |
| 107 {%- endif %} | |
| 108 retval = mojo::internal::ValidateMessagePayload< | |
| 109 internal::{{interface.name}}_{{method.name}}_Params_Data>( | |
| 110 message, err); | |
| 111 if (retval != mojo::internal::ValidationError::NONE) { | |
| 112 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 113 << "request validation error for interface '{{interface.name}}', " | |
| 114 "message name '" << message->header()->name << "': " << | |
| 115 (err ? *err : ""); | |
| 116 ReportValidationError(retval, err); | |
| 117 return retval; | |
| 118 } | |
| 119 return mojo::internal::ValidationError::NONE; | |
| 120 } | |
| 121 {%- endfor %} | |
| 122 default: | |
| 123 break; | |
| 124 } | |
| 125 | |
| 126 // Unrecognized message. | |
| 127 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "unknown request message name '" | |
| 128 << message->header()->name | |
| 129 << "' for interface " | |
| 130 "'{{interface.name}}'"; | |
| 131 ReportValidationError( | |
| 132 mojo::internal::ValidationError::MESSAGE_HEADER_UNKNOWN_METHOD, err); | |
| 133 return mojo::internal::ValidationError::MESSAGE_HEADER_UNKNOWN_METHOD; | |
| 134 } | |
| 135 | |
| 136 {#--- Response validator definitions #} | |
| 137 {%- if interface|has_callbacks %} | |
| 138 mojo::internal::ValidationError {{interface.name}}ResponseValidator::Validate( | |
| 139 const mojo::Message* message, | |
| 140 std::string* err) { | |
| 141 mojo::internal::ValidationError retval; | |
| 142 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) { | |
| 143 retval = mojo::internal::ValidateControlResponse(message, err); | |
| 144 if (retval != mojo::internal::ValidationError::NONE) { | |
| 145 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 146 << "response validation error for interface '{{interface.name}}', " | |
| 147 "message name '" << message->header()->name << "': " << | |
| 148 (err ? *err : ""); | |
| 149 ReportValidationError(retval, err); | |
| 150 return retval; | |
| 151 } | |
| 152 return mojo::internal::ValidationError::NONE; | |
| 153 } | |
| 154 | |
| 155 retval = mojo::internal::ValidateMessageIsResponse(message, err); | |
| 156 if (retval != mojo::internal::ValidationError::NONE) { | |
| 157 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 158 << "response validation error for interface '{{interface.name}}', " | |
| 159 "message name '" << message->header()->name << "': " << | |
| 160 (err ? *err : ""); | |
| 161 ReportValidationError(retval, err); | |
| 162 return retval; | |
| 163 } | |
| 164 | |
| 165 {{base_name}}::MessageOrdinals method_ordinal = | |
| 166 static_cast<{{base_name}}::MessageOrdinals>(message->header()->name); | |
| 167 switch (method_ordinal) { | |
| 168 {%- for method in interface.methods if method.response_parameters != None %} | |
| 169 case {{base_name}}::MessageOrdinals::{{method.name}}: { | |
| 170 retval = mojo::internal::ValidateMessagePayload< | |
| 171 internal::{{interface.name}}_{{method.name}}_ResponseParams_Da
ta>( | |
| 172 message, err); | |
| 173 if (retval != mojo::internal::ValidationError::NONE) { | |
| 174 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) | |
| 175 << "response validation error for interface '{{interface.name}}'," | |
| 176 " message name '" << message->header()->name << "': " << | |
| 177 (err ? *err : ""); | |
| 178 ReportValidationError(retval, err); | |
| 179 return retval; | |
| 180 } | |
| 181 return mojo::internal::ValidationError::NONE; | |
| 182 } | |
| 183 {%- endfor %} | |
| 184 default: | |
| 185 break; | |
| 186 } | |
| 187 | |
| 188 // Unrecognized message. | |
| 189 MOJO_INTERNAL_DEBUG_SET_ERROR_MSG(err) << "unknown response message name '" | |
| 190 << message->header()->name | |
| 191 << "' for interface " | |
| 192 "'{{interface.name}}'"; | |
| 193 ReportValidationError( | |
| 194 mojo::internal::ValidationError::MESSAGE_HEADER_UNKNOWN_METHOD, err); | |
| 195 return mojo::internal::ValidationError::MESSAGE_HEADER_UNKNOWN_METHOD; | |
| 196 } | |
| 197 {%- endif -%} | |
| 198 | |
| 199 {%- endfor %} {# for each interface #} | |
| 200 | |
| 201 // --- Enums --- | |
| 202 {%- from "enum_macros.tmpl" import is_valid_enum_def -%} | |
| 203 {%- from "enum_macros.tmpl" import global_enum_operators_def -%} | |
| 204 {%- for enum in enums -%} | |
| 205 {{is_valid_enum_def(enum, class_name='')}} | |
| 206 {{global_enum_operators_def(enum, class_name='')}} | |
| 207 {%- endfor %} | |
| 208 | |
| 209 // Base interface definitions (Name_, Version_, Constants, Enums) | |
| 210 {%- for interface in interfaces %} | |
| 211 {%- set base_name = "internal::%s_Base"|format(interface.name) -%} | |
| 212 {%- if interface.service_name %} | |
| 213 const char {{base_name}}::Name_[] = "{{interface.service_name}}"; | |
| 214 {%- endif %} | |
| 215 const uint32_t {{base_name}}::Version_; | |
| 216 | |
| 217 // Constants | |
| 218 {%- for constant in interface.constants %} | |
| 219 {%- if constant.kind|is_integral_kind %} | |
| 220 const {{constant.kind|cpp_pod_type}} {{base_name}}::{{constant.name}}; | |
| 221 {%- else %} | |
| 222 const {{constant.kind|cpp_pod_type}} {{base_name}}::{{constant.name}} = {{consta
nt|constant_value}}; | |
| 223 {%- endif %} | |
| 224 {%- endfor %} | |
| 225 | |
| 226 // Enums | |
| 227 {%- for enum in interface.enums %} | |
| 228 {{is_valid_enum_def(enum, class_name=base_name)}} | |
| 229 {{global_enum_operators_def(enum, class_name=base_name)}} | |
| 230 {%- endfor %} | |
| 231 {%- endfor %} | |
| 232 | |
| 233 // Struct Constants | |
| 234 {%- for struct in structs %} | |
| 235 {%- for constant in struct.constants %} | |
| 236 {%- if constant.kind|is_integral_kind %} | |
| 237 const {{constant.kind|cpp_pod_type}} {{struct.name}}::{{constant.name}}; | |
| 238 {%- else %} | |
| 239 const {{constant.kind|cpp_pod_type}} {{struct.name}}::{{constant.name}} = {{cons
tant|constant_value}}; | |
| 240 {%- endif %} | |
| 241 {%- endfor %} | |
| 242 {%- endfor %} | |
| 243 | |
| 244 // --- Struct builder definitions --- | |
| 245 {%- for struct in structs %} | |
| 246 {%- include "wrapper_class_definition.tmpl" %} | |
| 247 {%- endfor %} | |
| 248 | |
| 249 // --- Union builder definitions --- | |
| 250 {%- for union in unions %} | |
| 251 {%- include "wrapper_union_class_definition.tmpl" %} | |
| 252 {%- endfor %} | |
| 253 | |
| 254 // --- Struct Serialization Helpers --- | |
| 255 {%- for struct in structs %} | |
| 256 {%- include "struct_serialization_definition.tmpl" %} | |
| 257 {%- endfor %} | |
| 258 | |
| 259 // --- Union Serialization Helpers --- | |
| 260 {%- for union in unions %} | |
| 261 {%- include "union_serialization_definition.tmpl" %} | |
| 262 {%- endfor %} | |
| 263 | |
| 264 // --- Structs for interface method parameters --- | |
| 265 {%- for interface in interfaces %} | |
| 266 {%- for method in interface.methods %} | |
| 267 {% set struct = method.param_struct %} | |
| 268 {%- include "wrapper_class_definition.tmpl" %} | |
| 269 {%- include "struct_serialization_definition.tmpl" %} | |
| 270 {%- if method.response_parameters != None %} | |
| 271 {%- set struct = method.response_param_struct %} | |
| 272 {%- include "wrapper_class_definition.tmpl" %} | |
| 273 {%- include "struct_serialization_definition.tmpl" %} | |
| 274 {%- endif %} | |
| 275 {%- endfor %} | |
| 276 {%- endfor %} | |
| 277 | |
| 278 {%- for namespace in namespaces_as_array|reverse %} | |
| 279 } // namespace {{namespace}} | |
| 280 {%- endfor %} | |
| OLD | NEW |