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" |
Timur Iskhakov | 7fa79f6 | 2017-08-09 11:04:54 -0700 | [diff] [blame] | 22 | #include "Reference.h" |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 23 | #include "Scope.h" |
| 24 | |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 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 | |
Timur Iskhakov | 7fa79f6 | 2017-08-09 11:04:54 -0700 | [diff] [blame] | 30 | void AST::emitJavaReaderWriter(Formatter& out, const std::string& parcelObj, |
| 31 | const NamedReference<Type>* arg, bool isReader, |
| 32 | bool addPrefixToName) const { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 33 | if (isReader) { |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 34 | out << arg->type().getJavaType() |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 35 | << " " |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 36 | << (addPrefixToName ? "_hidl_out_" : "") |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 37 | << arg->name() |
| 38 | << " = "; |
| 39 | } |
| 40 | |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 41 | arg->type().emitJavaReaderWriter(out, parcelObj, |
| 42 | (addPrefixToName ? "_hidl_out_" : "") + arg->name(), |
| 43 | isReader); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 46 | status_t AST::generateJavaTypes( |
Andreas Huber | d29724f | 2016-09-14 09:33:13 -0700 | [diff] [blame] | 47 | const std::string &outputPath, const std::string &limitToType) const { |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 48 | // Splits types.hal up into one java file per declared type. |
| 49 | |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 50 | for (const auto& type : mRootScope.getSubTypes()) { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 51 | std::string typeName = type->localName(); |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 52 | |
| 53 | if (type->isTypeDef()) { |
| 54 | continue; |
| 55 | } |
| 56 | |
Andreas Huber | d29724f | 2016-09-14 09:33:13 -0700 | [diff] [blame] | 57 | if (!limitToType.empty() && typeName != limitToType) { |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 58 | continue; |
| 59 | } |
| 60 | |
Steven Moreland | a885d25 | 2017-09-25 18:44:43 -0700 | [diff] [blame] | 61 | Formatter out = mCoordinator->getFormatter( |
| 62 | outputPath, mPackage, Coordinator::Location::GEN_SANITIZED, typeName + ".java"); |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 63 | |
Steven Moreland | a885d25 | 2017-09-25 18:44:43 -0700 | [diff] [blame] | 64 | if (!out.isValid()) { |
| 65 | return UNKNOWN_ERROR; |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 68 | std::vector<std::string> packageComponents; |
| 69 | getPackageAndVersionComponents( |
| 70 | &packageComponents, true /* cpp_compatible */); |
| 71 | |
| 72 | out << "package " << mPackage.javaPackage() << ";\n\n"; |
| 73 | |
Iliyan Malchev | 800273d | 2016-09-02 15:25:07 -0700 | [diff] [blame] | 74 | out << "\n"; |
| 75 | |
Andreas Huber | 85eabdb | 2016-08-25 11:24:49 -0700 | [diff] [blame] | 76 | status_t err = |
| 77 | type->emitJavaTypeDeclarations(out, true /* atTopLevel */); |
| 78 | |
| 79 | if (err != OK) { |
| 80 | return err; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return OK; |
| 85 | } |
| 86 | |
Steven Moreland | 9bf5a09 | 2017-10-25 04:50:54 +0000 | [diff] [blame] | 87 | void emitGetService( |
| 88 | Formatter& out, |
| 89 | const std::string& ifaceName, |
| 90 | const std::string& fqName, |
| 91 | bool isRetry) { |
| 92 | out << "public static " |
| 93 | << ifaceName |
| 94 | << " getService(String serviceName"; |
| 95 | if (isRetry) { |
| 96 | out << ", boolean retry"; |
| 97 | } |
| 98 | out << ") throws android.os.RemoteException "; |
| 99 | out.block([&] { |
| 100 | out << "return " |
| 101 | << ifaceName |
| 102 | << ".asInterface(android.os.HwBinder.getService(\"" |
| 103 | << fqName |
| 104 | << "\", serviceName"; |
| 105 | if (isRetry) { |
| 106 | out << ", retry"; |
| 107 | } |
| 108 | out << "));\n"; |
| 109 | }).endl().endl(); |
| 110 | |
| 111 | out << "public static " |
| 112 | << ifaceName |
| 113 | << " getService("; |
| 114 | if (isRetry) { |
| 115 | out << "boolean retry"; |
| 116 | } |
| 117 | out << ") throws android.os.RemoteException "; |
| 118 | out.block([&] { |
| 119 | out << "return getService(\"default\""; |
| 120 | if (isRetry) { |
| 121 | out << ", retry"; |
| 122 | } |
| 123 | out <<");\n"; |
| 124 | }).endl().endl(); |
| 125 | } |
| 126 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 127 | status_t AST::generateJava( |
Andreas Huber | d29724f | 2016-09-14 09:33:13 -0700 | [diff] [blame] | 128 | const std::string &outputPath, const std::string &limitToType) const { |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 129 | if (!isJavaCompatible()) { |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 130 | fprintf(stderr, |
| 131 | "ERROR: This interface is not Java compatible. The Java backend" |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 132 | " does NOT support union types nor native handles. " |
| 133 | "In addition, vectors of arrays are limited to at most " |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 134 | "one-dimensional arrays and vectors of {vectors,interfaces} are" |
| 135 | " not supported.\n"); |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 136 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 137 | return UNKNOWN_ERROR; |
| 138 | } |
| 139 | |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 140 | if (!AST::isInterface()) { |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 141 | return generateJavaTypes(outputPath, limitToType); |
| 142 | } |
| 143 | |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 144 | const Interface* iface = mRootScope.getInterface(); |
Steven Moreland | 19f11b5 | 2017-05-12 18:22:21 -0700 | [diff] [blame] | 145 | std::string ifaceName = iface->localName(); |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 146 | |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 147 | const std::string baseName = iface->getBaseName(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 148 | |
Steven Moreland | a885d25 | 2017-09-25 18:44:43 -0700 | [diff] [blame] | 149 | Formatter out = mCoordinator->getFormatter( |
| 150 | outputPath, mPackage, Coordinator::Location::GEN_SANITIZED, ifaceName + ".java"); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 151 | |
Steven Moreland | a885d25 | 2017-09-25 18:44:43 -0700 | [diff] [blame] | 152 | if (!out.isValid()) { |
| 153 | return UNKNOWN_ERROR; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 156 | std::vector<std::string> packageComponents; |
| 157 | getPackageAndVersionComponents( |
| 158 | &packageComponents, true /* cpp_compatible */); |
| 159 | |
| 160 | out << "package " << mPackage.javaPackage() << ";\n\n"; |
| 161 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 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 { |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 171 | out << "android.os.IHwInterface"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 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 | |
Andreas Huber | a2abe98 | 2017-04-04 14:42:09 -0700 | [diff] [blame] | 183 | out << "/* package private */ static " |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 184 | << ifaceName |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 185 | << " asInterface(android.os.IHwBinder binder) {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 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 | |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 195 | out << "android.os.IHwInterface iface =\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 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 | |
Andreas Huber | a2abe98 | 2017-04-04 14:42:09 -0700 | [diff] [blame] | 211 | out << ifaceName << " proxy = new " << ifaceName << ".Proxy(binder);\n\n"; |
| 212 | out << "try {\n"; |
| 213 | out.indent(); |
| 214 | out << "for (String descriptor : proxy.interfaceChain()) {\n"; |
| 215 | out.indent(); |
| 216 | out << "if (descriptor.equals(kInterfaceName)) {\n"; |
| 217 | out.indent(); |
| 218 | out << "return proxy;\n"; |
| 219 | out.unindent(); |
| 220 | out << "}\n"; |
| 221 | out.unindent(); |
| 222 | out << "}\n"; |
| 223 | out.unindent(); |
| 224 | out << "} catch (android.os.RemoteException e) {\n"; |
| 225 | out.indent(); |
| 226 | out.unindent(); |
| 227 | out << "}\n\n"; |
| 228 | |
| 229 | out << "return null;\n"; |
| 230 | |
| 231 | out.unindent(); |
| 232 | out << "}\n\n"; |
| 233 | |
| 234 | out << "public static " |
| 235 | << ifaceName |
| 236 | << " castFrom(android.os.IHwInterface iface) {\n"; |
| 237 | out.indent(); |
| 238 | |
| 239 | out << "return (iface == null) ? null : " |
| 240 | << ifaceName |
| 241 | << ".asInterface(iface.asBinder());\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 242 | |
| 243 | out.unindent(); |
| 244 | out << "}\n\n"; |
| 245 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 246 | out << "@Override\npublic android.os.IHwBinder asBinder();\n\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 247 | |
Steven Moreland | 9bf5a09 | 2017-10-25 04:50:54 +0000 | [diff] [blame] | 248 | emitGetService(out, ifaceName, iface->fqName().string(), true /* isRetry */); |
| 249 | emitGetService(out, ifaceName, iface->fqName().string(), false /* isRetry */); |
Chris Phoenix | db0d634 | 2017-01-11 16:10:00 -0800 | [diff] [blame] | 250 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 251 | status_t err = emitJavaTypeDeclarations(out); |
| 252 | |
| 253 | if (err != OK) { |
| 254 | return err; |
| 255 | } |
| 256 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 257 | for (const auto &method : iface->methods()) { |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 258 | if (method->isHiddenFromJava()) { |
| 259 | continue; |
| 260 | } |
| 261 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 262 | const bool returnsValue = !method->results().empty(); |
| 263 | const bool needsCallback = method->results().size() > 1; |
| 264 | |
| 265 | if (needsCallback) { |
Yifan Hong | 601cfca | 2017-05-24 12:20:17 -0700 | [diff] [blame] | 266 | out << "\n@java.lang.FunctionalInterface\npublic interface " << method->name() |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 267 | << "Callback {\n"; |
| 268 | |
| 269 | out.indent(); |
| 270 | |
Yifan Hong | 932464e | 2017-03-30 15:40:22 -0700 | [diff] [blame] | 271 | out << "public void onValues("; |
| 272 | method->emitJavaResultSignature(out); |
| 273 | out << ");\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 274 | |
| 275 | out.unindent(); |
| 276 | out << "}\n\n"; |
| 277 | } |
| 278 | |
| 279 | if (returnsValue && !needsCallback) { |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 280 | out << method->results()[0]->type().getJavaType(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 281 | } else { |
| 282 | out << "void"; |
| 283 | } |
| 284 | |
| 285 | out << " " |
| 286 | << method->name() |
Yifan Hong | 932464e | 2017-03-30 15:40:22 -0700 | [diff] [blame] | 287 | << "("; |
| 288 | method->emitJavaArgSignature(out); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 289 | |
| 290 | if (needsCallback) { |
| 291 | if (!method->args().empty()) { |
| 292 | out << ", "; |
| 293 | } |
| 294 | |
| 295 | out << method->name() |
Steven Moreland | 4ddd833 | 2017-04-27 19:27:18 -0700 | [diff] [blame] | 296 | << "Callback _hidl_cb"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 299 | out << ")\n"; |
| 300 | out.indent(); |
Yifan Hong | 320a349 | 2017-03-27 10:33:09 -0700 | [diff] [blame] | 301 | out << "throws android.os.RemoteException;\n"; |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 302 | out.unindent(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | out << "\npublic static final class Proxy implements " |
| 306 | << ifaceName |
| 307 | << " {\n"; |
| 308 | |
| 309 | out.indent(); |
| 310 | |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 311 | out << "private android.os.IHwBinder mRemote;\n\n"; |
| 312 | out << "public Proxy(android.os.IHwBinder remote) {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 313 | out.indent(); |
Yifan Hong | 729e796 | 2016-12-21 16:04:27 -0800 | [diff] [blame] | 314 | out << "mRemote = java.util.Objects.requireNonNull(remote);\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 315 | out.unindent(); |
| 316 | out << "}\n\n"; |
| 317 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 318 | out << "@Override\npublic android.os.IHwBinder asBinder() {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 319 | out.indent(); |
| 320 | out << "return mRemote;\n"; |
| 321 | out.unindent(); |
| 322 | out << "}\n\n"; |
| 323 | |
Yifan Hong | e45b530 | 2017-02-22 10:49:07 -0800 | [diff] [blame] | 324 | |
| 325 | out << "@Override\npublic String toString() "; |
| 326 | out.block([&] { |
| 327 | out.sTry([&] { |
| 328 | out << "return this.interfaceDescriptor() + \"@Proxy\";\n"; |
Yifan Hong | 320a349 | 2017-03-27 10:33:09 -0700 | [diff] [blame] | 329 | }).sCatch("android.os.RemoteException ex", [&] { |
Yifan Hong | e45b530 | 2017-02-22 10:49:07 -0800 | [diff] [blame] | 330 | out << "/* ignored; handled below. */\n"; |
| 331 | }).endl(); |
| 332 | out << "return \"[class or subclass of \" + " |
| 333 | << ifaceName << ".kInterfaceName + \"]@Proxy\";\n"; |
| 334 | }).endl().endl(); |
| 335 | |
Yifan Hong | f89e106 | 2017-10-31 17:31:08 -0700 | [diff] [blame] | 336 | // Equals when internal binder object is equal (even if the interface Proxy object |
| 337 | // itself is different). This is similar to interfacesEqual in C++. |
| 338 | out << "@Override\npublic final boolean equals(java.lang.Object other) "; |
| 339 | out.block([&] { |
| 340 | out << "return android.os.HidlSupport.interfacesEqual(this, other);\n"; |
| 341 | }).endl().endl(); |
| 342 | |
| 343 | out << "@Override\npublic final int hashCode() "; |
| 344 | out.block([&] { |
| 345 | out << "return this.asBinder().hashCode();\n"; |
| 346 | }).endl().endl(); |
| 347 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 348 | const Interface *prevInterface = nullptr; |
| 349 | for (const auto &tuple : iface->allMethodsFromRoot()) { |
| 350 | const Method *method = tuple.method(); |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 351 | |
| 352 | if (method->isHiddenFromJava()) { |
| 353 | continue; |
| 354 | } |
| 355 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 356 | const Interface *superInterface = tuple.interface(); |
| 357 | if (prevInterface != superInterface) { |
| 358 | out << "// Methods from " |
| 359 | << superInterface->fullName() |
| 360 | << " follow.\n"; |
| 361 | prevInterface = superInterface; |
| 362 | } |
| 363 | const bool returnsValue = !method->results().empty(); |
| 364 | const bool needsCallback = method->results().size() > 1; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 365 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 366 | out << "@Override\npublic "; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 367 | if (returnsValue && !needsCallback) { |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 368 | out << method->results()[0]->type().getJavaType(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 369 | } else { |
| 370 | out << "void"; |
| 371 | } |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 372 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 373 | out << " " |
| 374 | << method->name() |
Yifan Hong | 932464e | 2017-03-30 15:40:22 -0700 | [diff] [blame] | 375 | << "("; |
| 376 | method->emitJavaArgSignature(out); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 377 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 378 | if (needsCallback) { |
| 379 | if (!method->args().empty()) { |
| 380 | out << ", "; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 383 | out << method->name() |
Steven Moreland | 4ddd833 | 2017-04-27 19:27:18 -0700 | [diff] [blame] | 384 | << "Callback _hidl_cb"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 385 | } |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 386 | |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 387 | out << ")\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 388 | out.indent(); |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 389 | out.indent(); |
Yifan Hong | 320a349 | 2017-03-27 10:33:09 -0700 | [diff] [blame] | 390 | out << "throws android.os.RemoteException {\n"; |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 391 | out.unindent(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 392 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 393 | if (method->isHidlReserved() && method->overridesJavaImpl(IMPL_PROXY)) { |
| 394 | method->javaImpl(IMPL_PROXY, out); |
| 395 | out.unindent(); |
| 396 | out << "}\n"; |
| 397 | continue; |
| 398 | } |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 399 | out << "android.os.HwParcel _hidl_request = new android.os.HwParcel();\n"; |
| 400 | out << "_hidl_request.writeInterfaceToken(" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 401 | << superInterface->fullJavaName() |
| 402 | << ".kInterfaceName);\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 403 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 404 | for (const auto &arg : method->args()) { |
| 405 | emitJavaReaderWriter( |
| 406 | out, |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 407 | "_hidl_request", |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 408 | arg, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 409 | false /* isReader */, |
| 410 | false /* addPrefixToName */); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 411 | } |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 412 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 413 | out << "\nandroid.os.HwParcel _hidl_reply = new android.os.HwParcel();\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 414 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 415 | out.sTry([&] { |
| 416 | out << "mRemote.transact(" |
| 417 | << method->getSerialId() |
| 418 | << " /* " |
| 419 | << method->name() |
| 420 | << " */, _hidl_request, _hidl_reply, "; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 421 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 422 | if (method->isOneway()) { |
| 423 | out << "android.os.IHwBinder.FLAG_ONEWAY"; |
| 424 | } else { |
| 425 | out << "0 /* flags */"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 428 | out << ");\n"; |
Andreas Huber | 8b5da22 | 2016-08-18 14:28:18 -0700 | [diff] [blame] | 429 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 430 | if (!method->isOneway()) { |
| 431 | out << "_hidl_reply.verifySuccess();\n"; |
| 432 | } else { |
| 433 | CHECK(!returnsValue); |
| 434 | } |
| 435 | |
| 436 | out << "_hidl_request.releaseTemporaryStorage();\n"; |
| 437 | |
| 438 | if (returnsValue) { |
| 439 | out << "\n"; |
| 440 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 441 | for (const auto &arg : method->results()) { |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 442 | emitJavaReaderWriter( |
| 443 | out, |
| 444 | "_hidl_reply", |
| 445 | arg, |
| 446 | true /* isReader */, |
| 447 | true /* addPrefixToName */); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 448 | } |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 449 | |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 450 | if (needsCallback) { |
Steven Moreland | 4ddd833 | 2017-04-27 19:27:18 -0700 | [diff] [blame] | 451 | out << "_hidl_cb.onValues("; |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 452 | |
| 453 | bool firstField = true; |
| 454 | for (const auto &arg : method->results()) { |
| 455 | if (!firstField) { |
| 456 | out << ", "; |
| 457 | } |
| 458 | |
| 459 | out << "_hidl_out_" << arg->name(); |
| 460 | firstField = false; |
| 461 | } |
| 462 | |
| 463 | out << ");\n"; |
| 464 | } else { |
| 465 | const std::string returnName = method->results()[0]->name(); |
| 466 | out << "return _hidl_out_" << returnName << ";\n"; |
| 467 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 468 | } |
Martijn Coenen | 4de083b | 2017-03-16 18:49:43 +0100 | [diff] [blame] | 469 | }).sFinally([&] { |
| 470 | out << "_hidl_reply.release();\n"; |
| 471 | }).endl(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 472 | |
| 473 | out.unindent(); |
| 474 | out << "}\n\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | out.unindent(); |
| 478 | out << "}\n"; |
| 479 | |
| 480 | //////////////////////////////////////////////////////////////////////////// |
| 481 | |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 482 | out << "\npublic static abstract class Stub extends android.os.HwBinder " |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 483 | << "implements " |
| 484 | << ifaceName << " {\n"; |
| 485 | |
| 486 | out.indent(); |
| 487 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 488 | out << "@Override\npublic android.os.IHwBinder asBinder() {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 489 | out.indent(); |
Yifan Hong | f89e106 | 2017-10-31 17:31:08 -0700 | [diff] [blame] | 490 | // If we change this behavior in the future and asBinder does not return "this", |
| 491 | // equals and hashCode should also be overridden. |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 492 | out << "return this;\n"; |
| 493 | out.unindent(); |
| 494 | out << "}\n\n"; |
| 495 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 496 | for (Method *method : iface->hidlReservedMethods()) { |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 497 | if (method->isHiddenFromJava()) { |
| 498 | continue; |
| 499 | } |
| 500 | |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 501 | // b/32383557 this is a hack. We need to change this if we have more reserved methods. |
| 502 | CHECK_LE(method->results().size(), 1u); |
| 503 | std::string resultType = method->results().size() == 0 ? "void" : |
| 504 | method->results()[0]->type().getJavaType(); |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 505 | out << "@Override\npublic final " |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 506 | << resultType |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 507 | << " " |
| 508 | << method->name() |
Yifan Hong | 932464e | 2017-03-30 15:40:22 -0700 | [diff] [blame] | 509 | << "("; |
| 510 | method->emitJavaArgSignature(out); |
| 511 | out << ") {\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 512 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 513 | out.indent(); |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 514 | method->javaImpl(IMPL_INTERFACE, out); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 515 | out.unindent(); |
| 516 | out << "\n}\n\n"; |
| 517 | } |
| 518 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 519 | out << "@Override\n" |
| 520 | << "public android.os.IHwInterface queryLocalInterface(String descriptor) {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 521 | out.indent(); |
| 522 | // XXX what about potential superClasses? |
| 523 | out << "if (kInterfaceName.equals(descriptor)) {\n"; |
| 524 | out.indent(); |
| 525 | out << "return this;\n"; |
| 526 | out.unindent(); |
| 527 | out << "}\n"; |
| 528 | out << "return null;\n"; |
| 529 | out.unindent(); |
| 530 | out << "}\n\n"; |
| 531 | |
Yifan Hong | 320a349 | 2017-03-27 10:33:09 -0700 | [diff] [blame] | 532 | out << "public void registerAsService(String serviceName) throws android.os.RemoteException {\n"; |
Andreas Huber | 2bb6e1e | 2016-10-25 13:26:43 -0700 | [diff] [blame] | 533 | out.indent(); |
| 534 | |
Martijn Coenen | bc9f5c9 | 2017-03-06 13:04:05 +0100 | [diff] [blame] | 535 | out << "registerService(serviceName);\n"; |
Andreas Huber | 2bb6e1e | 2016-10-25 13:26:43 -0700 | [diff] [blame] | 536 | |
| 537 | out.unindent(); |
| 538 | out << "}\n\n"; |
| 539 | |
Yifan Hong | e45b530 | 2017-02-22 10:49:07 -0800 | [diff] [blame] | 540 | out << "@Override\npublic String toString() "; |
| 541 | out.block([&] { |
| 542 | out << "return this.interfaceDescriptor() + \"@Stub\";\n"; |
| 543 | }).endl().endl(); |
| 544 | |
Yifan Hong | 084d11f | 2016-12-21 15:33:43 -0800 | [diff] [blame] | 545 | out << "@Override\n" |
| 546 | << "public void onTransact(" |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 547 | << "int _hidl_code, " |
| 548 | << "android.os.HwParcel _hidl_request, " |
| 549 | << "final android.os.HwParcel _hidl_reply, " |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 550 | << "int _hidl_flags)\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 551 | out.indent(); |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 552 | out.indent(); |
Yifan Hong | 320a349 | 2017-03-27 10:33:09 -0700 | [diff] [blame] | 553 | out << "throws android.os.RemoteException {\n"; |
Steven Moreland | dad1b30 | 2016-12-20 15:56:00 -0800 | [diff] [blame] | 554 | out.unindent(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 555 | |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 556 | out << "switch (_hidl_code) {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 557 | |
| 558 | out.indent(); |
| 559 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 560 | for (const auto &tuple : iface->allMethodsFromRoot()) { |
| 561 | const Method *method = tuple.method(); |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 562 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 563 | const Interface *superInterface = tuple.interface(); |
| 564 | const bool returnsValue = !method->results().empty(); |
| 565 | const bool needsCallback = method->results().size() > 1; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 566 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 567 | out << "case " |
| 568 | << method->getSerialId() |
| 569 | << " /* " |
| 570 | << method->name() |
| 571 | << " */:\n{\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 572 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 573 | out.indent(); |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 574 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 575 | if (method->isHidlReserved() && method->overridesJavaImpl(IMPL_STUB)) { |
| 576 | method->javaImpl(IMPL_STUB, out); |
| 577 | out.unindent(); |
| 578 | out << "break;\n"; |
| 579 | out << "}\n\n"; |
| 580 | continue; |
| 581 | } |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 582 | |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 583 | out << "_hidl_request.enforceInterface(" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 584 | << superInterface->fullJavaName() |
| 585 | << ".kInterfaceName);\n\n"; |
| 586 | |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 587 | if (method->isHiddenFromJava()) { |
| 588 | // This is a method hidden from the Java side of things, it must not |
| 589 | // return any value and will simply signal success. |
| 590 | CHECK(!returnsValue); |
| 591 | |
| 592 | out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n"; |
| 593 | out << "_hidl_reply.send();\n"; |
| 594 | out << "break;\n"; |
| 595 | out.unindent(); |
| 596 | out << "}\n\n"; |
| 597 | continue; |
| 598 | } |
| 599 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 600 | for (const auto &arg : method->args()) { |
| 601 | emitJavaReaderWriter( |
| 602 | out, |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 603 | "_hidl_request", |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 604 | arg, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 605 | true /* isReader */, |
| 606 | false /* addPrefixToName */); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | if (!needsCallback && returnsValue) { |
Timur Iskhakov | 7fa79f6 | 2017-08-09 11:04:54 -0700 | [diff] [blame] | 610 | const NamedReference<Type>* returnArg = method->results()[0]; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 611 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 612 | out << returnArg->type().getJavaType() |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 613 | << " _hidl_out_" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 614 | << returnArg->name() |
| 615 | << " = "; |
| 616 | } |
| 617 | |
| 618 | out << method->name() |
| 619 | << "("; |
| 620 | |
| 621 | bool firstField = true; |
| 622 | for (const auto &arg : method->args()) { |
| 623 | if (!firstField) { |
| 624 | out << ", "; |
| 625 | } |
| 626 | |
| 627 | out << arg->name(); |
| 628 | |
| 629 | firstField = false; |
| 630 | } |
| 631 | |
| 632 | if (needsCallback) { |
| 633 | if (!firstField) { |
| 634 | out << ", "; |
| 635 | } |
| 636 | |
| 637 | out << "new " << method->name() << "Callback() {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 638 | out.indent(); |
| 639 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 640 | out << "@Override\n" |
Yifan Hong | 932464e | 2017-03-30 15:40:22 -0700 | [diff] [blame] | 641 | << "public void onValues("; |
| 642 | method->emitJavaResultSignature(out); |
| 643 | out << ") {\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 644 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 645 | out.indent(); |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 646 | out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 647 | |
| 648 | for (const auto &arg : method->results()) { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 649 | emitJavaReaderWriter( |
| 650 | out, |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 651 | "_hidl_reply", |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 652 | arg, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 653 | false /* isReader */, |
| 654 | false /* addPrefixToName */); |
| 655 | // no need to add _hidl_out because out vars are are scoped |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 658 | out << "_hidl_reply.send();\n" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 659 | << "}}"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 660 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 661 | out.unindent(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 662 | out.unindent(); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 663 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 664 | |
| 665 | out << ");\n"; |
| 666 | |
Martijn Coenen | 0bb0d41 | 2017-02-08 10:21:30 +0100 | [diff] [blame] | 667 | if (!needsCallback && !method->isOneway()) { |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 668 | out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 669 | |
| 670 | if (returnsValue) { |
Timur Iskhakov | 7fa79f6 | 2017-08-09 11:04:54 -0700 | [diff] [blame] | 671 | const NamedReference<Type>* returnArg = method->results()[0]; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 672 | |
| 673 | emitJavaReaderWriter( |
| 674 | out, |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 675 | "_hidl_reply", |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 676 | returnArg, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 677 | false /* isReader */, |
| 678 | true /* addPrefixToName */); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Steven Moreland | 4b39bc1 | 2016-11-16 10:42:24 -0800 | [diff] [blame] | 681 | out << "_hidl_reply.send();\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | out << "break;\n"; |
| 685 | out.unindent(); |
| 686 | out << "}\n\n"; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | out.unindent(); |
| 690 | out << "}\n"; |
| 691 | |
| 692 | out.unindent(); |
| 693 | out << "}\n"; |
| 694 | |
| 695 | out.unindent(); |
| 696 | out << "}\n"; |
| 697 | |
| 698 | out.unindent(); |
| 699 | out << "}\n"; |
| 700 | |
| 701 | return OK; |
| 702 | } |
| 703 | |
| 704 | status_t AST::emitJavaTypeDeclarations(Formatter &out) const { |
Timur Iskhakov | cb0ba52 | 2017-07-17 20:01:37 -0700 | [diff] [blame] | 705 | return mRootScope.emitJavaTypeDeclarations(out, false /* atTopLevel */); |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | } // namespace android |