OLD | NEW |
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ALLOW_UNUSED_LOCAL(ok); | 288 ALLOW_UNUSED_LOCAL(ok); |
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 {#--- StubDispatch definition #} |
299 : sink_(nullptr) { | |
300 } | |
301 | 299 |
302 {{class_name}}Stub::~{{interface.name}}Stub() {} | 300 // static |
303 | 301 bool {{class_name}}StubDispatch::Accept( |
304 {#--- Stub definition #} | 302 {{interface.name}}* impl, |
305 | 303 mojo::internal::SerializationContext* context, |
306 bool {{class_name}}Stub::Accept(mojo::Message* message) { | 304 mojo::Message* message) { |
307 {%- if interface.methods %} | 305 {%- if interface.methods %} |
308 switch (message->header()->name) { | 306 switch (message->header()->name) { |
309 {%- for method in interface.methods %} | 307 {%- for method in interface.methods %} |
310 case internal::k{{class_name}}_{{method.name}}_Name: { | 308 case internal::k{{class_name}}_{{method.name}}_Name: { |
311 {%- if method.response_parameters == None %} | 309 {%- if method.response_parameters == None %} |
312 internal::{{class_name}}_{{method.name}}_Params_Data* params = | 310 internal::{{class_name}}_{{method.name}}_Params_Data* params = |
313 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( | 311 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( |
314 message->mutable_payload()); | 312 message->mutable_payload()); |
315 | 313 |
316 {%- set desc = class_name~"::"~method.name %} | 314 {%- set desc = class_name~"::"~method.name %} |
317 {{alloc_params(method.param_struct, "params", "message", | 315 {{alloc_params(method.param_struct, "params", "message", "context", desc)| |
318 "&serialization_context_", desc)|indent(4)}} | 316 indent(4)}} |
319 // A null |sink_| means no implementation was bound. | 317 // A null |impl| means no implementation was bound. |
320 assert(sink_); | 318 assert(impl); |
321 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); | 319 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); |
322 mojo::internal::MessageDispatchContext context(message); | 320 mojo::internal::MessageDispatchContext context(message); |
323 sink_->{{method.name}}({{pass_params(method.parameters)}}); | 321 impl->{{method.name}}({{pass_params(method.parameters)}}); |
324 return true; | 322 return true; |
325 {%- else %} | 323 {%- else %} |
326 break; | 324 break; |
327 {%- endif %} | 325 {%- endif %} |
328 } | 326 } |
329 {%- endfor %} | 327 {%- endfor %} |
330 } | 328 } |
331 {%- endif %} | 329 {%- endif %} |
332 return false; | 330 return false; |
333 } | 331 } |
334 | 332 |
335 bool {{class_name}}Stub::AcceptWithResponder( | 333 // static |
336 mojo::Message* message, mojo::MessageReceiverWithStatus* responder) { | 334 bool {{class_name}}StubDispatch::AcceptWithResponder( |
| 335 {{interface.name}}* impl, |
| 336 mojo::internal::SerializationContext* context, |
| 337 mojo::Message* message, |
| 338 mojo::MessageReceiverWithStatus* responder) { |
337 {%- if interface.methods %} | 339 {%- if interface.methods %} |
338 switch (message->header()->name) { | 340 switch (message->header()->name) { |
339 {%- for method in interface.methods %} | 341 {%- for method in interface.methods %} |
340 case internal::k{{class_name}}_{{method.name}}_Name: { | 342 case internal::k{{class_name}}_{{method.name}}_Name: { |
341 {%- if method.response_parameters != None %} | 343 {%- if method.response_parameters != None %} |
342 internal::{{class_name}}_{{method.name}}_Params_Data* params = | 344 internal::{{class_name}}_{{method.name}}_Params_Data* params = |
343 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( | 345 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( |
344 message->mutable_payload()); | 346 message->mutable_payload()); |
345 | 347 |
346 {%- set desc = class_name~"::"~method.name %} | 348 {%- set desc = class_name~"::"~method.name %} |
347 {{alloc_params(method.param_struct, "params", "message", | 349 {{alloc_params(method.param_struct, "params", "message", "context", desc)| |
348 "&serialization_context_", desc)| | 350 indent(4)}} |
349 indent(4)}} | |
350 {{class_name}}::{{method.name}}Callback callback = | 351 {{class_name}}::{{method.name}}Callback callback = |
351 {{class_name}}_{{method.name}}_ProxyToResponder::CreateCallback( | 352 {{class_name}}_{{method.name}}_ProxyToResponder::CreateCallback( |
352 message->request_id(), | 353 message->request_id(), |
353 message->has_flag(mojo::Message::kFlagIsSync), | 354 message->has_flag(mojo::Message::kFlagIsSync), responder, |
354 responder, | 355 context->group_controller); |
355 serialization_context_.group_controller); | 356 // A null |impl| means no implementation was bound. |
356 // A null |sink_| means no implementation was bound. | 357 assert(impl); |
357 assert(sink_); | |
358 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); | 358 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); |
359 mojo::internal::MessageDispatchContext context(message); | 359 mojo::internal::MessageDispatchContext context(message); |
360 sink_->{{method.name}}( | 360 impl->{{method.name}}( |
361 {%- if method.parameters -%}{{pass_params(method.parameters)}}, {% endif -%}call
back); | 361 {%- if method.parameters -%}{{pass_params(method.parameters)}}, {% endif -%}call
back); |
362 return true; | 362 return true; |
363 {%- else %} | 363 {%- else %} |
364 break; | 364 break; |
365 {%- endif %} | 365 {%- endif %} |
366 } | 366 } |
367 {%- endfor %} | 367 {%- endfor %} |
368 } | 368 } |
369 {%- endif %} | 369 {%- endif %} |
370 return false; | 370 return false; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 break; | 440 break; |
441 } | 441 } |
442 | 442 |
443 // Unrecognized message. | 443 // Unrecognized message. |
444 ReportValidationError( | 444 ReportValidationError( |
445 &validation_context, | 445 &validation_context, |
446 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); | 446 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
447 return false; | 447 return false; |
448 } | 448 } |
449 {%- endif -%} | 449 {%- endif -%} |
OLD | NEW |