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([&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 161 | out << "::android::sp<" << interfaceName << "> iface;\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, [&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 169 | out << "sm->get(\"" << package << "::" << interfaceName << "\", serviceName.c_str());\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(); |
| 178 | out << "const int dlMode = RTLD_LAZY;\n"; |
| 179 | out << "void *handle = nullptr;\n"; |
| 180 | for (const auto &path : std::vector<std::string>({ |
| 181 | "HAL_LIBRARY_PATH_ODM", "HAL_LIBRARY_PATH_VENDOR", "HAL_LIBRARY_PATH_SYSTEM" |
| 182 | })) { |
| 183 | out.sIf("handle == nullptr", [&] { |
| 184 | out << "handle = dlopen(" |
| 185 | << path << " \"" << package << "-impl.so\", dlMode);\n"; |
| 186 | }).endl(); |
| 187 | } |
| 188 | out.sIf("handle == nullptr", [&] { |
| 189 | out << "return iface;\n"; |
| 190 | }).endl(); |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 191 | out << "" << interfaceName << "* (*generator)(const char* name);\n" |
| 192 | << "*(void **)(&generator) = dlsym(handle, \"HIDL_FETCH_" << interfaceName << "\");\n"; |
Yifan Hong | 83c8e5f | 2016-12-13 14:33:53 -0800 | [diff] [blame] | 193 | out.sIf("generator", [&] { |
| 194 | out << "iface = (*generator)(serviceName.c_str());\n"; |
| 195 | out.sIf("iface != nullptr", [&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 196 | out << "iface = new " << fqName.getInterfacePassthroughName() << "(iface);\n"; |
Yifan Hong | 83c8e5f | 2016-12-13 14:33:53 -0800 | [diff] [blame] | 197 | }).endl(); |
| 198 | }).endl(); |
| 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 | 05cd423 | 2016-11-21 16:01:12 -0800 | [diff] [blame] | 923 | out << "#include <android/log.h>\n"; |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 924 | out << "#include <cutils/trace.h>\n"; |
| 925 | out << "#include <hidl/HidlTransportSupport.h>\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 926 | if (isInterface) { |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 927 | // This is a no-op for IServiceManager itself. |
| 928 | out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n"; |
| 929 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 930 | generateCppPackageInclude(out, mPackage, iface->getProxyName()); |
| 931 | generateCppPackageInclude(out, mPackage, iface->getStubName()); |
| 932 | generateCppPackageInclude(out, mPackage, iface->getPassthroughName()); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 933 | |
| 934 | for (const Interface *superType : iface->superTypeChain()) { |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 935 | generateCppPackageInclude(out, |
| 936 | superType->fqName(), |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 937 | superType->fqName().getInterfaceProxyName()); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 938 | } |
Yifan Hong | 2cbbdf9 | 2016-12-05 15:20:50 -0800 | [diff] [blame] | 939 | |
| 940 | out << "#include <hidl/ServiceManagement.h>\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 941 | } else { |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 942 | generateCppPackageInclude(out, mPackage, "types"); |
Yifan Hong | 244e82d | 2016-11-11 11:13:57 -0800 | [diff] [blame] | 943 | generateCppPackageInclude(out, mPackage, "hwtypes"); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | out << "\n"; |
| 947 | |
| 948 | enterLeaveNamespace(out, true /* enter */); |
| 949 | out << "\n"; |
| 950 | |
| 951 | status_t err = generateTypeSource(out, ifaceName); |
| 952 | |
| 953 | if (err == OK && isInterface) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 954 | const Interface *iface = mRootScope->getInterface(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 955 | |
| 956 | // need to be put here, generateStubSource is using this. |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 957 | out << "const char* " |
| 958 | << iface->localName() |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 959 | << "::descriptor(\"" |
| 960 | << iface->fqName().string() |
| 961 | << "\");\n\n"; |
| 962 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 963 | out << "int " |
| 964 | << iface->localName() |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 965 | << "::hidlStaticBlock = []() -> int {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 966 | out.indent([&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 967 | out << "::android::hardware::gBnConstructorMap[" |
| 968 | << iface->localName() |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 969 | << "::descriptor]\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 970 | out.indent(2, [&] { |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 971 | out << "= [](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 972 | out.indent([&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 973 | out << "return new " |
| 974 | << iface->getStubName() |
| 975 | << "(reinterpret_cast<" |
| 976 | << iface->localName() |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 977 | << " *>(iIntf));\n"; |
| 978 | }); |
| 979 | out << "};\n"; |
| 980 | }); |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 981 | out << "::android::hardware::gBsConstructorMap[" |
| 982 | << iface->localName() |
Yifan Hong | 7a118f5 | 2016-12-07 11:21:15 -0800 | [diff] [blame] | 983 | << "::descriptor]\n"; |
| 984 | out.indent(2, [&] { |
| 985 | out << "= [](void *iIntf) -> ::android::sp<" |
| 986 | << gIBaseFqName.cppName() |
| 987 | << "> {\n"; |
| 988 | out.indent([&] { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 989 | out << "return new " |
| 990 | << iface->getPassthroughName() |
| 991 | << "(reinterpret_cast<" |
| 992 | << iface->localName() |
Yifan Hong | 7a118f5 | 2016-12-07 11:21:15 -0800 | [diff] [blame] | 993 | << " *>(iIntf));\n"; |
| 994 | }); |
| 995 | out << "};\n"; |
| 996 | }); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 997 | out << "return 1;\n"; |
| 998 | }); |
| 999 | out << "}();\n\n"; |
| 1000 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1001 | err = generateInterfaceSource(out); |
| 1002 | } |
| 1003 | |
| 1004 | if (err == OK && isInterface) { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1005 | err = generateProxySource(out, iface->fqName()); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | if (err == OK && isInterface) { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1009 | err = generateStubSource(out, iface); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1012 | if (err == OK && isInterface) { |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1013 | err = generatePassthroughSource(out); |
| 1014 | } |
| 1015 | |
| 1016 | if (err == OK && isInterface) { |
Steven Moreland | 9c38761 | 2016-09-07 09:54:26 -0700 | [diff] [blame] | 1017 | const Interface *iface = mRootScope->getInterface(); |
| 1018 | |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1019 | if (isIBase()) { |
Yifan Hong | 83c8e5f | 2016-12-13 14:33:53 -0800 | [diff] [blame] | 1020 | out << "// skipped getService, registerAsService, registerForNotifications\n"; |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1021 | } else { |
Yifan Hong | 83c8e5f | 2016-12-13 14:33:53 -0800 | [diff] [blame] | 1022 | std::string package = iface->fqName().package() |
| 1023 | + iface->fqName().atVersion(); |
| 1024 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1025 | implementServiceManagerInteractions(out, iface->fqName(), package); |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1026 | } |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1029 | enterLeaveNamespace(out, false /* enter */); |
| 1030 | |
| 1031 | return err; |
| 1032 | } |
| 1033 | |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1034 | // static |
| 1035 | void AST::generateCheckNonNull(Formatter &out, const std::string &nonNull) { |
Yifan Hong | a018ed5 | 2016-12-13 16:35:08 -0800 | [diff] [blame] | 1036 | out.sIf(nonNull + " == nullptr", [&] { |
| 1037 | out << "return ::android::hardware::Status::fromExceptionCode(\n"; |
| 1038 | out.indent(2, [&] { |
| 1039 | out << "::android::hardware::Status::EX_ILLEGAL_ARGUMENT);\n"; |
| 1040 | }); |
| 1041 | }).endl().endl(); |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1044 | status_t AST::generateTypeSource( |
| 1045 | Formatter &out, const std::string &ifaceName) const { |
| 1046 | return mRootScope->emitTypeDefinitions(out, ifaceName); |
| 1047 | } |
| 1048 | |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1049 | void AST::declareCppReaderLocals( |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1050 | Formatter &out, |
| 1051 | const std::vector<TypedVar *> &args, |
| 1052 | bool forResults) const { |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1053 | if (args.empty()) { |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | for (const auto &arg : args) { |
| 1058 | const Type &type = arg->type(); |
| 1059 | |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1060 | out << type.getCppResultType() |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1061 | << " " |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1062 | << (forResults ? "_hidl_out_" : "") + arg->name() |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1063 | << ";\n"; |
| 1064 | } |
| 1065 | |
| 1066 | out << "\n"; |
| 1067 | } |
| 1068 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1069 | void AST::emitCppReaderWriter( |
| 1070 | Formatter &out, |
| 1071 | const std::string &parcelObj, |
| 1072 | bool parcelObjIsPointer, |
| 1073 | const TypedVar *arg, |
| 1074 | bool isReader, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1075 | Type::ErrorMode mode, |
| 1076 | bool addPrefixToName) const { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1077 | const Type &type = arg->type(); |
| 1078 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1079 | type.emitReaderWriter( |
| 1080 | out, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1081 | addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(), |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1082 | parcelObj, |
| 1083 | parcelObjIsPointer, |
| 1084 | isReader, |
| 1085 | mode); |
| 1086 | } |
| 1087 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1088 | void AST::emitCppResolveReferences( |
| 1089 | Formatter &out, |
| 1090 | const std::string &parcelObj, |
| 1091 | bool parcelObjIsPointer, |
| 1092 | const TypedVar *arg, |
| 1093 | bool isReader, |
| 1094 | Type::ErrorMode mode, |
| 1095 | bool addPrefixToName) const { |
| 1096 | const Type &type = arg->type(); |
| 1097 | if(type.needsResolveReferences()) { |
| 1098 | type.emitResolveReferences( |
| 1099 | out, |
| 1100 | addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(), |
| 1101 | isReader, // nameIsPointer |
| 1102 | parcelObj, |
| 1103 | parcelObjIsPointer, |
| 1104 | isReader, |
| 1105 | mode); |
| 1106 | } |
| 1107 | } |
| 1108 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1109 | status_t AST::generateProxyMethodSource(Formatter &out, |
| 1110 | const std::string &klassName, |
| 1111 | const Method *method, |
| 1112 | const Interface *superInterface) const { |
| 1113 | |
| 1114 | method->generateCppSignature(out, |
| 1115 | klassName, |
| 1116 | true /* specify namespaces */); |
| 1117 | |
| 1118 | const bool returnsValue = !method->results().empty(); |
| 1119 | const TypedVar *elidedReturn = method->canElideCallback(); |
| 1120 | |
Steven Moreland | 41c6d2e | 2016-11-07 12:26:54 -0800 | [diff] [blame] | 1121 | out << " {\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1122 | |
| 1123 | out.indent(); |
| 1124 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 1125 | if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) { |
| 1126 | method->cppImpl(IMPL_PROXY, out); |
| 1127 | out.unindent(); |
| 1128 | out << "}\n\n"; |
| 1129 | return OK; |
| 1130 | } |
| 1131 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1132 | if (returnsValue && elidedReturn == nullptr) { |
| 1133 | generateCheckNonNull(out, "_hidl_cb"); |
| 1134 | } |
| 1135 | |
| 1136 | status_t status = generateCppInstrumentationCall( |
| 1137 | out, |
| 1138 | InstrumentationEvent::CLIENT_API_ENTRY, |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1139 | method); |
| 1140 | if (status != OK) { |
| 1141 | return status; |
| 1142 | } |
| 1143 | |
| 1144 | out << "::android::hardware::Parcel _hidl_data;\n"; |
| 1145 | out << "::android::hardware::Parcel _hidl_reply;\n"; |
| 1146 | out << "::android::status_t _hidl_err;\n"; |
| 1147 | out << "::android::hardware::Status _hidl_status;\n\n"; |
| 1148 | |
| 1149 | declareCppReaderLocals( |
| 1150 | out, method->results(), true /* forResults */); |
| 1151 | |
| 1152 | out << "_hidl_err = _hidl_data.writeInterfaceToken("; |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1153 | out << superInterface->fqName().cppName(); |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1154 | out << "::descriptor);\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1155 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1156 | |
Martijn Coenen | fff7335 | 2017-01-04 16:36:31 +0100 | [diff] [blame] | 1157 | bool hasInterfaceArgument = false; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1158 | // First DFS: write all buffers and resolve pointers for parent |
| 1159 | for (const auto &arg : method->args()) { |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 1160 | if (arg->type().isInterface()) { |
| 1161 | hasInterfaceArgument = true; |
| 1162 | } |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1163 | emitCppReaderWriter( |
| 1164 | out, |
| 1165 | "_hidl_data", |
| 1166 | false /* parcelObjIsPointer */, |
| 1167 | arg, |
| 1168 | false /* reader */, |
| 1169 | Type::ErrorMode_Goto, |
| 1170 | false /* addPrefixToName */); |
| 1171 | } |
| 1172 | |
| 1173 | // Second DFS: resolve references. |
| 1174 | for (const auto &arg : method->args()) { |
| 1175 | emitCppResolveReferences( |
| 1176 | out, |
| 1177 | "_hidl_data", |
| 1178 | false /* parcelObjIsPointer */, |
| 1179 | arg, |
| 1180 | false /* reader */, |
| 1181 | Type::ErrorMode_Goto, |
| 1182 | false /* addPrefixToName */); |
| 1183 | } |
| 1184 | |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 1185 | if (hasInterfaceArgument) { |
| 1186 | // Start binder threadpool to handle incoming transactions |
| 1187 | out << "::android::hardware::ProcessState::self()->startThreadPool();\n"; |
| 1188 | } |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1189 | out << "_hidl_err = remote()->transact(" |
| 1190 | << method->getSerialId() |
| 1191 | << " /* " |
| 1192 | << method->name() |
| 1193 | << " */, _hidl_data, &_hidl_reply"; |
| 1194 | |
| 1195 | if (method->isOneway()) { |
| 1196 | out << ", ::android::hardware::IBinder::FLAG_ONEWAY"; |
| 1197 | } |
| 1198 | out << ");\n"; |
| 1199 | |
| 1200 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1201 | |
| 1202 | if (!method->isOneway()) { |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1203 | out << "_hidl_err = ::android::hardware::readFromParcel(&_hidl_status, _hidl_reply);\n"; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1204 | out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n"; |
| 1205 | out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n"; |
| 1206 | |
| 1207 | |
| 1208 | // First DFS: write all buffers and resolve pointers for parent |
| 1209 | for (const auto &arg : method->results()) { |
| 1210 | emitCppReaderWriter( |
| 1211 | out, |
| 1212 | "_hidl_reply", |
| 1213 | false /* parcelObjIsPointer */, |
| 1214 | arg, |
| 1215 | true /* reader */, |
| 1216 | Type::ErrorMode_Goto, |
| 1217 | true /* addPrefixToName */); |
| 1218 | } |
| 1219 | |
| 1220 | // Second DFS: resolve references. |
| 1221 | for (const auto &arg : method->results()) { |
| 1222 | emitCppResolveReferences( |
| 1223 | out, |
| 1224 | "_hidl_reply", |
| 1225 | false /* parcelObjIsPointer */, |
| 1226 | arg, |
| 1227 | true /* reader */, |
| 1228 | Type::ErrorMode_Goto, |
| 1229 | true /* addPrefixToName */); |
| 1230 | } |
| 1231 | |
| 1232 | if (returnsValue && elidedReturn == nullptr) { |
| 1233 | out << "_hidl_cb("; |
| 1234 | |
| 1235 | bool first = true; |
| 1236 | for (const auto &arg : method->results()) { |
| 1237 | if (!first) { |
| 1238 | out << ", "; |
| 1239 | } |
| 1240 | |
| 1241 | if (arg->type().resultNeedsDeref()) { |
| 1242 | out << "*"; |
| 1243 | } |
| 1244 | out << "_hidl_out_" << arg->name(); |
| 1245 | |
| 1246 | first = false; |
| 1247 | } |
| 1248 | |
| 1249 | out << ");\n\n"; |
| 1250 | } |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1251 | } |
| 1252 | status = generateCppInstrumentationCall( |
| 1253 | out, |
| 1254 | InstrumentationEvent::CLIENT_API_EXIT, |
| 1255 | method); |
| 1256 | if (status != OK) { |
| 1257 | return status; |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | if (elidedReturn != nullptr) { |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1261 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1262 | out << "return ::android::hardware::Return<"; |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1263 | out << elidedReturn->type().getCppResultType() |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1264 | << ">(_hidl_out_" << elidedReturn->name() << ");\n\n"; |
| 1265 | } else { |
| 1266 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1267 | out << "return ::android::hardware::Return<void>();\n\n"; |
| 1268 | } |
| 1269 | |
| 1270 | out.unindent(); |
| 1271 | out << "_hidl_error:\n"; |
| 1272 | out.indent(); |
| 1273 | out << "_hidl_status.setFromStatusT(_hidl_err);\n"; |
| 1274 | out << "return ::android::hardware::Return<"; |
| 1275 | if (elidedReturn != nullptr) { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1276 | out << method->results().at(0)->type().getCppResultType(); |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1277 | } else { |
| 1278 | out << "void"; |
| 1279 | } |
| 1280 | out << ">(_hidl_status);\n"; |
| 1281 | |
| 1282 | out.unindent(); |
| 1283 | out << "}\n\n"; |
| 1284 | return OK; |
| 1285 | } |
| 1286 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1287 | status_t AST::generateProxySource( |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1288 | Formatter &out, const FQName &fqName) const { |
| 1289 | const std::string klassName = fqName.getInterfaceProxyName(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1290 | |
| 1291 | out << klassName |
| 1292 | << "::" |
| 1293 | << klassName |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1294 | << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1295 | |
| 1296 | out.indent(); |
| 1297 | out.indent(); |
| 1298 | |
| 1299 | out << ": BpInterface" |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1300 | << "<" |
| 1301 | << fqName.getInterfaceName() |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1302 | << ">(_hidl_impl),\n" |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1303 | << " ::android::hardware::HidlInstrumentor(\"" |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1304 | << mPackage.string() |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1305 | << "::" |
| 1306 | << fqName.getInterfaceName() |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1307 | << "\") {\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1308 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1309 | out.unindent(); |
| 1310 | out.unindent(); |
| 1311 | out << "}\n\n"; |
| 1312 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1313 | status_t err = generateMethods(out, [&](const Method *method, const Interface *superInterface) { |
| 1314 | return generateProxyMethodSource(out, klassName, method, superInterface); |
| 1315 | }); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1316 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1317 | return err; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | status_t AST::generateStubSource( |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1321 | Formatter &out, |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1322 | const Interface *iface) const { |
| 1323 | const std::string interfaceName = iface->localName(); |
| 1324 | const std::string klassName = iface->getStubName(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1325 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1326 | out << klassName |
| 1327 | << "::" |
| 1328 | << klassName |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1329 | << "(const ::android::sp<" << interfaceName <<"> &_hidl_impl)\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1330 | |
| 1331 | out.indent(); |
| 1332 | out.indent(); |
| 1333 | |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1334 | if (iface->isIBase()) { |
| 1335 | out << ": ::android::hardware::HidlInstrumentor(\""; |
| 1336 | } else { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1337 | out << ": " |
| 1338 | << gIBaseFqName.getInterfaceStubFqName().cppName() |
| 1339 | << "(_hidl_impl, \""; |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | out << mPackage.string() |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1343 | << "::" |
| 1344 | << interfaceName |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1345 | << "\") { \n"; |
| 1346 | out.indent(); |
| 1347 | out << "_hidl_mImpl = _hidl_impl;\n"; |
| 1348 | out.unindent(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 1349 | |
| 1350 | out.unindent(); |
| 1351 | out.unindent(); |
| 1352 | out << "}\n\n"; |
| 1353 | |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1354 | if (iface->isIBase()) { |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 1355 | // BnHwBase has a constructor to initialize the HidlInstrumentor |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1356 | // class properly. |
| 1357 | out << klassName |
| 1358 | << "::" |
| 1359 | << klassName |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1360 | << "(const ::android::sp<" << interfaceName <<"> &_hidl_impl," |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1361 | << " const std::string &prefix)\n"; |
| 1362 | |
| 1363 | out.indent(); |
| 1364 | out.indent(); |
| 1365 | |
| 1366 | out << ": ::android::hardware::HidlInstrumentor(prefix) { \n"; |
| 1367 | out.indent(); |
| 1368 | out << "_hidl_mImpl = _hidl_impl;\n"; |
| 1369 | out.unindent(); |
| 1370 | |
| 1371 | out.unindent(); |
| 1372 | out.unindent(); |
| 1373 | out << "}\n\n"; |
| 1374 | } |
| 1375 | |
| 1376 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1377 | out << "::android::status_t " << klassName << "::onTransact(\n"; |
| 1378 | |
| 1379 | out.indent(); |
| 1380 | out.indent(); |
| 1381 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1382 | out << "uint32_t _hidl_code,\n" |
| 1383 | << "const ::android::hardware::Parcel &_hidl_data,\n" |
| 1384 | << "::android::hardware::Parcel *_hidl_reply,\n" |
| 1385 | << "uint32_t _hidl_flags,\n" |
| 1386 | << "TransactCallback _hidl_cb) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1387 | |
| 1388 | out.unindent(); |
| 1389 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1390 | out << "::android::status_t _hidl_err = ::android::OK;\n\n"; |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1391 | out << "switch (_hidl_code) {\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1392 | out.indent(); |
| 1393 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1394 | for (const auto &tuple : iface->allMethodsFromRoot()) { |
| 1395 | const Method *method = tuple.method(); |
| 1396 | const Interface *superInterface = tuple.interface(); |
| 1397 | out << "case " |
| 1398 | << method->getSerialId() |
| 1399 | << " /* " |
| 1400 | << method->name() |
| 1401 | << " */:\n{\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1402 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1403 | out.indent(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1404 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1405 | status_t err = |
| 1406 | generateStubSourceForMethod(out, superInterface, method); |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1407 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1408 | if (err != OK) { |
| 1409 | return err; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1410 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 1411 | |
| 1412 | out.unindent(); |
| 1413 | out << "}\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | out << "default:\n{\n"; |
| 1417 | out.indent(); |
| 1418 | |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1419 | out << "return onTransact(\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1420 | |
| 1421 | out.indent(); |
| 1422 | out.indent(); |
| 1423 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1424 | out << "_hidl_code, _hidl_data, _hidl_reply, " |
| 1425 | << "_hidl_flags, _hidl_cb);\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1426 | |
| 1427 | out.unindent(); |
| 1428 | out.unindent(); |
| 1429 | |
| 1430 | out.unindent(); |
| 1431 | out << "}\n"; |
| 1432 | |
| 1433 | out.unindent(); |
| 1434 | out << "}\n\n"; |
| 1435 | |
Yifan Hong | a018ed5 | 2016-12-13 16:35:08 -0800 | [diff] [blame] | 1436 | out.sIf("_hidl_err == ::android::UNEXPECTED_NULL", [&] { |
| 1437 | out << "_hidl_err = ::android::hardware::writeToParcel(\n"; |
| 1438 | out.indent(2, [&] { |
| 1439 | out << "::android::hardware::Status::fromExceptionCode(::android::hardware::Status::EX_NULL_POINTER),\n"; |
| 1440 | out << "_hidl_reply);\n"; |
| 1441 | }); |
| 1442 | }); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1443 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1444 | out << "return _hidl_err;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1445 | |
| 1446 | out.unindent(); |
| 1447 | out << "}\n\n"; |
| 1448 | |
| 1449 | return OK; |
| 1450 | } |
| 1451 | |
| 1452 | status_t AST::generateStubSourceForMethod( |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1453 | Formatter &out, const Interface *iface, const Method *method) const { |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 1454 | if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB)) { |
| 1455 | method->cppImpl(IMPL_STUB, out); |
| 1456 | out << "break;\n"; |
| 1457 | return OK; |
| 1458 | } |
| 1459 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1460 | out << "if (!_hidl_data.enforceInterface(" |
| 1461 | << iface->fullName() |
| 1462 | << "::descriptor)) {\n"; |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1463 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1464 | out.indent(); |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1465 | out << "_hidl_err = ::android::BAD_TYPE;\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1466 | out << "break;\n"; |
| 1467 | out.unindent(); |
| 1468 | out << "}\n\n"; |
| 1469 | |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1470 | declareCppReaderLocals(out, method->args(), false /* forResults */); |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 1471 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1472 | // First DFS: write buffers |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1473 | for (const auto &arg : method->args()) { |
| 1474 | emitCppReaderWriter( |
| 1475 | out, |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1476 | "_hidl_data", |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1477 | false /* parcelObjIsPointer */, |
| 1478 | arg, |
| 1479 | true /* reader */, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1480 | Type::ErrorMode_Break, |
| 1481 | false /* addPrefixToName */); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1484 | // Second DFS: resolve references |
| 1485 | for (const auto &arg : method->args()) { |
| 1486 | emitCppResolveReferences( |
| 1487 | out, |
| 1488 | "_hidl_data", |
| 1489 | false /* parcelObjIsPointer */, |
| 1490 | arg, |
| 1491 | true /* reader */, |
| 1492 | Type::ErrorMode_Break, |
| 1493 | false /* addPrefixToName */); |
| 1494 | } |
| 1495 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1496 | status_t status = generateCppInstrumentationCall( |
| 1497 | out, |
| 1498 | InstrumentationEvent::SERVER_API_ENTRY, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1499 | method); |
| 1500 | if (status != OK) { |
| 1501 | return status; |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1504 | const bool returnsValue = !method->results().empty(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1505 | const TypedVar *elidedReturn = method->canElideCallback(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1506 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1507 | if (elidedReturn != nullptr) { |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1508 | out << elidedReturn->type().getCppResultType() |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1509 | << " _hidl_out_" |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1510 | << elidedReturn->name() |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1511 | << " = " |
| 1512 | << "_hidl_mImpl->" << method->name() |
Yifan Hong | 3b320f8 | 2016-11-01 15:15:54 -0700 | [diff] [blame] | 1513 | << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1514 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1515 | bool first = true; |
| 1516 | for (const auto &arg : method->args()) { |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1517 | if (!first) { |
| 1518 | out << ", "; |
| 1519 | } |
| 1520 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1521 | if (arg->type().resultNeedsDeref()) { |
| 1522 | out << "*"; |
| 1523 | } |
| 1524 | |
| 1525 | out << arg->name(); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1526 | |
| 1527 | first = false; |
| 1528 | } |
| 1529 | |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 1530 | out << ");\n\n"; |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1531 | out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), " |
| 1532 | << "_hidl_reply);\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1533 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1534 | elidedReturn->type().emitReaderWriter( |
| 1535 | out, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1536 | "_hidl_out_" + elidedReturn->name(), |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1537 | "_hidl_reply", |
| 1538 | true, /* parcelObjIsPointer */ |
| 1539 | false, /* isReader */ |
| 1540 | Type::ErrorMode_Ignore); |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1541 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1542 | emitCppResolveReferences( |
| 1543 | out, |
| 1544 | "_hidl_reply", |
| 1545 | true /* parcelObjIsPointer */, |
| 1546 | elidedReturn, |
| 1547 | false /* reader */, |
| 1548 | Type::ErrorMode_Ignore, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1549 | true /* addPrefixToName */); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1550 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1551 | status_t status = generateCppInstrumentationCall( |
| 1552 | out, |
| 1553 | InstrumentationEvent::SERVER_API_EXIT, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1554 | method); |
| 1555 | if (status != OK) { |
| 1556 | return status; |
| 1557 | } |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1558 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 1559 | out << "_hidl_cb(*_hidl_reply);\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1560 | } else { |
| 1561 | if (returnsValue) { |
| 1562 | out << "bool _hidl_callbackCalled = false;\n\n"; |
| 1563 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1564 | |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1565 | out << "_hidl_mImpl->" << method->name() << "("; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1566 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1567 | bool first = true; |
| 1568 | for (const auto &arg : method->args()) { |
| 1569 | if (!first) { |
| 1570 | out << ", "; |
| 1571 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1572 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1573 | if (arg->type().resultNeedsDeref()) { |
| 1574 | out << "*"; |
| 1575 | } |
| 1576 | |
| 1577 | out << arg->name(); |
| 1578 | |
| 1579 | first = false; |
| 1580 | } |
| 1581 | |
| 1582 | if (returnsValue) { |
| 1583 | if (!first) { |
| 1584 | out << ", "; |
| 1585 | } |
| 1586 | |
| 1587 | out << "[&]("; |
| 1588 | |
| 1589 | first = true; |
| 1590 | for (const auto &arg : method->results()) { |
| 1591 | if (!first) { |
| 1592 | out << ", "; |
| 1593 | } |
| 1594 | |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1595 | out << "const auto &_hidl_out_" << arg->name(); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1596 | |
| 1597 | first = false; |
| 1598 | } |
| 1599 | |
| 1600 | out << ") {\n"; |
| 1601 | out.indent(); |
Steven Moreland | 05cd423 | 2016-11-21 16:01:12 -0800 | [diff] [blame] | 1602 | out << "if (_hidl_callbackCalled) {\n"; |
| 1603 | out.indent(); |
| 1604 | out << "LOG_ALWAYS_FATAL(\"" |
| 1605 | << method->name() |
| 1606 | << ": _hidl_cb called a second time, but must be called once.\");\n"; |
| 1607 | out.unindent(); |
| 1608 | out << "}\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1609 | out << "_hidl_callbackCalled = true;\n\n"; |
| 1610 | |
Yifan Hong | 859e53f | 2016-11-14 19:08:24 -0800 | [diff] [blame] | 1611 | out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), " |
| 1612 | << "_hidl_reply);\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1613 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1614 | // First DFS: buffers |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1615 | for (const auto &arg : method->results()) { |
| 1616 | emitCppReaderWriter( |
| 1617 | out, |
| 1618 | "_hidl_reply", |
| 1619 | true /* parcelObjIsPointer */, |
| 1620 | arg, |
| 1621 | false /* reader */, |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1622 | Type::ErrorMode_Ignore, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1623 | true /* addPrefixToName */); |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1626 | // Second DFS: resolve references |
| 1627 | for (const auto &arg : method->results()) { |
| 1628 | emitCppResolveReferences( |
| 1629 | out, |
| 1630 | "_hidl_reply", |
| 1631 | true /* parcelObjIsPointer */, |
| 1632 | arg, |
| 1633 | false /* reader */, |
| 1634 | Type::ErrorMode_Ignore, |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1635 | true /* addPrefixToName */); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1638 | status_t status = generateCppInstrumentationCall( |
| 1639 | out, |
| 1640 | InstrumentationEvent::SERVER_API_EXIT, |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1641 | method); |
| 1642 | if (status != OK) { |
| 1643 | return status; |
Zhuoyao Zhang | de57800 | 2016-09-07 18:24:17 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1646 | out << "_hidl_cb(*_hidl_reply);\n"; |
| 1647 | |
| 1648 | out.unindent(); |
Martijn Coenen | 8e4fc84 | 2017-01-09 16:28:59 +0100 | [diff] [blame] | 1649 | out << "});\n\n"; |
| 1650 | } else { |
| 1651 | out << ");\n\n"; |
| 1652 | status_t status = generateCppInstrumentationCall( |
| 1653 | out, |
| 1654 | InstrumentationEvent::SERVER_API_EXIT, |
| 1655 | method); |
| 1656 | if (status != OK) { |
| 1657 | return status; |
| 1658 | } |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1659 | } |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame] | 1660 | |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1661 | if (returnsValue) { |
| 1662 | out << "if (!_hidl_callbackCalled) {\n"; |
| 1663 | out.indent(); |
Steven Moreland | 05cd423 | 2016-11-21 16:01:12 -0800 | [diff] [blame] | 1664 | out << "LOG_ALWAYS_FATAL(\"" |
| 1665 | << method->name() |
| 1666 | << ": _hidl_cb not called, but must be called once.\");\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1667 | out.unindent(); |
| 1668 | out << "}\n\n"; |
Steven Moreland | 05cd423 | 2016-11-21 16:01:12 -0800 | [diff] [blame] | 1669 | } else { |
| 1670 | out << "::android::hardware::writeToParcel(" |
| 1671 | << "::android::hardware::Status::ok(), " |
| 1672 | << "_hidl_reply);\n\n"; |
Iliyan Malchev | 40d474a | 2016-08-16 06:20:17 -0700 | [diff] [blame] | 1673 | } |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | out << "break;\n"; |
| 1677 | |
| 1678 | return OK; |
| 1679 | } |
| 1680 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1681 | status_t AST::generatePassthroughHeader(const std::string &outputPath) const { |
| 1682 | std::string ifaceName; |
| 1683 | if (!AST::isInterface(&ifaceName)) { |
| 1684 | // types.hal does not get a stub header. |
| 1685 | return OK; |
| 1686 | } |
| 1687 | |
| 1688 | const Interface *iface = mRootScope->getInterface(); |
| 1689 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1690 | const std::string klassName = iface->getPassthroughName(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1691 | |
| 1692 | bool supportOneway = iface->hasOnewayMethods(); |
| 1693 | |
| 1694 | std::string path = outputPath; |
| 1695 | path.append(mCoordinator->convertPackageRootToPath(mPackage)); |
| 1696 | path.append(mCoordinator->getPackagePath(mPackage, true /* relative */)); |
| 1697 | path.append(klassName); |
| 1698 | path.append(".h"); |
| 1699 | |
| 1700 | CHECK(Coordinator::MakeParentHierarchy(path)); |
| 1701 | FILE *file = fopen(path.c_str(), "w"); |
| 1702 | |
| 1703 | if (file == NULL) { |
| 1704 | return -errno; |
| 1705 | } |
| 1706 | |
| 1707 | Formatter out(file); |
| 1708 | |
| 1709 | const std::string guard = makeHeaderGuard(klassName); |
| 1710 | |
| 1711 | out << "#ifndef " << guard << "\n"; |
| 1712 | out << "#define " << guard << "\n\n"; |
| 1713 | |
| 1714 | std::vector<std::string> packageComponents; |
| 1715 | getPackageAndVersionComponents( |
| 1716 | &packageComponents, false /* cpp_compatible */); |
| 1717 | |
Yifan Hong | b094943 | 2016-12-15 15:32:24 -0800 | [diff] [blame] | 1718 | out << "#include <cutils/trace.h>\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1719 | out << "#include <future>\n"; |
Steven Moreland | ee88eed | 2016-10-31 17:49:00 -0700 | [diff] [blame] | 1720 | |
| 1721 | generateCppPackageInclude(out, mPackage, ifaceName); |
| 1722 | out << "\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1723 | |
Yifan Hong | 7a118f5 | 2016-12-07 11:21:15 -0800 | [diff] [blame] | 1724 | out << "#include <hidl/HidlPassthroughSupport.h>\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1725 | if (supportOneway) { |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1726 | out << "#include <hidl/TaskRunner.h>\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | enterLeaveNamespace(out, true /* enter */); |
| 1730 | out << "\n"; |
| 1731 | |
| 1732 | out << "struct " |
| 1733 | << klassName |
| 1734 | << " : " << ifaceName |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1735 | << ", ::android::hardware::HidlInstrumentor {\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1736 | |
| 1737 | out.indent(); |
| 1738 | out << "explicit " |
| 1739 | << klassName |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1740 | << "(const ::android::sp<" |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1741 | << ifaceName |
| 1742 | << "> impl);\n"; |
| 1743 | |
Yifan Hong | 068c552 | 2016-10-31 14:07:25 -0700 | [diff] [blame] | 1744 | status_t err = generateMethods(out, [&](const Method *method, const Interface *) { |
| 1745 | return generatePassthroughMethod(out, method); |
| 1746 | }); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1747 | |
| 1748 | if (err != OK) { |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | out.unindent(); |
| 1753 | out << "private:\n"; |
| 1754 | out.indent(); |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1755 | out << "const ::android::sp<" << ifaceName << "> mImpl;\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1756 | |
| 1757 | if (supportOneway) { |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1758 | out << "::android::hardware::TaskRunner mOnewayQueue;\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1759 | |
| 1760 | out << "\n"; |
| 1761 | |
| 1762 | out << "::android::hardware::Return<void> addOnewayTask(" |
| 1763 | "std::function<void(void)>);\n\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | out.unindent(); |
| 1767 | |
| 1768 | out << "};\n\n"; |
| 1769 | |
| 1770 | enterLeaveNamespace(out, false /* enter */); |
| 1771 | |
| 1772 | out << "\n#endif // " << guard << "\n"; |
| 1773 | |
| 1774 | return OK; |
| 1775 | } |
| 1776 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1777 | status_t AST::generateInterfaceSource(Formatter &out) const { |
| 1778 | const Interface *iface = mRootScope->getInterface(); |
| 1779 | |
Yifan Hong | 2d7126b | 2016-10-20 15:12:57 -0700 | [diff] [blame] | 1780 | // generate castFrom functions |
Yifan Hong | 3d74609 | 2016-12-07 14:26:33 -0800 | [diff] [blame] | 1781 | std::string childTypeResult = iface->getCppResultType(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1782 | |
Yifan Hong | 3d74609 | 2016-12-07 14:26:33 -0800 | [diff] [blame] | 1783 | for (const Interface *superType : iface->typeChain()) { |
| 1784 | out << "// static \n" |
| 1785 | << childTypeResult |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1786 | << " " |
| 1787 | << iface->localName() |
Yifan Hong | 3d74609 | 2016-12-07 14:26:33 -0800 | [diff] [blame] | 1788 | << "::castFrom(" |
| 1789 | << superType->getCppArgumentType() |
| 1790 | << " parent) {\n"; |
| 1791 | out.indent(); |
| 1792 | if (iface == superType) { |
| 1793 | out << "return parent;\n"; |
| 1794 | } else { |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1795 | out << "return ::android::hardware::castInterface<"; |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1796 | out << iface->localName() << ", " |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1797 | << superType->fqName().cppName() << ", " |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1798 | << iface->getProxyName() << ", " |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 1799 | << superType->getProxyFqName().cppName() |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1800 | << ">(\n"; |
| 1801 | out.indent(); |
| 1802 | out.indent(); |
| 1803 | out << "parent, \"" |
| 1804 | << iface->fqName().string() |
| 1805 | << "\");\n"; |
| 1806 | out.unindent(); |
| 1807 | out.unindent(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1808 | } |
Yifan Hong | 3d74609 | 2016-12-07 14:26:33 -0800 | [diff] [blame] | 1809 | out.unindent(); |
| 1810 | out << "}\n\n"; |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | return OK; |
| 1814 | } |
| 1815 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1816 | status_t AST::generatePassthroughSource(Formatter &out) const { |
| 1817 | const Interface *iface = mRootScope->getInterface(); |
| 1818 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1819 | const std::string klassName = iface->getPassthroughName(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1820 | |
| 1821 | out << klassName |
| 1822 | << "::" |
| 1823 | << klassName |
Steven Moreland | c46e984 | 2016-11-02 13:21:26 -0700 | [diff] [blame] | 1824 | << "(const ::android::sp<" |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1825 | << iface->fullName() |
Steven Moreland | 19d5c17 | 2016-10-20 19:20:25 -0700 | [diff] [blame] | 1826 | << "> impl) : ::android::hardware::HidlInstrumentor(\"" |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1827 | << iface->fqName().string() |
| 1828 | << "\"), mImpl(impl) {"; |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1829 | if (iface->hasOnewayMethods()) { |
| 1830 | out << "\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 1831 | out.indent([&] { |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1832 | out << "mOnewayQueue.setLimit(3000 /* similar limit to binderized */);\n"; |
| 1833 | }); |
| 1834 | } |
| 1835 | out << "}\n\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1836 | |
| 1837 | if (iface->hasOnewayMethods()) { |
| 1838 | out << "::android::hardware::Return<void> " |
| 1839 | << klassName |
| 1840 | << "::addOnewayTask(std::function<void(void)> fun) {\n"; |
| 1841 | out.indent(); |
Yifan Hong | 2cbc147 | 2016-10-25 19:02:40 -0700 | [diff] [blame] | 1842 | out << "if (!mOnewayQueue.push(fun)) {\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1843 | out.indent(); |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1844 | out << "return ::android::hardware::Status::fromExceptionCode(\n"; |
| 1845 | out.indent(); |
| 1846 | out.indent(); |
| 1847 | out << "::android::hardware::Status::EX_TRANSACTION_FAILED);\n"; |
| 1848 | out.unindent(); |
| 1849 | out.unindent(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1850 | out.unindent(); |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1851 | out << "}\n"; |
| 1852 | |
Steven Moreland | d366c26 | 2016-10-11 15:29:10 -0700 | [diff] [blame] | 1853 | out << "return ::android::hardware::Status();\n"; |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 1854 | |
| 1855 | out.unindent(); |
| 1856 | out << "}\n\n"; |
| 1857 | |
| 1858 | |
| 1859 | } |
| 1860 | |
| 1861 | return OK; |
| 1862 | } |
| 1863 | |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1864 | status_t AST::generateCppAtraceCall(Formatter &out, |
| 1865 | InstrumentationEvent event, |
| 1866 | const Method *method) const { |
| 1867 | const Interface *iface = mRootScope->getInterface(); |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 1868 | std::string baseString = "HIDL::" + iface->localName() + "::" + method->name(); |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1869 | switch (event) { |
| 1870 | case SERVER_API_ENTRY: |
| 1871 | { |
| 1872 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1873 | << baseString + "::server\");\n"; |
| 1874 | break; |
| 1875 | } |
| 1876 | case CLIENT_API_ENTRY: |
| 1877 | { |
| 1878 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1879 | << baseString + "::client\");\n"; |
| 1880 | break; |
| 1881 | } |
| 1882 | case PASSTHROUGH_ENTRY: |
| 1883 | { |
| 1884 | out << "atrace_begin(ATRACE_TAG_HAL, \"" |
| 1885 | << baseString + "::passthrough\");\n"; |
| 1886 | break; |
| 1887 | } |
| 1888 | case SERVER_API_EXIT: |
| 1889 | case CLIENT_API_EXIT: |
| 1890 | case PASSTHROUGH_EXIT: |
| 1891 | { |
| 1892 | out << "atrace_end(ATRACE_TAG_HAL);\n"; |
| 1893 | break; |
| 1894 | } |
| 1895 | default: |
| 1896 | { |
| 1897 | LOG(ERROR) << "Unsupported instrumentation event: " << event; |
| 1898 | return UNKNOWN_ERROR; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | return OK; |
| 1903 | } |
| 1904 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1905 | status_t AST::generateCppInstrumentationCall( |
| 1906 | Formatter &out, |
| 1907 | InstrumentationEvent event, |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1908 | const Method *method) const { |
Martijn Coenen | 7b29524 | 2016-11-04 16:52:56 +0100 | [diff] [blame] | 1909 | status_t err = generateCppAtraceCall(out, event, method); |
| 1910 | if (err != OK) { |
| 1911 | return err; |
| 1912 | } |
| 1913 | |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1914 | out << "if (UNLIKELY(mEnableInstrumentation)) {\n"; |
| 1915 | out.indent(); |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1916 | out << "std::vector<void *> _hidl_args;\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1917 | std::string event_str = ""; |
| 1918 | switch (event) { |
| 1919 | case SERVER_API_ENTRY: |
| 1920 | { |
| 1921 | event_str = "InstrumentationEvent::SERVER_API_ENTRY"; |
| 1922 | for (const auto &arg : method->args()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1923 | out << "_hidl_args.push_back((void *)" |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1924 | << (arg->type().resultNeedsDeref() ? "" : "&") |
| 1925 | << arg->name() |
| 1926 | << ");\n"; |
| 1927 | } |
| 1928 | break; |
| 1929 | } |
| 1930 | case SERVER_API_EXIT: |
| 1931 | { |
| 1932 | event_str = "InstrumentationEvent::SERVER_API_EXIT"; |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1933 | for (const auto &arg : method->results()) { |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1934 | out << "_hidl_args.push_back((void *)&_hidl_out_" |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1935 | << arg->name() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1936 | << ");\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1937 | } |
| 1938 | break; |
| 1939 | } |
| 1940 | case CLIENT_API_ENTRY: |
| 1941 | { |
| 1942 | event_str = "InstrumentationEvent::CLIENT_API_ENTRY"; |
| 1943 | for (const auto &arg : method->args()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1944 | out << "_hidl_args.push_back((void *)&" |
| 1945 | << arg->name() |
| 1946 | << ");\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1947 | } |
| 1948 | break; |
| 1949 | } |
| 1950 | case CLIENT_API_EXIT: |
| 1951 | { |
| 1952 | event_str = "InstrumentationEvent::CLIENT_API_EXIT"; |
| 1953 | for (const auto &arg : method->results()) { |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1954 | out << "_hidl_args.push_back((void *)" |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1955 | << (arg->type().resultNeedsDeref() ? "" : "&") |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 1956 | << "_hidl_out_" |
| 1957 | << arg->name() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1958 | << ");\n"; |
| 1959 | } |
| 1960 | break; |
| 1961 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1962 | case PASSTHROUGH_ENTRY: |
| 1963 | { |
| 1964 | event_str = "InstrumentationEvent::PASSTHROUGH_ENTRY"; |
| 1965 | for (const auto &arg : method->args()) { |
| 1966 | out << "_hidl_args.push_back((void *)&" |
| 1967 | << arg->name() |
| 1968 | << ");\n"; |
| 1969 | } |
| 1970 | break; |
| 1971 | } |
| 1972 | case PASSTHROUGH_EXIT: |
| 1973 | { |
| 1974 | event_str = "InstrumentationEvent::PASSTHROUGH_EXIT"; |
Zhuoyao Zhang | 085a8c3 | 2016-11-17 15:35:49 -0800 | [diff] [blame] | 1975 | for (const auto &arg : method->results()) { |
Yifan Hong | a47eef3 | 2016-12-12 10:38:54 -0800 | [diff] [blame] | 1976 | out << "_hidl_args.push_back((void *)&_hidl_out_" |
Zhuoyao Zhang | 085a8c3 | 2016-11-17 15:35:49 -0800 | [diff] [blame] | 1977 | << arg->name() |
| 1978 | << ");\n"; |
| 1979 | } |
Steven Moreland | 9b1cbdf | 2016-11-01 12:23:27 -0700 | [diff] [blame] | 1980 | break; |
| 1981 | } |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1982 | default: |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1983 | { |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1984 | LOG(ERROR) << "Unsupported instrumentation event: " << event; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1985 | return UNKNOWN_ERROR; |
| 1986 | } |
| 1987 | } |
| 1988 | |
Steven Moreland | 031ccf1 | 2016-10-31 15:54:38 -0700 | [diff] [blame] | 1989 | const Interface *iface = mRootScope->getInterface(); |
| 1990 | |
Steven Moreland | 1ab3144 | 2016-11-03 18:37:51 -0700 | [diff] [blame] | 1991 | out << "for (const auto &callback: mInstrumentationCallbacks) {\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1992 | out.indent(); |
| 1993 | out << "callback(" |
| 1994 | << event_str |
| 1995 | << ", \"" |
| 1996 | << mPackage.package() |
| 1997 | << "\", \"" |
Yifan Hong | 90ea87f | 2016-11-01 14:25:47 -0700 | [diff] [blame] | 1998 | << mPackage.version() |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 1999 | << "\", \"" |
| 2000 | << iface->localName() |
| 2001 | << "\", \"" |
| 2002 | << method->name() |
Zhuoyao Zhang | 964f72f | 2016-10-21 11:12:03 -0700 | [diff] [blame] | 2003 | << "\", &_hidl_args);\n"; |
Zhuoyao Zhang | 8f49294 | 2016-09-28 14:27:56 -0700 | [diff] [blame] | 2004 | out.unindent(); |
| 2005 | out << "}\n"; |
| 2006 | out.unindent(); |
| 2007 | out << "}\n\n"; |
| 2008 | |
| 2009 | return OK; |
| 2010 | } |
| 2011 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 2012 | } // namespace android |