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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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
OLDNEW
(Empty)
1 {% from "constant_definition.tmpl" import constant_def %}
2 {% from "enum_definition.tmpl" import enum_def %}
3 {% from "struct_definition.tmpl" import struct_def %}
4
5 {%- macro declare_params(parameters, boxed=false) %}
6 {%- for param in parameters -%}
7 {{param.kind|java_type(boxed)}} {{param|name}}
8 {%- if not loop.last %}, {% endif %}
9 {%- endfor %}
10 {%- endmacro %}
11
12 {% macro declare_request_params(method) %}
13 {{declare_params(method.parameters)}}
14 {%- if method.response_parameters != None -%}
15 {%- if method.parameters %}, {% endif %}
16 {{method|interface_response_name}} callback
17 {%- endif -%}
18 {% endmacro %}
19
20 {%- macro declare_callback(method) -%}
21
22 interface {{method|interface_response_name}} extends org.chromium.mojo.bindings. Callbacks.Callback{{method.response_parameters|length}}{% if method.response_par ameters %}<
23 {%- for param in method.response_parameters -%}
24 {{param.kind|java_type(True)}}
25 {%- if not loop.last %}, {% endif %}
26 {%- endfor -%}
27 >{% endif %} { }
28 {%- endmacro -%}
29
30 {%- macro run_callback(variable, parameters) -%}
31 {%- if parameters -%}
32 {%- for param in parameters -%}
33 {{variable}}.{{param|name}}
34 {%- if not loop.last %}, {% endif %}
35 {%- endfor -%}
36 {%- endif -%}
37 {%- endmacro -%}
38
39 {%- macro super_class(client, with_generic=True) -%}
40 {%- if client -%}
41 org.chromium.mojo.bindings.InterfaceWithClient{% if with_generic %}<{{client|jav a_type}}>{% endif %}
42 {%- else -%}
43 org.chromium.mojo.bindings.Interface
44 {%- endif -%}
45 {%- endmacro -%}
46
47 {%- macro flags_for_method(method, is_parameter) -%}
48 {{flags(method.response_parameters, is_parameter)}}
49 {%- endmacro -%}
50
51 {%- macro flags(has_response_parameters, is_parameter) -%}
52 {%- if not has_response_parameters -%}
53 org.chromium.mojo.bindings.MessageHeader.NO_FLAG
54 {%- elif is_parameter: -%}
55 org.chromium.mojo.bindings.MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG
56 {%- else -%}
57 org.chromium.mojo.bindings.MessageHeader.MESSAGE_IS_RESPONSE_FLAG
58 {%- endif -%}
59 {%- endmacro -%}
60
61 {%- macro manager_class(interface, client, fully_qualified=False) -%}
62 {% if fully_qualified %}{{super_class(client, False)}}.{% endif %}Manager<{{inte rface|name}}, {{interface|name}}.Proxy
63 {%- if client -%}, {{client|java_type}}{%- endif -%}
64 >
65 {%- endmacro -%}
66
67 {%- macro manager_def(interface, client) -%}
68 public static final {{manager_class(interface, client, True)}} MANAGER =
69 new {{manager_class(interface, client, True)}}() {
70
71 public String getName() {
72 return "{{namespace|replace(".","::")}}::{{interface.name}}";
73 }
74
75 public Proxy buildProxy(org.chromium.mojo.system.Core core,
76 org.chromium.mojo.bindings.MessageReceiverWithRespon der messageReceiver) {
77 return new Proxy(core, messageReceiver);
78 }
79
80 public Stub buildStub(org.chromium.mojo.system.Core core, {{interface|name}} impl) {
81 return new Stub(core, impl);
82 }
83
84 public {{interface|name}}[] buildArray(int size) {
85 return new {{interface|name}}[size];
86 }
87 {% if client %}
88
89 protected org.chromium.mojo.bindings.Interface.Manager<{{client|java_type}}, ?> getClientManager() {
90 return {{client|java_type}}.MANAGER;
91 }
92 {% endif %}
93 };
94 {%- endmacro -%}
95
96 {%- macro accept_body(interface, with_response) -%}
97 {% if (interface|has_method_with_response and with_response) or
98 (interface|has_method_without_response and not with_response) %}
99 try {
100 org.chromium.mojo.bindings.ServiceMessage messageWithHeader =
101 message.asServiceMessage();
102 org.chromium.mojo.bindings.MessageHeader header = messageWithHeader.getHeade r();
103 if (!header.validateHeader({{flags(with_response, True)}})) {
104 return false;
105 }
106 switch(header.getType()) {
107 {% for method in interface.methods %}
108 {% if (with_response and method.response_parameters != None) or
109 (not with_response and method.response_parameters == None) %}
110 {% set request_struct = method|struct_from_method %}
111 {% if with_response %}
112 {% set response_struct = method|response_struct_from_method %}
113 {% endif %}
114 case {{method|method_ordinal_name}}: {
115 {% if method.parameters %}
116 {{request_struct|name}} data =
117 {{request_struct|name}}.deserialize(messageWithHeader.getPay load());
118 {% else %}
119 {{request_struct|name}}.deserialize(messageWithHeader.getPayload());
120 {% endif %}
121 getImpl().{{method|name}}({{run_callback('data', method.parameters)} }{% if with_response %}{% if method.parameters %}, {% endif %}new {{response_str uct|name}}ProxyToResponder(getCore(), receiver, header.getRequestId()){% endif % });
122 return true;
123 }
124 {% endif %}
125 {% endfor %}
126 default:
127 return false;
128 }
129 } catch (org.chromium.mojo.bindings.DeserializationException e) {
130 return false;
131 }
132 {% else %}
133 return false;
134 {% endif %}
135 {%- endmacro -%}
136
137 {% macro interface_def(interface, client) %}
138 public interface {{interface|name}} extends {{super_class(client)}} {
139 {% for constant in interface.constants %}
140
141 {{constant_def(constant)|indent(4)}}
142 {% endfor %}
143 {% for enum in interface.enums %}
144
145 {{enum_def(enum, false)|indent(4)}}
146 {% endfor %}
147
148 public interface Proxy extends {{interface|name}}, {{super_class(client, Fal se)}}.Proxy{% if client %}<{{client|java_type}}>{% endif %} {
149 }
150
151 {{manager_class(interface, client)}} MANAGER = {{interface|name}}_Internal.M ANAGER;
152 {% for method in interface.methods %}
153
154 void {{method|name}}({{declare_request_params(method)}});
155 {% if method.response_parameters != None %}
156 {{declare_callback(method)|indent(4)}}
157 {% endif %}
158 {% endfor %}
159 }
160 {% endmacro %}
161
162 {% macro interface_internal_def(interface, client) %}
163 class {{interface|name}}_Internal {
164
165 {{manager_def(interface, client)|indent(4)}}
166
167 {% for method in interface.methods %}
168 private static final int {{method|method_ordinal_name}} = {{method.ordinal}} ;
169 {% endfor %}
170
171 static final class Proxy extends {% if client %}org.chromium.mojo.bindings.I nterfaceWithClient.AbstractProxy<{{client|java_type}}>{% else %}org.chromium.moj o.bindings.Interface.AbstractProxy{% endif %} implements {{interface|name}}.Prox y {
172
173 Proxy(org.chromium.mojo.system.Core core,
174 org.chromium.mojo.bindings.MessageReceiverWithResponder messageRec eiver) {
175 super(core, messageReceiver);
176 }
177 {% for method in interface.methods %}
178
179 @Override
180 public void {{method|name}}({{declare_request_params(method)}}) {
181 {% set request_struct = method|struct_from_method %}
182 {{request_struct|name}} _message = new {{request_struct|name}}();
183 {% for param in method.parameters %}
184 _message.{{param|name}} = {{param|name}};
185 {% endfor %}
186 {% if method.response_parameters != None %}
187 getMessageReceiver().acceptWithResponder(
188 _message.serializeWithHeader(
189 getCore(),
190 new org.chromium.mojo.bindings.MessageHeader(
191 {{method|method_ordinal_name}},
192 {{flags_for_method(method, True)}},
193 0)),
194 new {{method|response_struct_from_method|name}}ForwardToCall back(callback));
195 {% else %}
196 getMessageReceiver().accept(
197 _message.serializeWithHeader(
198 getCore(),
199 new org.chromium.mojo.bindings.MessageHeader({{metho d|method_ordinal_name}})));
200 {% endif %}
201 }
202 {% endfor %}
203
204 }
205
206 static final class Stub extends org.chromium.mojo.bindings.Interface.Stub<{{ interface|name}}> {
207
208 Stub(org.chromium.mojo.system.Core core, {{interface|name}} impl) {
209 super(core, impl);
210 }
211
212 @Override
213 public boolean accept(org.chromium.mojo.bindings.Message message) {
214 {{accept_body(interface, False)|indent(12)}}
215 }
216
217 @Override
218 public boolean acceptWithResponder(org.chromium.mojo.bindings.Message me ssage, org.chromium.mojo.bindings.MessageReceiver receiver) {
219 {{accept_body(interface, True)|indent(12)}}
220 }
221 }
222 {% for method in interface.methods %}
223
224 {{ struct_def(method|struct_from_method, True)|indent(4) }}
225 {% if method.response_parameters != None %}
226 {% set response_struct = method|response_struct_from_method %}
227
228 {{ struct_def(response_struct, True)|indent(4) }}
229
230 static class {{response_struct|name}}ForwardToCallback extends org.chromium. mojo.bindings.SideEffectFreeCloseable
231 implements org.chromium.mojo.bindings.MessageReceiver {
232 private final {{interface|name}}.{{method|interface_response_name}} mCal lback;
233
234 {{response_struct|name}}ForwardToCallback({{interface|name}}.{{method|in terface_response_name}} callback) {
235 this.mCallback = callback;
236 }
237
238 @Override
239 public boolean accept(org.chromium.mojo.bindings.Message message) {
240 try {
241 org.chromium.mojo.bindings.ServiceMessage messageWithHeader =
242 message.asServiceMessage();
243 org.chromium.mojo.bindings.MessageHeader header = messageWithHea der.getHeader();
244 if (!header.validateHeader({{method|method_ordinal_name}},
245 {{flags_for_method(method, False)}})) {
246 return false;
247 }
248 {% if method.response_parameters|length %}
249 {{response_struct|name}} response = {{response_struct|name}}.des erialize(messageWithHeader.getPayload());
250 {% endif %}
251 mCallback.call({{run_callback('response', method.response_parame ters)}});
252 return true;
253 } catch (org.chromium.mojo.bindings.DeserializationException e) {
254 return false;
255 }
256 }
257 }
258
259 static class {{response_struct|name}}ProxyToResponder implements {{interface |name}}.{{method|interface_response_name}} {
260
261 private final org.chromium.mojo.system.Core mCore;
262 private final org.chromium.mojo.bindings.MessageReceiver mMessageReceive r;
263 private final long mRequestId;
264
265 {{response_struct|name}}ProxyToResponder(
266 org.chromium.mojo.system.Core core,
267 org.chromium.mojo.bindings.MessageReceiver messageReceiver,
268 long requestId) {
269 mCore = core;
270 mMessageReceiver = messageReceiver;
271 mRequestId = requestId;
272 }
273
274 @Override
275 public void call({{declare_params(method.response_parameters, true)}}) {
276 {{response_struct|name}} _response = new {{response_struct|name}}();
277 {% for param in method.response_parameters %}
278 _response.{{param|name}} = {{param|name}};
279 {% endfor %}
280 org.chromium.mojo.bindings.ServiceMessage _message =
281 _response.serializeWithHeader(
282 mCore,
283 new org.chromium.mojo.bindings.MessageHeader(
284 {{method|method_ordinal_name}},
285 {{flags_for_method(method, False)}},
286 mRequestId));
287 mMessageReceiver.accept(_message);
288 }
289 }
290 {% endif %}
291 {% endfor %}
292
293 }
294 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698