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 | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 17 | #include "AST.h" |
| 18 | |
| 19 | #include "Coordinator.h" |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 20 | #include "EnumType.h" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 21 | #include "Formatter.h" |
| 22 | #include "Interface.h" |
| 23 | #include "Method.h" |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 24 | #include "ScalarType.h" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 25 | #include "Scope.h" |
| 26 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 27 | #include <algorithm> |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 28 | #include <android-base/logging.h> |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 29 | #include <string> |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 30 | #include <vector> |
| 31 | |
| 32 | namespace android { |
| 33 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 34 | static std::string upcase(const std::string in) { |
| 35 | std::string out{in}; |
| 36 | |
| 37 | for (auto &ch : out) { |
| 38 | ch = toupper(ch); |
| 39 | } |
| 40 | |
| 41 | return out; |
| 42 | } |
| 43 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 44 | status_t AST::generateCpp(const std::string &outputPath) const { |
| 45 | status_t err = generateInterfaceHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 46 | |
| 47 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 48 | err = generateStubHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | if (err == OK) { |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 52 | err = generateHwBinderHeader(outputPath); |
| 53 | } |
| 54 | |
| 55 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 56 | err = generateProxyHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 60 | err = generateAllSource(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | return err; |
| 64 | } |
| 65 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 66 | void AST::getPackageComponents( |
| 67 | std::vector<std::string> *components) const { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 68 | mPackage.getPackageComponents(components); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void AST::getPackageAndVersionComponents( |
| 72 | std::vector<std::string> *components, bool cpp_compatible) const { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 73 | mPackage.getPackageAndVersionComponents(components, cpp_compatible); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 76 | std::string AST::makeHeaderGuard(const std::string &baseName) const { |
| 77 | std::vector<std::string> packageComponents; |
| 78 | getPackageAndVersionComponents( |
| 79 | &packageComponents, true /* cpp_compatible */); |
| 80 | |
| 81 | std::string guard = "HIDL_GENERATED"; |
| 82 | for (const auto &component : packageComponents) { |
| 83 | guard += "_"; |
| 84 | guard += component; |
| 85 | } |
| 86 | |
| 87 | guard += "_"; |
| 88 | guard += baseName; |
| 89 | guard += "_H_"; |
| 90 | |
| 91 | return guard; |
| 92 | } |
| 93 | |
| 94 | void AST::enterLeaveNamespace(Formatter &out, bool enter) const { |
| 95 | std::vector<std::string> packageComponents; |
| 96 | getPackageAndVersionComponents( |
| 97 | &packageComponents, true /* cpp_compatible */); |
| 98 | |
| 99 | if (enter) { |
| 100 | for (const auto &component : packageComponents) { |
| 101 | out << "namespace " << component << " {\n"; |
| 102 | } |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 103 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 104 | out.setNamespace(mPackage.cppNamespace() + "::"); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 105 | } else { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 106 | out.setNamespace(std::string()); |
| 107 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 108 | for (auto it = packageComponents.rbegin(); |
| 109 | it != packageComponents.rend(); |
| 110 | ++it) { |
| 111 | out << "} // namespace " << *it << "\n"; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 116 | status_t AST::generateInterfaceHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 117 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 118 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 119 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 120 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 121 | |
| 122 | std::string ifaceName; |
| 123 | bool isInterface = true; |
| 124 | if (!AST::isInterface(&ifaceName)) { |
| 125 | ifaceName = "types"; |
| 126 | isInterface = false; |
| 127 | } |
| 128 | path.append(ifaceName); |
| 129 | path.append(".h"); |
| 130 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 131 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 132 | FILE *file = fopen(path.c_str(), "w"); |
| 133 | |
| 134 | if (file == NULL) { |
| 135 | return -errno; |
| 136 | } |
| 137 | |
| 138 | Formatter out(file); |
| 139 | |
| 140 | const std::string guard = makeHeaderGuard(ifaceName); |
| 141 | |
| 142 | out << "#ifndef " << guard << "\n"; |
| 143 | out << "#define " << guard << "\n\n"; |
| 144 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 145 | for (const auto &item : mImportedNames) { |
| 146 | out << "#include <"; |
| 147 | |
| 148 | std::vector<std::string> components; |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 149 | item.getPackageAndVersionComponents( |
| 150 | &components, false /* cpp_compatible */); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 151 | |
| 152 | for (const auto &component : components) { |
| 153 | out << component << "/"; |
| 154 | } |
| 155 | |
| 156 | out << item.name() |
| 157 | << ".h>\n"; |
| 158 | } |
| 159 | |
| 160 | if (!mImportedNames.empty()) { |
| 161 | out << "\n"; |
| 162 | } |
| 163 | |
Martijn Coenen | 7473fab | 2016-08-19 14:05:40 +0200 | [diff] [blame] | 164 | out << "#include <hidl/HidlSupport.h>\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 165 | out << "#include <hidl/IServiceManager.h>\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 166 | |
| 167 | if (isInterface) { |
Martijn Coenen | 9391510 | 2016-09-01 01:35:52 +0200 | [diff] [blame] | 168 | out << "#include <hidl/Status.h>\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | out << "#include <utils/NativeHandle.h>\n\n"; |
| 172 | |
| 173 | enterLeaveNamespace(out, true /* enter */); |
| 174 | out << "\n"; |
| 175 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 176 | // cut off the leading 'I'. |
| 177 | const std::string baseName = ifaceName.substr(1); |
| 178 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 179 | if (isInterface) { |
| 180 | out << "struct " |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 181 | << ifaceName; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 182 | |
| 183 | const Interface *iface = mRootScope->getInterface(); |
| 184 | const Interface *superType = iface->superType(); |
| 185 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 186 | if (superType == NULL) { |
| 187 | out << " : virtual public RefBase"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 188 | } else { |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 189 | out << " : public " |
| 190 | << superType->fullName(); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | out << " {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 194 | |
| 195 | out.indent(); |
| 196 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | status_t err = emitTypeDeclarations(out); |
| 200 | |
| 201 | if (err != OK) { |
| 202 | return err; |
| 203 | } |
| 204 | |
| 205 | if (isInterface) { |
| 206 | const Interface *iface = mRootScope->getInterface(); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 207 | const Interface *superType = iface->superType(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 208 | |
Iliyan Malchev | 795dd43 | 2016-09-02 11:48:26 -0700 | [diff] [blame] | 209 | out << "virtual bool isRemote() const { return false; }\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 210 | bool haveCallbacks = false; |
| 211 | for (const auto &method : iface->methods()) { |
| 212 | const bool returnsValue = !method->results().empty(); |
| 213 | |
| 214 | if (!returnsValue) { |
| 215 | continue; |
| 216 | } |
| 217 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 218 | if (method->canElideCallback() != nullptr) { |
| 219 | continue; |
| 220 | } |
| 221 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 222 | haveCallbacks = true; |
| 223 | |
| 224 | out << "using " |
| 225 | << method->name() |
| 226 | << "_cb = std::function<void(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 227 | << Method::GetArgSignature(method->results()) |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 228 | << ")>;\n"; |
| 229 | } |
| 230 | |
| 231 | if (haveCallbacks) { |
| 232 | out << "\n"; |
| 233 | } |
| 234 | |
| 235 | for (const auto &method : iface->methods()) { |
| 236 | const bool returnsValue = !method->results().empty(); |
| 237 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 238 | method->dumpAnnotations(out); |
| 239 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 240 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 241 | if (elidedReturn) { |
| 242 | std::string extra; |
Iliyan Malchev | 2b6591b | 2016-08-18 19:15:19 -0700 | [diff] [blame] | 243 | out << "virtual ::android::hardware::Return<"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 244 | out << elidedReturn->type().getCppResultType(&extra) << "> "; |
| 245 | } else { |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame^] | 246 | out << "virtual ::android::hardware::Return<void> "; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | out << method->name() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 250 | << "(" |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 251 | << Method::GetArgSignature(method->args()); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 252 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 253 | if (returnsValue && elidedReturn == nullptr) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 254 | if (!method->args().empty()) { |
| 255 | out << ", "; |
| 256 | } |
| 257 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 258 | out << method->name() << "_cb _hidl_cb = nullptr"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | out << ") = 0;\n"; |
| 262 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 263 | |
| 264 | out << "DECLARE_REGISTER_AND_GET_SERVICE(" << baseName << ")\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (isInterface) { |
| 268 | out.unindent(); |
| 269 | |
| 270 | out << "};\n"; |
| 271 | } |
| 272 | |
| 273 | out << "\n"; |
| 274 | enterLeaveNamespace(out, false /* enter */); |
| 275 | |
| 276 | out << "\n#endif // " << guard << "\n"; |
| 277 | |
| 278 | return OK; |
| 279 | } |
| 280 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 281 | status_t AST::generateHwBinderHeader(const std::string &outputPath) const { |
| 282 | std::string ifaceName; |
| 283 | if(!AST::isInterface(&ifaceName)) { |
| 284 | // types.hal does not get an HwBinder header. |
| 285 | return OK; |
| 286 | } |
| 287 | |
| 288 | // cut off the leading 'I'. |
| 289 | const std::string baseName = ifaceName.substr(1); |
| 290 | |
| 291 | const std::string klassName = "IHw" + baseName; |
| 292 | |
| 293 | std::string path = outputPath; |
| 294 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 295 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 296 | path.append(klassName + ".h"); |
| 297 | |
| 298 | FILE* file = fopen(path.c_str(), "w"); |
| 299 | |
| 300 | if (file == NULL) { |
| 301 | return -errno; |
| 302 | } |
| 303 | |
| 304 | Formatter out(file); |
| 305 | |
| 306 | const std::string guard = makeHeaderGuard(klassName); |
| 307 | |
| 308 | out << "#ifndef " << guard << "\n"; |
| 309 | out << "#define " << guard << "\n\n"; |
| 310 | |
| 311 | std::vector<std::string> packageComponents; |
| 312 | getPackageAndVersionComponents( |
| 313 | &packageComponents, false /* cpp_compatible */); |
| 314 | |
| 315 | out << "#include <"; |
| 316 | for (const auto &component : packageComponents) { |
| 317 | out << component << "/"; |
| 318 | } |
| 319 | out << ifaceName << ".h>\n\n"; |
| 320 | |
| 321 | for (const auto &item : mImportedNames) { |
| 322 | if (item.name() == "types") { |
| 323 | continue; |
| 324 | } |
| 325 | |
| 326 | out << "#include <"; |
| 327 | |
| 328 | std::vector<std::string> components; |
| 329 | item.getPackageAndVersionComponents( |
| 330 | &components, false /* cpp_compatible */); |
| 331 | |
| 332 | for (const auto &component : components) { |
| 333 | out << component << "/"; |
| 334 | } |
| 335 | |
| 336 | // cut off the leading I |
| 337 | const std::string itemBaseName = item.name().substr(1); |
| 338 | |
| 339 | out << "Bn" |
| 340 | << itemBaseName |
| 341 | << ".h>\n"; |
| 342 | } |
| 343 | |
| 344 | out << "\n"; |
| 345 | |
| 346 | out << "#include <hidl/HidlSupport.h>\n"; |
Martijn Coenen | 9391510 | 2016-09-01 01:35:52 +0200 | [diff] [blame] | 347 | out << "#include <hidl/Status.h>\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 348 | out << "#include <hwbinder/IBinder.h>\n"; |
| 349 | out << "#include <hwbinder/IInterface.h>\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 350 | |
| 351 | out << "\n"; |
| 352 | |
| 353 | enterLeaveNamespace(out, true /* enter */); |
| 354 | out << "\n"; |
| 355 | |
| 356 | out << "struct " |
| 357 | << klassName |
| 358 | << " : public " |
| 359 | << ifaceName; |
| 360 | |
| 361 | const Interface *iface = mRootScope->getInterface(); |
| 362 | const Interface *superType = iface->superType(); |
| 363 | |
| 364 | out << ", public ::android::hardware::IInterface"; |
| 365 | |
| 366 | out << " {\n"; |
| 367 | |
| 368 | out.indent(); |
| 369 | |
| 370 | out << "DECLARE_HWBINDER_META_INTERFACE(" << baseName << ");\n\n"; |
| 371 | |
| 372 | out << "enum Call {\n"; |
| 373 | out.indent(); |
| 374 | |
| 375 | bool first = true; |
| 376 | for (const auto &method : iface->methods()) { |
| 377 | out << upcase(method->name()); |
| 378 | |
| 379 | if (first) { |
| 380 | out << " = "; |
| 381 | if (superType != NULL) { |
| 382 | out << superType->fqName().cppNamespace() |
| 383 | << "::IHw" |
| 384 | << superType->getBaseName() |
| 385 | << "::Call::CallCount"; |
| 386 | } else { |
| 387 | out << "::android::hardware::IBinder::FIRST_CALL_TRANSACTION"; |
| 388 | } |
| 389 | |
| 390 | first = false; |
| 391 | } |
| 392 | |
| 393 | out << ",\n"; |
| 394 | } |
| 395 | |
| 396 | out << "CallCount\n"; |
| 397 | |
| 398 | out.unindent(); |
| 399 | out << "};\n\n"; |
| 400 | |
| 401 | out.unindent(); |
| 402 | |
| 403 | out << "};\n\n"; |
| 404 | |
| 405 | enterLeaveNamespace(out, false /* enter */); |
| 406 | |
| 407 | out << "\n#endif // " << guard << "\n"; |
| 408 | |
| 409 | return OK; |
| 410 | } |
| 411 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 412 | status_t AST::emitTypeDeclarations(Formatter &out) const { |
| 413 | return mRootScope->emitTypeDeclarations(out); |
| 414 | } |
| 415 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 416 | status_t AST::generateStubMethod(Formatter &out, |
| 417 | const std::string &className, |
| 418 | const Method *method) const { |
| 419 | out << "inline "; |
| 420 | |
| 421 | method->generateCppSignature(out, className); |
| 422 | |
| 423 | const bool returnsValue = !method->results().empty(); |
| 424 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 425 | out << " {\n"; |
| 426 | out.indent(); |
| 427 | out << "return mImpl->" |
| 428 | << method->name() |
| 429 | << "("; |
| 430 | bool first = true; |
| 431 | for (const auto &arg : method->args()) { |
| 432 | if (!first) { |
| 433 | out << ", "; |
| 434 | } |
| 435 | first = false; |
| 436 | out << arg->name(); |
| 437 | } |
| 438 | if (returnsValue && elidedReturn == nullptr) { |
| 439 | if (!method->args().empty()) { |
| 440 | out << ", "; |
| 441 | } |
| 442 | |
| 443 | out << "_hidl_cb"; |
| 444 | } |
| 445 | out << ");\n"; |
| 446 | out.unindent(); |
| 447 | out << "}"; |
| 448 | |
| 449 | out << ";\n"; |
| 450 | |
| 451 | return OK; |
| 452 | } |
| 453 | |
| 454 | status_t AST::generateProxyMethod(Formatter &out, |
| 455 | const std::string &className, |
| 456 | const Method *method) const { |
| 457 | |
| 458 | method->generateCppSignature(out, className); |
| 459 | out << " override;\n"; |
| 460 | |
| 461 | return OK; |
| 462 | } |
| 463 | |
| 464 | status_t AST::generateMethods( |
| 465 | Formatter &out, |
| 466 | const std::string &className, |
| 467 | MethodLocation type) const { |
| 468 | |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 469 | const Interface *iface = mRootScope->getInterface(); |
| 470 | |
| 471 | std::vector<const Interface *> chain; |
| 472 | while (iface != NULL) { |
| 473 | chain.push_back(iface); |
| 474 | iface = iface->superType(); |
| 475 | } |
| 476 | |
| 477 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 478 | const Interface *superInterface = *it; |
| 479 | |
| 480 | out << "// Methods from " |
| 481 | << superInterface->fullName() |
| 482 | << " follow.\n"; |
| 483 | |
| 484 | for (const auto &method : superInterface->methods()) { |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 485 | status_t err; |
| 486 | switch(type) { |
| 487 | case STUB_HEADER: |
| 488 | err = generateStubMethod(out, |
| 489 | className, |
| 490 | method); |
| 491 | break; |
| 492 | case PROXY_HEADER: |
| 493 | err = generateProxyMethod(out, |
| 494 | className, |
| 495 | method); |
| 496 | break; |
| 497 | default: |
| 498 | err = UNKNOWN_ERROR; |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 501 | if (err != OK) { |
| 502 | return err; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 503 | } |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | out << "\n"; |
| 507 | } |
| 508 | |
| 509 | return OK; |
| 510 | } |
| 511 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 512 | status_t AST::generateStubHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 513 | std::string ifaceName; |
| 514 | if (!AST::isInterface(&ifaceName)) { |
| 515 | // types.hal does not get a stub header. |
| 516 | return OK; |
| 517 | } |
| 518 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 519 | // cut off the leading 'I'. |
| 520 | const std::string baseName = ifaceName.substr(1); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 521 | const std::string klassName = "Bn" + baseName; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 522 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 523 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 524 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 525 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 526 | path.append(klassName); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 527 | path.append(".h"); |
| 528 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 529 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 530 | FILE *file = fopen(path.c_str(), "w"); |
| 531 | |
| 532 | if (file == NULL) { |
| 533 | return -errno; |
| 534 | } |
| 535 | |
| 536 | Formatter out(file); |
| 537 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 538 | const std::string guard = makeHeaderGuard(klassName); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 539 | |
| 540 | out << "#ifndef " << guard << "\n"; |
| 541 | out << "#define " << guard << "\n\n"; |
| 542 | |
| 543 | std::vector<std::string> packageComponents; |
| 544 | getPackageAndVersionComponents( |
| 545 | &packageComponents, false /* cpp_compatible */); |
| 546 | |
| 547 | out << "#include <"; |
| 548 | for (const auto &component : packageComponents) { |
| 549 | out << component << "/"; |
| 550 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 551 | out << "IHw" << baseName << ".h>\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 552 | |
| 553 | enterLeaveNamespace(out, true /* enter */); |
| 554 | out << "\n"; |
| 555 | |
| 556 | out << "struct " |
| 557 | << "Bn" |
| 558 | << baseName |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 559 | << " : public ::android::hardware::BnInterface<I" |
| 560 | << baseName << ", IHw" << baseName |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 561 | << "> {\n"; |
| 562 | |
| 563 | out.indent(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 564 | out << "explicit Bn" |
| 565 | << baseName |
| 566 | << "(const ::android::sp<" << ifaceName << "> &_hidl_impl);" |
| 567 | << "\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 568 | out << "::android::status_t onTransact(\n"; |
| 569 | out.indent(); |
| 570 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 571 | out << "uint32_t _hidl_code,\n"; |
| 572 | out << "const ::android::hardware::Parcel &_hidl_data,\n"; |
| 573 | out << "::android::hardware::Parcel *_hidl_reply,\n"; |
| 574 | out << "uint32_t _hidl_flags = 0,\n"; |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 575 | out << "TransactCallback _hidl_cb = nullptr) override;\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 576 | out.unindent(); |
| 577 | out.unindent(); |
| 578 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 579 | generateMethods(out, |
| 580 | "" /* class name */, |
| 581 | MethodLocation::STUB_HEADER); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 582 | out.unindent(); |
| 583 | |
| 584 | out << "};\n\n"; |
| 585 | |
| 586 | enterLeaveNamespace(out, false /* enter */); |
| 587 | |
| 588 | out << "\n#endif // " << guard << "\n"; |
| 589 | |
| 590 | return OK; |
| 591 | } |
| 592 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 593 | status_t AST::generateProxyHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 594 | std::string ifaceName; |
| 595 | if (!AST::isInterface(&ifaceName)) { |
| 596 | // types.hal does not get a proxy header. |
| 597 | return OK; |
| 598 | } |
| 599 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 600 | // cut off the leading 'I'. |
| 601 | const std::string baseName = ifaceName.substr(1); |
| 602 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 603 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 604 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 605 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 606 | path.append("Bp"); |
| 607 | path.append(baseName); |
| 608 | path.append(".h"); |
| 609 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 610 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 611 | FILE *file = fopen(path.c_str(), "w"); |
| 612 | |
| 613 | if (file == NULL) { |
| 614 | return -errno; |
| 615 | } |
| 616 | |
| 617 | Formatter out(file); |
| 618 | |
| 619 | const std::string guard = makeHeaderGuard("Bp" + baseName); |
| 620 | |
| 621 | out << "#ifndef " << guard << "\n"; |
| 622 | out << "#define " << guard << "\n\n"; |
| 623 | |
| 624 | std::vector<std::string> packageComponents; |
| 625 | getPackageAndVersionComponents( |
| 626 | &packageComponents, false /* cpp_compatible */); |
| 627 | |
| 628 | out << "#include <"; |
| 629 | for (const auto &component : packageComponents) { |
| 630 | out << component << "/"; |
| 631 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 632 | out << "IHw" << baseName << ".h>\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 633 | |
| 634 | enterLeaveNamespace(out, true /* enter */); |
| 635 | out << "\n"; |
| 636 | |
| 637 | out << "struct " |
| 638 | << "Bp" |
| 639 | << baseName |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 640 | << " : public ::android::hardware::BpInterface<IHw" |
| 641 | << baseName |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 642 | << "> {\n"; |
| 643 | |
| 644 | out.indent(); |
| 645 | |
| 646 | out << "explicit Bp" |
| 647 | << baseName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 648 | << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl);" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 649 | << "\n\n"; |
| 650 | |
Iliyan Malchev | 795dd43 | 2016-09-02 11:48:26 -0700 | [diff] [blame] | 651 | out << "virtual bool isRemote() const { return true; }\n\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 652 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 653 | generateMethods(out, |
| 654 | "" /* class name */, |
| 655 | MethodLocation::PROXY_HEADER); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 656 | |
| 657 | out.unindent(); |
| 658 | |
| 659 | out << "};\n\n"; |
| 660 | |
| 661 | enterLeaveNamespace(out, false /* enter */); |
| 662 | |
| 663 | out << "\n#endif // " << guard << "\n"; |
| 664 | |
| 665 | return OK; |
| 666 | } |
| 667 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 668 | status_t AST::generateAllSource(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 669 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 670 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 671 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 672 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 673 | |
| 674 | std::string ifaceName; |
| 675 | std::string baseName; |
| 676 | |
| 677 | bool isInterface = true; |
| 678 | if (!AST::isInterface(&ifaceName)) { |
| 679 | baseName = "types"; |
| 680 | isInterface = false; |
| 681 | } else { |
| 682 | baseName = ifaceName.substr(1); // cut off the leading 'I'. |
| 683 | } |
| 684 | |
| 685 | path.append(baseName); |
| 686 | |
| 687 | if (baseName != "types") { |
| 688 | path.append("All"); |
| 689 | } |
| 690 | |
| 691 | path.append(".cpp"); |
| 692 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 693 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 694 | FILE *file = fopen(path.c_str(), "w"); |
| 695 | |
| 696 | if (file == NULL) { |
| 697 | return -errno; |
| 698 | } |
| 699 | |
| 700 | Formatter out(file); |
| 701 | |
| 702 | std::vector<std::string> packageComponents; |
| 703 | getPackageAndVersionComponents( |
| 704 | &packageComponents, false /* cpp_compatible */); |
| 705 | |
| 706 | std::string prefix; |
| 707 | for (const auto &component : packageComponents) { |
| 708 | prefix += component; |
| 709 | prefix += "/"; |
| 710 | } |
| 711 | |
| 712 | if (isInterface) { |
| 713 | out << "#include <" << prefix << "/Bp" << baseName << ".h>\n"; |
| 714 | out << "#include <" << prefix << "/Bn" << baseName << ".h>\n"; |
| 715 | } else { |
| 716 | out << "#include <" << prefix << "types.h>\n"; |
| 717 | } |
| 718 | |
| 719 | out << "\n"; |
| 720 | |
| 721 | enterLeaveNamespace(out, true /* enter */); |
| 722 | out << "\n"; |
| 723 | |
| 724 | status_t err = generateTypeSource(out, ifaceName); |
| 725 | |
| 726 | if (err == OK && isInterface) { |
| 727 | err = generateProxySource(out, baseName); |
| 728 | } |
| 729 | |
| 730 | if (err == OK && isInterface) { |
| 731 | err = generateStubSource(out, baseName); |
| 732 | } |
| 733 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 734 | if (err == OK && isInterface) { |
| 735 | out << "IMPLEMENT_REGISTER_AND_GET_SERVICE(" << baseName << ")\n"; |
| 736 | } |
| 737 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 738 | enterLeaveNamespace(out, false /* enter */); |
| 739 | |
| 740 | return err; |
| 741 | } |
| 742 | |
| 743 | status_t AST::generateTypeSource( |
| 744 | Formatter &out, const std::string &ifaceName) const { |
| 745 | return mRootScope->emitTypeDefinitions(out, ifaceName); |
| 746 | } |
| 747 | |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 748 | void AST::declareCppReaderLocals( |
| 749 | Formatter &out, const std::vector<TypedVar *> &args) const { |
| 750 | if (args.empty()) { |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | for (const auto &arg : args) { |
| 755 | const Type &type = arg->type(); |
| 756 | |
| 757 | std::string extra; |
| 758 | out << type.getCppResultType(&extra) |
| 759 | << " " |
| 760 | << arg->name() |
| 761 | << extra |
| 762 | << ";\n"; |
| 763 | } |
| 764 | |
| 765 | out << "\n"; |
| 766 | } |
| 767 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 768 | void AST::emitCppReaderWriter( |
| 769 | Formatter &out, |
| 770 | const std::string &parcelObj, |
| 771 | bool parcelObjIsPointer, |
| 772 | const TypedVar *arg, |
| 773 | bool isReader, |
| 774 | Type::ErrorMode mode) const { |
| 775 | const Type &type = arg->type(); |
| 776 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 777 | type.emitReaderWriter( |
| 778 | out, |
| 779 | arg->name(), |
| 780 | parcelObj, |
| 781 | parcelObjIsPointer, |
| 782 | isReader, |
| 783 | mode); |
| 784 | } |
| 785 | |
| 786 | status_t AST::generateProxySource( |
| 787 | Formatter &out, const std::string &baseName) const { |
| 788 | const std::string klassName = "Bp" + baseName; |
| 789 | |
| 790 | out << klassName |
| 791 | << "::" |
| 792 | << klassName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 793 | << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 794 | |
| 795 | out.indent(); |
| 796 | out.indent(); |
| 797 | |
| 798 | out << ": BpInterface" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 799 | << "<IHw" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 800 | << baseName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 801 | << ">(_hidl_impl) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 802 | |
| 803 | out.unindent(); |
| 804 | out.unindent(); |
| 805 | out << "}\n\n"; |
| 806 | |
| 807 | const Interface *iface = mRootScope->getInterface(); |
| 808 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 809 | std::vector<const Interface *> chain; |
| 810 | while (iface != NULL) { |
| 811 | chain.push_back(iface); |
| 812 | iface = iface->superType(); |
| 813 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 814 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 815 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 816 | const Interface *superInterface = *it; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 817 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 818 | for (const auto &method : superInterface->methods()) { |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 819 | method->generateCppSignature(out, klassName); |
| 820 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 821 | const bool returnsValue = !method->results().empty(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 822 | const TypedVar *elidedReturn = method->canElideCallback(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 823 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 824 | out << "{\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 825 | |
| 826 | out.indent(); |
| 827 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 828 | out << "::android::hardware::Parcel _hidl_data;\n"; |
| 829 | out << "::android::hardware::Parcel _hidl_reply;\n"; |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 830 | out << "::android::status_t _hidl_err;\n"; |
| 831 | out << "::android::hardware::Status _hidl_status;\n\n"; |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 832 | declareCppReaderLocals(out, method->results()); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 833 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 834 | out << "_hidl_err = _hidl_data.writeInterfaceToken(" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 835 | << superInterface->fqName().cppNamespace() |
| 836 | << "::IHw" |
| 837 | << superInterface->getBaseName() |
| 838 | << "::descriptor);\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 839 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 840 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 841 | |
| 842 | for (const auto &arg : method->args()) { |
| 843 | emitCppReaderWriter( |
| 844 | out, |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 845 | "_hidl_data", |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 846 | false /* parcelObjIsPointer */, |
| 847 | arg, |
| 848 | false /* reader */, |
| 849 | Type::ErrorMode_Goto); |
| 850 | } |
| 851 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 852 | out << "_hidl_err = remote()->transact(" |
| 853 | << superInterface->fqName().cppNamespace() |
| 854 | << "::IHw" |
| 855 | << superInterface->getBaseName() |
| 856 | << "::Call::" |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 857 | << upcase(method->name()) |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 858 | << ", _hidl_data, &_hidl_reply"; |
| 859 | if (method->isOneway()) { |
| 860 | out << ", ::android::hardware::IBinder::FLAG_ONEWAY"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 861 | } |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 862 | out << ");\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 863 | |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 864 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 865 | |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 866 | if (!method->isOneway()) { |
| 867 | out << "_hidl_err = _hidl_status.readFromParcel(_hidl_reply);\n"; |
| 868 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 869 | out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n"; |
| 870 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 871 | for (const auto &arg : method->results()) { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 872 | emitCppReaderWriter( |
| 873 | out, |
| 874 | "_hidl_reply", |
| 875 | false /* parcelObjIsPointer */, |
| 876 | arg, |
| 877 | true /* reader */, |
| 878 | Type::ErrorMode_Goto); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 881 | if (returnsValue && elidedReturn == nullptr) { |
Iliyan Malchev | 639bff8 | 2016-08-13 14:24:11 -0700 | [diff] [blame] | 882 | out << "if (_hidl_cb != nullptr) {\n"; |
| 883 | out.indent(); |
| 884 | out << "_hidl_cb("; |
| 885 | |
| 886 | bool first = true; |
| 887 | for (const auto &arg : method->results()) { |
| 888 | if (!first) { |
| 889 | out << ", "; |
| 890 | } |
| 891 | |
| 892 | if (arg->type().resultNeedsDeref()) { |
| 893 | out << "*"; |
| 894 | } |
| 895 | out << arg->name(); |
| 896 | |
| 897 | first = false; |
| 898 | } |
| 899 | |
| 900 | out << ");\n"; |
| 901 | out.unindent(); |
| 902 | out << "}\n\n"; |
| 903 | } |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 906 | if (elidedReturn != nullptr) { |
| 907 | std::string extra; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 908 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
Iliyan Malchev | 2b6591b | 2016-08-18 19:15:19 -0700 | [diff] [blame] | 909 | out << "return ::android::hardware::Return<"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 910 | out << elidedReturn->type().getCppResultType(&extra) |
| 911 | << ">(" << elidedReturn->name() << ");\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 912 | } else { |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 913 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame^] | 914 | out << "return ::android::hardware::Return<void>();\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 915 | } |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 916 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 917 | out.unindent(); |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame^] | 918 | out << "_hidl_error:\n"; |
| 919 | out.indent(); |
| 920 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 921 | out << "return ::android::hardware::Return<"; |
| 922 | if (elidedReturn != nullptr) { |
| 923 | std::string extra; |
| 924 | out << method->results().at(0)->type().getCppResultType(&extra); |
| 925 | } else { |
| 926 | out << "void"; |
| 927 | } |
| 928 | out << ">(_hidl_status);\n"; |
| 929 | |
| 930 | out.unindent(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 931 | out << "}\n\n"; |
| 932 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | return OK; |
| 936 | } |
| 937 | |
| 938 | status_t AST::generateStubSource( |
| 939 | Formatter &out, const std::string &baseName) const { |
| 940 | out << "IMPLEMENT_HWBINDER_META_INTERFACE(" |
| 941 | << baseName |
| 942 | << ", \"" |
| 943 | << mPackage.string() |
| 944 | << "::I" |
| 945 | << baseName |
| 946 | << "\");\n\n"; |
| 947 | |
| 948 | const std::string klassName = "Bn" + baseName; |
| 949 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 950 | out << klassName |
| 951 | << "::" |
| 952 | << klassName |
| 953 | << "(const ::android::sp<I" << baseName <<"> &_hidl_impl)\n"; |
| 954 | |
| 955 | out.indent(); |
| 956 | out.indent(); |
| 957 | |
| 958 | out << ": BnInterface" |
| 959 | << "<I" |
| 960 | << baseName |
| 961 | << ", IHw" |
| 962 | << baseName |
| 963 | << ">(_hidl_impl) {\n"; |
| 964 | |
| 965 | out.unindent(); |
| 966 | out.unindent(); |
| 967 | out << "}\n\n"; |
| 968 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 969 | out << "::android::status_t " << klassName << "::onTransact(\n"; |
| 970 | |
| 971 | out.indent(); |
| 972 | out.indent(); |
| 973 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 974 | out << "uint32_t _hidl_code,\n" |
| 975 | << "const ::android::hardware::Parcel &_hidl_data,\n" |
| 976 | << "::android::hardware::Parcel *_hidl_reply,\n" |
| 977 | << "uint32_t _hidl_flags,\n" |
| 978 | << "TransactCallback _hidl_cb) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 979 | |
| 980 | out.unindent(); |
| 981 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 982 | out << "::android::status_t _hidl_err = ::android::OK;\n\n"; |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 983 | out << "switch (_hidl_code) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 984 | out.indent(); |
| 985 | |
| 986 | const Interface *iface = mRootScope->getInterface(); |
| 987 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 988 | std::vector<const Interface *> chain; |
| 989 | while (iface != NULL) { |
| 990 | chain.push_back(iface); |
| 991 | iface = iface->superType(); |
| 992 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 993 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 994 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 995 | const Interface *superInterface = *it; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 996 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 997 | for (const auto &method : superInterface->methods()) { |
| 998 | out << "case " |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 999 | << superInterface->fqName().cppNamespace() |
| 1000 | << "::IHw" |
| 1001 | << superInterface->getBaseName() |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1002 | << "::Call::" |
| 1003 | << upcase(method->name()) |
| 1004 | << ":\n{\n"; |
| 1005 | |
| 1006 | out.indent(); |
| 1007 | |
| 1008 | status_t err = |
| 1009 | generateStubSourceForMethod(out, superInterface, method); |
| 1010 | |
| 1011 | if (err != OK) { |
| 1012 | return err; |
| 1013 | } |
| 1014 | |
| 1015 | out.unindent(); |
| 1016 | out << "}\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1017 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | out << "default:\n{\n"; |
| 1021 | out.indent(); |
| 1022 | |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 1023 | out << "return ::android::hardware::BnInterface<I" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1024 | << baseName << ", IHw" << baseName |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1025 | << ">::onTransact(\n"; |
| 1026 | |
| 1027 | out.indent(); |
| 1028 | out.indent(); |
| 1029 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1030 | out << "_hidl_code, _hidl_data, _hidl_reply, " |
| 1031 | << "_hidl_flags, _hidl_cb);\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1032 | |
| 1033 | out.unindent(); |
| 1034 | out.unindent(); |
| 1035 | |
| 1036 | out.unindent(); |
| 1037 | out << "}\n"; |
| 1038 | |
| 1039 | out.unindent(); |
| 1040 | out << "}\n\n"; |
| 1041 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1042 | out << "if (_hidl_err == ::android::UNEXPECTED_NULL) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1043 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1044 | out << "_hidl_err = ::android::hardware::Status::fromExceptionCode(\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1045 | out.indent(); |
| 1046 | out.indent(); |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 1047 | out << "::android::hardware::Status::EX_NULL_POINTER)\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1048 | out.indent(); |
| 1049 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1050 | out << ".writeToParcel(_hidl_reply);\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1051 | out.unindent(); |
| 1052 | out.unindent(); |
| 1053 | out.unindent(); |
| 1054 | out.unindent(); |
| 1055 | |
| 1056 | out.unindent(); |
| 1057 | out << "}\n\n"; |
| 1058 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1059 | out << "return _hidl_err;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1060 | |
| 1061 | out.unindent(); |
| 1062 | out << "}\n\n"; |
| 1063 | |
| 1064 | return OK; |
| 1065 | } |
| 1066 | |
| 1067 | status_t AST::generateStubSourceForMethod( |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1068 | Formatter &out, const Interface *iface, const Method *method) const { |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1069 | out << "if (!_hidl_data.enforceInterface(" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1070 | << iface->fqName().cppNamespace() |
| 1071 | << "::IHw" |
| 1072 | << iface->getBaseName() |
| 1073 | << "::descriptor)) {\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1074 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1075 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1076 | out << "_hidl_err = ::android::BAD_TYPE;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1077 | out << "break;\n"; |
| 1078 | out.unindent(); |
| 1079 | out << "}\n\n"; |
| 1080 | |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1081 | declareCppReaderLocals(out, method->args()); |
| 1082 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1083 | for (const auto &arg : method->args()) { |
| 1084 | emitCppReaderWriter( |
| 1085 | out, |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1086 | "_hidl_data", |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1087 | false /* parcelObjIsPointer */, |
| 1088 | arg, |
| 1089 | true /* reader */, |
| 1090 | Type::ErrorMode_Break); |
| 1091 | } |
| 1092 | |
| 1093 | const bool returnsValue = !method->results().empty(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1094 | const TypedVar *elidedReturn = method->canElideCallback(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1095 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1096 | if (elidedReturn != nullptr) { |
| 1097 | std::string extra; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1098 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1099 | out << elidedReturn->type().getCppResultType(&extra) << " "; |
| 1100 | out << elidedReturn->name() << " = "; |
| 1101 | out << method->name() << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1102 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1103 | bool first = true; |
| 1104 | for (const auto &arg : method->args()) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1105 | if (!first) { |
| 1106 | out << ", "; |
| 1107 | } |
| 1108 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1109 | if (arg->type().resultNeedsDeref()) { |
| 1110 | out << "*"; |
| 1111 | } |
| 1112 | |
| 1113 | out << arg->name(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1114 | |
| 1115 | first = false; |
| 1116 | } |
| 1117 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1118 | out << ");\n\n"; |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 1119 | out << "::android::hardware::Status::ok()" |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1120 | << ".writeToParcel(_hidl_reply);\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1121 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1122 | elidedReturn->type().emitReaderWriter( |
| 1123 | out, |
| 1124 | elidedReturn->name(), |
| 1125 | "_hidl_reply", |
| 1126 | true, /* parcelObjIsPointer */ |
| 1127 | false, /* isReader */ |
| 1128 | Type::ErrorMode_Ignore); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1129 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1130 | out << "_hidl_cb(*_hidl_reply);\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1131 | } else { |
| 1132 | if (returnsValue) { |
| 1133 | out << "bool _hidl_callbackCalled = false;\n\n"; |
| 1134 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1135 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1136 | out << method->name() << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1137 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1138 | bool first = true; |
| 1139 | for (const auto &arg : method->args()) { |
| 1140 | if (!first) { |
| 1141 | out << ", "; |
| 1142 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1143 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1144 | if (arg->type().resultNeedsDeref()) { |
| 1145 | out << "*"; |
| 1146 | } |
| 1147 | |
| 1148 | out << arg->name(); |
| 1149 | |
| 1150 | first = false; |
| 1151 | } |
| 1152 | |
| 1153 | if (returnsValue) { |
| 1154 | if (!first) { |
| 1155 | out << ", "; |
| 1156 | } |
| 1157 | |
| 1158 | out << "[&]("; |
| 1159 | |
| 1160 | first = true; |
| 1161 | for (const auto &arg : method->results()) { |
| 1162 | if (!first) { |
| 1163 | out << ", "; |
| 1164 | } |
| 1165 | |
| 1166 | out << "const auto &" << arg->name(); |
| 1167 | |
| 1168 | first = false; |
| 1169 | } |
| 1170 | |
| 1171 | out << ") {\n"; |
| 1172 | out.indent(); |
| 1173 | out << "_hidl_callbackCalled = true;\n\n"; |
| 1174 | |
| 1175 | out << "::android::hardware::Status::ok()" |
| 1176 | << ".writeToParcel(_hidl_reply);\n\n"; |
| 1177 | |
| 1178 | for (const auto &arg : method->results()) { |
| 1179 | emitCppReaderWriter( |
| 1180 | out, |
| 1181 | "_hidl_reply", |
| 1182 | true /* parcelObjIsPointer */, |
| 1183 | arg, |
| 1184 | false /* reader */, |
| 1185 | Type::ErrorMode_Ignore); |
| 1186 | } |
| 1187 | |
| 1188 | out << "_hidl_cb(*_hidl_reply);\n"; |
| 1189 | |
| 1190 | out.unindent(); |
| 1191 | out << "}\n"; |
| 1192 | } |
| 1193 | |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame^] | 1194 | out << ");\n\n"; |
| 1195 | |
| 1196 | // What to do if the stub implementation has a synchronous callback |
| 1197 | // which does not get invoked? This is not a transport error but a |
| 1198 | // service error of sorts. For now, return OK to the caller, as this is |
| 1199 | // not a transport error. |
| 1200 | // |
| 1201 | // TODO(b/31365311) Figure out how to deal with this later. |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1202 | |
| 1203 | if (returnsValue) { |
| 1204 | out << "if (!_hidl_callbackCalled) {\n"; |
| 1205 | out.indent(); |
| 1206 | } |
| 1207 | |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame^] | 1208 | out << "::android::hardware::Status::ok()" |
| 1209 | << ".writeToParcel(_hidl_reply);\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1210 | |
| 1211 | if (returnsValue) { |
| 1212 | out.unindent(); |
| 1213 | out << "}\n\n"; |
| 1214 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | out << "break;\n"; |
| 1218 | |
| 1219 | return OK; |
| 1220 | } |
| 1221 | |
| 1222 | } // namespace android |
| 1223 | |