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

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

Issue 1475813002: Mojo C++ bindings: support passing associated interface pointers/requests in method parameter lists… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_use_multiplex_router
Patch Set: Created 5 years 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 {%- from "enum_macros.tmpl" import is_valid_enum_def %} 3 {%- from "enum_macros.tmpl" import is_valid_enum_def %}
4 4
5 {%- set class_name = interface.name %} 5 {%- set class_name = interface.name %}
6 {%- set proxy_name = interface.name ~ "Proxy" %} 6 {%- set proxy_name = interface.name ~ "Proxy" %}
7 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} 7 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %}
8 8
9 {%- macro alloc_params(struct) %} 9 {%- macro alloc_params(struct, serialization_context) %}
10 {%- for param in struct.packed.packed_fields_in_ordinal_order %} 10 {%- for param in struct.packed.packed_fields_in_ordinal_order %}
11 {{param.field.kind|cpp_result_type}} p_{{param.field.name}}{}; 11 {{param.field.kind|cpp_result_type}} p_{{param.field.name}}{};
12 {%- endfor %} 12 {%- endfor %}
13 {{struct_macros.deserialize(struct, "params", "p_%s")}} 13 {{struct_macros.deserialize(struct, "params", "p_%s", serialization_context)}}
14 {%- endmacro %} 14 {%- endmacro %}
15 15
16 {%- macro pass_params(parameters) %} 16 {%- macro pass_params(parameters) %}
17 {%- for param in parameters %} 17 {%- for param in parameters %}
18 {%- if param.kind|is_move_only_kind -%} 18 {%- if param.kind|is_move_only_kind -%}
19 p_{{param.name}}.Pass() 19 p_{{param.name}}.Pass()
20 {%- else -%} 20 {%- else -%}
21 p_{{param.name}} 21 p_{{param.name}}
22 {%- endif -%} 22 {%- endif -%}
23 {%- if not loop.last %}, {% endif %} 23 {%- if not loop.last %}, {% endif %}
(...skipping 23 matching lines...) Expand all
47 {{is_valid_enum_def(enum, class_name=interface.name)|indent(2)}} 47 {{is_valid_enum_def(enum, class_name=interface.name)|indent(2)}}
48 {%- endfor %} 48 {%- endfor %}
49 49
50 {#--- ForwardToCallback definition #} 50 {#--- ForwardToCallback definition #}
51 {%- for method in interface.methods -%} 51 {%- for method in interface.methods -%}
52 {%- if method.response_parameters != None %} 52 {%- if method.response_parameters != None %}
53 class {{class_name}}_{{method.name}}_ForwardToCallback 53 class {{class_name}}_{{method.name}}_ForwardToCallback
54 : public mojo::MessageReceiver { 54 : public mojo::MessageReceiver {
55 public: 55 public:
56 {{class_name}}_{{method.name}}_ForwardToCallback( 56 {{class_name}}_{{method.name}}_ForwardToCallback(
57 const {{class_name}}::{{method.name}}Callback& callback) 57 const {{class_name}}::{{method.name}}Callback& callback,
58 : callback_(callback) { 58 scoped_refptr<mojo::internal::MultiplexRouter> router)
59 : callback_(callback), serialization_context_(router.Pass()) {
59 } 60 }
60 bool Accept(mojo::Message* message) override; 61 bool Accept(mojo::Message* message) override;
61 private: 62 private:
62 {{class_name}}::{{method.name}}Callback callback_; 63 {{class_name}}::{{method.name}}Callback callback_;
64 mojo::internal::SerializationContext serialization_context_;
63 MOJO_DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ForwardToCallback ); 65 MOJO_DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ForwardToCallback );
64 }; 66 };
65 bool {{class_name}}_{{method.name}}_ForwardToCallback::Accept( 67 bool {{class_name}}_{{method.name}}_ForwardToCallback::Accept(
66 mojo::Message* message) { 68 mojo::Message* message) {
67 internal::{{class_name}}_{{method.name}}_ResponseParams_Data* params = 69 internal::{{class_name}}_{{method.name}}_ResponseParams_Data* params =
68 reinterpret_cast<internal::{{class_name}}_{{method.name}}_ResponseParams_D ata*>( 70 reinterpret_cast<internal::{{class_name}}_{{method.name}}_ResponseParams_D ata*>(
69 message->mutable_payload()); 71 message->mutable_payload());
70 72
71 params->DecodePointersAndHandles(message->mutable_handles()); 73 params->DecodePointersAndHandles(message->mutable_handles());
72 {{alloc_params(method.response_param_struct)}} 74 {{alloc_params(method.response_param_struct, "&serialization_context_")}}
73 callback_.Run({{pass_params(method.response_parameters)}}); 75 callback_.Run({{pass_params(method.response_parameters)}});
74 return true; 76 return true;
75 } 77 }
76 {%- endif %} 78 {%- endif %}
77 {%- endfor %} 79 {%- endfor %}
78 80
79 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiverWithResponder* receiver) 81 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiverWithResponder* receiver)
80 : ControlMessageProxy(receiver) { 82 : ControlMessageProxy(receiver) {
81 } 83 }
82 84
(...skipping 12 matching lines...) Expand all
95 {%- if method.response_parameters != None %} 97 {%- if method.response_parameters != None %}
96 mojo::internal::RequestMessageBuilder builder({{message_name}}, size); 98 mojo::internal::RequestMessageBuilder builder({{message_name}}, size);
97 {%- else %} 99 {%- else %}
98 mojo::internal::MessageBuilder builder({{message_name}}, size); 100 mojo::internal::MessageBuilder builder({{message_name}}, size);
99 {%- endif %} 101 {%- endif %}
100 102
101 {{build_message(params_struct, params_description)}} 103 {{build_message(params_struct, params_description)}}
102 104
103 {%- if method.response_parameters != None %} 105 {%- if method.response_parameters != None %}
104 mojo::MessageReceiver* responder = 106 mojo::MessageReceiver* responder =
105 new {{class_name}}_{{method.name}}_ForwardToCallback(callback); 107 new {{class_name}}_{{method.name}}_ForwardToCallback(callback, serializati on_context_.router);
106 if (!receiver_->AcceptWithResponder(builder.message(), responder)) 108 if (!receiver_->AcceptWithResponder(builder.message(), responder))
107 delete responder; 109 delete responder;
108 {%- else %} 110 {%- else %}
109 bool ok = receiver_->Accept(builder.message()); 111 bool ok = receiver_->Accept(builder.message());
110 // This return value may be ignored as !ok implies the Connector has 112 // This return value may be ignored as !ok implies the Connector has
111 // encountered an error, which will be visible through other means. 113 // encountered an error, which will be visible through other means.
112 MOJO_ALLOW_UNUSED_LOCAL(ok); 114 MOJO_ALLOW_UNUSED_LOCAL(ok);
113 {%- endif %} 115 {%- endif %}
114 } 116 }
115 {%- endfor %} 117 {%- endfor %}
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 switch (message->header()->name) { 186 switch (message->header()->name) {
185 {%- for method in interface.methods %} 187 {%- for method in interface.methods %}
186 case internal::k{{class_name}}_{{method.name}}_Name: { 188 case internal::k{{class_name}}_{{method.name}}_Name: {
187 mojo::internal::ScopedTaskTracking task_id("mojo.{{namespace_as_string}}.{ {class_name}}.{{method.name}}", __FILE__, __LINE__); 189 mojo::internal::ScopedTaskTracking task_id("mojo.{{namespace_as_string}}.{ {class_name}}.{{method.name}}", __FILE__, __LINE__);
188 {%- if method.response_parameters == None %} 190 {%- if method.response_parameters == None %}
189 internal::{{class_name}}_{{method.name}}_Params_Data* params = 191 internal::{{class_name}}_{{method.name}}_Params_Data* params =
190 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >( 192 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >(
191 message->mutable_payload()); 193 message->mutable_payload());
192 194
193 params->DecodePointersAndHandles(message->mutable_handles()); 195 params->DecodePointersAndHandles(message->mutable_handles());
194 {{alloc_params(method.param_struct)|indent(4)}} 196 {{alloc_params(method.param_struct, "&serialization_context_")|indent(4)}}
195 // A null |sink_| means no implementation was bound. 197 // A null |sink_| means no implementation was bound.
196 assert(sink_); 198 assert(sink_);
197 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); 199 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}");
198 sink_->{{method.name}}({{pass_params(method.parameters)}}); 200 sink_->{{method.name}}({{pass_params(method.parameters)}});
199 return true; 201 return true;
200 {%- else %} 202 {%- else %}
201 break; 203 break;
202 {%- endif %} 204 {%- endif %}
203 } 205 }
204 {%- endfor %} 206 {%- endfor %}
(...skipping 14 matching lines...) Expand all
219 {%- if method.response_parameters != None %} 221 {%- if method.response_parameters != None %}
220 internal::{{class_name}}_{{method.name}}_Params_Data* params = 222 internal::{{class_name}}_{{method.name}}_Params_Data* params =
221 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >( 223 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >(
222 message->mutable_payload()); 224 message->mutable_payload());
223 225
224 params->DecodePointersAndHandles(message->mutable_handles()); 226 params->DecodePointersAndHandles(message->mutable_handles());
225 {{class_name}}::{{method.name}}Callback::Runnable* runnable = 227 {{class_name}}::{{method.name}}Callback::Runnable* runnable =
226 new {{class_name}}_{{method.name}}_ProxyToResponder( 228 new {{class_name}}_{{method.name}}_ProxyToResponder(
227 message->request_id(), responder); 229 message->request_id(), responder);
228 {{class_name}}::{{method.name}}Callback callback(runnable); 230 {{class_name}}::{{method.name}}Callback callback(runnable);
229 {{alloc_params(method.param_struct)|indent(4)}} 231 {{alloc_params(method.param_struct, "&serialization_context_")|indent(4)}}
230 // A null |sink_| means no implementation was bound. 232 // A null |sink_| means no implementation was bound.
231 assert(sink_); 233 assert(sink_);
232 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}"); 234 TRACE_EVENT0("mojom", "{{class_name}}::{{method.name}}");
233 sink_->{{method.name}}( 235 sink_->{{method.name}}(
234 {%- if method.parameters -%}{{pass_params(method.parameters)}}, {% endif -%}call back); 236 {%- if method.parameters -%}{{pass_params(method.parameters)}}, {% endif -%}call back);
235 return true; 237 return true;
236 {%- else %} 238 {%- else %}
237 break; 239 break;
238 {%- endif %} 240 {%- endif %}
239 } 241 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 default: 317 default:
316 break; 318 break;
317 } 319 }
318 320
319 // Unrecognized message. 321 // Unrecognized message.
320 ReportValidationError( 322 ReportValidationError(
321 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); 323 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
322 return false; 324 return false;
323 } 325 }
324 {%- endif -%} 326 {%- endif -%}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698