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