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