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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.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 {# TODO(yzshen): Make these templates more readable. #} 1 {# TODO(yzshen): Make these templates more readable. #}
2 2
3 {# Computes the serialized size for the specified struct. 3 {# Computes the serialized size for the specified struct.
4 |struct| is the struct definition. 4 |struct| is the struct definition.
5 |input_field_pattern| should be a pattern that contains one string 5 |input_field_pattern| should be a pattern that contains one string
6 placeholder, for example, "input->%s", "p_%s". The placeholder will be 6 placeholder, for example, "input->%s", "p_%s". The placeholder will be
7 substituted with struct field names to refer to the input fields. 7 substituted with struct field names to refer to the input fields.
8 This macro is expanded to compute seriailized size for both: 8 This macro is expanded to compute seriailized size for both:
9 - user-defined structs: the input is an instance of the corresponding struct 9 - user-defined structs: the input is an instance of the corresponding struct
10 wrapper class. 10 wrapper class.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 83 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
84 {%- if kind|is_interface_kind %} 84 {%- if kind|is_interface_kind %}
85 !{{output}}->{{name}}.handle.is_valid(), 85 !{{output}}->{{name}}.handle.is_valid(),
86 {%- else %} 86 {%- else %}
87 !{{output}}->{{name}}.is_valid(), 87 !{{output}}->{{name}}.is_valid(),
88 {%- endif %} 88 {%- endif %}
89 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, 89 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
90 "invalid {{name}} in {{struct_display_name}}"); 90 "invalid {{name}} in {{struct_display_name}}");
91 {%- endif %} 91 {%- endif %}
92 {%- elif kind|is_associated_kind %} 92 {%- elif kind|is_associated_kind %}
93 // TODO(yzshen): add serialization logic for associated kinds. 93 // TODO(yzshen): add some DCHECKs for non-nullable, is_local, correct router, etc.
94 {%- if kind|is_associated_interface_kind %}
95 mojo::internal::AssociatedInterfacePtrInfoToData({{input_field}}.Pass(), &{{ou tput}}->{{name}});
96 {%- else %}
97 {{output}}->{{name}} = mojo::internal::AssociatedInterfaceRequestHelper::PassH andle(&{{input_field}}).release();
98 {%- endif %}
94 {%- else %} 99 {%- else %}
95 {{output}}->{{name}} = {{input_field}}; 100 {{output}}->{{name}} = {{input_field}};
96 {%- endif %} 101 {%- endif %}
97 {%- endfor %} 102 {%- endfor %}
98 {%- endmacro -%} 103 {%- endmacro -%}
99 104
100 {# Deserializes the specified struct. 105 {# Deserializes the specified struct.
101 |struct| is the struct definition. 106 |struct| is the struct definition.
102 |input| is the name of the input struct instance. 107 |input| is the name of the input struct instance.
103 |output_field_pattern| should be a pattern that contains one string 108 |output_field_pattern| should be a pattern that contains one string
104 placeholder, for example, "result->%s", "p_%s". The placeholder will be 109 placeholder, for example, "result->%s", "p_%s". The placeholder will be
105 substituted with struct field names to refer to the output fields. 110 substituted with struct field names to refer to the output fields.
106 This macro is expanded to do deserialization for both: 111 This macro is expanded to do deserialization for both:
107 - user-defined structs: the output is an instance of the corresponding 112 - user-defined structs: the output is an instance of the corresponding
108 struct wrapper class. 113 struct wrapper class.
109 - method parameters/response parameters: the output is a list of 114 - method parameters/response parameters: the output is a list of
110 arguments. #} 115 arguments. #}
111 {%- macro deserialize(struct, input, output_field_pattern) -%} 116 |context| is the name of the serialization context.
117 {%- macro deserialize(struct, input, output_field_pattern, context) -%}
112 do { 118 do {
113 // NOTE: The memory backing |{{input}}| may has be smaller than 119 // NOTE: The memory backing |{{input}}| may has be smaller than
114 // |sizeof(*{{input}})| if the message comes from an older version. 120 // |sizeof(*{{input}})| if the message comes from an older version.
115 {#- Before deserialize fields introduced at a certain version, we need to add 121 {#- Before deserialize fields introduced at a certain version, we need to add
116 a version check, which makes sure we skip further deserialization if 122 a version check, which makes sure we skip further deserialization if
117 |input| is from an earlier version. |last_checked_version| records the 123 |input| is from an earlier version. |last_checked_version| records the
118 last version that we have added such version check. #} 124 last version that we have added such version check. #}
119 {%- set last_checked_version = 0 %} 125 {%- set last_checked_version = 0 %}
120 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} 126 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
121 {%- set output_field = output_field_pattern|format(pf.field.name) %} 127 {%- set output_field = output_field_pattern|format(pf.field.name) %}
122 {%- set name = pf.field.name %} 128 {%- set name = pf.field.name %}
123 {%- set kind = pf.field.kind %} 129 {%- set kind = pf.field.kind %}
124 {%- if pf.min_version > last_checked_version %} 130 {%- if pf.min_version > last_checked_version %}
125 {%- set last_checked_version = pf.min_version %} 131 {%- set last_checked_version = pf.min_version %}
126 if ({{input}}->header_.version < {{pf.min_version}}) 132 if ({{input}}->header_.version < {{pf.min_version}})
127 break; 133 break;
128 {%- endif %} 134 {%- endif %}
129 {%- if kind|is_object_kind %} 135 {%- if kind|is_object_kind %}
130 {%- if kind|is_union_kind %} 136 {%- if kind|is_union_kind %}
131 Deserialize_(&{{input}}->{{name}}, &{{output_field}}); 137 Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}});
132 {%- else %} 138 {%- else %}
133 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); 139 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}});
134 {%- endif %} 140 {%- endif %}
135 {%- elif kind|is_interface_kind %} 141 {%- elif kind|is_interface_kind %}
136 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); 142 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }});
137 {%- elif kind|is_interface_request_kind %} 143 {%- elif kind|is_interface_request_kind %}
138 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); 144 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}})));
139 {%- elif kind|is_any_handle_kind %} 145 {%- elif kind|is_any_handle_kind %}
140 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 146 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
141 {%- elif kind|is_associated_kind %} 147 {%- elif kind|is_associated_interface_kind %}
142 // TODO(yzshen): add deserialization logic for associated kinds. 148 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou tput_field}}, ({{context}})->router.get());
149 {%- elif kind|is_associated_interface_request_kind %}
150 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle(
151 &{{output_field}},
152 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn dReset(&{{input}}->{{name}})));
143 {%- elif kind|is_enum_kind %} 153 {%- elif kind|is_enum_kind %}
144 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 154 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
145 {%- else %} 155 {%- else %}
146 {{output_field}} = {{input}}->{{name}}; 156 {{output_field}} = {{input}}->{{name}};
147 {%- endif %} 157 {%- endif %}
148 {%- endfor %} 158 {%- endfor %}
149 } while (false); 159 } while (false);
150 {%- endmacro %} 160 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698