Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 17 | #include "AST.h" |
| 18 | |
| 19 | #include "Coordinator.h" |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 20 | #include "Interface.h" |
| 21 | #include "Method.h" |
| 22 | #include "Scope.h" |
| 23 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 24 | #include <hidl-util/StringHelper.h> |
| 25 | #include <hidl-util/Formatter.h> |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 26 | #include <android-base/logging.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 30 | void AST::emitJavaReaderWriter( |
| 31 | Formatter &out, |
| 32 | const std::string &parcelObj, |
| 33 | const TypedVar *arg, |
| 34 | bool isReader) const { |
| 35 | if (isReader) { |
| 36 | out << arg->type().getJavaType() |
| 37 | << " " |
| 38 | << arg->name() |
| 39 | << " = "; |
| 40 | } |
| 41 | |
| 42 | arg->type().emitJavaReaderWriter(out, parcelObj, arg->name(), isReader); |
| 43 | } |
| 44 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 45 | status_t AST::generateJavaTypes( |
| 46 | const std::string &outputPath, const char *limitToType) const { |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 47 | // Splits types.hal up into one java file per declared type. |
| 48 | |
| 49 | for (size_t i = 0; i < mRootScope->countTypes(); ++i) { |
| 50 | std::string typeName; |
| 51 | const Type *type = mRootScope->typeAt(i, &typeName); |
| 52 | |
| 53 | if (type->isTypeDef()) { |
| 54 | continue; |
| 55 | } |
| 56 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 57 | if ((limitToType != nullptr) && typeName != limitToType) { |
| 58 | continue; |
| 59 | } |
| 60 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 61 | std::string path = outputPath; |
| 62 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 63 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 64 | path.append(typeName); |
| 65 | path.append(".java"); |
| 66 | |
| 67 | CHECK(Coordinator::MakeParentHierarchy(path)); |
| 68 | FILE *file = fopen(path.c_str(), "w"); |
| 69 | |
| 70 | if (file == NULL) { |
| 71 | return -errno; |
| 72 | } |
| 73 | |
| 74 | Formatter out(file); |
| 75 | |
| 76 | std::vector<std::string> packageComponents; |
| 77 | getPackageAndVersionComponents( |
| 78 | &packageComponents, true /* cpp_compatible */); |
| 79 | |
| 80 | out << "package " << mPackage.javaPackage() << ";\n\n"; |
| 81 | |
| 82 | out << "import android.os.HwBlob;\n"; |
| 83 | out << "import android.os.HwParcel;\n\n"; |
| 84 | |
Andreas Huber | f630bc8 | 2016-09-09 14:52:25 -0700 | [diff] [blame] | 85 | out << "import java.util.Arrays;\n"; |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 86 | out << "import java.util.Vector;\n\n"; |
| 87 | |
Iliyan Malchev | 800273d | 2016-09-02 15:25:07 -0700 | [diff] [blame] | 88 | for (const auto &item : mImportedNamesForJava) { |
| 89 | out << "import " << item.javaName() << ";\n"; |
| 90 | } |
| 91 | out << "\n"; |
| 92 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 93 | status_t err = |
| 94 | type->emitJavaTypeDeclarations(out, true /* atTopLevel */); |
| 95 | |
| 96 | if (err != OK) { |
| 97 | return err; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return OK; |
| 102 | } |
| 103 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 104 | status_t AST::generateJava( |
| 105 | const std::string &outputPath, const char *limitToType) const { |
| 106 | if (!isJavaCompatible()) { |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 107 | fprintf(stderr, |
| 108 | "ERROR: This interface is not Java compatible. The Java backend" |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 109 | " does NOT support union types or native handles.\n"); |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 110 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 111 | return UNKNOWN_ERROR; |
| 112 | } |
| 113 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 114 | std::string ifaceName; |
| 115 | if (!AST::isInterface(&ifaceName)) { |
| 116 | return generateJavaTypes(outputPath, limitToType); |
| 117 | } |
| 118 | |
| 119 | const Interface *iface = mRootScope->getInterface(); |
| 120 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 121 | // cut off the leading 'I'. |
| 122 | const std::string baseName = ifaceName.substr(1); |
| 123 | |
| 124 | std::string path = outputPath; |
| 125 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 126 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 127 | path.append(ifaceName); |
| 128 | path.append(".java"); |
| 129 | |
| 130 | CHECK(Coordinator::MakeParentHierarchy(path)); |
| 131 | FILE *file = fopen(path.c_str(), "w"); |
| 132 | |
| 133 | if (file == NULL) { |
| 134 | return -errno; |
| 135 | } |
| 136 | |
| 137 | Formatter out(file); |
| 138 | |
| 139 | std::vector<std::string> packageComponents; |
| 140 | getPackageAndVersionComponents( |
| 141 | &packageComponents, true /* cpp_compatible */); |
| 142 | |
| 143 | out << "package " << mPackage.javaPackage() << ";\n\n"; |
| 144 | |
| 145 | out << "import android.os.IHwBinder;\n"; |
| 146 | out << "import android.os.IHwInterface;\n"; |
| 147 | out << "import android.os.HwBinder;\n"; |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 148 | out << "import android.os.HwBlob;\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 149 | out << "import android.os.HwParcel;\n\n"; |
Andreas Huber | f630bc8 | 2016-09-09 14:52:25 -0700 | [diff] [blame] | 150 | |
| 151 | out << "import java.util.Arrays;\n"; |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 152 | out << "import java.util.Vector;\n\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 153 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 154 | for (const auto &item : mImportedNamesForJava) { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 155 | out << "import " << item.javaName() << ";\n"; |
| 156 | } |
| 157 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 158 | if (!mImportedNamesForJava.empty()) { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 159 | out << "\n"; |
| 160 | } |
| 161 | |
| 162 | out.setNamespace(mPackage.javaPackage() + "."); |
| 163 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 164 | const Interface *superType = iface->superType(); |
| 165 | |
| 166 | out << "public interface " << ifaceName << " extends "; |
| 167 | |
| 168 | if (superType != NULL) { |
| 169 | out << superType->fullJavaName(); |
| 170 | } else { |
| 171 | out << "IHwInterface"; |
| 172 | } |
| 173 | |
| 174 | out << " {\n"; |
| 175 | out.indent(); |
| 176 | |
| 177 | out << "public static final String kInterfaceName = \"" |
| 178 | << mPackage.string() |
| 179 | << "::" |
| 180 | << ifaceName |
| 181 | << "\";\n\n"; |
| 182 | |
| 183 | out << "public static " |
| 184 | << ifaceName |
| 185 | << " asInterface(IHwBinder binder) {\n"; |
| 186 | |
| 187 | out.indent(); |
| 188 | |
| 189 | out << "if (binder == null) {\n"; |
| 190 | out.indent(); |
| 191 | out << "return null;\n"; |
| 192 | out.unindent(); |
| 193 | out << "}\n\n"; |
| 194 | |
| 195 | out << "IHwInterface iface =\n"; |
| 196 | out.indent(); |
| 197 | out.indent(); |
| 198 | out << "binder.queryLocalInterface(kInterfaceName);\n\n"; |
| 199 | out.unindent(); |
| 200 | out.unindent(); |
| 201 | |
| 202 | out << "if ((iface != null) && (iface instanceof " |
| 203 | << ifaceName |
| 204 | << ")) {\n"; |
| 205 | |
| 206 | out.indent(); |
| 207 | out << "return (" << ifaceName << ")iface;\n"; |
| 208 | out.unindent(); |
| 209 | out << "}\n\n"; |
| 210 | |
| 211 | out << "return new " << ifaceName << ".Proxy(binder);\n"; |
| 212 | |
| 213 | out.unindent(); |
| 214 | out << "}\n\n"; |
| 215 | |
| 216 | out << "public IHwBinder asBinder();\n\n"; |
| 217 | |
| 218 | status_t err = emitJavaTypeDeclarations(out); |
| 219 | |
| 220 | if (err != OK) { |
| 221 | return err; |
| 222 | } |
| 223 | |
| 224 | const std::string base = (superType != NULL) |
| 225 | ? (superType->fullJavaName() + ".kOpEnd") |
| 226 | : "IHwBinder.FIRST_CALL_TRANSACTION"; |
| 227 | |
| 228 | bool first = true; |
| 229 | size_t index = 0; |
| 230 | for (const auto &method : iface->methods()) { |
| 231 | out << "public static final int kOp_" |
Steven Moreland | af44014 | 2016-09-07 10:09:11 -0700 | [diff] [blame] | 232 | << StringHelper::Upcase(method->name()) |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 233 | << " = " |
| 234 | << base; |
| 235 | |
| 236 | if (!first) { |
| 237 | out << " + " << index; |
| 238 | } |
| 239 | |
| 240 | out << ";\n"; |
| 241 | |
| 242 | ++index; |
| 243 | first = false; |
| 244 | } |
| 245 | |
| 246 | out << "public static final int kOpEnd = " |
| 247 | << base |
| 248 | << " + " |
| 249 | << index |
| 250 | << ";"; |
| 251 | |
| 252 | out << "\n\n"; |
| 253 | |
| 254 | for (const auto &method : iface->methods()) { |
| 255 | const bool returnsValue = !method->results().empty(); |
| 256 | const bool needsCallback = method->results().size() > 1; |
| 257 | |
| 258 | if (needsCallback) { |
| 259 | out << "\npublic abstract class " |
| 260 | << method->name() |
| 261 | << "Callback {\n"; |
| 262 | |
| 263 | out.indent(); |
| 264 | |
| 265 | out << "public abstract void onValues(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 266 | << Method::GetJavaArgSignature(method->results()) |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 267 | << ");\n"; |
| 268 | |
| 269 | out.unindent(); |
| 270 | out << "}\n\n"; |
| 271 | } |
| 272 | |
| 273 | if (returnsValue && !needsCallback) { |
| 274 | out << method->results()[0]->type().getJavaType(); |
| 275 | } else { |
| 276 | out << "void"; |
| 277 | } |
| 278 | |
| 279 | out << " " |
| 280 | << method->name() |
| 281 | << "(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 282 | << Method::GetJavaArgSignature(method->args()); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 283 | |
| 284 | if (needsCallback) { |
| 285 | if (!method->args().empty()) { |
| 286 | out << ", "; |
| 287 | } |
| 288 | |
| 289 | out << method->name() |
| 290 | << "Callback cb"; |
| 291 | } |
| 292 | |
| 293 | out << ");\n"; |
| 294 | } |
| 295 | |
| 296 | out << "\npublic static final class Proxy implements " |
| 297 | << ifaceName |
| 298 | << " {\n"; |
| 299 | |
| 300 | out.indent(); |
| 301 | |
| 302 | out << "private IHwBinder mRemote;\n\n"; |
| 303 | out << "public Proxy(IHwBinder remote) {\n"; |
| 304 | out.indent(); |
| 305 | out << "mRemote = remote;\n"; |
| 306 | out.unindent(); |
| 307 | out << "}\n\n"; |
| 308 | |
| 309 | out << "public IHwBinder asBinder() {\n"; |
| 310 | out.indent(); |
| 311 | out << "return mRemote;\n"; |
| 312 | out.unindent(); |
| 313 | out << "}\n\n"; |
| 314 | |
| 315 | std::vector<const Interface *> chain; |
| 316 | while (iface != NULL) { |
| 317 | chain.push_back(iface); |
| 318 | iface = iface->superType(); |
| 319 | } |
| 320 | |
| 321 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 322 | const Interface *superInterface = *it; |
| 323 | |
| 324 | out << "// Methods from " |
| 325 | << superInterface->fullName() |
| 326 | << " follow.\n"; |
| 327 | |
| 328 | for (const auto &method : superInterface->methods()) { |
| 329 | const bool returnsValue = !method->results().empty(); |
| 330 | const bool needsCallback = method->results().size() > 1; |
| 331 | |
| 332 | out << "public "; |
| 333 | if (returnsValue && !needsCallback) { |
| 334 | out << method->results()[0]->type().getJavaType(); |
| 335 | } else { |
| 336 | out << "void"; |
| 337 | } |
| 338 | |
| 339 | out << " " |
| 340 | << method->name() |
| 341 | << "(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 342 | << Method::GetJavaArgSignature(method->args()); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 343 | |
| 344 | if (needsCallback) { |
| 345 | if (!method->args().empty()) { |
| 346 | out << ", "; |
| 347 | } |
| 348 | |
| 349 | out << method->name() |
| 350 | << "Callback cb"; |
| 351 | } |
| 352 | |
| 353 | out << ") {\n"; |
| 354 | out.indent(); |
| 355 | |
| 356 | out << "HwParcel request = new HwParcel();\n"; |
| 357 | out << "request.writeInterfaceToken(" |
| 358 | << superInterface->fullJavaName() |
| 359 | << ".kInterfaceName);\n"; |
| 360 | |
| 361 | for (const auto &arg : method->args()) { |
| 362 | emitJavaReaderWriter( |
| 363 | out, |
| 364 | "request", |
| 365 | arg, |
| 366 | false /* isReader */); |
| 367 | } |
| 368 | |
| 369 | out << "\nHwParcel reply = new HwParcel();\n" |
Andreas Huber | 8b5da22 | 2016-08-18 14:28:18 -0700 | [diff] [blame] | 370 | << "mRemote.transact(kOp_" |
Steven Moreland | af44014 | 2016-09-07 10:09:11 -0700 | [diff] [blame] | 371 | << StringHelper::Upcase(method->name()) |
Andreas Huber | 8b5da22 | 2016-08-18 14:28:18 -0700 | [diff] [blame] | 372 | << ", request, reply, "; |
| 373 | |
| 374 | if (method->isOneway()) { |
| 375 | out << "IHwBinder.FLAG_ONEWAY"; |
| 376 | } else { |
| 377 | out << "0 /* flags */"; |
| 378 | } |
| 379 | |
| 380 | out << ");\n"; |
| 381 | |
| 382 | if (!method->isOneway()) { |
| 383 | out << "reply.verifySuccess();\n"; |
| 384 | } else { |
| 385 | CHECK(!returnsValue); |
| 386 | } |
| 387 | |
| 388 | out << "request.releaseTemporaryStorage();\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 389 | |
| 390 | if (returnsValue) { |
| 391 | out << "\n"; |
| 392 | |
| 393 | for (const auto &arg : method->results()) { |
| 394 | emitJavaReaderWriter( |
| 395 | out, |
| 396 | "reply", |
| 397 | arg, |
| 398 | true /* isReader */); |
| 399 | } |
| 400 | |
| 401 | if (needsCallback) { |
| 402 | out << "cb.onValues("; |
| 403 | |
| 404 | bool firstField = true; |
| 405 | for (const auto &arg : method->results()) { |
| 406 | if (!firstField) { |
| 407 | out << ", "; |
| 408 | } |
| 409 | |
| 410 | out << arg->name(); |
| 411 | firstField = false; |
| 412 | } |
| 413 | |
| 414 | out << ");\n"; |
| 415 | } else { |
| 416 | const std::string returnName = method->results()[0]->name(); |
| 417 | out << "return " << returnName << ";\n"; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | out.unindent(); |
| 422 | out << "}\n\n"; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | out.unindent(); |
| 427 | out << "}\n"; |
| 428 | |
| 429 | //////////////////////////////////////////////////////////////////////////// |
| 430 | |
| 431 | out << "\npublic static abstract class Stub extends HwBinder " |
| 432 | << "implements " |
| 433 | << ifaceName << " {\n"; |
| 434 | |
| 435 | out.indent(); |
| 436 | |
| 437 | out << "public IHwBinder asBinder() {\n"; |
| 438 | out.indent(); |
| 439 | out << "return this;\n"; |
| 440 | out.unindent(); |
| 441 | out << "}\n\n"; |
| 442 | |
| 443 | out << "public IHwInterface queryLocalInterface(String descriptor) {\n"; |
| 444 | out.indent(); |
| 445 | // XXX what about potential superClasses? |
| 446 | out << "if (kInterfaceName.equals(descriptor)) {\n"; |
| 447 | out.indent(); |
| 448 | out << "return this;\n"; |
| 449 | out.unindent(); |
| 450 | out << "}\n"; |
| 451 | out << "return null;\n"; |
| 452 | out.unindent(); |
| 453 | out << "}\n\n"; |
| 454 | |
| 455 | out << "public void onTransact(" |
| 456 | << "int code, HwParcel request, final HwParcel reply, " |
| 457 | << "int flags) {\n"; |
| 458 | |
| 459 | out.indent(); |
| 460 | |
| 461 | out << "switch (code) {\n"; |
| 462 | |
| 463 | out.indent(); |
| 464 | |
| 465 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 466 | const Interface *superInterface = *it; |
| 467 | |
| 468 | for (const auto &method : superInterface->methods()) { |
| 469 | const bool returnsValue = !method->results().empty(); |
| 470 | const bool needsCallback = method->results().size() > 1; |
| 471 | |
| 472 | out << "case " |
| 473 | << superInterface->fullJavaName() |
| 474 | << ".kOp_" |
| 475 | << |
Steven Moreland | af44014 | 2016-09-07 10:09:11 -0700 | [diff] [blame] | 476 | StringHelper::Upcase(method->name()) |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 477 | << ":\n{\n"; |
| 478 | |
| 479 | out.indent(); |
| 480 | |
| 481 | out << "request.enforceInterface(" |
| 482 | << superInterface->fullJavaName() |
| 483 | << ".kInterfaceName);\n\n"; |
| 484 | |
| 485 | for (const auto &arg : method->args()) { |
| 486 | emitJavaReaderWriter( |
| 487 | out, |
| 488 | "request", |
| 489 | arg, |
| 490 | true /* isReader */); |
| 491 | } |
| 492 | |
| 493 | if (!needsCallback && returnsValue) { |
| 494 | const TypedVar *returnArg = method->results()[0]; |
| 495 | |
| 496 | out << returnArg->type().getJavaType() |
| 497 | << " " |
| 498 | << returnArg->name() |
| 499 | << " = "; |
| 500 | } |
| 501 | |
| 502 | out << method->name() |
| 503 | << "("; |
| 504 | |
| 505 | bool firstField = true; |
| 506 | for (const auto &arg : method->args()) { |
| 507 | if (!firstField) { |
| 508 | out << ", "; |
| 509 | } |
| 510 | |
| 511 | out << arg->name(); |
| 512 | |
| 513 | firstField = false; |
| 514 | } |
| 515 | |
| 516 | if (needsCallback) { |
| 517 | if (!firstField) { |
| 518 | out << ", "; |
| 519 | } |
| 520 | |
| 521 | out << "new " << method->name() << "Callback() {\n"; |
| 522 | out.indent(); |
| 523 | |
| 524 | out << "@Override\n" |
| 525 | << "public void onValues(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 526 | << Method::GetJavaArgSignature(method->results()) |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 527 | << ") {\n"; |
| 528 | |
| 529 | out.indent(); |
| 530 | out << "reply.writeStatus(HwParcel.STATUS_SUCCESS);\n"; |
| 531 | |
| 532 | for (const auto &arg : method->results()) { |
| 533 | emitJavaReaderWriter( |
| 534 | out, |
| 535 | "reply", |
| 536 | arg, |
| 537 | false /* isReader */); |
| 538 | } |
| 539 | |
| 540 | out << "reply.send();\n" |
| 541 | << "}}"; |
| 542 | |
| 543 | out.unindent(); |
| 544 | out.unindent(); |
| 545 | } |
| 546 | |
| 547 | out << ");\n"; |
| 548 | |
| 549 | if (!needsCallback) { |
| 550 | out << "reply.writeStatus(HwParcel.STATUS_SUCCESS);\n"; |
| 551 | |
| 552 | if (returnsValue) { |
| 553 | const TypedVar *returnArg = method->results()[0]; |
| 554 | |
| 555 | emitJavaReaderWriter( |
| 556 | out, |
| 557 | "reply", |
| 558 | returnArg, |
| 559 | false /* isReader */); |
| 560 | } |
| 561 | |
| 562 | out << "reply.send();\n"; |
| 563 | } |
| 564 | |
| 565 | out << "break;\n"; |
| 566 | out.unindent(); |
| 567 | out << "}\n\n"; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | out.unindent(); |
| 572 | out << "}\n"; |
| 573 | |
| 574 | out.unindent(); |
| 575 | out << "}\n"; |
| 576 | |
| 577 | out.unindent(); |
| 578 | out << "}\n"; |
| 579 | |
| 580 | out.unindent(); |
| 581 | out << "}\n"; |
| 582 | |
| 583 | return OK; |
| 584 | } |
| 585 | |
| 586 | status_t AST::emitJavaTypeDeclarations(Formatter &out) const { |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 587 | return mRootScope->emitJavaTypeDeclarations(out, false /* atTopLevel */); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | } // namespace android |
| 591 | |