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 "Interface.h" |
| 22 | #include "Method.h" |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 23 | #include "ScalarType.h" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 24 | #include "Scope.h" |
| 25 | |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 26 | #include <algorithm> |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 27 | #include <hidl-util/Formatter.h> |
Steven Moreland | 5708edf | 2016-11-04 15:33:31 +0000 | [diff] [blame] | 28 | #include <hidl-util/StringHelper.h> |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 29 | #include <android-base/logging.h> |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 30 | #include <string> |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 31 | #include <vector> |
| 32 | |
| 33 | namespace android { |
| 34 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 35 | status_t AST::generateCpp(const std::string &outputPath) const { |
| 36 | status_t err = generateInterfaceHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 37 | |
| 38 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 39 | err = generateStubHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | if (err == OK) { |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 43 | err = generateHwBinderHeader(outputPath); |
| 44 | } |
| 45 | |
| 46 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 47 | err = generateProxyHeader(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | if (err == OK) { |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 51 | err = generateAllSource(outputPath); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 54 | if (err == OK) { |
| 55 | generatePassthroughHeader(outputPath); |
| 56 | } |
| 57 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 58 | return err; |
| 59 | } |
| 60 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 61 | void AST::getPackageComponents( |
| 62 | std::vector<std::string> *components) const { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 63 | mPackage.getPackageComponents(components); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void AST::getPackageAndVersionComponents( |
| 67 | std::vector<std::string> *components, bool cpp_compatible) const { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 68 | mPackage.getPackageAndVersionComponents(components, cpp_compatible); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Steven Moreland | 5708edf | 2016-11-04 15:33:31 +0000 | [diff] [blame] | 71 | std::string AST::makeHeaderGuard(const std::string &baseName, |
| 72 | bool indicateGenerated) const { |
| 73 | std::string guard; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 74 | |
Steven Moreland | 5708edf | 2016-11-04 15:33:31 +0000 | [diff] [blame] | 75 | if (indicateGenerated) { |
| 76 | guard += "HIDL_GENERATED_"; |
| 77 | } |
| 78 | |
| 79 | guard += StringHelper::Uppercase(mPackage.tokenName()); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 80 | guard += "_"; |
Steven Moreland | 5708edf | 2016-11-04 15:33:31 +0000 | [diff] [blame] | 81 | guard += StringHelper::Uppercase(baseName); |
| 82 | guard += "_H"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 83 | |
| 84 | return guard; |
| 85 | } |
| 86 | |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 87 | // static |
| 88 | void AST::generateCppPackageInclude( |
| 89 | Formatter &out, |
| 90 | const FQName &package, |
| 91 | const std::string &klass) { |
| 92 | |
| 93 | out << "#include <"; |
| 94 | |
| 95 | std::vector<std::string> components; |
| 96 | package.getPackageAndVersionComponents(&components, false /* cpp_compatible */); |
| 97 | |
| 98 | for (const auto &component : components) { |
| 99 | out << component << "/"; |
| 100 | } |
| 101 | |
| 102 | out << klass |
| 103 | << ".h>\n"; |
| 104 | } |
| 105 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 106 | void AST::enterLeaveNamespace(Formatter &out, bool enter) const { |
| 107 | std::vector<std::string> packageComponents; |
| 108 | getPackageAndVersionComponents( |
| 109 | &packageComponents, true /* cpp_compatible */); |
| 110 | |
| 111 | if (enter) { |
| 112 | for (const auto &component : packageComponents) { |
| 113 | out << "namespace " << component << " {\n"; |
| 114 | } |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 115 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 116 | out.setNamespace(mPackage.cppNamespace() + "::"); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 117 | } else { |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 118 | out.setNamespace(std::string()); |
| 119 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 120 | for (auto it = packageComponents.rbegin(); |
| 121 | it != packageComponents.rend(); |
| 122 | ++it) { |
| 123 | out << "} // namespace " << *it << "\n"; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 128 | status_t AST::generateInterfaceHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 129 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 130 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 131 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 132 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 133 | |
| 134 | std::string ifaceName; |
| 135 | bool isInterface = true; |
| 136 | if (!AST::isInterface(&ifaceName)) { |
| 137 | ifaceName = "types"; |
| 138 | isInterface = false; |
| 139 | } |
| 140 | path.append(ifaceName); |
| 141 | path.append(".h"); |
| 142 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 143 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 144 | FILE *file = fopen(path.c_str(), "w"); |
| 145 | |
| 146 | if (file == NULL) { |
| 147 | return -errno; |
| 148 | } |
| 149 | |
| 150 | Formatter out(file); |
| 151 | |
| 152 | const std::string guard = makeHeaderGuard(ifaceName); |
| 153 | |
| 154 | out << "#ifndef " << guard << "\n"; |
| 155 | out << "#define " << guard << "\n\n"; |
| 156 | |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 157 | for (const auto &item : mImportedNames) { |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 158 | generateCppPackageInclude(out, item, item.name()); |
Andreas Huber | 737080b | 2016-08-02 15:38:04 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | if (!mImportedNames.empty()) { |
| 162 | out << "\n"; |
| 163 | } |
| 164 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 165 | if (isInterface) { |
| 166 | out << "#include <android/hidl/manager/1.0/IServiceNotification.h>\n\n"; |
| 167 | } |
| 168 | |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 169 | // TODO b/32756130 change back to HidlSupport.h |
| 170 | out << "#include <hidl/HidlTransportSupport.h>\n"; |
Andreas Huber | 4bcf97d | 2016-08-30 11:27:49 -0700 | [diff] [blame] | 171 | out << "#include <hidl/MQDescriptor.h>\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 172 | |
| 173 | if (isInterface) { |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 174 | out << "#include <hidl/ServiceManagement.h>\n"; |
Martijn Coenen | 9391510 | 2016-09-01 01:35:52 +0200 | [diff] [blame] | 175 | out << "#include <hidl/Status.h>\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | out << "#include <utils/NativeHandle.h>\n\n"; |
| 179 | |
| 180 | enterLeaveNamespace(out, true /* enter */); |
| 181 | out << "\n"; |
| 182 | |
| 183 | if (isInterface) { |
| 184 | out << "struct " |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 185 | << ifaceName; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 186 | |
| 187 | const Interface *iface = mRootScope->getInterface(); |
| 188 | const Interface *superType = iface->superType(); |
| 189 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 190 | if (superType == NULL) { |
Yifan Hong | 5bd9aff | 2016-11-08 18:52:55 -0800 | [diff] [blame] | 191 | out << " : virtual public ::android::hardware::IBase"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 192 | } else { |
Steven Moreland | d916a70 | 2016-10-26 22:23:09 +0000 | [diff] [blame] | 193 | out << " : public " |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 194 | << superType->fullName(); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | out << " {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 198 | |
| 199 | out.indent(); |
| 200 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | status_t err = emitTypeDeclarations(out); |
| 204 | |
| 205 | if (err != OK) { |
| 206 | return err; |
| 207 | } |
| 208 | |
| 209 | if (isInterface) { |
| 210 | const Interface *iface = mRootScope->getInterface(); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 211 | const Interface *superType = iface->superType(); |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 212 | const std::string baseName = iface->getBaseName(); |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 213 | out << "constexpr static ::android::hardware::hidl_version version = {" |
Martijn Coenen | a21f149 | 2016-09-08 15:55:14 +0200 | [diff] [blame] | 214 | << mPackage.getPackageMajorVersion() << "," |
| 215 | << mPackage.getPackageMinorVersion() << "};\n"; |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 216 | out << "virtual const ::android::hardware::hidl_version&" |
| 217 | << "getInterfaceVersion() const {\n"; |
Martijn Coenen | a21f149 | 2016-09-08 15:55:14 +0200 | [diff] [blame] | 218 | out.indent(); |
| 219 | out << "return version;\n"; |
| 220 | out.unindent(); |
| 221 | out << "}\n\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 222 | out << "virtual bool isRemote() const override { return false; }\n\n"; |
Steven Moreland | d732ea1 | 2016-11-08 17:12:06 -0800 | [diff] [blame] | 223 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 224 | for (const auto &method : iface->methods()) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 225 | out << "\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 226 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 227 | const bool returnsValue = !method->results().empty(); |
Steven Moreland | d732ea1 | 2016-11-08 17:12:06 -0800 | [diff] [blame] | 228 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 229 | |
| 230 | if (elidedReturn == nullptr && returnsValue) { |
| 231 | out << "using " |
| 232 | << method->name() |
| 233 | << "_cb = std::function<void(" |
| 234 | << Method::GetArgSignature(method->results(), |
| 235 | true /* specify namespaces */) |
| 236 | << ")>;\n"; |
| 237 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 238 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 239 | method->dumpAnnotations(out); |
| 240 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 241 | if (elidedReturn) { |
Iliyan Malchev | 2b6591b | 2016-08-18 19:15:19 -0700 | [diff] [blame] | 242 | out << "virtual ::android::hardware::Return<"; |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 243 | out << elidedReturn->type().getCppResultType() << "> "; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 244 | } else { |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame] | 245 | out << "virtual ::android::hardware::Return<void> "; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | out << method->name() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 249 | << "(" |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 250 | << Method::GetArgSignature(method->args(), |
| 251 | true /* specify namespaces */); |
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 | |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 258 | out << method->name() << "_cb _hidl_cb"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 261 | out << ")"; |
| 262 | if (method->isHidlReserved()) { |
| 263 | out << " override"; |
| 264 | out << " {\n"; |
| 265 | out.indent(); |
| 266 | method->cppImpl(out); |
| 267 | out.unindent(); |
| 268 | out << "\n}\n"; |
| 269 | } else { |
| 270 | out << " = 0;\n"; |
| 271 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 272 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 273 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 274 | if (!iface->isRootType()) { |
| 275 | out << "// cast static functions\n"; |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 276 | std::string childTypeResult = iface->getCppResultType(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 277 | |
| 278 | for (const Interface *superType : iface->superTypeChain()) { |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 279 | out << "static " |
| 280 | << childTypeResult |
| 281 | << " castFrom(" |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 282 | << superType->getCppArgumentType() |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 283 | << " parent" |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 284 | << ");\n"; |
| 285 | } |
| 286 | } |
| 287 | |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 288 | out << "\nstatic const char* descriptor;\n\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 289 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 290 | out << "DECLARE_SERVICE_MANAGER_INTERACTIONS(" << baseName << ")\n\n"; |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 291 | |
| 292 | out << "private: static int hidlStaticBlock;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | if (isInterface) { |
| 296 | out.unindent(); |
| 297 | |
Andreas Huber | e3f769a | 2016-10-10 10:54:44 -0700 | [diff] [blame] | 298 | out << "};\n\n"; |
| 299 | } |
| 300 | |
| 301 | err = mRootScope->emitGlobalTypeDeclarations(out); |
| 302 | |
| 303 | if (err != OK) { |
| 304 | return err; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | out << "\n"; |
| 308 | enterLeaveNamespace(out, false /* enter */); |
| 309 | |
| 310 | out << "\n#endif // " << guard << "\n"; |
| 311 | |
| 312 | return OK; |
| 313 | } |
| 314 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 315 | status_t AST::generateHwBinderHeader(const std::string &outputPath) const { |
| 316 | std::string ifaceName; |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 317 | bool isInterface = AST::isInterface(&ifaceName); |
| 318 | const Interface *iface = nullptr; |
| 319 | std::string baseName{}; |
| 320 | std::string klassName{}; |
| 321 | |
| 322 | if(isInterface) { |
| 323 | iface = mRootScope->getInterface(); |
| 324 | baseName = iface->getBaseName(); |
| 325 | klassName = "IHw" + baseName; |
| 326 | } else { |
| 327 | klassName = "hwtypes"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 330 | std::string path = outputPath; |
| 331 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 332 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 333 | path.append(klassName + ".h"); |
| 334 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 335 | FILE *file = fopen(path.c_str(), "w"); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 336 | |
| 337 | if (file == NULL) { |
| 338 | return -errno; |
| 339 | } |
| 340 | |
| 341 | Formatter out(file); |
| 342 | |
| 343 | const std::string guard = makeHeaderGuard(klassName); |
| 344 | |
| 345 | out << "#ifndef " << guard << "\n"; |
| 346 | out << "#define " << guard << "\n\n"; |
| 347 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 348 | if (isInterface) { |
| 349 | generateCppPackageInclude(out, mPackage, ifaceName); |
| 350 | } else { |
| 351 | generateCppPackageInclude(out, mPackage, "types"); |
| 352 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 353 | |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 354 | out << "\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 355 | |
| 356 | for (const auto &item : mImportedNames) { |
| 357 | if (item.name() == "types") { |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 358 | generateCppPackageInclude(out, item, "hwtypes"); |
| 359 | } else { |
| 360 | generateCppPackageInclude(out, item, "Bn" + item.getInterfaceBaseName()); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 361 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | out << "\n"; |
| 365 | |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 366 | out << "#include <hidl/HidlTransportSupport.h>\n"; |
Martijn Coenen | 9391510 | 2016-09-01 01:35:52 +0200 | [diff] [blame] | 367 | out << "#include <hidl/Status.h>\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 368 | out << "#include <hwbinder/IBinder.h>\n"; |
| 369 | out << "#include <hwbinder/IInterface.h>\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 370 | |
| 371 | out << "\n"; |
| 372 | |
| 373 | enterLeaveNamespace(out, true /* enter */); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 374 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 375 | if (isInterface) { |
| 376 | out << "\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 377 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 378 | out << "struct " |
| 379 | << klassName |
| 380 | << " : public " |
| 381 | << ifaceName; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 382 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 383 | const Interface *superType = iface->superType(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 384 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 385 | out << ", public ::android::hardware::IInterface"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 386 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 387 | out << " {\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 388 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 389 | out.indent(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 390 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 391 | out << "DECLARE_HWBINDER_META_INTERFACE(" << baseName << ");\n\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 392 | |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 393 | out.unindent(); |
| 394 | |
| 395 | out << "};\n\n"; |
| 396 | } |
| 397 | |
| 398 | status_t err = mRootScope->emitGlobalHwDeclarations(out); |
| 399 | if (err != OK) { |
| 400 | return err; |
| 401 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 402 | |
| 403 | enterLeaveNamespace(out, false /* enter */); |
| 404 | |
| 405 | out << "\n#endif // " << guard << "\n"; |
| 406 | |
| 407 | return OK; |
| 408 | } |
| 409 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 410 | status_t AST::emitTypeDeclarations(Formatter &out) const { |
| 411 | return mRootScope->emitTypeDeclarations(out); |
| 412 | } |
| 413 | |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 414 | status_t AST::generateStubMethod(Formatter &out, |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 415 | const Method *method) const { |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 416 | out << "inline "; |
| 417 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 418 | method->generateCppSignature(out); |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 419 | |
| 420 | const bool returnsValue = !method->results().empty(); |
| 421 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 422 | out << " {\n"; |
| 423 | out.indent(); |
| 424 | out << "return mImpl->" |
| 425 | << method->name() |
| 426 | << "("; |
| 427 | bool first = true; |
| 428 | for (const auto &arg : method->args()) { |
| 429 | if (!first) { |
| 430 | out << ", "; |
| 431 | } |
| 432 | first = false; |
| 433 | out << arg->name(); |
| 434 | } |
| 435 | if (returnsValue && elidedReturn == nullptr) { |
| 436 | if (!method->args().empty()) { |
| 437 | out << ", "; |
| 438 | } |
| 439 | |
| 440 | out << "_hidl_cb"; |
| 441 | } |
| 442 | out << ");\n"; |
| 443 | out.unindent(); |
| 444 | out << "}"; |
| 445 | |
| 446 | out << ";\n"; |
| 447 | |
| 448 | return OK; |
| 449 | } |
| 450 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 451 | status_t AST::generatePassthroughMethod(Formatter &out, |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 452 | const Method *method) const { |
| 453 | method->generateCppSignature(out); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 454 | |
| 455 | out << " {\n"; |
| 456 | out.indent(); |
| 457 | |
| 458 | const bool returnsValue = !method->results().empty(); |
| 459 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 460 | |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 461 | if (returnsValue && elidedReturn == nullptr) { |
| 462 | generateCheckNonNull(out, "_hidl_cb"); |
| 463 | } |
| 464 | |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 465 | generateCppInstrumentationCall( |
| 466 | out, |
| 467 | InstrumentationEvent::PASSTHROUGH_ENTRY, |
| 468 | method); |
| 469 | |
| 470 | out << "auto _hidl_return = "; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 471 | |
| 472 | if (method->isOneway()) { |
| 473 | out << "addOnewayTask([this"; |
| 474 | for (const auto &arg : method->args()) { |
| 475 | out << ", " << arg->name(); |
| 476 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 477 | out << "] {\n"; |
| 478 | out.indent(); |
| 479 | out << "this->"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | out << "mImpl->" |
| 483 | << method->name() |
| 484 | << "("; |
| 485 | |
| 486 | bool first = true; |
| 487 | for (const auto &arg : method->args()) { |
| 488 | if (!first) { |
| 489 | out << ", "; |
| 490 | } |
| 491 | first = false; |
| 492 | out << arg->name(); |
| 493 | } |
| 494 | if (returnsValue && elidedReturn == nullptr) { |
| 495 | if (!method->args().empty()) { |
| 496 | out << ", "; |
| 497 | } |
Zhuoyao Zhang | 085a8c3 | 2016-11-17 15:35:49 -0800 | [diff] [blame^] | 498 | out << "[&]("; |
| 499 | first = true; |
| 500 | for (const auto &arg : method->results()) { |
| 501 | if (!first) { |
| 502 | out << ", "; |
| 503 | } |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 504 | |
Zhuoyao Zhang | 085a8c3 | 2016-11-17 15:35:49 -0800 | [diff] [blame^] | 505 | out << "const auto &" << arg->name(); |
| 506 | |
| 507 | first = false; |
| 508 | } |
| 509 | |
| 510 | out << ") {\n"; |
| 511 | out.indent(); |
| 512 | status_t status = generateCppInstrumentationCall( |
| 513 | out, |
| 514 | InstrumentationEvent::PASSTHROUGH_EXIT, |
| 515 | method); |
| 516 | if (status != OK) { |
| 517 | return status; |
| 518 | } |
| 519 | |
| 520 | out << "_hidl_cb("; |
| 521 | first = true; |
| 522 | for (const auto &arg : method->results()) { |
| 523 | if (!first) { |
| 524 | out << ", "; |
| 525 | } |
| 526 | |
| 527 | out << arg->name(); |
| 528 | |
| 529 | first = false; |
| 530 | } |
| 531 | out << ");\n"; |
| 532 | out.unindent(); |
| 533 | out << "});\n\n"; |
| 534 | } else { |
| 535 | out << ");\n\n"; |
| 536 | if (elidedReturn != nullptr) { |
| 537 | out << elidedReturn->type().getCppResultType() |
| 538 | << " " |
| 539 | << elidedReturn->name() |
| 540 | << " = _hidl_return;\n"; |
| 541 | } |
| 542 | status_t status = generateCppInstrumentationCall( |
| 543 | out, |
| 544 | InstrumentationEvent::PASSTHROUGH_EXIT, |
| 545 | method); |
| 546 | if (status != OK) { |
| 547 | return status; |
| 548 | } |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 549 | } |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 550 | |
| 551 | if (method->isOneway()) { |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 552 | out.unindent(); |
| 553 | out << "});\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 554 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 555 | |
| 556 | out << "return _hidl_return;\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 557 | |
| 558 | out.unindent(); |
| 559 | out << "}\n"; |
| 560 | |
| 561 | return OK; |
| 562 | } |
| 563 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 564 | status_t AST::generateMethods(Formatter &out, MethodGenerator gen) const { |
Steven Moreland | a7a421a | 2016-09-07 08:35:18 -0700 | [diff] [blame] | 565 | |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 566 | const Interface *iface = mRootScope->getInterface(); |
| 567 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 568 | const Interface *prevIterface = nullptr; |
| 569 | for (const auto &tuple : iface->allMethodsFromRoot()) { |
| 570 | const Method *method = tuple.method(); |
| 571 | const Interface *superInterface = tuple.interface(); |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 572 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 573 | if(prevIterface != superInterface) { |
| 574 | if (prevIterface != nullptr) { |
| 575 | out << "\n"; |
| 576 | } |
| 577 | out << "// Methods from " |
| 578 | << superInterface->fullName() |
| 579 | << " follow.\n"; |
| 580 | prevIterface = superInterface; |
| 581 | } |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 582 | status_t err = gen(method, superInterface); |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 583 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 584 | if (err != OK) { |
| 585 | return err; |
| 586 | } |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 589 | out << "\n"; |
| 590 | |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 591 | return OK; |
| 592 | } |
| 593 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 594 | status_t AST::generateStubHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 595 | std::string ifaceName; |
| 596 | if (!AST::isInterface(&ifaceName)) { |
| 597 | // types.hal does not get a stub header. |
| 598 | return OK; |
| 599 | } |
| 600 | |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 601 | const Interface *iface = mRootScope->getInterface(); |
| 602 | const std::string baseName = iface->getBaseName(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 603 | const std::string klassName = "Bn" + baseName; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 604 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 605 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 606 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 607 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 608 | path.append(klassName); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 609 | path.append(".h"); |
| 610 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 611 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 612 | FILE *file = fopen(path.c_str(), "w"); |
| 613 | |
| 614 | if (file == NULL) { |
| 615 | return -errno; |
| 616 | } |
| 617 | |
| 618 | Formatter out(file); |
| 619 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 620 | const std::string guard = makeHeaderGuard(klassName); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 621 | |
| 622 | out << "#ifndef " << guard << "\n"; |
| 623 | out << "#define " << guard << "\n\n"; |
| 624 | |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 625 | generateCppPackageInclude(out, mPackage, "IHw" + baseName); |
| 626 | out << "\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 627 | |
| 628 | enterLeaveNamespace(out, true /* enter */); |
| 629 | out << "\n"; |
| 630 | |
| 631 | out << "struct " |
| 632 | << "Bn" |
| 633 | << baseName |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 634 | << " : public ::android::hardware::BnInterface<I" |
| 635 | << baseName << ", IHw" << baseName |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 636 | << ">, public ::android::hardware::HidlInstrumentor {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 637 | |
| 638 | out.indent(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 639 | out << "explicit Bn" |
| 640 | << baseName |
| 641 | << "(const ::android::sp<" << ifaceName << "> &_hidl_impl);" |
| 642 | << "\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 643 | out << "::android::status_t onTransact(\n"; |
| 644 | out.indent(); |
| 645 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 646 | out << "uint32_t _hidl_code,\n"; |
| 647 | out << "const ::android::hardware::Parcel &_hidl_data,\n"; |
| 648 | out << "::android::hardware::Parcel *_hidl_reply,\n"; |
| 649 | out << "uint32_t _hidl_flags = 0,\n"; |
Iliyan Malchev | 62c3d18 | 2016-08-16 20:33:39 -0700 | [diff] [blame] | 650 | out << "TransactCallback _hidl_cb = nullptr) override;\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 651 | out.unindent(); |
| 652 | out.unindent(); |
| 653 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 654 | status_t err = generateMethods(out, [&](const Method *method, const Interface *) { |
| 655 | return generateStubMethod(out, method); |
| 656 | }); |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 657 | |
| 658 | if (err != OK) { |
| 659 | return err; |
| 660 | } |
| 661 | |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 662 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 663 | out.unindent(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 664 | out << "};\n\n"; |
| 665 | |
| 666 | enterLeaveNamespace(out, false /* enter */); |
| 667 | |
| 668 | out << "\n#endif // " << guard << "\n"; |
| 669 | |
| 670 | return OK; |
| 671 | } |
| 672 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 673 | status_t AST::generateProxyHeader(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 674 | std::string ifaceName; |
| 675 | if (!AST::isInterface(&ifaceName)) { |
| 676 | // types.hal does not get a proxy header. |
| 677 | return OK; |
| 678 | } |
| 679 | |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 680 | const Interface *iface = mRootScope->getInterface(); |
| 681 | const std::string baseName = iface->getBaseName(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 682 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 683 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 684 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 685 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 686 | path.append("Bp"); |
| 687 | path.append(baseName); |
| 688 | path.append(".h"); |
| 689 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 690 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 691 | FILE *file = fopen(path.c_str(), "w"); |
| 692 | |
| 693 | if (file == NULL) { |
| 694 | return -errno; |
| 695 | } |
| 696 | |
| 697 | Formatter out(file); |
| 698 | |
| 699 | const std::string guard = makeHeaderGuard("Bp" + baseName); |
| 700 | |
| 701 | out << "#ifndef " << guard << "\n"; |
| 702 | out << "#define " << guard << "\n\n"; |
| 703 | |
| 704 | std::vector<std::string> packageComponents; |
| 705 | getPackageAndVersionComponents( |
| 706 | &packageComponents, false /* cpp_compatible */); |
| 707 | |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 708 | generateCppPackageInclude(out, mPackage, "IHw" + baseName); |
| 709 | out << "\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 710 | |
| 711 | enterLeaveNamespace(out, true /* enter */); |
| 712 | out << "\n"; |
| 713 | |
| 714 | out << "struct " |
| 715 | << "Bp" |
| 716 | << baseName |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 717 | << " : public ::android::hardware::BpInterface<IHw" |
| 718 | << baseName |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 719 | << ">, public ::android::hardware::HidlInstrumentor {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 720 | |
| 721 | out.indent(); |
| 722 | |
| 723 | out << "explicit Bp" |
| 724 | << baseName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 725 | << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl);" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 726 | << "\n\n"; |
| 727 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 728 | out << "virtual bool isRemote() const override { return true; }\n\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 729 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 730 | status_t err = generateMethods(out, [&](const Method *method, const Interface *) { |
| 731 | method->generateCppSignature(out); |
| 732 | out << " override;\n"; |
| 733 | return OK; |
| 734 | }); |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 735 | |
| 736 | if (err != OK) { |
| 737 | return err; |
| 738 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 739 | |
| 740 | out.unindent(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 741 | out << "};\n\n"; |
| 742 | |
| 743 | enterLeaveNamespace(out, false /* enter */); |
| 744 | |
| 745 | out << "\n#endif // " << guard << "\n"; |
| 746 | |
| 747 | return OK; |
| 748 | } |
| 749 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 750 | status_t AST::generateAllSource(const std::string &outputPath) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 751 | |
Andreas Huber | b82318c | 2016-08-02 14:45:54 -0700 | [diff] [blame] | 752 | std::string path = outputPath; |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 753 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
Andreas Huber | dca261f | 2016-08-04 13:47:51 -0700 | [diff] [blame] | 754 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 755 | |
| 756 | std::string ifaceName; |
| 757 | std::string baseName; |
| 758 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 759 | const Interface *iface = nullptr; |
| 760 | bool isInterface; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 761 | if (!AST::isInterface(&ifaceName)) { |
| 762 | baseName = "types"; |
| 763 | isInterface = false; |
| 764 | } else { |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 765 | iface = mRootScope->getInterface(); |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 766 | baseName = iface->getBaseName(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 767 | isInterface = true; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | path.append(baseName); |
| 771 | |
| 772 | if (baseName != "types") { |
| 773 | path.append("All"); |
| 774 | } |
| 775 | |
| 776 | path.append(".cpp"); |
| 777 | |
Andreas Huber | d2943e1 | 2016-08-05 11:59:31 -0700 | [diff] [blame] | 778 | CHECK(Coordinator::MakeParentHierarchy(path)); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 779 | FILE *file = fopen(path.c_str(), "w"); |
| 780 | |
| 781 | if (file == NULL) { |
| 782 | return -errno; |
| 783 | } |
| 784 | |
| 785 | Formatter out(file); |
| 786 | |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 787 | |
| 788 | out << "#include <cutils/trace.h>\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 789 | if (isInterface) { |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 790 | // This is a no-op for IServiceManager itself. |
| 791 | out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n"; |
| 792 | |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 793 | generateCppPackageInclude(out, mPackage, "Bp" + baseName); |
| 794 | generateCppPackageInclude(out, mPackage, "Bn" + baseName); |
| 795 | generateCppPackageInclude(out, mPackage, "Bs" + baseName); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 796 | |
| 797 | for (const Interface *superType : iface->superTypeChain()) { |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 798 | generateCppPackageInclude(out, |
| 799 | superType->fqName(), |
| 800 | "Bp" + superType->getBaseName()); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 801 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 802 | } else { |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 803 | generateCppPackageInclude(out, mPackage, "types"); |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 804 | generateCppPackageInclude(out, mPackage, "hwtypes"); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | out << "\n"; |
| 808 | |
| 809 | enterLeaveNamespace(out, true /* enter */); |
| 810 | out << "\n"; |
| 811 | |
| 812 | status_t err = generateTypeSource(out, ifaceName); |
| 813 | |
| 814 | if (err == OK && isInterface) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 815 | const Interface *iface = mRootScope->getInterface(); |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 816 | out << "constexpr ::android::hardware::hidl_version " |
| 817 | << ifaceName |
| 818 | << "::version;\n\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 819 | |
| 820 | // need to be put here, generateStubSource is using this. |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 821 | out << "const char* I" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 822 | << iface->getBaseName() |
| 823 | << "::descriptor(\"" |
| 824 | << iface->fqName().string() |
| 825 | << "\");\n\n"; |
| 826 | |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 827 | out << "int I" |
| 828 | << iface->getBaseName() |
| 829 | << "::hidlStaticBlock = []() -> int {\n"; |
| 830 | out.indentBlock([&] { |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 831 | out << "::android::hardware::gBnConstructorMap[I" |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 832 | << iface->getBaseName() |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 833 | << "::descriptor]\n"; |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 834 | out.indentBlock(2, [&] { |
| 835 | out << "= [](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n"; |
| 836 | out.indentBlock([&] { |
| 837 | out << "return new Bn" |
| 838 | << iface->getBaseName() |
| 839 | << "(reinterpret_cast<I" |
| 840 | << iface->getBaseName() |
| 841 | << " *>(iIntf));\n"; |
| 842 | }); |
| 843 | out << "};\n"; |
| 844 | }); |
| 845 | out << "return 1;\n"; |
| 846 | }); |
| 847 | out << "}();\n\n"; |
| 848 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 849 | err = generateInterfaceSource(out); |
| 850 | } |
| 851 | |
| 852 | if (err == OK && isInterface) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 853 | err = generateProxySource(out, baseName); |
| 854 | } |
| 855 | |
| 856 | if (err == OK && isInterface) { |
| 857 | err = generateStubSource(out, baseName); |
| 858 | } |
| 859 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 860 | if (err == OK && isInterface) { |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 861 | err = generatePassthroughSource(out); |
| 862 | } |
| 863 | |
| 864 | if (err == OK && isInterface) { |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 865 | const Interface *iface = mRootScope->getInterface(); |
| 866 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 867 | out << "IMPLEMENT_SERVICE_MANAGER_INTERACTIONS(" |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 868 | << baseName << ", " |
| 869 | << "\"" << iface->fqName().package() |
Steven Moreland | 7e367bf | 2016-11-04 11:31:41 -0700 | [diff] [blame] | 870 | << iface->fqName().atVersion() |
| 871 | << "\")\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 874 | enterLeaveNamespace(out, false /* enter */); |
| 875 | |
| 876 | return err; |
| 877 | } |
| 878 | |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 879 | // static |
| 880 | void AST::generateCheckNonNull(Formatter &out, const std::string &nonNull) { |
| 881 | out << "if (" << nonNull << " == nullptr) {\n"; |
| 882 | out.indent(); |
| 883 | out << "return ::android::hardware::Status::fromExceptionCode(\n"; |
| 884 | out.indent(); |
| 885 | out.indent(); |
| 886 | out << "::android::hardware::Status::EX_ILLEGAL_ARGUMENT);\n"; |
| 887 | out.unindent(); |
| 888 | out.unindent(); |
| 889 | out.unindent(); |
| 890 | out << "}\n\n"; |
| 891 | } |
| 892 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 893 | status_t AST::generateTypeSource( |
| 894 | Formatter &out, const std::string &ifaceName) const { |
| 895 | return mRootScope->emitTypeDefinitions(out, ifaceName); |
| 896 | } |
| 897 | |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 898 | void AST::declareCppReaderLocals( |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 899 | Formatter &out, |
| 900 | const std::vector<TypedVar *> &args, |
| 901 | bool forResults) const { |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 902 | if (args.empty()) { |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | for (const auto &arg : args) { |
| 907 | const Type &type = arg->type(); |
| 908 | |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 909 | out << type.getCppResultType() |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 910 | << " " |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 911 | << (forResults ? "_hidl_out_" : "") + arg->name() |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 912 | << ";\n"; |
| 913 | } |
| 914 | |
| 915 | out << "\n"; |
| 916 | } |
| 917 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 918 | void AST::emitCppReaderWriter( |
| 919 | Formatter &out, |
| 920 | const std::string &parcelObj, |
| 921 | bool parcelObjIsPointer, |
| 922 | const TypedVar *arg, |
| 923 | bool isReader, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 924 | Type::ErrorMode mode, |
| 925 | bool addPrefixToName) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 926 | const Type &type = arg->type(); |
| 927 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 928 | type.emitReaderWriter( |
| 929 | out, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 930 | addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(), |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 931 | parcelObj, |
| 932 | parcelObjIsPointer, |
| 933 | isReader, |
| 934 | mode); |
| 935 | } |
| 936 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 937 | void AST::emitCppResolveReferences( |
| 938 | Formatter &out, |
| 939 | const std::string &parcelObj, |
| 940 | bool parcelObjIsPointer, |
| 941 | const TypedVar *arg, |
| 942 | bool isReader, |
| 943 | Type::ErrorMode mode, |
| 944 | bool addPrefixToName) const { |
| 945 | const Type &type = arg->type(); |
| 946 | if(type.needsResolveReferences()) { |
| 947 | type.emitResolveReferences( |
| 948 | out, |
| 949 | addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(), |
| 950 | isReader, // nameIsPointer |
| 951 | parcelObj, |
| 952 | parcelObjIsPointer, |
| 953 | isReader, |
| 954 | mode); |
| 955 | } |
| 956 | } |
| 957 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 958 | status_t AST::generateProxyMethodSource(Formatter &out, |
| 959 | const std::string &klassName, |
| 960 | const Method *method, |
| 961 | const Interface *superInterface) const { |
| 962 | |
| 963 | method->generateCppSignature(out, |
| 964 | klassName, |
| 965 | true /* specify namespaces */); |
| 966 | |
| 967 | const bool returnsValue = !method->results().empty(); |
| 968 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 969 | |
Steven Moreland | 41c6d2e | 2016-11-07 12:26:54 -0800 | [diff] [blame] | 970 | out << " {\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 971 | |
| 972 | out.indent(); |
| 973 | |
| 974 | if (returnsValue && elidedReturn == nullptr) { |
| 975 | generateCheckNonNull(out, "_hidl_cb"); |
| 976 | } |
| 977 | |
| 978 | status_t status = generateCppInstrumentationCall( |
| 979 | out, |
| 980 | InstrumentationEvent::CLIENT_API_ENTRY, |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 981 | method); |
| 982 | if (status != OK) { |
| 983 | return status; |
| 984 | } |
| 985 | |
| 986 | out << "::android::hardware::Parcel _hidl_data;\n"; |
| 987 | out << "::android::hardware::Parcel _hidl_reply;\n"; |
| 988 | out << "::android::status_t _hidl_err;\n"; |
| 989 | out << "::android::hardware::Status _hidl_status;\n\n"; |
| 990 | |
| 991 | declareCppReaderLocals( |
| 992 | out, method->results(), true /* forResults */); |
| 993 | |
| 994 | out << "_hidl_err = _hidl_data.writeInterfaceToken("; |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 995 | if (method->isHidlReserved()) { |
Yifan Hong | 5bd9aff | 2016-11-08 18:52:55 -0800 | [diff] [blame] | 996 | out << "::android::hardware::IBase"; |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 997 | } else { |
| 998 | out << superInterface->fqName().cppNamespace() |
| 999 | << "::I" |
| 1000 | << superInterface->getBaseName(); |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1001 | } |
| 1002 | out << "::descriptor);\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1003 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1004 | |
| 1005 | // First DFS: write all buffers and resolve pointers for parent |
| 1006 | for (const auto &arg : method->args()) { |
| 1007 | emitCppReaderWriter( |
| 1008 | out, |
| 1009 | "_hidl_data", |
| 1010 | false /* parcelObjIsPointer */, |
| 1011 | arg, |
| 1012 | false /* reader */, |
| 1013 | Type::ErrorMode_Goto, |
| 1014 | false /* addPrefixToName */); |
| 1015 | } |
| 1016 | |
| 1017 | // Second DFS: resolve references. |
| 1018 | for (const auto &arg : method->args()) { |
| 1019 | emitCppResolveReferences( |
| 1020 | out, |
| 1021 | "_hidl_data", |
| 1022 | false /* parcelObjIsPointer */, |
| 1023 | arg, |
| 1024 | false /* reader */, |
| 1025 | Type::ErrorMode_Goto, |
| 1026 | false /* addPrefixToName */); |
| 1027 | } |
| 1028 | |
| 1029 | out << "_hidl_err = remote()->transact(" |
| 1030 | << method->getSerialId() |
| 1031 | << " /* " |
| 1032 | << method->name() |
| 1033 | << " */, _hidl_data, &_hidl_reply"; |
| 1034 | |
| 1035 | if (method->isOneway()) { |
| 1036 | out << ", ::android::hardware::IBinder::FLAG_ONEWAY"; |
| 1037 | } |
| 1038 | out << ");\n"; |
| 1039 | |
| 1040 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1041 | |
| 1042 | if (!method->isOneway()) { |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1043 | out << "_hidl_err = ::android::hardware::readFromParcel(&_hidl_status, _hidl_reply);\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1044 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1045 | out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n"; |
| 1046 | |
| 1047 | |
| 1048 | // First DFS: write all buffers and resolve pointers for parent |
| 1049 | for (const auto &arg : method->results()) { |
| 1050 | emitCppReaderWriter( |
| 1051 | out, |
| 1052 | "_hidl_reply", |
| 1053 | false /* parcelObjIsPointer */, |
| 1054 | arg, |
| 1055 | true /* reader */, |
| 1056 | Type::ErrorMode_Goto, |
| 1057 | true /* addPrefixToName */); |
| 1058 | } |
| 1059 | |
| 1060 | // Second DFS: resolve references. |
| 1061 | for (const auto &arg : method->results()) { |
| 1062 | emitCppResolveReferences( |
| 1063 | out, |
| 1064 | "_hidl_reply", |
| 1065 | false /* parcelObjIsPointer */, |
| 1066 | arg, |
| 1067 | true /* reader */, |
| 1068 | Type::ErrorMode_Goto, |
| 1069 | true /* addPrefixToName */); |
| 1070 | } |
| 1071 | |
| 1072 | if (returnsValue && elidedReturn == nullptr) { |
| 1073 | out << "_hidl_cb("; |
| 1074 | |
| 1075 | bool first = true; |
| 1076 | for (const auto &arg : method->results()) { |
| 1077 | if (!first) { |
| 1078 | out << ", "; |
| 1079 | } |
| 1080 | |
| 1081 | if (arg->type().resultNeedsDeref()) { |
| 1082 | out << "*"; |
| 1083 | } |
| 1084 | out << "_hidl_out_" << arg->name(); |
| 1085 | |
| 1086 | first = false; |
| 1087 | } |
| 1088 | |
| 1089 | out << ");\n\n"; |
| 1090 | } |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1091 | } |
| 1092 | status = generateCppInstrumentationCall( |
| 1093 | out, |
| 1094 | InstrumentationEvent::CLIENT_API_EXIT, |
| 1095 | method); |
| 1096 | if (status != OK) { |
| 1097 | return status; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | if (elidedReturn != nullptr) { |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1101 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1102 | out << "return ::android::hardware::Return<"; |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1103 | out << elidedReturn->type().getCppResultType() |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1104 | << ">(_hidl_out_" << elidedReturn->name() << ");\n\n"; |
| 1105 | } else { |
| 1106 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1107 | out << "return ::android::hardware::Return<void>();\n\n"; |
| 1108 | } |
| 1109 | |
| 1110 | out.unindent(); |
| 1111 | out << "_hidl_error:\n"; |
| 1112 | out.indent(); |
| 1113 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1114 | out << "return ::android::hardware::Return<"; |
| 1115 | if (elidedReturn != nullptr) { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1116 | out << method->results().at(0)->type().getCppResultType(); |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1117 | } else { |
| 1118 | out << "void"; |
| 1119 | } |
| 1120 | out << ">(_hidl_status);\n"; |
| 1121 | |
| 1122 | out.unindent(); |
| 1123 | out << "}\n\n"; |
| 1124 | return OK; |
| 1125 | } |
| 1126 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1127 | status_t AST::generateProxySource( |
| 1128 | Formatter &out, const std::string &baseName) const { |
| 1129 | const std::string klassName = "Bp" + baseName; |
| 1130 | |
| 1131 | out << klassName |
| 1132 | << "::" |
| 1133 | << klassName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1134 | << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1135 | |
| 1136 | out.indent(); |
| 1137 | out.indent(); |
| 1138 | |
| 1139 | out << ": BpInterface" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1140 | << "<IHw" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1141 | << baseName |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1142 | << ">(_hidl_impl),\n" |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1143 | << " ::android::hardware::HidlInstrumentor(\"" |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1144 | << mPackage.string() |
| 1145 | << "::I" |
| 1146 | << baseName |
| 1147 | << "\") {\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1148 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1149 | out.unindent(); |
| 1150 | out.unindent(); |
| 1151 | out << "}\n\n"; |
| 1152 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1153 | status_t err = generateMethods(out, [&](const Method *method, const Interface *superInterface) { |
| 1154 | return generateProxyMethodSource(out, klassName, method, superInterface); |
| 1155 | }); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1156 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1157 | return err; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | status_t AST::generateStubSource( |
| 1161 | Formatter &out, const std::string &baseName) const { |
| 1162 | out << "IMPLEMENT_HWBINDER_META_INTERFACE(" |
| 1163 | << baseName |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1164 | << ", " |
| 1165 | << mPackage.cppNamespace() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1166 | << "::I" |
| 1167 | << baseName |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1168 | << "::descriptor);\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1169 | |
| 1170 | const std::string klassName = "Bn" + baseName; |
| 1171 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1172 | out << klassName |
| 1173 | << "::" |
| 1174 | << klassName |
| 1175 | << "(const ::android::sp<I" << baseName <<"> &_hidl_impl)\n"; |
| 1176 | |
| 1177 | out.indent(); |
| 1178 | out.indent(); |
| 1179 | |
| 1180 | out << ": BnInterface" |
| 1181 | << "<I" |
| 1182 | << baseName |
| 1183 | << ", IHw" |
| 1184 | << baseName |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1185 | << ">(_hidl_impl),\n" |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1186 | << " ::android::hardware::HidlInstrumentor(\"" |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1187 | << mPackage.string() |
| 1188 | << "::I" |
| 1189 | << baseName |
| 1190 | << "\") {\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1191 | |
| 1192 | out.unindent(); |
| 1193 | out.unindent(); |
| 1194 | out << "}\n\n"; |
| 1195 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1196 | out << "::android::status_t " << klassName << "::onTransact(\n"; |
| 1197 | |
| 1198 | out.indent(); |
| 1199 | out.indent(); |
| 1200 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1201 | out << "uint32_t _hidl_code,\n" |
| 1202 | << "const ::android::hardware::Parcel &_hidl_data,\n" |
| 1203 | << "::android::hardware::Parcel *_hidl_reply,\n" |
| 1204 | << "uint32_t _hidl_flags,\n" |
| 1205 | << "TransactCallback _hidl_cb) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1206 | |
| 1207 | out.unindent(); |
| 1208 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1209 | out << "::android::status_t _hidl_err = ::android::OK;\n\n"; |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1210 | out << "switch (_hidl_code) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1211 | out.indent(); |
| 1212 | |
| 1213 | const Interface *iface = mRootScope->getInterface(); |
| 1214 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1215 | for (const auto &tuple : iface->allMethodsFromRoot()) { |
| 1216 | const Method *method = tuple.method(); |
| 1217 | const Interface *superInterface = tuple.interface(); |
| 1218 | out << "case " |
| 1219 | << method->getSerialId() |
| 1220 | << " /* " |
| 1221 | << method->name() |
| 1222 | << " */:\n{\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1223 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1224 | out.indent(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1225 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1226 | status_t err = |
| 1227 | generateStubSourceForMethod(out, superInterface, method); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1228 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1229 | if (err != OK) { |
| 1230 | return err; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1231 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1232 | |
| 1233 | out.unindent(); |
| 1234 | out << "}\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | out << "default:\n{\n"; |
| 1238 | out.indent(); |
| 1239 | |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 1240 | out << "return ::android::hardware::BnInterface<I" |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1241 | << baseName << ", IHw" << baseName |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1242 | << ">::onTransact(\n"; |
| 1243 | |
| 1244 | out.indent(); |
| 1245 | out.indent(); |
| 1246 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1247 | out << "_hidl_code, _hidl_data, _hidl_reply, " |
| 1248 | << "_hidl_flags, _hidl_cb);\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1249 | |
| 1250 | out.unindent(); |
| 1251 | out.unindent(); |
| 1252 | |
| 1253 | out.unindent(); |
| 1254 | out << "}\n"; |
| 1255 | |
| 1256 | out.unindent(); |
| 1257 | out << "}\n\n"; |
| 1258 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1259 | out << "if (_hidl_err == ::android::UNEXPECTED_NULL) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1260 | out.indent(); |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1261 | out << "_hidl_err = ::android::hardware::writeToParcel(\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1262 | out.indent(); |
| 1263 | out.indent(); |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1264 | out << "::android::hardware::Status::fromExceptionCode(::android::hardware::Status::EX_NULL_POINTER),\n"; |
| 1265 | out << "_hidl_reply);\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1266 | out.unindent(); |
| 1267 | out.unindent(); |
| 1268 | |
| 1269 | out.unindent(); |
| 1270 | out << "}\n\n"; |
| 1271 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1272 | out << "return _hidl_err;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1273 | |
| 1274 | out.unindent(); |
| 1275 | out << "}\n\n"; |
| 1276 | |
| 1277 | return OK; |
| 1278 | } |
| 1279 | |
| 1280 | status_t AST::generateStubSourceForMethod( |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1281 | Formatter &out, const Interface *iface, const Method *method) const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1282 | out << "if (!_hidl_data.enforceInterface("; |
| 1283 | |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 1284 | if (method->isHidlReserved()) { |
Yifan Hong | 5bd9aff | 2016-11-08 18:52:55 -0800 | [diff] [blame] | 1285 | out << "::android::hardware::IBase"; |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 1286 | } else { |
| 1287 | out << iface->fqName().cppNamespace() |
| 1288 | << "::I" |
| 1289 | << iface->getBaseName(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | out << "::descriptor)) {\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1293 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1294 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1295 | out << "_hidl_err = ::android::BAD_TYPE;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1296 | out << "break;\n"; |
| 1297 | out.unindent(); |
| 1298 | out << "}\n\n"; |
| 1299 | |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1300 | declareCppReaderLocals(out, method->args(), false /* forResults */); |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1301 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1302 | // First DFS: write buffers |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1303 | for (const auto &arg : method->args()) { |
| 1304 | emitCppReaderWriter( |
| 1305 | out, |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1306 | "_hidl_data", |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1307 | false /* parcelObjIsPointer */, |
| 1308 | arg, |
| 1309 | true /* reader */, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1310 | Type::ErrorMode_Break, |
| 1311 | false /* addPrefixToName */); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1314 | // Second DFS: resolve references |
| 1315 | for (const auto &arg : method->args()) { |
| 1316 | emitCppResolveReferences( |
| 1317 | out, |
| 1318 | "_hidl_data", |
| 1319 | false /* parcelObjIsPointer */, |
| 1320 | arg, |
| 1321 | true /* reader */, |
| 1322 | Type::ErrorMode_Break, |
| 1323 | false /* addPrefixToName */); |
| 1324 | } |
| 1325 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1326 | status_t status = generateCppInstrumentationCall( |
| 1327 | out, |
| 1328 | InstrumentationEvent::SERVER_API_ENTRY, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1329 | method); |
| 1330 | if (status != OK) { |
| 1331 | return status; |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1334 | const bool returnsValue = !method->results().empty(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1335 | const TypedVar *elidedReturn = method->canElideCallback(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1336 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1337 | if (elidedReturn != nullptr) { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1338 | out << elidedReturn->type().getCppResultType() |
| 1339 | << " " |
| 1340 | << elidedReturn->name() |
| 1341 | << " = " |
| 1342 | << method->name() |
| 1343 | << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1344 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1345 | bool first = true; |
| 1346 | for (const auto &arg : method->args()) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1347 | if (!first) { |
| 1348 | out << ", "; |
| 1349 | } |
| 1350 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1351 | if (arg->type().resultNeedsDeref()) { |
| 1352 | out << "*"; |
| 1353 | } |
| 1354 | |
| 1355 | out << arg->name(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1356 | |
| 1357 | first = false; |
| 1358 | } |
| 1359 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1360 | out << ");\n\n"; |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1361 | out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), " |
| 1362 | << "_hidl_reply);\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1363 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1364 | elidedReturn->type().emitReaderWriter( |
| 1365 | out, |
| 1366 | elidedReturn->name(), |
| 1367 | "_hidl_reply", |
| 1368 | true, /* parcelObjIsPointer */ |
| 1369 | false, /* isReader */ |
| 1370 | Type::ErrorMode_Ignore); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1371 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1372 | emitCppResolveReferences( |
| 1373 | out, |
| 1374 | "_hidl_reply", |
| 1375 | true /* parcelObjIsPointer */, |
| 1376 | elidedReturn, |
| 1377 | false /* reader */, |
| 1378 | Type::ErrorMode_Ignore, |
| 1379 | false /* addPrefixToName */); |
| 1380 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1381 | status_t status = generateCppInstrumentationCall( |
| 1382 | out, |
| 1383 | InstrumentationEvent::SERVER_API_EXIT, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1384 | method); |
| 1385 | if (status != OK) { |
| 1386 | return status; |
| 1387 | } |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1388 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1389 | out << "_hidl_cb(*_hidl_reply);\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1390 | } else { |
| 1391 | if (returnsValue) { |
| 1392 | out << "bool _hidl_callbackCalled = false;\n\n"; |
| 1393 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1394 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1395 | out << method->name() << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1396 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1397 | bool first = true; |
| 1398 | for (const auto &arg : method->args()) { |
| 1399 | if (!first) { |
| 1400 | out << ", "; |
| 1401 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1402 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1403 | if (arg->type().resultNeedsDeref()) { |
| 1404 | out << "*"; |
| 1405 | } |
| 1406 | |
| 1407 | out << arg->name(); |
| 1408 | |
| 1409 | first = false; |
| 1410 | } |
| 1411 | |
| 1412 | if (returnsValue) { |
| 1413 | if (!first) { |
| 1414 | out << ", "; |
| 1415 | } |
| 1416 | |
| 1417 | out << "[&]("; |
| 1418 | |
| 1419 | first = true; |
| 1420 | for (const auto &arg : method->results()) { |
| 1421 | if (!first) { |
| 1422 | out << ", "; |
| 1423 | } |
| 1424 | |
| 1425 | out << "const auto &" << arg->name(); |
| 1426 | |
| 1427 | first = false; |
| 1428 | } |
| 1429 | |
| 1430 | out << ") {\n"; |
| 1431 | out.indent(); |
| 1432 | out << "_hidl_callbackCalled = true;\n\n"; |
| 1433 | |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1434 | out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), " |
| 1435 | << "_hidl_reply);\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1436 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1437 | // First DFS: buffers |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1438 | for (const auto &arg : method->results()) { |
| 1439 | emitCppReaderWriter( |
| 1440 | out, |
| 1441 | "_hidl_reply", |
| 1442 | true /* parcelObjIsPointer */, |
| 1443 | arg, |
| 1444 | false /* reader */, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1445 | Type::ErrorMode_Ignore, |
| 1446 | false /* addPrefixToName */); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1449 | // Second DFS: resolve references |
| 1450 | for (const auto &arg : method->results()) { |
| 1451 | emitCppResolveReferences( |
| 1452 | out, |
| 1453 | "_hidl_reply", |
| 1454 | true /* parcelObjIsPointer */, |
| 1455 | arg, |
| 1456 | false /* reader */, |
| 1457 | Type::ErrorMode_Ignore, |
| 1458 | false /* addPrefixToName */); |
| 1459 | } |
| 1460 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1461 | status_t status = generateCppInstrumentationCall( |
| 1462 | out, |
| 1463 | InstrumentationEvent::SERVER_API_EXIT, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1464 | method); |
| 1465 | if (status != OK) { |
| 1466 | return status; |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1469 | out << "_hidl_cb(*_hidl_reply);\n"; |
| 1470 | |
| 1471 | out.unindent(); |
| 1472 | out << "}\n"; |
| 1473 | } |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame] | 1474 | out << ");\n\n"; |
| 1475 | |
| 1476 | // What to do if the stub implementation has a synchronous callback |
| 1477 | // which does not get invoked? This is not a transport error but a |
| 1478 | // service error of sorts. For now, return OK to the caller, as this is |
| 1479 | // not a transport error. |
| 1480 | // |
| 1481 | // TODO(b/31365311) Figure out how to deal with this later. |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1482 | |
| 1483 | if (returnsValue) { |
| 1484 | out << "if (!_hidl_callbackCalled) {\n"; |
| 1485 | out.indent(); |
| 1486 | } |
| 1487 | |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1488 | out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), " |
| 1489 | << "_hidl_reply);\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1490 | |
| 1491 | if (returnsValue) { |
| 1492 | out.unindent(); |
| 1493 | out << "}\n\n"; |
| 1494 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | out << "break;\n"; |
| 1498 | |
| 1499 | return OK; |
| 1500 | } |
| 1501 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1502 | status_t AST::generatePassthroughHeader(const std::string &outputPath) const { |
| 1503 | std::string ifaceName; |
| 1504 | if (!AST::isInterface(&ifaceName)) { |
| 1505 | // types.hal does not get a stub header. |
| 1506 | return OK; |
| 1507 | } |
| 1508 | |
| 1509 | const Interface *iface = mRootScope->getInterface(); |
| 1510 | |
| 1511 | const std::string baseName = iface->getBaseName(); |
| 1512 | const std::string klassName = "Bs" + baseName; |
| 1513 | |
| 1514 | bool supportOneway = iface->hasOnewayMethods(); |
| 1515 | |
| 1516 | std::string path = outputPath; |
| 1517 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 1518 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 1519 | path.append(klassName); |
| 1520 | path.append(".h"); |
| 1521 | |
| 1522 | CHECK(Coordinator::MakeParentHierarchy(path)); |
| 1523 | FILE *file = fopen(path.c_str(), "w"); |
| 1524 | |
| 1525 | if (file == NULL) { |
| 1526 | return -errno; |
| 1527 | } |
| 1528 | |
| 1529 | Formatter out(file); |
| 1530 | |
| 1531 | const std::string guard = makeHeaderGuard(klassName); |
| 1532 | |
| 1533 | out << "#ifndef " << guard << "\n"; |
| 1534 | out << "#define " << guard << "\n\n"; |
| 1535 | |
| 1536 | std::vector<std::string> packageComponents; |
| 1537 | getPackageAndVersionComponents( |
| 1538 | &packageComponents, false /* cpp_compatible */); |
| 1539 | |
| 1540 | out << "#include <future>\n"; |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 1541 | |
| 1542 | generateCppPackageInclude(out, mPackage, ifaceName); |
| 1543 | out << "\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1544 | |
| 1545 | if (supportOneway) { |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1546 | out << "#include <hidl/TaskRunner.h>\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | enterLeaveNamespace(out, true /* enter */); |
| 1550 | out << "\n"; |
| 1551 | |
| 1552 | out << "struct " |
| 1553 | << klassName |
| 1554 | << " : " << ifaceName |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1555 | << ", ::android::hardware::HidlInstrumentor {\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1556 | |
| 1557 | out.indent(); |
| 1558 | out << "explicit " |
| 1559 | << klassName |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1560 | << "(const ::android::sp<" |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1561 | << ifaceName |
| 1562 | << "> impl);\n"; |
| 1563 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1564 | status_t err = generateMethods(out, [&](const Method *method, const Interface *) { |
| 1565 | return generatePassthroughMethod(out, method); |
| 1566 | }); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1567 | |
| 1568 | if (err != OK) { |
| 1569 | return err; |
| 1570 | } |
| 1571 | |
| 1572 | out.unindent(); |
| 1573 | out << "private:\n"; |
| 1574 | out.indent(); |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1575 | out << "const ::android::sp<" << ifaceName << "> mImpl;\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1576 | |
| 1577 | if (supportOneway) { |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1578 | out << "::android::hardware::TaskRunner mOnewayQueue;\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1579 | |
| 1580 | out << "\n"; |
| 1581 | |
| 1582 | out << "::android::hardware::Return<void> addOnewayTask(" |
| 1583 | "std::function<void(void)>);\n\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | out.unindent(); |
| 1587 | |
| 1588 | out << "};\n\n"; |
| 1589 | |
| 1590 | enterLeaveNamespace(out, false /* enter */); |
| 1591 | |
| 1592 | out << "\n#endif // " << guard << "\n"; |
| 1593 | |
| 1594 | return OK; |
| 1595 | } |
| 1596 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1597 | status_t AST::generateInterfaceSource(Formatter &out) const { |
| 1598 | const Interface *iface = mRootScope->getInterface(); |
| 1599 | |
Yifan Hong | 2d7126b | 2016-10-20 15:12:57 -0700 | [diff] [blame] | 1600 | // generate castFrom functions |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1601 | if (!iface->isRootType()) { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1602 | std::string childTypeResult = iface->getCppResultType(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1603 | |
| 1604 | for (const Interface *superType : iface->superTypeChain()) { |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1605 | out << "// static \n" |
| 1606 | << childTypeResult |
| 1607 | << " I" |
| 1608 | << iface->getBaseName() |
| 1609 | << "::castFrom(" |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1610 | << superType->getCppArgumentType() |
| 1611 | << " parent) {\n"; |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1612 | out.indent(); |
| 1613 | out << "return ::android::hardware::castInterface<"; |
| 1614 | out << "I" << iface->getBaseName() << ", " |
| 1615 | << superType->fqName().cppName() << ", " |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 1616 | << "Bp" << iface->getBaseName() << ", " |
| 1617 | << superType->getHwName().cppName() |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1618 | << ">(\n"; |
| 1619 | out.indent(); |
| 1620 | out.indent(); |
| 1621 | out << "parent, \"" |
| 1622 | << iface->fqName().string() |
| 1623 | << "\");\n"; |
| 1624 | out.unindent(); |
| 1625 | out.unindent(); |
| 1626 | out.unindent(); |
| 1627 | out << "}\n\n"; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | return OK; |
| 1632 | } |
| 1633 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1634 | status_t AST::generatePassthroughSource(Formatter &out) const { |
| 1635 | const Interface *iface = mRootScope->getInterface(); |
| 1636 | |
| 1637 | const std::string baseName = iface->getBaseName(); |
| 1638 | const std::string klassName = "Bs" + baseName; |
| 1639 | |
| 1640 | out << klassName |
| 1641 | << "::" |
| 1642 | << klassName |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1643 | << "(const ::android::sp<" |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1644 | << iface->fullName() |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1645 | << "> impl) : ::android::hardware::HidlInstrumentor(\"" |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1646 | << iface->fqName().string() |
| 1647 | << "\"), mImpl(impl) {"; |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1648 | if (iface->hasOnewayMethods()) { |
| 1649 | out << "\n"; |
| 1650 | out.indentBlock([&] { |
| 1651 | out << "mOnewayQueue.setLimit(3000 /* similar limit to binderized */);\n"; |
| 1652 | }); |
| 1653 | } |
| 1654 | out << "}\n\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1655 | |
| 1656 | if (iface->hasOnewayMethods()) { |
| 1657 | out << "::android::hardware::Return<void> " |
| 1658 | << klassName |
| 1659 | << "::addOnewayTask(std::function<void(void)> fun) {\n"; |
| 1660 | out.indent(); |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1661 | out << "if (!mOnewayQueue.push(fun)) {\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1662 | out.indent(); |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1663 | out << "return ::android::hardware::Status::fromExceptionCode(\n"; |
| 1664 | out.indent(); |
| 1665 | out.indent(); |
| 1666 | out << "::android::hardware::Status::EX_TRANSACTION_FAILED);\n"; |
| 1667 | out.unindent(); |
| 1668 | out.unindent(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1669 | out.unindent(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1670 | out << "}\n"; |
| 1671 | |
Steven Moreland | d366c26 | 2016-10-11 15:29:10 -0700 | [diff] [blame] | 1672 | out << "return ::android::hardware::Status();\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1673 | |
| 1674 | out.unindent(); |
| 1675 | out << "}\n\n"; |
| 1676 | |
| 1677 | |
| 1678 | } |
| 1679 | |
| 1680 | return OK; |
| 1681 | } |
| 1682 | |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1683 | status_t AST::generateCppAtraceCall(Formatter &out, |
| 1684 | InstrumentationEvent event, |
| 1685 | const Method *method) const { |
| 1686 | const Interface *iface = mRootScope->getInterface(); |
| 1687 | std::string baseString = "HIDL::I" + iface->getBaseName() + "::" + method->name(); |
| 1688 | switch (event) { |
| 1689 | case SERVER_API_ENTRY: |
| 1690 | { |
| 1691 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1692 | << baseString + "::server\");\n"; |
| 1693 | break; |
| 1694 | } |
| 1695 | case CLIENT_API_ENTRY: |
| 1696 | { |
| 1697 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1698 | << baseString + "::client\");\n"; |
| 1699 | break; |
| 1700 | } |
| 1701 | case PASSTHROUGH_ENTRY: |
| 1702 | { |
| 1703 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1704 | << baseString + "::passthrough\");\n"; |
| 1705 | break; |
| 1706 | } |
| 1707 | case SERVER_API_EXIT: |
| 1708 | case CLIENT_API_EXIT: |
| 1709 | case PASSTHROUGH_EXIT: |
| 1710 | { |
| 1711 | out << "atrace_end(ATRACE_TAG_HAL);\n"; |
| 1712 | break; |
| 1713 | } |
| 1714 | default: |
| 1715 | { |
| 1716 | LOG(ERROR) << "Unsupported instrumentation event: " << event; |
| 1717 | return UNKNOWN_ERROR; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | return OK; |
| 1722 | } |
| 1723 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1724 | status_t AST::generateCppInstrumentationCall( |
| 1725 | Formatter &out, |
| 1726 | InstrumentationEvent event, |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1727 | const Method *method) const { |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1728 | status_t err = generateCppAtraceCall(out, event, method); |
| 1729 | if (err != OK) { |
| 1730 | return err; |
| 1731 | } |
| 1732 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1733 | out << "if (UNLIKELY(mEnableInstrumentation)) {\n"; |
| 1734 | out.indent(); |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1735 | out << "std::vector<void *> _hidl_args;\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1736 | std::string event_str = ""; |
| 1737 | switch (event) { |
| 1738 | case SERVER_API_ENTRY: |
| 1739 | { |
| 1740 | event_str = "InstrumentationEvent::SERVER_API_ENTRY"; |
| 1741 | for (const auto &arg : method->args()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1742 | out << "_hidl_args.push_back((void *)" |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1743 | << (arg->type().resultNeedsDeref() ? "" : "&") |
| 1744 | << arg->name() |
| 1745 | << ");\n"; |
| 1746 | } |
| 1747 | break; |
| 1748 | } |
| 1749 | case SERVER_API_EXIT: |
| 1750 | { |
| 1751 | event_str = "InstrumentationEvent::SERVER_API_EXIT"; |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1752 | for (const auto &arg : method->results()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1753 | out << "_hidl_args.push_back((void *)&" |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1754 | << arg->name() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1755 | << ");\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1756 | } |
| 1757 | break; |
| 1758 | } |
| 1759 | case CLIENT_API_ENTRY: |
| 1760 | { |
| 1761 | event_str = "InstrumentationEvent::CLIENT_API_ENTRY"; |
| 1762 | for (const auto &arg : method->args()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1763 | out << "_hidl_args.push_back((void *)&" |
| 1764 | << arg->name() |
| 1765 | << ");\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1766 | } |
| 1767 | break; |
| 1768 | } |
| 1769 | case CLIENT_API_EXIT: |
| 1770 | { |
| 1771 | event_str = "InstrumentationEvent::CLIENT_API_EXIT"; |
| 1772 | for (const auto &arg : method->results()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1773 | out << "_hidl_args.push_back((void *)" |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1774 | << (arg->type().resultNeedsDeref() ? "" : "&") |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1775 | << "_hidl_out_" |
| 1776 | << arg->name() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1777 | << ");\n"; |
| 1778 | } |
| 1779 | break; |
| 1780 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1781 | case PASSTHROUGH_ENTRY: |
| 1782 | { |
| 1783 | event_str = "InstrumentationEvent::PASSTHROUGH_ENTRY"; |
| 1784 | for (const auto &arg : method->args()) { |
| 1785 | out << "_hidl_args.push_back((void *)&" |
| 1786 | << arg->name() |
| 1787 | << ");\n"; |
| 1788 | } |
| 1789 | break; |
| 1790 | } |
| 1791 | case PASSTHROUGH_EXIT: |
| 1792 | { |
| 1793 | event_str = "InstrumentationEvent::PASSTHROUGH_EXIT"; |
Zhuoyao Zhang | 085a8c3 | 2016-11-17 15:35:49 -0800 | [diff] [blame^] | 1794 | for (const auto &arg : method->results()) { |
| 1795 | out << "_hidl_args.push_back((void *)&" |
| 1796 | << arg->name() |
| 1797 | << ");\n"; |
| 1798 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1799 | break; |
| 1800 | } |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1801 | default: |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1802 | { |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1803 | LOG(ERROR) << "Unsupported instrumentation event: " << event; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1804 | return UNKNOWN_ERROR; |
| 1805 | } |
| 1806 | } |
| 1807 | |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1808 | const Interface *iface = mRootScope->getInterface(); |
| 1809 | |
Steven Moreland | 1ab3144 | 2016-11-03 18:37:51 -0700 | [diff] [blame] | 1810 | out << "for (const auto &callback: mInstrumentationCallbacks) {\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1811 | out.indent(); |
| 1812 | out << "callback(" |
| 1813 | << event_str |
| 1814 | << ", \"" |
| 1815 | << mPackage.package() |
| 1816 | << "\", \"" |
Yifan Hong | 90ea87f | 2016-11-01 14:25:47 -0700 | [diff] [blame] | 1817 | << mPackage.version() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1818 | << "\", \"" |
| 1819 | << iface->localName() |
| 1820 | << "\", \"" |
| 1821 | << method->name() |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1822 | << "\", &_hidl_args);\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1823 | out.unindent(); |
| 1824 | out << "}\n"; |
| 1825 | out.unindent(); |
| 1826 | out << "}\n\n"; |
| 1827 | |
| 1828 | return OK; |
| 1829 | } |
| 1830 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1831 | } // namespace android |
| 1832 | |