Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(986)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {%- import "interface_macros.tmpl" as interface_macros %} 1 {%- import "interface_macros.tmpl" as interface_macros %}
2 {%- import "struct_macros.tmpl" as struct_macros %} 2 {%- import "struct_macros.tmpl" as struct_macros %}
3 3
4 {%- set class_name = interface.name %} 4 {%- set class_name = interface.name %}
5 {%- set proxy_name = interface.name ~ "Proxy" %} 5 {%- set proxy_name = interface.name ~ "Proxy" %}
6 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} 6 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %}
7 7
8 {%- macro alloc_params(struct, params, message, serialization_context, 8 {%- macro alloc_params(struct, params, message, serialization_context,
9 description) %} 9 description) %}
10 ({{serialization_context}})->handles.Swap(({{message}})->mutable_handles()); 10 ({{serialization_context}})->handles.Swap(({{message}})->mutable_handles());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (!callback_.is_null()) { 138 if (!callback_.is_null()) {
139 mojo::internal::MessageDispatchContext context(message); 139 mojo::internal::MessageDispatchContext context(message);
140 callback_.Run({{pass_params(method.response_parameters)}}); 140 callback_.Run({{pass_params(method.response_parameters)}});
141 } 141 }
142 return true; 142 return true;
143 } 143 }
144 {%- endif %} 144 {%- endif %}
145 {%- endfor %} 145 {%- endfor %}
146 146
147 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiverWithResponder* receiver) 147 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiverWithResponder* receiver)
148 : ControlMessageProxy(receiver) { 148 : receiver_(receiver) {
149 } 149 }
150 150
151 {#--- Proxy definitions #} 151 {#--- Proxy definitions #}
152 152
153 {%- for method in interface.methods %} 153 {%- for method in interface.methods %}
154 {%- set message_name = 154 {%- set message_name =
155 "internal::k%s_%s_Name"|format(interface.name, method.name) %} 155 "internal::k%s_%s_Name"|format(interface.name, method.name) %}
156 {%- set params_struct = method.param_struct %} 156 {%- set params_struct = method.param_struct %}
157 {%- set params_description = 157 {%- set params_description =
158 "%s.%s request"|format(interface.name, method.name) %} 158 "%s.%s request"|format(interface.name, method.name) %}
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // TODO(darin): !ok returned here indicates a malformed message, and that may 289 // TODO(darin): !ok returned here indicates a malformed message, and that may
290 // be good reason to close the connection. However, we don't have a way to do 290 // be good reason to close the connection. However, we don't have a way to do
291 // that from here. We should add a way. 291 // that from here. We should add a way.
292 delete responder_; 292 delete responder_;
293 responder_ = nullptr; 293 responder_ = nullptr;
294 } 294 }
295 {%- endif -%} 295 {%- endif -%}
296 {%- endfor %} 296 {%- endfor %}
297 297
298 {{class_name}}Stub::{{class_name}}Stub() 298 {{class_name}}Stub::{{class_name}}Stub()
299 : sink_(nullptr), 299 : sink_(nullptr) {
300 control_message_handler_({{interface.name}}::Version_) {
301 } 300 }
302 301
303 {{class_name}}Stub::~{{interface.name}}Stub() {} 302 {{class_name}}Stub::~{{interface.name}}Stub() {}
304 303
305 {#--- Stub definition #} 304 {#--- Stub definition #}
306 305
307 bool {{class_name}}Stub::Accept(mojo::Message* message) { 306 bool {{class_name}}Stub::Accept(mojo::Message* message) {
308 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
309 return control_message_handler_.Accept(message);
310 {%- if interface.methods %} 307 {%- if interface.methods %}
311 switch (message->header()->name) { 308 switch (message->header()->name) {
312 {%- for method in interface.methods %} 309 {%- for method in interface.methods %}
313 case internal::k{{class_name}}_{{method.name}}_Name: { 310 case internal::k{{class_name}}_{{method.name}}_Name: {
314 {%- if method.response_parameters == None %} 311 {%- if method.response_parameters == None %}
315 internal::{{class_name}}_{{method.name}}_Params_Data* params = 312 internal::{{class_name}}_{{method.name}}_Params_Data* params =
316 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >( 313 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >(
317 message->mutable_payload()); 314 message->mutable_payload());
318 315
319 {%- set desc = class_name~"::"~method.name %} 316 {%- set desc = class_name~"::"~method.name %}
(...skipping 10 matching lines...) Expand all
330 {%- endif %} 327 {%- endif %}
331 } 328 }
332 {%- endfor %} 329 {%- endfor %}
333 } 330 }
334 {%- endif %} 331 {%- endif %}
335 return false; 332 return false;
336 } 333 }
337 334
338 bool {{class_name}}Stub::AcceptWithResponder( 335 bool {{class_name}}Stub::AcceptWithResponder(
339 mojo::Message* message, mojo::MessageReceiverWithStatus* responder) { 336 mojo::Message* message, mojo::MessageReceiverWithStatus* responder) {
340 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
341 return control_message_handler_.AcceptWithResponder(message, responder);
342 {%- if interface.methods %} 337 {%- if interface.methods %}
343 switch (message->header()->name) { 338 switch (message->header()->name) {
344 {%- for method in interface.methods %} 339 {%- for method in interface.methods %}
345 case internal::k{{class_name}}_{{method.name}}_Name: { 340 case internal::k{{class_name}}_{{method.name}}_Name: {
346 {%- if method.response_parameters != None %} 341 {%- if method.response_parameters != None %}
347 internal::{{class_name}}_{{method.name}}_Params_Data* params = 342 internal::{{class_name}}_{{method.name}}_Params_Data* params =
348 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >( 343 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >(
349 message->mutable_payload()); 344 message->mutable_payload());
350 345
351 {%- set desc = class_name~"::"~method.name %} 346 {%- set desc = class_name~"::"~method.name %}
(...skipping 19 matching lines...) Expand all
371 } 366 }
372 {%- endfor %} 367 {%- endfor %}
373 } 368 }
374 {%- endif %} 369 {%- endif %}
375 return false; 370 return false;
376 } 371 }
377 372
378 {#--- Request validator definitions #} 373 {#--- Request validator definitions #}
379 374
380 bool {{class_name}}RequestValidator::Accept(mojo::Message* message) { 375 bool {{class_name}}RequestValidator::Accept(mojo::Message* message) {
376 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
377 return true;
378
381 mojo::internal::ValidationContext validation_context( 379 mojo::internal::ValidationContext validation_context(
382 message->data(), message->data_num_bytes(), message->handles()->size(), 380 message->data(), message->data_num_bytes(), message->handles()->size(),
383 message, "{{class_name}} RequestValidator"); 381 message, "{{class_name}} RequestValidator");
384 382
385 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
386 if (!mojo::internal::ValidateControlRequest(message, &validation_context))
387 return false;
388 return true;
389 }
390
391 switch (message->header()->name) { 383 switch (message->header()->name) {
392 {%- for method in interface.methods %} 384 {%- for method in interface.methods %}
393 case internal::k{{class_name}}_{{method.name}}_Name: { 385 case internal::k{{class_name}}_{{method.name}}_Name: {
394 {%- if method.response_parameters != None %} 386 {%- if method.response_parameters != None %}
395 if (!mojo::internal::ValidateMessageIsRequestExpectingResponse( 387 if (!mojo::internal::ValidateMessageIsRequestExpectingResponse(
396 message, &validation_context)) { 388 message, &validation_context)) {
397 return false; 389 return false;
398 } 390 }
399 {%- else %} 391 {%- else %}
400 if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( 392 if (!mojo::internal::ValidateMessageIsRequestWithoutResponse(
(...skipping 16 matching lines...) Expand all
417 // Unrecognized message. 409 // Unrecognized message.
418 ReportValidationError( 410 ReportValidationError(
419 &validation_context, 411 &validation_context,
420 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); 412 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
421 return false; 413 return false;
422 } 414 }
423 415
424 {#--- Response validator definitions #} 416 {#--- Response validator definitions #}
425 {% if interface|has_callbacks %} 417 {% if interface|has_callbacks %}
426 bool {{class_name}}ResponseValidator::Accept(mojo::Message* message) { 418 bool {{class_name}}ResponseValidator::Accept(mojo::Message* message) {
419 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
420 return true;
421
427 mojo::internal::ValidationContext validation_context( 422 mojo::internal::ValidationContext validation_context(
428 message->data(), message->data_num_bytes(), message->handles()->size(), 423 message->data(), message->data_num_bytes(), message->handles()->size(),
429 message, "{{class_name}} ResponseValidator"); 424 message, "{{class_name}} ResponseValidator");
430 425
431 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
432 if (!mojo::internal::ValidateControlResponse(message, &validation_context))
433 return false;
434 return true;
435 }
436
437 if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context)) 426 if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context))
438 return false; 427 return false;
439 switch (message->header()->name) { 428 switch (message->header()->name) {
440 {%- for method in interface.methods if method.response_parameters != None %} 429 {%- for method in interface.methods if method.response_parameters != None %}
441 case internal::k{{class_name}}_{{method.name}}_Name: { 430 case internal::k{{class_name}}_{{method.name}}_Name: {
442 if (!mojo::internal::ValidateMessagePayload< 431 if (!mojo::internal::ValidateMessagePayload<
443 internal::{{class_name}}_{{method.name}}_ResponseParams_Data>( 432 internal::{{class_name}}_{{method.name}}_ResponseParams_Data>(
444 message, &validation_context)) { 433 message, &validation_context)) {
445 return false; 434 return false;
446 } 435 }
447 return true; 436 return true;
448 } 437 }
449 {%- endfor %} 438 {%- endfor %}
450 default: 439 default:
451 break; 440 break;
452 } 441 }
453 442
454 // Unrecognized message. 443 // Unrecognized message.
455 ReportValidationError( 444 ReportValidationError(
456 &validation_context, 445 &validation_context,
457 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); 446 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
458 return false; 447 return false;
459 } 448 }
460 {%- endif -%} 449 {%- endif -%}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698