blob: ee76e1807da9ba836814f454c77389f0ebbaa19c [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Huber2831d512016-08-15 09:33:47 -070017#include "AST.h"
18
19#include "Coordinator.h"
Andreas Huber2831d512016-08-15 09:33:47 -070020#include "Interface.h"
21#include "Method.h"
22#include "Scope.h"
23
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070024#include <hidl-util/Formatter.h>
Andreas Huber2831d512016-08-15 09:33:47 -070025#include <android-base/logging.h>
26
27namespace android {
28
Andreas Huber2831d512016-08-15 09:33:47 -070029void AST::emitJavaReaderWriter(
30 Formatter &out,
31 const std::string &parcelObj,
32 const TypedVar *arg,
33 bool isReader) const {
34 if (isReader) {
Yifan Hong4ed13472016-11-02 10:44:11 -070035 out << arg->type().getJavaType()
Andreas Huber2831d512016-08-15 09:33:47 -070036 << " "
37 << arg->name()
38 << " = ";
39 }
40
41 arg->type().emitJavaReaderWriter(out, parcelObj, arg->name(), isReader);
42}
43
Andreas Huber0fa9e392016-08-31 09:05:44 -070044status_t AST::generateJavaTypes(
Andreas Huberd29724f2016-09-14 09:33:13 -070045 const std::string &outputPath, const std::string &limitToType) const {
Andreas Huber85eabdb2016-08-25 11:24:49 -070046 // Splits types.hal up into one java file per declared type.
47
Steven Morelandd537ab02016-09-12 10:32:01 -070048 for (const auto &type : mRootScope->getSubTypes()) {
49 std::string typeName = type->localName();
Andreas Huber85eabdb2016-08-25 11:24:49 -070050
51 if (type->isTypeDef()) {
52 continue;
53 }
54
Andreas Huberd29724f2016-09-14 09:33:13 -070055 if (!limitToType.empty() && typeName != limitToType) {
Andreas Huber0fa9e392016-08-31 09:05:44 -070056 continue;
57 }
58
Andreas Huber85eabdb2016-08-25 11:24:49 -070059 std::string path = outputPath;
60 path.append(mCoordinator->convertPackageRootToPath(mPackage));
61 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
62 path.append(typeName);
63 path.append(".java");
64
65 CHECK(Coordinator::MakeParentHierarchy(path));
66 FILE *file = fopen(path.c_str(), "w");
67
68 if (file == NULL) {
69 return -errno;
70 }
71
72 Formatter out(file);
73
74 std::vector<std::string> packageComponents;
75 getPackageAndVersionComponents(
76 &packageComponents, true /* cpp_compatible */);
77
78 out << "package " << mPackage.javaPackage() << ";\n\n";
79
Iliyan Malchev800273d2016-09-02 15:25:07 -070080 for (const auto &item : mImportedNamesForJava) {
81 out << "import " << item.javaName() << ";\n";
82 }
83 out << "\n";
84
Andreas Huber85eabdb2016-08-25 11:24:49 -070085 status_t err =
86 type->emitJavaTypeDeclarations(out, true /* atTopLevel */);
87
88 if (err != OK) {
89 return err;
90 }
91 }
92
93 return OK;
94}
95
Andreas Huber0fa9e392016-08-31 09:05:44 -070096status_t AST::generateJava(
Andreas Huberd29724f2016-09-14 09:33:13 -070097 const std::string &outputPath, const std::string &limitToType) const {
Andreas Huber0fa9e392016-08-31 09:05:44 -070098 if (!isJavaCompatible()) {
Andreas Huber70a59e12016-08-16 12:57:01 -070099 fprintf(stderr,
100 "ERROR: This interface is not Java compatible. The Java backend"
Andreas Huberf03332a2016-09-22 15:35:43 -0700101 " does NOT support union types nor native handles. "
102 "In addition, vectors of arrays are limited to at most "
Andreas Huber86a112b2016-10-19 14:25:16 -0700103 "one-dimensional arrays and vectors of {vectors,interfaces} are"
104 " not supported.\n");
Andreas Huber70a59e12016-08-16 12:57:01 -0700105
Andreas Huber2831d512016-08-15 09:33:47 -0700106 return UNKNOWN_ERROR;
107 }
108
Andreas Huber0fa9e392016-08-31 09:05:44 -0700109 std::string ifaceName;
110 if (!AST::isInterface(&ifaceName)) {
111 return generateJavaTypes(outputPath, limitToType);
112 }
113
114 const Interface *iface = mRootScope->getInterface();
115
Jayant Chowdhary3f32c1f2016-09-15 16:53:56 -0700116 const std::string baseName = iface->getBaseName();
Andreas Huber2831d512016-08-15 09:33:47 -0700117
118 std::string path = outputPath;
119 path.append(mCoordinator->convertPackageRootToPath(mPackage));
120 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
121 path.append(ifaceName);
122 path.append(".java");
123
124 CHECK(Coordinator::MakeParentHierarchy(path));
125 FILE *file = fopen(path.c_str(), "w");
126
127 if (file == NULL) {
128 return -errno;
129 }
130
131 Formatter out(file);
132
133 std::vector<std::string> packageComponents;
134 getPackageAndVersionComponents(
135 &packageComponents, true /* cpp_compatible */);
136
137 out << "package " << mPackage.javaPackage() << ";\n\n";
138
Andreas Huber85eabdb2016-08-25 11:24:49 -0700139 for (const auto &item : mImportedNamesForJava) {
Andreas Huber2831d512016-08-15 09:33:47 -0700140 out << "import " << item.javaName() << ";\n";
141 }
142
Andreas Huber85eabdb2016-08-25 11:24:49 -0700143 if (!mImportedNamesForJava.empty()) {
Andreas Huber2831d512016-08-15 09:33:47 -0700144 out << "\n";
145 }
146
147 out.setNamespace(mPackage.javaPackage() + ".");
148
Andreas Huber2831d512016-08-15 09:33:47 -0700149 const Interface *superType = iface->superType();
150
151 out << "public interface " << ifaceName << " extends ";
152
153 if (superType != NULL) {
154 out << superType->fullJavaName();
155 } else {
Yifan Hong1af73532016-11-09 14:32:58 -0800156 out << "android.os.IHwInterface";
Andreas Huber2831d512016-08-15 09:33:47 -0700157 }
158
159 out << " {\n";
160 out.indent();
161
162 out << "public static final String kInterfaceName = \""
163 << mPackage.string()
164 << "::"
165 << ifaceName
166 << "\";\n\n";
167
168 out << "public static "
169 << ifaceName
Yifan Hong1af73532016-11-09 14:32:58 -0800170 << " asInterface(android.os.IHwBinder binder) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700171
172 out.indent();
173
174 out << "if (binder == null) {\n";
175 out.indent();
176 out << "return null;\n";
177 out.unindent();
178 out << "}\n\n";
179
Yifan Hong1af73532016-11-09 14:32:58 -0800180 out << "android.os.IHwInterface iface =\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700181 out.indent();
182 out.indent();
183 out << "binder.queryLocalInterface(kInterfaceName);\n\n";
184 out.unindent();
185 out.unindent();
186
187 out << "if ((iface != null) && (iface instanceof "
188 << ifaceName
189 << ")) {\n";
190
191 out.indent();
192 out << "return (" << ifaceName << ")iface;\n";
193 out.unindent();
194 out << "}\n\n";
195
196 out << "return new " << ifaceName << ".Proxy(binder);\n";
197
198 out.unindent();
199 out << "}\n\n";
200
Yifan Hong1af73532016-11-09 14:32:58 -0800201 out << "public android.os.IHwBinder asBinder();\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700202
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700203 out << "public static "
204 << ifaceName
205 << " getService(String serviceName) {\n";
206
207 out.indent();
208
209 out << "return "
210 << ifaceName
Yifan Hong1af73532016-11-09 14:32:58 -0800211 << ".asInterface(android.os.HwBinder.getService(\""
Steven Moreland7e367bf2016-11-04 11:31:41 -0700212 << iface->fqName().string()
213 << "\",serviceName));\n";
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700214
215 out.unindent();
216
217 out << "}\n\n";
218
Andreas Huber2831d512016-08-15 09:33:47 -0700219 status_t err = emitJavaTypeDeclarations(out);
220
221 if (err != OK) {
222 return err;
223 }
224
Andreas Huber2831d512016-08-15 09:33:47 -0700225 for (const auto &method : iface->methods()) {
226 const bool returnsValue = !method->results().empty();
227 const bool needsCallback = method->results().size() > 1;
228
229 if (needsCallback) {
230 out << "\npublic abstract class "
231 << method->name()
232 << "Callback {\n";
233
234 out.indent();
235
236 out << "public abstract void onValues("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700237 << Method::GetJavaArgSignature(method->results())
Andreas Huber2831d512016-08-15 09:33:47 -0700238 << ");\n";
239
240 out.unindent();
241 out << "}\n\n";
242 }
243
244 if (returnsValue && !needsCallback) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700245 out << method->results()[0]->type().getJavaType();
Andreas Huber2831d512016-08-15 09:33:47 -0700246 } else {
247 out << "void";
248 }
249
250 out << " "
251 << method->name()
252 << "("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700253 << Method::GetJavaArgSignature(method->args());
Andreas Huber2831d512016-08-15 09:33:47 -0700254
255 if (needsCallback) {
256 if (!method->args().empty()) {
257 out << ", ";
258 }
259
260 out << method->name()
261 << "Callback cb";
262 }
263
264 out << ");\n";
265 }
266
267 out << "\npublic static final class Proxy implements "
268 << ifaceName
269 << " {\n";
270
271 out.indent();
272
Yifan Hong1af73532016-11-09 14:32:58 -0800273 out << "private android.os.IHwBinder mRemote;\n\n";
274 out << "public Proxy(android.os.IHwBinder remote) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700275 out.indent();
276 out << "mRemote = remote;\n";
277 out.unindent();
278 out << "}\n\n";
279
Yifan Hong1af73532016-11-09 14:32:58 -0800280 out << "public android.os.IHwBinder asBinder() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700281 out.indent();
282 out << "return mRemote;\n";
283 out.unindent();
284 out << "}\n\n";
285
Yifan Hong10fe0b52016-10-19 14:20:17 -0700286 const Interface *prevInterface = nullptr;
287 for (const auto &tuple : iface->allMethodsFromRoot()) {
288 const Method *method = tuple.method();
289 const Interface *superInterface = tuple.interface();
290 if (prevInterface != superInterface) {
291 out << "// Methods from "
292 << superInterface->fullName()
293 << " follow.\n";
294 prevInterface = superInterface;
295 }
296 const bool returnsValue = !method->results().empty();
297 const bool needsCallback = method->results().size() > 1;
Andreas Huber2831d512016-08-15 09:33:47 -0700298
Yifan Hong10fe0b52016-10-19 14:20:17 -0700299 out << "public ";
300 if (returnsValue && !needsCallback) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700301 out << method->results()[0]->type().getJavaType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700302 } else {
303 out << "void";
304 }
Andreas Huber2831d512016-08-15 09:33:47 -0700305
Yifan Hong10fe0b52016-10-19 14:20:17 -0700306 out << " "
307 << method->name()
308 << "("
309 << Method::GetJavaArgSignature(method->args());
Andreas Huber2831d512016-08-15 09:33:47 -0700310
Yifan Hong10fe0b52016-10-19 14:20:17 -0700311 if (needsCallback) {
312 if (!method->args().empty()) {
313 out << ", ";
Andreas Huber2831d512016-08-15 09:33:47 -0700314 }
315
Yifan Hong10fe0b52016-10-19 14:20:17 -0700316 out << method->name()
317 << "Callback cb";
318 }
Andreas Huber2831d512016-08-15 09:33:47 -0700319
Yifan Hong10fe0b52016-10-19 14:20:17 -0700320 out << ") {\n";
321 out.indent();
Andreas Huber2831d512016-08-15 09:33:47 -0700322
Steven Moreland4b39bc12016-11-16 10:42:24 -0800323 out << "android.os.HwParcel _hidl_request = new android.os.HwParcel();\n";
324 out << "_hidl_request.writeInterfaceToken("
Yifan Hong10fe0b52016-10-19 14:20:17 -0700325 << superInterface->fullJavaName()
326 << ".kInterfaceName);\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700327
Yifan Hong10fe0b52016-10-19 14:20:17 -0700328 for (const auto &arg : method->args()) {
329 emitJavaReaderWriter(
330 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800331 "_hidl_request",
Yifan Hong10fe0b52016-10-19 14:20:17 -0700332 arg,
333 false /* isReader */);
334 }
Andreas Huber2831d512016-08-15 09:33:47 -0700335
Steven Moreland4b39bc12016-11-16 10:42:24 -0800336 out << "\nandroid.os.HwParcel _hidl_reply = new android.os.HwParcel();\n"
Yifan Hong10fe0b52016-10-19 14:20:17 -0700337 << "mRemote.transact("
338 << method->getSerialId()
339 << " /* "
340 << method->name()
Steven Moreland4b39bc12016-11-16 10:42:24 -0800341 << " */, _hidl_request, _hidl_reply, ";
Andreas Huber2831d512016-08-15 09:33:47 -0700342
Yifan Hong10fe0b52016-10-19 14:20:17 -0700343 if (method->isOneway()) {
Yifan Hong1af73532016-11-09 14:32:58 -0800344 out << "android.os.IHwBinder.FLAG_ONEWAY";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700345 } else {
346 out << "0 /* flags */";
347 }
348
349 out << ");\n";
350
351 if (!method->isOneway()) {
Steven Moreland4b39bc12016-11-16 10:42:24 -0800352 out << "_hidl_reply.verifySuccess();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700353 } else {
354 CHECK(!returnsValue);
355 }
356
Steven Moreland4b39bc12016-11-16 10:42:24 -0800357 out << "_hidl_request.releaseTemporaryStorage();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700358
359 if (returnsValue) {
360 out << "\n";
361
362 for (const auto &arg : method->results()) {
Andreas Huber2831d512016-08-15 09:33:47 -0700363 emitJavaReaderWriter(
364 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800365 "_hidl_reply",
Andreas Huber2831d512016-08-15 09:33:47 -0700366 arg,
Yifan Hong10fe0b52016-10-19 14:20:17 -0700367 true /* isReader */);
Andreas Huber2831d512016-08-15 09:33:47 -0700368 }
369
Yifan Hong10fe0b52016-10-19 14:20:17 -0700370 if (needsCallback) {
371 out << "cb.onValues(";
Andreas Huber8b5da222016-08-18 14:28:18 -0700372
Yifan Hong10fe0b52016-10-19 14:20:17 -0700373 bool firstField = true;
Andreas Huber2831d512016-08-15 09:33:47 -0700374 for (const auto &arg : method->results()) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700375 if (!firstField) {
376 out << ", ";
Andreas Huber2831d512016-08-15 09:33:47 -0700377 }
378
Yifan Hong10fe0b52016-10-19 14:20:17 -0700379 out << arg->name();
380 firstField = false;
Andreas Huber2831d512016-08-15 09:33:47 -0700381 }
Andreas Huber2831d512016-08-15 09:33:47 -0700382
Yifan Hong10fe0b52016-10-19 14:20:17 -0700383 out << ");\n";
384 } else {
385 const std::string returnName = method->results()[0]->name();
386 out << "return " << returnName << ";\n";
387 }
Andreas Huber2831d512016-08-15 09:33:47 -0700388 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700389
390 out.unindent();
391 out << "}\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700392 }
393
394 out.unindent();
395 out << "}\n";
396
397 ////////////////////////////////////////////////////////////////////////////
398
Yifan Hong1af73532016-11-09 14:32:58 -0800399 out << "\npublic static abstract class Stub extends android.os.HwBinder "
Andreas Huber2831d512016-08-15 09:33:47 -0700400 << "implements "
401 << ifaceName << " {\n";
402
403 out.indent();
404
Yifan Hong1af73532016-11-09 14:32:58 -0800405 out << "public android.os.IHwBinder asBinder() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700406 out.indent();
407 out << "return this;\n";
408 out.unindent();
409 out << "}\n\n";
410
Yifan Hong10fe0b52016-10-19 14:20:17 -0700411 for (Method *method : iface->hidlReservedMethods()) {
Martijn Coenenaf712c02016-11-16 15:26:27 +0100412 // b/32383557 this is a hack. We need to change this if we have more reserved methods.
413 CHECK_LE(method->results().size(), 1u);
414 std::string resultType = method->results().size() == 0 ? "void" :
415 method->results()[0]->type().getJavaType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700416 out << "public final "
Martijn Coenenaf712c02016-11-16 15:26:27 +0100417 << resultType
Yifan Hong10fe0b52016-10-19 14:20:17 -0700418 << " "
419 << method->name()
420 << "() {\n";
421 out.indent();
422 method->javaImpl(out);
423 out.unindent();
424 out << "\n}\n\n";
425 }
426
Yifan Hong1af73532016-11-09 14:32:58 -0800427 out << "public android.os.IHwInterface queryLocalInterface(String descriptor) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700428 out.indent();
429 // XXX what about potential superClasses?
430 out << "if (kInterfaceName.equals(descriptor)) {\n";
431 out.indent();
432 out << "return this;\n";
433 out.unindent();
434 out << "}\n";
435 out << "return null;\n";
436 out.unindent();
437 out << "}\n\n";
438
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700439 out << "public void registerAsService(String serviceName) {\n";
440 out.indent();
441
Steven Moreland7e367bf2016-11-04 11:31:41 -0700442 out << "registerService(interfaceChain(), serviceName);\n";
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700443
444 out.unindent();
445 out << "}\n\n";
446
Andreas Huber2831d512016-08-15 09:33:47 -0700447 out << "public void onTransact("
Steven Moreland4b39bc12016-11-16 10:42:24 -0800448 << "int _hidl_code, "
449 << "android.os.HwParcel _hidl_request, "
450 << "final android.os.HwParcel _hidl_reply, "
451 << "int _hidl_flags) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700452
453 out.indent();
454
Steven Moreland4b39bc12016-11-16 10:42:24 -0800455 out << "switch (_hidl_code) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700456
457 out.indent();
458
Yifan Hong10fe0b52016-10-19 14:20:17 -0700459 for (const auto &tuple : iface->allMethodsFromRoot()) {
460 const Method *method = tuple.method();
461 const Interface *superInterface = tuple.interface();
462 const bool returnsValue = !method->results().empty();
463 const bool needsCallback = method->results().size() > 1;
Andreas Huber2831d512016-08-15 09:33:47 -0700464
Yifan Hong10fe0b52016-10-19 14:20:17 -0700465 out << "case "
466 << method->getSerialId()
467 << " /* "
468 << method->name()
469 << " */:\n{\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700470
Yifan Hong10fe0b52016-10-19 14:20:17 -0700471 out.indent();
Andreas Huber2831d512016-08-15 09:33:47 -0700472
Steven Moreland4b39bc12016-11-16 10:42:24 -0800473 out << "_hidl_request.enforceInterface("
Yifan Hong10fe0b52016-10-19 14:20:17 -0700474 << superInterface->fullJavaName()
475 << ".kInterfaceName);\n\n";
476
477 for (const auto &arg : method->args()) {
478 emitJavaReaderWriter(
479 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800480 "_hidl_request",
Yifan Hong10fe0b52016-10-19 14:20:17 -0700481 arg,
482 true /* isReader */);
483 }
484
485 if (!needsCallback && returnsValue) {
486 const TypedVar *returnArg = method->results()[0];
Yifan Hong10fe0b52016-10-19 14:20:17 -0700487
Yifan Hong4ed13472016-11-02 10:44:11 -0700488 out << returnArg->type().getJavaType()
Yifan Hong10fe0b52016-10-19 14:20:17 -0700489 << " "
490 << returnArg->name()
491 << " = ";
492 }
493
494 out << method->name()
495 << "(";
496
497 bool firstField = true;
498 for (const auto &arg : method->args()) {
499 if (!firstField) {
500 out << ", ";
501 }
502
503 out << arg->name();
504
505 firstField = false;
506 }
507
508 if (needsCallback) {
509 if (!firstField) {
510 out << ", ";
511 }
512
513 out << "new " << method->name() << "Callback() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700514 out.indent();
515
Yifan Hong10fe0b52016-10-19 14:20:17 -0700516 out << "@Override\n"
517 << "public void onValues("
518 << Method::GetJavaArgSignature(method->results())
519 << ") {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700520
Yifan Hong10fe0b52016-10-19 14:20:17 -0700521 out.indent();
Steven Moreland4b39bc12016-11-16 10:42:24 -0800522 out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700523
524 for (const auto &arg : method->results()) {
Andreas Huber2831d512016-08-15 09:33:47 -0700525 emitJavaReaderWriter(
526 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800527 "_hidl_reply",
Andreas Huber2831d512016-08-15 09:33:47 -0700528 arg,
Yifan Hong10fe0b52016-10-19 14:20:17 -0700529 false /* isReader */);
Andreas Huber2831d512016-08-15 09:33:47 -0700530 }
531
Steven Moreland4b39bc12016-11-16 10:42:24 -0800532 out << "_hidl_reply.send();\n"
Yifan Hong10fe0b52016-10-19 14:20:17 -0700533 << "}}";
Andreas Huber2831d512016-08-15 09:33:47 -0700534
Andreas Huber2831d512016-08-15 09:33:47 -0700535 out.unindent();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700536 out.unindent();
Andreas Huber2831d512016-08-15 09:33:47 -0700537 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700538
539 out << ");\n";
540
541 if (!needsCallback) {
Steven Moreland4b39bc12016-11-16 10:42:24 -0800542 out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700543
544 if (returnsValue) {
545 const TypedVar *returnArg = method->results()[0];
546
547 emitJavaReaderWriter(
548 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800549 "_hidl_reply",
Yifan Hong10fe0b52016-10-19 14:20:17 -0700550 returnArg,
551 false /* isReader */);
552 }
553
Steven Moreland4b39bc12016-11-16 10:42:24 -0800554 out << "_hidl_reply.send();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700555 }
556
557 out << "break;\n";
558 out.unindent();
559 out << "}\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700560 }
561
562 out.unindent();
563 out << "}\n";
564
565 out.unindent();
566 out << "}\n";
567
568 out.unindent();
569 out << "}\n";
570
571 out.unindent();
572 out << "}\n";
573
574 return OK;
575}
576
577status_t AST::emitJavaTypeDeclarations(Formatter &out) const {
Andreas Huber85eabdb2016-08-25 11:24:49 -0700578 return mRootScope->emitJavaTypeDeclarations(out, false /* atTopLevel */);
Andreas Huber2831d512016-08-15 09:33:47 -0700579}
580
581} // namespace android
582