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

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

Issue 131033002: Mojo: Simplify object serialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indentation error Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/bindings/generators/cpp_templates/module.cc.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {%- set class_name = interface.name %} 1 {%- set class_name = interface.name %}
2 {%- set proxy_name = interface.name ~ "Proxy" %} 2 {%- set proxy_name = interface.name ~ "Proxy" %}
3 3
4 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiver* receiver) 4 {{proxy_name}}::{{proxy_name}}(mojo::MessageReceiver* receiver)
5 : receiver_(receiver) { 5 : receiver_(receiver) {
6 } 6 }
7 7
8 {#--- Proxy definitions #} 8 {#--- Proxy definitions #}
9 {%- macro params_list(method) %} 9 {%- macro params_list(method) %}
10 {%- for param in method.parameters -%} 10 {%- for param in method.parameters -%}
11 {{param.kind|cpp_const_wrapper_type}} {{param.name}} 11 {{param.kind|cpp_const_wrapper_type}} {{param.name}}
12 {%- if not loop.last %}, {% endif %} 12 {%- if not loop.last %}, {% endif %}
13 {%- endfor %} 13 {%- endfor %}
14 {%- endmacro %} 14 {%- endmacro %}
15 15
16 {%- for method in interface.methods %} 16 {%- for method in interface.methods %}
17 {%- set name = "internal::k%s_%s_Name"|format(interface.name, method.name) %} 17 {%- set name = "internal::k%s_%s_Name"|format(interface.name, method.name) %}
18 {%- set params_name = 18 {%- set params_name =
19 "internal::%s_%s_Params_Data"|format(interface.name, method.name) %} 19 "internal::%s_%s_Params_Data"|format(interface.name, method.name) %}
20 void {{proxy_name}}::{{method.name}}({{params_list(method)}}) { 20 void {{proxy_name}}::{{method.name}}({{params_list(method)}}) {
21 size_t payload_size = 21 size_t payload_size =
22 mojo::internal::Align(sizeof({{params_name}})); 22 mojo::internal::Align(sizeof({{params_name}}));
23 {#--- Computes #} 23 {#--- Computes #}
24 {%- for param in method.parameters %} 24 {%- for param in method.parameters %}
25 {%- if param.kind|is_object_kind %} 25 {%- if param.kind|is_object_kind %}
26 payload_size += mojo::internal::ComputeSizeOf( 26 if (!{{param.name}}.is_null())
27 mojo::internal::Unwrap({{param.name}})); 27 payload_size += mojo::internal::Unwrap({{param.name}})->ComputeSize();
28 {%- endif %} 28 {%- endif %}
29 {%- endfor %} 29 {%- endfor %}
30 30
31 mojo::internal::MessageBuilder builder({{name}}, payload_size); 31 mojo::internal::MessageBuilder builder({{name}}, payload_size);
32 32
33 {{params_name}}* params = 33 {{params_name}}* params =
34 {{params_name}}::New(builder.buffer()); 34 {{params_name}}::New(builder.buffer());
35 35
36 {#--- Sets #} 36 {#--- Sets #}
37 {% for param in method.parameters %} 37 {% for param in method.parameters %}
38 {%- if param.kind|is_object_kind %} 38 {%- if param.kind|is_object_kind %}
39 params->set_{{param.name}}( 39 if (!{{param.name}}.is_null())
40 mojo::internal::Clone(mojo::internal::Unwrap({{param.name}}), 40 params->set_{{param.name}}(
41 builder.buffer())); 41 mojo::internal::Unwrap({{param.name}})->Clone(builder.buffer()));
42 {%- elif param.kind|is_handle_kind %} 42 {%- elif param.kind|is_handle_kind %}
43 params->set_{{param.name}}({{param.name}}.release()); 43 params->set_{{param.name}}({{param.name}}.release());
44 {%- else %} 44 {%- else %}
45 params->set_{{param.name}}({{param.name}}); 45 params->set_{{param.name}}({{param.name}});
46 {%- endif %} 46 {%- endif %}
47 {%- endfor %} 47 {%- endfor %}
48 48
49 mojo::Message message; 49 mojo::Message message;
50 mojo::internal::EncodePointersAndHandles(params, &message.handles); 50 params->EncodePointersAndHandles(&message.handles);
51 51
52 message.data = builder.Finish(); 52 message.data = builder.Finish();
53 53
54 receiver_->Accept(&message); 54 receiver_->Accept(&message);
55 } 55 }
56 {%- endfor %} 56 {%- endfor %}
57 57
58 {{class_name}}Stub::{{class_name}}Stub({{class_name}}* sink) 58 {{class_name}}Stub::{{class_name}}Stub({{class_name}}* sink)
59 : sink_(sink) { 59 : sink_(sink) {
60 } 60 }
(...skipping 13 matching lines...) Expand all
74 {%- endmacro %} 74 {%- endmacro %}
75 75
76 bool {{class_name}}Stub::Accept(mojo::Message* message) { 76 bool {{class_name}}Stub::Accept(mojo::Message* message) {
77 switch (message->data->header.name) { 77 switch (message->data->header.name) {
78 {%- for method in interface.methods %} 78 {%- for method in interface.methods %}
79 case internal::k{{class_name}}_{{method.name}}_Name: { 79 case internal::k{{class_name}}_{{method.name}}_Name: {
80 internal::{{class_name}}_{{method.name}}_Params_Data* params = 80 internal::{{class_name}}_{{method.name}}_Params_Data* params =
81 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >( 81 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data* >(
82 message->data->payload); 82 message->data->payload);
83 83
84 if (!mojo::internal::DecodePointersAndHandles(params, message)) 84 if (!params->DecodePointersAndHandles(message))
85 return false; 85 return false;
86 sink_->{{method.name}}({{params(method)}}); 86 sink_->{{method.name}}({{params(method)}});
87 mojo::internal::CloseHandles(params); 87 params->CloseHandles();
88 break; 88 break;
89 } 89 }
90 {%- endfor %} 90 {%- endfor %}
91 } 91 }
92 return true; 92 return true;
93 } 93 }
OLDNEW
« no previous file with comments | « no previous file | mojo/public/bindings/generators/cpp_templates/module.cc.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698