blob: 6faf52d85690d6e9d6433446077252b61c4770f4 [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,
Yifan Honga47eef32016-12-12 10:38:54 -080033 bool isReader,
34 bool addPrefixToName) const {
Andreas Huber2831d512016-08-15 09:33:47 -070035 if (isReader) {
Yifan Hong4ed13472016-11-02 10:44:11 -070036 out << arg->type().getJavaType()
Andreas Huber2831d512016-08-15 09:33:47 -070037 << " "
Yifan Honga47eef32016-12-12 10:38:54 -080038 << (addPrefixToName ? "_hidl_out_" : "")
Andreas Huber2831d512016-08-15 09:33:47 -070039 << arg->name()
40 << " = ";
41 }
42
Yifan Honga47eef32016-12-12 10:38:54 -080043 arg->type().emitJavaReaderWriter(out, parcelObj,
44 (addPrefixToName ? "_hidl_out_" : "") + arg->name(),
45 isReader);
Andreas Huber2831d512016-08-15 09:33:47 -070046}
47
Andreas Huber0fa9e392016-08-31 09:05:44 -070048status_t AST::generateJavaTypes(
Andreas Huberd29724f2016-09-14 09:33:13 -070049 const std::string &outputPath, const std::string &limitToType) const {
Andreas Huber85eabdb2016-08-25 11:24:49 -070050 // Splits types.hal up into one java file per declared type.
51
Steven Morelandd537ab02016-09-12 10:32:01 -070052 for (const auto &type : mRootScope->getSubTypes()) {
53 std::string typeName = type->localName();
Andreas Huber85eabdb2016-08-25 11:24:49 -070054
55 if (type->isTypeDef()) {
56 continue;
57 }
58
Andreas Huberd29724f2016-09-14 09:33:13 -070059 if (!limitToType.empty() && typeName != limitToType) {
Andreas Huber0fa9e392016-08-31 09:05:44 -070060 continue;
61 }
62
Andreas Huber85eabdb2016-08-25 11:24:49 -070063 std::string path = outputPath;
64 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Yifan Hong97288ac2016-12-12 16:03:51 -080065 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */,
66 true /* sanitized */));
Andreas Huber85eabdb2016-08-25 11:24:49 -070067 path.append(typeName);
68 path.append(".java");
69
70 CHECK(Coordinator::MakeParentHierarchy(path));
71 FILE *file = fopen(path.c_str(), "w");
72
73 if (file == NULL) {
74 return -errno;
75 }
76
77 Formatter out(file);
78
79 std::vector<std::string> packageComponents;
80 getPackageAndVersionComponents(
81 &packageComponents, true /* cpp_compatible */);
82
83 out << "package " << mPackage.javaPackage() << ";\n\n";
84
Iliyan Malchev800273d2016-09-02 15:25:07 -070085 out << "\n";
86
Andreas Huber85eabdb2016-08-25 11:24:49 -070087 status_t err =
88 type->emitJavaTypeDeclarations(out, true /* atTopLevel */);
89
90 if (err != OK) {
91 return err;
92 }
93 }
94
95 return OK;
96}
97
Andreas Huber0fa9e392016-08-31 09:05:44 -070098status_t AST::generateJava(
Andreas Huberd29724f2016-09-14 09:33:13 -070099 const std::string &outputPath, const std::string &limitToType) const {
Andreas Huber0fa9e392016-08-31 09:05:44 -0700100 if (!isJavaCompatible()) {
Andreas Huber70a59e12016-08-16 12:57:01 -0700101 fprintf(stderr,
102 "ERROR: This interface is not Java compatible. The Java backend"
Andreas Huberf03332a2016-09-22 15:35:43 -0700103 " does NOT support union types nor native handles. "
104 "In addition, vectors of arrays are limited to at most "
Andreas Huber86a112b2016-10-19 14:25:16 -0700105 "one-dimensional arrays and vectors of {vectors,interfaces} are"
106 " not supported.\n");
Andreas Huber70a59e12016-08-16 12:57:01 -0700107
Andreas Huber2831d512016-08-15 09:33:47 -0700108 return UNKNOWN_ERROR;
109 }
110
Andreas Huber0fa9e392016-08-31 09:05:44 -0700111 std::string ifaceName;
112 if (!AST::isInterface(&ifaceName)) {
113 return generateJavaTypes(outputPath, limitToType);
114 }
115
116 const Interface *iface = mRootScope->getInterface();
117
Jayant Chowdhary3f32c1f2016-09-15 16:53:56 -0700118 const std::string baseName = iface->getBaseName();
Andreas Huber2831d512016-08-15 09:33:47 -0700119
120 std::string path = outputPath;
121 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Yifan Hong97288ac2016-12-12 16:03:51 -0800122 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */,
123 true /* sanitized */));
Andreas Huber2831d512016-08-15 09:33:47 -0700124 path.append(ifaceName);
125 path.append(".java");
126
127 CHECK(Coordinator::MakeParentHierarchy(path));
128 FILE *file = fopen(path.c_str(), "w");
129
130 if (file == NULL) {
131 return -errno;
132 }
133
134 Formatter out(file);
135
136 std::vector<std::string> packageComponents;
137 getPackageAndVersionComponents(
138 &packageComponents, true /* cpp_compatible */);
139
140 out << "package " << mPackage.javaPackage() << ";\n\n";
141
Andreas Huber2831d512016-08-15 09:33:47 -0700142 out.setNamespace(mPackage.javaPackage() + ".");
143
Andreas Huber2831d512016-08-15 09:33:47 -0700144 const Interface *superType = iface->superType();
145
146 out << "public interface " << ifaceName << " extends ";
147
148 if (superType != NULL) {
149 out << superType->fullJavaName();
150 } else {
Yifan Hong1af73532016-11-09 14:32:58 -0800151 out << "android.os.IHwInterface";
Andreas Huber2831d512016-08-15 09:33:47 -0700152 }
153
154 out << " {\n";
155 out.indent();
156
157 out << "public static final String kInterfaceName = \""
158 << mPackage.string()
159 << "::"
160 << ifaceName
161 << "\";\n\n";
162
163 out << "public static "
164 << ifaceName
Yifan Hong1af73532016-11-09 14:32:58 -0800165 << " asInterface(android.os.IHwBinder binder) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700166
167 out.indent();
168
169 out << "if (binder == null) {\n";
170 out.indent();
171 out << "return null;\n";
172 out.unindent();
173 out << "}\n\n";
174
Yifan Hong1af73532016-11-09 14:32:58 -0800175 out << "android.os.IHwInterface iface =\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700176 out.indent();
177 out.indent();
178 out << "binder.queryLocalInterface(kInterfaceName);\n\n";
179 out.unindent();
180 out.unindent();
181
182 out << "if ((iface != null) && (iface instanceof "
183 << ifaceName
184 << ")) {\n";
185
186 out.indent();
187 out << "return (" << ifaceName << ")iface;\n";
188 out.unindent();
189 out << "}\n\n";
190
191 out << "return new " << ifaceName << ".Proxy(binder);\n";
192
193 out.unindent();
194 out << "}\n\n";
195
Yifan Hong1af73532016-11-09 14:32:58 -0800196 out << "public android.os.IHwBinder asBinder();\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700197
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700198 out << "public static "
199 << ifaceName
200 << " getService(String serviceName) {\n";
201
202 out.indent();
203
204 out << "return "
205 << ifaceName
Yifan Hong1af73532016-11-09 14:32:58 -0800206 << ".asInterface(android.os.HwBinder.getService(\""
Steven Moreland7e367bf2016-11-04 11:31:41 -0700207 << iface->fqName().string()
208 << "\",serviceName));\n";
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700209
210 out.unindent();
211
212 out << "}\n\n";
213
Andreas Huber2831d512016-08-15 09:33:47 -0700214 status_t err = emitJavaTypeDeclarations(out);
215
216 if (err != OK) {
217 return err;
218 }
219
Andreas Huber2831d512016-08-15 09:33:47 -0700220 for (const auto &method : iface->methods()) {
221 const bool returnsValue = !method->results().empty();
222 const bool needsCallback = method->results().size() > 1;
223
224 if (needsCallback) {
Steven Morelandbcd79032016-12-16 20:50:23 -0800225 out << "\npublic interface "
Andreas Huber2831d512016-08-15 09:33:47 -0700226 << method->name()
227 << "Callback {\n";
228
229 out.indent();
230
Steven Morelandbcd79032016-12-16 20:50:23 -0800231 out << "public void onValues("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700232 << Method::GetJavaArgSignature(method->results())
Andreas Huber2831d512016-08-15 09:33:47 -0700233 << ");\n";
234
235 out.unindent();
236 out << "}\n\n";
237 }
238
239 if (returnsValue && !needsCallback) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700240 out << method->results()[0]->type().getJavaType();
Andreas Huber2831d512016-08-15 09:33:47 -0700241 } else {
242 out << "void";
243 }
244
245 out << " "
246 << method->name()
247 << "("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700248 << Method::GetJavaArgSignature(method->args());
Andreas Huber2831d512016-08-15 09:33:47 -0700249
250 if (needsCallback) {
251 if (!method->args().empty()) {
252 out << ", ";
253 }
254
255 out << method->name()
256 << "Callback cb";
257 }
258
259 out << ");\n";
260 }
261
262 out << "\npublic static final class Proxy implements "
263 << ifaceName
264 << " {\n";
265
266 out.indent();
267
Yifan Hong1af73532016-11-09 14:32:58 -0800268 out << "private android.os.IHwBinder mRemote;\n\n";
269 out << "public Proxy(android.os.IHwBinder remote) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700270 out.indent();
271 out << "mRemote = remote;\n";
272 out.unindent();
273 out << "}\n\n";
274
Yifan Hong1af73532016-11-09 14:32:58 -0800275 out << "public android.os.IHwBinder asBinder() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700276 out.indent();
277 out << "return mRemote;\n";
278 out.unindent();
279 out << "}\n\n";
280
Yifan Hong10fe0b52016-10-19 14:20:17 -0700281 const Interface *prevInterface = nullptr;
282 for (const auto &tuple : iface->allMethodsFromRoot()) {
283 const Method *method = tuple.method();
284 const Interface *superInterface = tuple.interface();
285 if (prevInterface != superInterface) {
286 out << "// Methods from "
287 << superInterface->fullName()
288 << " follow.\n";
289 prevInterface = superInterface;
290 }
291 const bool returnsValue = !method->results().empty();
292 const bool needsCallback = method->results().size() > 1;
Andreas Huber2831d512016-08-15 09:33:47 -0700293
Yifan Hong10fe0b52016-10-19 14:20:17 -0700294 out << "public ";
295 if (returnsValue && !needsCallback) {
Yifan Hong4ed13472016-11-02 10:44:11 -0700296 out << method->results()[0]->type().getJavaType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700297 } else {
298 out << "void";
299 }
Andreas Huber2831d512016-08-15 09:33:47 -0700300
Yifan Hong10fe0b52016-10-19 14:20:17 -0700301 out << " "
302 << method->name()
303 << "("
304 << Method::GetJavaArgSignature(method->args());
Andreas Huber2831d512016-08-15 09:33:47 -0700305
Yifan Hong10fe0b52016-10-19 14:20:17 -0700306 if (needsCallback) {
307 if (!method->args().empty()) {
308 out << ", ";
Andreas Huber2831d512016-08-15 09:33:47 -0700309 }
310
Yifan Hong10fe0b52016-10-19 14:20:17 -0700311 out << method->name()
312 << "Callback cb";
313 }
Andreas Huber2831d512016-08-15 09:33:47 -0700314
Yifan Hong10fe0b52016-10-19 14:20:17 -0700315 out << ") {\n";
316 out.indent();
Andreas Huber2831d512016-08-15 09:33:47 -0700317
Steven Moreland4b39bc12016-11-16 10:42:24 -0800318 out << "android.os.HwParcel _hidl_request = new android.os.HwParcel();\n";
319 out << "_hidl_request.writeInterfaceToken("
Yifan Hong10fe0b52016-10-19 14:20:17 -0700320 << superInterface->fullJavaName()
321 << ".kInterfaceName);\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700322
Yifan Hong10fe0b52016-10-19 14:20:17 -0700323 for (const auto &arg : method->args()) {
324 emitJavaReaderWriter(
325 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800326 "_hidl_request",
Yifan Hong10fe0b52016-10-19 14:20:17 -0700327 arg,
Yifan Honga47eef32016-12-12 10:38:54 -0800328 false /* isReader */,
329 false /* addPrefixToName */);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700330 }
Andreas Huber2831d512016-08-15 09:33:47 -0700331
Steven Moreland4b39bc12016-11-16 10:42:24 -0800332 out << "\nandroid.os.HwParcel _hidl_reply = new android.os.HwParcel();\n"
Yifan Hong10fe0b52016-10-19 14:20:17 -0700333 << "mRemote.transact("
334 << method->getSerialId()
335 << " /* "
336 << method->name()
Steven Moreland4b39bc12016-11-16 10:42:24 -0800337 << " */, _hidl_request, _hidl_reply, ";
Andreas Huber2831d512016-08-15 09:33:47 -0700338
Yifan Hong10fe0b52016-10-19 14:20:17 -0700339 if (method->isOneway()) {
Yifan Hong1af73532016-11-09 14:32:58 -0800340 out << "android.os.IHwBinder.FLAG_ONEWAY";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700341 } else {
342 out << "0 /* flags */";
343 }
344
345 out << ");\n";
346
347 if (!method->isOneway()) {
Steven Moreland4b39bc12016-11-16 10:42:24 -0800348 out << "_hidl_reply.verifySuccess();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700349 } else {
350 CHECK(!returnsValue);
351 }
352
Steven Moreland4b39bc12016-11-16 10:42:24 -0800353 out << "_hidl_request.releaseTemporaryStorage();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700354
355 if (returnsValue) {
356 out << "\n";
357
358 for (const auto &arg : method->results()) {
Andreas Huber2831d512016-08-15 09:33:47 -0700359 emitJavaReaderWriter(
360 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800361 "_hidl_reply",
Andreas Huber2831d512016-08-15 09:33:47 -0700362 arg,
Yifan Honga47eef32016-12-12 10:38:54 -0800363 true /* isReader */,
364 true /* addPrefixToName */);
Andreas Huber2831d512016-08-15 09:33:47 -0700365 }
366
Yifan Hong10fe0b52016-10-19 14:20:17 -0700367 if (needsCallback) {
368 out << "cb.onValues(";
Andreas Huber8b5da222016-08-18 14:28:18 -0700369
Yifan Hong10fe0b52016-10-19 14:20:17 -0700370 bool firstField = true;
Andreas Huber2831d512016-08-15 09:33:47 -0700371 for (const auto &arg : method->results()) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700372 if (!firstField) {
373 out << ", ";
Andreas Huber2831d512016-08-15 09:33:47 -0700374 }
375
Yifan Honga47eef32016-12-12 10:38:54 -0800376 out << "_hidl_out_" << arg->name();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700377 firstField = false;
Andreas Huber2831d512016-08-15 09:33:47 -0700378 }
Andreas Huber2831d512016-08-15 09:33:47 -0700379
Yifan Hong10fe0b52016-10-19 14:20:17 -0700380 out << ");\n";
381 } else {
382 const std::string returnName = method->results()[0]->name();
Yifan Honga47eef32016-12-12 10:38:54 -0800383 out << "return _hidl_out_" << returnName << ";\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700384 }
Andreas Huber2831d512016-08-15 09:33:47 -0700385 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700386
387 out.unindent();
388 out << "}\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700389 }
390
391 out.unindent();
392 out << "}\n";
393
394 ////////////////////////////////////////////////////////////////////////////
395
Yifan Hong1af73532016-11-09 14:32:58 -0800396 out << "\npublic static abstract class Stub extends android.os.HwBinder "
Andreas Huber2831d512016-08-15 09:33:47 -0700397 << "implements "
398 << ifaceName << " {\n";
399
400 out.indent();
401
Yifan Hong1af73532016-11-09 14:32:58 -0800402 out << "public android.os.IHwBinder asBinder() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700403 out.indent();
404 out << "return this;\n";
405 out.unindent();
406 out << "}\n\n";
407
Yifan Hong10fe0b52016-10-19 14:20:17 -0700408 for (Method *method : iface->hidlReservedMethods()) {
Martijn Coenenaf712c02016-11-16 15:26:27 +0100409 // b/32383557 this is a hack. We need to change this if we have more reserved methods.
410 CHECK_LE(method->results().size(), 1u);
411 std::string resultType = method->results().size() == 0 ? "void" :
412 method->results()[0]->type().getJavaType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700413 out << "public final "
Martijn Coenenaf712c02016-11-16 15:26:27 +0100414 << resultType
Yifan Hong10fe0b52016-10-19 14:20:17 -0700415 << " "
416 << method->name()
417 << "() {\n";
418 out.indent();
419 method->javaImpl(out);
420 out.unindent();
421 out << "\n}\n\n";
422 }
423
Yifan Hong1af73532016-11-09 14:32:58 -0800424 out << "public android.os.IHwInterface queryLocalInterface(String descriptor) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700425 out.indent();
426 // XXX what about potential superClasses?
427 out << "if (kInterfaceName.equals(descriptor)) {\n";
428 out.indent();
429 out << "return this;\n";
430 out.unindent();
431 out << "}\n";
432 out << "return null;\n";
433 out.unindent();
434 out << "}\n\n";
435
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700436 out << "public void registerAsService(String serviceName) {\n";
437 out.indent();
438
Steven Moreland7e367bf2016-11-04 11:31:41 -0700439 out << "registerService(interfaceChain(), serviceName);\n";
Andreas Huber2bb6e1e2016-10-25 13:26:43 -0700440
441 out.unindent();
442 out << "}\n\n";
443
Andreas Huber2831d512016-08-15 09:33:47 -0700444 out << "public void onTransact("
Steven Moreland4b39bc12016-11-16 10:42:24 -0800445 << "int _hidl_code, "
446 << "android.os.HwParcel _hidl_request, "
447 << "final android.os.HwParcel _hidl_reply, "
448 << "int _hidl_flags) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700449
450 out.indent();
451
Steven Moreland4b39bc12016-11-16 10:42:24 -0800452 out << "switch (_hidl_code) {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700453
454 out.indent();
455
Yifan Hong10fe0b52016-10-19 14:20:17 -0700456 for (const auto &tuple : iface->allMethodsFromRoot()) {
457 const Method *method = tuple.method();
458 const Interface *superInterface = tuple.interface();
459 const bool returnsValue = !method->results().empty();
460 const bool needsCallback = method->results().size() > 1;
Andreas Huber2831d512016-08-15 09:33:47 -0700461
Yifan Hong10fe0b52016-10-19 14:20:17 -0700462 out << "case "
463 << method->getSerialId()
464 << " /* "
465 << method->name()
466 << " */:\n{\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700467
Yifan Hong10fe0b52016-10-19 14:20:17 -0700468 out.indent();
Andreas Huber2831d512016-08-15 09:33:47 -0700469
Steven Moreland4b39bc12016-11-16 10:42:24 -0800470 out << "_hidl_request.enforceInterface("
Yifan Hong10fe0b52016-10-19 14:20:17 -0700471 << superInterface->fullJavaName()
472 << ".kInterfaceName);\n\n";
473
474 for (const auto &arg : method->args()) {
475 emitJavaReaderWriter(
476 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800477 "_hidl_request",
Yifan Hong10fe0b52016-10-19 14:20:17 -0700478 arg,
Yifan Honga47eef32016-12-12 10:38:54 -0800479 true /* isReader */,
480 false /* addPrefixToName */);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700481 }
482
483 if (!needsCallback && returnsValue) {
484 const TypedVar *returnArg = method->results()[0];
Yifan Hong10fe0b52016-10-19 14:20:17 -0700485
Yifan Hong4ed13472016-11-02 10:44:11 -0700486 out << returnArg->type().getJavaType()
Yifan Honga47eef32016-12-12 10:38:54 -0800487 << " _hidl_out_"
Yifan Hong10fe0b52016-10-19 14:20:17 -0700488 << returnArg->name()
489 << " = ";
490 }
491
492 out << method->name()
493 << "(";
494
495 bool firstField = true;
496 for (const auto &arg : method->args()) {
497 if (!firstField) {
498 out << ", ";
499 }
500
501 out << arg->name();
502
503 firstField = false;
504 }
505
506 if (needsCallback) {
507 if (!firstField) {
508 out << ", ";
509 }
510
511 out << "new " << method->name() << "Callback() {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700512 out.indent();
513
Yifan Hong10fe0b52016-10-19 14:20:17 -0700514 out << "@Override\n"
515 << "public void onValues("
516 << Method::GetJavaArgSignature(method->results())
517 << ") {\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700518
Yifan Hong10fe0b52016-10-19 14:20:17 -0700519 out.indent();
Steven Moreland4b39bc12016-11-16 10:42:24 -0800520 out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700521
522 for (const auto &arg : method->results()) {
Andreas Huber2831d512016-08-15 09:33:47 -0700523 emitJavaReaderWriter(
524 out,
Steven Moreland4b39bc12016-11-16 10:42:24 -0800525 "_hidl_reply",
Andreas Huber2831d512016-08-15 09:33:47 -0700526 arg,
Yifan Honga47eef32016-12-12 10:38:54 -0800527 false /* isReader */,
528 false /* addPrefixToName */);
529 // no need to add _hidl_out because out vars are are scoped
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,
Yifan Honga47eef32016-12-12 10:38:54 -0800551 false /* isReader */,
552 true /* addPrefixToName */);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700553 }
554
Steven Moreland4b39bc12016-11-16 10:42:24 -0800555 out << "_hidl_reply.send();\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700556 }
557
558 out << "break;\n";
559 out.unindent();
560 out << "}\n\n";
Andreas Huber2831d512016-08-15 09:33:47 -0700561 }
562
563 out.unindent();
564 out << "}\n";
565
566 out.unindent();
567 out << "}\n";
568
569 out.unindent();
570 out << "}\n";
571
572 out.unindent();
573 out << "}\n";
574
575 return OK;
576}
577
578status_t AST::emitJavaTypeDeclarations(Formatter &out) const {
Andreas Huber85eabdb2016-08-25 11:24:49 -0700579 return mRootScope->emitJavaTypeDeclarations(out, false /* atTopLevel */);
Andreas Huber2831d512016-08-15 09:33:47 -0700580}
581
582} // namespace android
583