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