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