blob: 1c1ff88cd5062f2bc57ab472db8de95068b72bed [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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 Huber881227d2016-08-02 14:20:21 -070017#include "AST.h"
18
19#include "Coordinator.h"
Iliyan Malchev40d474a2016-08-16 06:20:17 -070020#include "EnumType.h"
Andreas Huber6755e9d2017-04-06 11:09:07 -070021#include "HidlTypeAssertion.h"
Timur Iskhakov7fa79f62017-08-09 11:04:54 -070022#include "Interface.h"
Neel Mehta291d02e2019-06-06 17:51:07 -070023#include "Location.h"
Andreas Huber881227d2016-08-02 14:20:21 -070024#include "Method.h"
Timur Iskhakov7fa79f62017-08-09 11:04:54 -070025#include "Reference.h"
Iliyan Malchev40d474a2016-08-16 06:20:17 -070026#include "ScalarType.h"
Andreas Huber881227d2016-08-02 14:20:21 -070027#include "Scope.h"
28
Andreas Huberdca261f2016-08-04 13:47:51 -070029#include <algorithm>
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070030#include <hidl-util/Formatter.h>
Steven Moreland5708edf2016-11-04 15:33:31 +000031#include <hidl-util/StringHelper.h>
Andreas Huber881227d2016-08-02 14:20:21 -070032#include <android-base/logging.h>
Andreas Huberdca261f2016-08-04 13:47:51 -070033#include <string>
Andreas Huber881227d2016-08-02 14:20:21 -070034#include <vector>
35
36namespace android {
37
Andreas Huber737080b2016-08-02 15:38:04 -070038void AST::getPackageComponents(
39 std::vector<std::string> *components) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070040 mPackage.getPackageComponents(components);
Andreas Huber737080b2016-08-02 15:38:04 -070041}
42
43void AST::getPackageAndVersionComponents(
44 std::vector<std::string> *components, bool cpp_compatible) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070045 mPackage.getPackageAndVersionComponents(components, cpp_compatible);
Andreas Huber737080b2016-08-02 15:38:04 -070046}
47
Steven Moreland5708edf2016-11-04 15:33:31 +000048std::string AST::makeHeaderGuard(const std::string &baseName,
49 bool indicateGenerated) const {
50 std::string guard;
Andreas Huber881227d2016-08-02 14:20:21 -070051
Steven Moreland5708edf2016-11-04 15:33:31 +000052 if (indicateGenerated) {
53 guard += "HIDL_GENERATED_";
54 }
55
56 guard += StringHelper::Uppercase(mPackage.tokenName());
Andreas Huber881227d2016-08-02 14:20:21 -070057 guard += "_";
Steven Moreland5708edf2016-11-04 15:33:31 +000058 guard += StringHelper::Uppercase(baseName);
59 guard += "_H";
Andreas Huber881227d2016-08-02 14:20:21 -070060
61 return guard;
62}
63
Steven Morelandee88eed2016-10-31 17:49:00 -070064void AST::generateCppPackageInclude(
65 Formatter &out,
66 const FQName &package,
67 const std::string &klass) {
68
69 out << "#include <";
70
71 std::vector<std::string> components;
72 package.getPackageAndVersionComponents(&components, false /* cpp_compatible */);
73
74 for (const auto &component : components) {
75 out << component << "/";
76 }
77
78 out << klass
79 << ".h>\n";
80}
81
Andreas Huber881227d2016-08-02 14:20:21 -070082void AST::enterLeaveNamespace(Formatter &out, bool enter) const {
83 std::vector<std::string> packageComponents;
84 getPackageAndVersionComponents(
85 &packageComponents, true /* cpp_compatible */);
86
87 if (enter) {
88 for (const auto &component : packageComponents) {
89 out << "namespace " << component << " {\n";
90 }
91 } else {
92 for (auto it = packageComponents.rbegin();
93 it != packageComponents.rend();
94 ++it) {
95 out << "} // namespace " << *it << "\n";
96 }
97 }
98}
99
Steven Moreland038903b2017-03-30 12:11:24 -0700100static void declareGetService(Formatter &out, const std::string &interfaceName, bool isTry) {
101 const std::string functionName = isTry ? "tryGetService" : "getService";
102
Steven Moreland7645fbd2019-03-12 18:49:28 -0700103 if (isTry) {
104 DocComment(
105 "This gets the service of this type with the specified instance name. If the\n"
106 "service is currently not available or not in the VINTF manifest on a Trebilized\n"
107 "device, this will return nullptr. This is useful when you don't want to block\n"
108 "during device boot. If getStub is true, this will try to return an unwrapped\n"
109 "passthrough implementation in the same process. This is useful when getting an\n"
110 "implementation from the same partition/compilation group.\n\n"
Neel Mehta291d02e2019-06-06 17:51:07 -0700111 "In general, prefer getService(std::string,bool)",
112 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700113 .emit(out);
114 } else {
115 DocComment(
116 "This gets the service of this type with the specified instance name. If the\n"
117 "service is not in the VINTF manifest on a Trebilized device, this will return\n"
118 "nullptr. If the service is not available, this will wait for the service to\n"
119 "become available. If the service is a lazy service, this will start the service\n"
120 "and return when it becomes available. If getStub is true, this will try to\n"
121 "return an unwrapped passthrough implementation in the same process. This is\n"
Neel Mehta291d02e2019-06-06 17:51:07 -0700122 "useful when getting an implementation from the same partition/compilation group.",
123 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700124 .emit(out);
125 }
Steven Moreland038903b2017-03-30 12:11:24 -0700126 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
Chris Phoenixdb0d6342017-01-11 16:10:00 -0800127 << "const std::string &serviceName=\"default\", bool getStub=false);\n";
Neel Mehta291d02e2019-06-06 17:51:07 -0700128 DocComment("Deprecated. See " + functionName + "(std::string, bool)", HIDL_LOCATION_HERE)
129 .emit(out);
Steven Moreland038903b2017-03-30 12:11:24 -0700130 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
Chris Phoenixdb0d6342017-01-11 16:10:00 -0800131 << "const char serviceName[], bool getStub=false)"
132 << " { std::string str(serviceName ? serviceName : \"\");"
Steven Moreland038903b2017-03-30 12:11:24 -0700133 << " return " << functionName << "(str, getStub); }\n";
Neel Mehta291d02e2019-06-06 17:51:07 -0700134 DocComment("Deprecated. See " + functionName + "(std::string, bool)", HIDL_LOCATION_HERE)
135 .emit(out);
Steven Moreland038903b2017-03-30 12:11:24 -0700136 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
Chris Phoenixdb0d6342017-01-11 16:10:00 -0800137 << "const ::android::hardware::hidl_string& serviceName, bool getStub=false)"
138 // without c_str the std::string constructor is ambiguous
139 << " { std::string str(serviceName.c_str());"
Steven Moreland038903b2017-03-30 12:11:24 -0700140 << " return " << functionName << "(str, getStub); }\n";
Steven Moreland7645fbd2019-03-12 18:49:28 -0700141 DocComment("Calls " + functionName +
Neel Mehta291d02e2019-06-06 17:51:07 -0700142 "(\"default\", bool). This is the recommended instance name for singleton "
143 "services.",
144 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700145 .emit(out);
Steven Moreland038903b2017-03-30 12:11:24 -0700146 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
147 << "bool getStub) { return " << functionName << "(\"default\", getStub); }\n";
148}
149
150static void declareServiceManagerInteractions(Formatter &out, const std::string &interfaceName) {
151 declareGetService(out, interfaceName, true /* isTry */);
152 declareGetService(out, interfaceName, false /* isTry */);
153
Steven Moreland7645fbd2019-03-12 18:49:28 -0700154 DocComment(
155 "Registers a service with the service manager. For Trebilized devices, the service\n"
Neel Mehta291d02e2019-06-06 17:51:07 -0700156 "must also be in the VINTF manifest.",
157 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700158 .emit(out);
Steven Moreland90831502017-03-27 12:08:40 -0700159 out << "__attribute__ ((warn_unused_result))"
160 << "::android::status_t registerAsService(const std::string &serviceName=\"default\");\n";
Neel Mehta291d02e2019-06-06 17:51:07 -0700161 DocComment("Registers for notifications for when a service is registered.", HIDL_LOCATION_HERE)
162 .emit(out);
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800163 out << "static bool registerForNotifications(\n";
164 out.indent(2, [&] {
165 out << "const std::string &serviceName,\n"
166 << "const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> "
167 << "&notification);\n";
168 });
169
170}
171
Steven Moreland038903b2017-03-30 12:11:24 -0700172static void implementGetService(Formatter &out,
173 const FQName &fqName,
174 bool isTry) {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800175
176 const std::string interfaceName = fqName.getInterfaceName();
Steven Moreland038903b2017-03-30 12:11:24 -0700177 const std::string functionName = isTry ? "tryGetService" : "getService";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800178
Steven Moreland23cc5fa2018-05-09 10:48:48 -0700179 out << "::android::sp<" << interfaceName << "> " << interfaceName << "::" << functionName << "("
Yifan Hong31f07ff2017-03-21 18:56:35 +0000180 << "const std::string &serviceName, const bool getStub) ";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800181 out.block([&] {
Steven Moreland78f95f92017-10-06 17:07:40 -0700182 out << "return ::android::hardware::details::getServiceInternal<"
183 << fqName.getInterfaceProxyName()
184 << ">(serviceName, "
185 << (!isTry ? "true" : "false") // retry
186 << ", getStub);\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800187 }).endl().endl();
Steven Moreland038903b2017-03-30 12:11:24 -0700188}
189
190static void implementServiceManagerInteractions(Formatter &out,
191 const FQName &fqName, const std::string &package) {
192
193 const std::string interfaceName = fqName.getInterfaceName();
194
195 implementGetService(out, fqName, true /* isTry */);
196 implementGetService(out, fqName, false /* isTry */);
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800197
Yifan Hongeefe4f22017-01-04 15:32:42 -0800198 out << "::android::status_t " << interfaceName << "::registerAsService("
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800199 << "const std::string &serviceName) ";
200 out.block([&] {
Steven Moreland5f84b382018-10-11 12:10:35 -0700201 out << "return ::android::hardware::details::registerAsServiceInternal(this, serviceName);\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800202 }).endl().endl();
203
Yifan Hongeefe4f22017-01-04 15:32:42 -0800204 out << "bool " << interfaceName << "::registerForNotifications(\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800205 out.indent(2, [&] {
206 out << "const std::string &serviceName,\n"
207 << "const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> "
208 << "&notification) ";
209 });
210 out.block([&] {
211 out << "const ::android::sp<::android::hidl::manager::V1_0::IServiceManager> sm\n";
212 out.indent(2, [&] {
213 out << "= ::android::hardware::defaultServiceManager();\n";
214 });
215 out.sIf("sm == nullptr", [&] {
216 out << "return false;\n";
217 }).endl();
218 out << "::android::hardware::Return<bool> success =\n";
219 out.indent(2, [&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800220 out << "sm->registerForNotifications(\"" << package << "::" << interfaceName << "\",\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800221 out.indent(2, [&] {
222 out << "serviceName, notification);\n";
223 });
224 });
225 out << "return success.isOk() && success;\n";
226 }).endl().endl();
227}
228
Steven Moreland368e4602018-02-16 14:21:49 -0800229void AST::generateInterfaceHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700230 const Interface *iface = getInterface();
231 std::string ifaceName = iface ? iface->localName() : "types";
Andreas Huber881227d2016-08-02 14:20:21 -0700232 const std::string guard = makeHeaderGuard(ifaceName);
233
234 out << "#ifndef " << guard << "\n";
235 out << "#define " << guard << "\n\n";
236
Andreas Huber737080b2016-08-02 15:38:04 -0700237 for (const auto &item : mImportedNames) {
Steven Morelandee88eed2016-10-31 17:49:00 -0700238 generateCppPackageInclude(out, item, item.name());
Andreas Huber737080b2016-08-02 15:38:04 -0700239 }
240
241 if (!mImportedNames.empty()) {
242 out << "\n";
243 }
244
Steven Moreland19f11b52017-05-12 18:22:21 -0700245 if (iface) {
Yifan Hongc8934042016-11-17 17:10:52 -0800246 if (isIBase()) {
247 out << "// skipped #include IServiceNotification.h\n\n";
248 } else {
249 out << "#include <android/hidl/manager/1.0/IServiceNotification.h>\n\n";
250 }
Steven Moreland0693f312016-11-09 15:06:14 -0800251 }
252
Yifan Hongc8934042016-11-17 17:10:52 -0800253 out << "#include <hidl/HidlSupport.h>\n";
Andreas Huber4bcf97d2016-08-30 11:27:49 -0700254 out << "#include <hidl/MQDescriptor.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700255
Steven Moreland19f11b52017-05-12 18:22:21 -0700256 if (iface) {
Martijn Coenen93915102016-09-01 01:35:52 +0200257 out << "#include <hidl/Status.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700258 }
259
Martijn Coenenaf712c02016-11-16 15:26:27 +0100260 out << "#include <utils/NativeHandle.h>\n";
261 out << "#include <utils/misc.h>\n\n"; /* for report_sysprop_change() */
Andreas Huber881227d2016-08-02 14:20:21 -0700262
263 enterLeaveNamespace(out, true /* enter */);
264 out << "\n";
265
Steven Moreland19f11b52017-05-12 18:22:21 -0700266 if (iface) {
Steven Moreland70cb55e2019-03-12 17:20:54 -0700267 iface->emitDocComment(out);
268
Andreas Huber881227d2016-08-02 14:20:21 -0700269 out << "struct "
Steven Moreland40786312016-08-16 10:29:40 -0700270 << ifaceName;
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700271
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700272 const Interface *superType = iface->superType();
273
Yi Kong56758da2018-07-24 16:21:37 -0700274 if (superType == nullptr) {
Yifan Hongc8934042016-11-17 17:10:52 -0800275 out << " : virtual public ::android::RefBase";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700276 } else {
Steven Morelandd916a702016-10-26 22:23:09 +0000277 out << " : public "
Steven Moreland40786312016-08-16 10:29:40 -0700278 << superType->fullName();
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700279 }
280
281 out << " {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700282
283 out.indent();
284
Neel Mehta291d02e2019-06-06 17:51:07 -0700285 DocComment("Type tag for use in template logic that indicates this is a 'pure' class.",
286 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700287 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700288 generateCppTag(out, "android::hardware::details::i_tag");
Andreas Huber881227d2016-08-02 14:20:21 -0700289
Neel Mehta291d02e2019-06-06 17:51:07 -0700290 DocComment("Fully qualified interface name: \"" + iface->fqName().string() + "\"",
291 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700292 .emit(out);
293 out << "static const char* descriptor;\n\n";
294
Steven Moreland70cb55e2019-03-12 17:20:54 -0700295 iface->emitTypeDeclarations(out);
296 } else {
297 mRootScope.emitTypeDeclarations(out);
298 }
Andreas Huber881227d2016-08-02 14:20:21 -0700299
Steven Moreland19f11b52017-05-12 18:22:21 -0700300 if (iface) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700301 DocComment(
Neel Mehta291d02e2019-06-06 17:51:07 -0700302 "Returns whether this object's implementation is outside of the current process.",
303 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700304 .emit(out);
Yifan Hongc8934042016-11-17 17:10:52 -0800305 out << "virtual bool isRemote() const ";
306 if (!isIBase()) {
307 out << "override ";
308 }
Steven Moreland7645fbd2019-03-12 18:49:28 -0700309 out << "{ return false; }\n";
Steven Morelandd732ea12016-11-08 17:12:06 -0800310
Steven Morelandf7f2a9a2017-07-21 18:05:38 -0700311 for (const auto& tuple : iface->allMethodsFromRoot()) {
312 const Method* method = tuple.method();
313
Andreas Huber881227d2016-08-02 14:20:21 -0700314 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700315
Andreas Huber881227d2016-08-02 14:20:21 -0700316 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700317 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Morelandd732ea12016-11-08 17:12:06 -0800318
319 if (elidedReturn == nullptr && returnsValue) {
Neel Mehta291d02e2019-06-06 17:51:07 -0700320 DocComment("Return callback for " + method->name(), HIDL_LOCATION_HERE).emit(out);
Steven Morelandd732ea12016-11-08 17:12:06 -0800321 out << "using "
322 << method->name()
Yifan Hong932464e2017-03-30 15:40:22 -0700323 << "_cb = std::function<void(";
324 method->emitCppResultSignature(out, true /* specify namespaces */);
325 out << ")>;\n";
Steven Morelandd732ea12016-11-08 17:12:06 -0800326 }
Andreas Huber881227d2016-08-02 14:20:21 -0700327
Andreas Huber3599d922016-08-09 10:42:57 -0700328 method->dumpAnnotations(out);
329
Steven Moreland49bad8d2018-05-17 15:45:26 -0700330 method->emitDocComment(out);
331
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700332 if (elidedReturn) {
Iliyan Malchev2b6591b2016-08-18 19:15:19 -0700333 out << "virtual ::android::hardware::Return<";
Yifan Hong3b320f82016-11-01 15:15:54 -0700334 out << elidedReturn->type().getCppResultType() << "> ";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700335 } else {
Iliyan Malchevd57066f2016-09-08 13:59:38 -0700336 out << "virtual ::android::hardware::Return<void> ";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700337 }
338
339 out << method->name()
Yifan Hong932464e2017-03-30 15:40:22 -0700340 << "(";
341 method->emitCppArgSignature(out, true /* specify namespaces */);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700342 out << ")";
343 if (method->isHidlReserved()) {
Yifan Hongc8934042016-11-17 17:10:52 -0800344 if (!isIBase()) {
345 out << " override";
346 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700347 } else {
Steven Morelandd4b068a2017-03-20 06:30:51 -0700348 out << " = 0";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700349 }
Steven Morelandd4b068a2017-03-20 06:30:51 -0700350 out << ";\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700351 }
Steven Moreland40786312016-08-16 10:29:40 -0700352
Steven Moreland7645fbd2019-03-12 18:49:28 -0700353 out << "\n// cast static functions\n";
Yifan Hong3d746092016-12-07 14:26:33 -0800354 std::string childTypeResult = iface->getCppResultType();
Yifan Hongfe95aa22016-10-19 17:26:45 -0700355
Yifan Hong3d746092016-12-07 14:26:33 -0800356 for (const Interface *superType : iface->typeChain()) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700357 DocComment(
358 "This performs a checked cast based on what the underlying implementation "
Neel Mehta291d02e2019-06-06 17:51:07 -0700359 "actually is.",
360 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700361 .emit(out);
Yifan Hong200209c2017-03-29 03:39:09 -0700362 out << "static ::android::hardware::Return<"
Yifan Hong3d746092016-12-07 14:26:33 -0800363 << childTypeResult
Yifan Hong200209c2017-03-29 03:39:09 -0700364 << "> castFrom("
Yifan Hong3d746092016-12-07 14:26:33 -0800365 << superType->getCppArgumentType()
366 << " parent"
Yifan Hong200209c2017-03-29 03:39:09 -0700367 << ", bool emitError = false);\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -0700368 }
369
Yifan Hongc8934042016-11-17 17:10:52 -0800370 if (isIBase()) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700371 out << "\n// skipped getService, registerAsService, registerForNotifications\n\n";
Yifan Hongc8934042016-11-17 17:10:52 -0800372 } else {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700373 out << "\n// helper methods for interactions with the hwservicemanager\n";
Yifan Hongeefe4f22017-01-04 15:32:42 -0800374 declareServiceManagerInteractions(out, iface->localName());
Yifan Hongc8934042016-11-17 17:10:52 -0800375 }
Andreas Huber881227d2016-08-02 14:20:21 -0700376 }
377
Steven Moreland19f11b52017-05-12 18:22:21 -0700378 if (iface) {
Andreas Huber881227d2016-08-02 14:20:21 -0700379 out.unindent();
380
Andreas Hubere3f769a2016-10-10 10:54:44 -0700381 out << "};\n\n";
382 }
383
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700384 out << "//\n";
385 out << "// type declarations for package\n";
386 out << "//\n\n";
Steven Moreland368e4602018-02-16 14:21:49 -0800387 mRootScope.emitPackageTypeDeclarations(out);
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700388 out << "//\n";
389 out << "// type header definitions for package\n";
390 out << "//\n\n";
391 mRootScope.emitPackageTypeHeaderDefinitions(out);
Andreas Huber881227d2016-08-02 14:20:21 -0700392
393 out << "\n";
394 enterLeaveNamespace(out, false /* enter */);
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700395 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700396
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700397 out << "//\n";
398 out << "// global type declarations for package\n";
399 out << "//\n\n";
Steven Moreland8e61c5a2017-11-17 15:55:28 -0800400 mRootScope.emitGlobalTypeDeclarations(out);
401
Andreas Huber881227d2016-08-02 14:20:21 -0700402 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700403}
404
Steven Moreland368e4602018-02-16 14:21:49 -0800405void AST::generateHwBinderHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700406 const Interface *iface = getInterface();
407 std::string klassName = iface ? iface->getHwName() : "hwtypes";
Steven Moreland40786312016-08-16 10:29:40 -0700408
Steven Moreland40786312016-08-16 10:29:40 -0700409 const std::string guard = makeHeaderGuard(klassName);
410
411 out << "#ifndef " << guard << "\n";
412 out << "#define " << guard << "\n\n";
413
Steven Moreland19f11b52017-05-12 18:22:21 -0700414 generateCppPackageInclude(out, mPackage, iface ? iface->localName() : "types");
Steven Moreland40786312016-08-16 10:29:40 -0700415
Steven Morelandee88eed2016-10-31 17:49:00 -0700416 out << "\n";
Steven Moreland40786312016-08-16 10:29:40 -0700417
418 for (const auto &item : mImportedNames) {
419 if (item.name() == "types") {
Yifan Hong244e82d2016-11-11 11:13:57 -0800420 generateCppPackageInclude(out, item, "hwtypes");
421 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800422 generateCppPackageInclude(out, item, item.getInterfaceStubName());
423 generateCppPackageInclude(out, item, item.getInterfaceProxyName());
Steven Moreland40786312016-08-16 10:29:40 -0700424 }
Steven Moreland40786312016-08-16 10:29:40 -0700425 }
426
427 out << "\n";
428
Martijn Coenen93915102016-09-01 01:35:52 +0200429 out << "#include <hidl/Status.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700430 out << "#include <hwbinder/IBinder.h>\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100431 out << "#include <hwbinder/Parcel.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700432
433 out << "\n";
434
435 enterLeaveNamespace(out, true /* enter */);
Steven Moreland40786312016-08-16 10:29:40 -0700436
Steven Moreland368e4602018-02-16 14:21:49 -0800437 mRootScope.emitPackageHwDeclarations(out);
Steven Moreland40786312016-08-16 10:29:40 -0700438
439 enterLeaveNamespace(out, false /* enter */);
440
441 out << "\n#endif // " << guard << "\n";
Steven Moreland40786312016-08-16 10:29:40 -0700442}
443
Steven Moreland58a20c72018-10-09 12:30:51 -0700444static std::string wrapPassthroughArg(Formatter& out, const NamedReference<Type>* arg,
445 std::string name, std::function<void(void)> handleError) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800446 if (!arg->type().isInterface()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700447 return name;
Yifan Hong7a118f52016-12-07 11:21:15 -0800448 }
Steven Moreland58a20c72018-10-09 12:30:51 -0700449 std::string wrappedName = "_hidl_wrapped_" + name;
Yifan Hong7a118f52016-12-07 11:21:15 -0800450 const Interface &iface = static_cast<const Interface &>(arg->type());
451 out << iface.getCppStackType() << " " << wrappedName << ";\n";
452 // TODO(elsk): b/33754152 Should not wrap this if object is Bs*
453 out.sIf(name + " != nullptr && !" + name + "->isRemote()", [&] {
454 out << wrappedName
455 << " = "
Steven Morelandbff4bd22017-10-02 14:46:06 -0700456 << "::android::hardware::details::wrapPassthrough("
457 << name
458 << ");\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800459 out.sIf(wrappedName + " == nullptr", [&] {
460 // Fatal error. Happens when the BsFoo class is not found in the binary
461 // or any dynamic libraries.
462 handleError();
463 }).endl();
464 }).sElse([&] {
465 out << wrappedName << " = " << name << ";\n";
466 }).endl().endl();
Steven Moreland58a20c72018-10-09 12:30:51 -0700467
468 return wrappedName;
Yifan Hong7a118f52016-12-07 11:21:15 -0800469}
470
Steven Moreland616cf4d2018-10-02 13:52:18 -0700471void AST::generatePassthroughMethod(Formatter& out, const Method* method, const Interface* superInterface) const {
Yifan Hong068c5522016-10-31 14:07:25 -0700472 method->generateCppSignature(out);
Steven Moreland69e7c702016-09-09 11:16:32 -0700473
Steven Moreland58a20c72018-10-09 12:30:51 -0700474 out << " override {\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700475 out.indent();
476
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800477 if (method->isHidlReserved()
478 && method->overridesCppImpl(IMPL_PASSTHROUGH)) {
479 method->cppImpl(IMPL_PASSTHROUGH, out);
480 out.unindent();
481 out << "}\n\n";
Steven Moreland368e4602018-02-16 14:21:49 -0800482 return;
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800483 }
484
Steven Moreland69e7c702016-09-09 11:16:32 -0700485 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700486 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland69e7c702016-09-09 11:16:32 -0700487
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700488 generateCppInstrumentationCall(
489 out,
490 InstrumentationEvent::PASSTHROUGH_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700491 method,
492 superInterface);
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700493
Steven Moreland58a20c72018-10-09 12:30:51 -0700494 std::vector<std::string> wrappedArgNames;
Yifan Hong7a118f52016-12-07 11:21:15 -0800495 for (const auto &arg : method->args()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700496 std::string name = wrapPassthroughArg(out, arg, arg->name(), [&] {
Yifan Hong7a118f52016-12-07 11:21:15 -0800497 out << "return ::android::hardware::Status::fromExceptionCode(\n";
498 out.indent(2, [&] {
499 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
Yifan Hong0abd7392016-12-20 16:43:26 -0800500 << "\"Cannot wrap passthrough interface.\");\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800501 });
502 });
Steven Moreland58a20c72018-10-09 12:30:51 -0700503
504 wrappedArgNames.push_back(name);
Yifan Hong7a118f52016-12-07 11:21:15 -0800505 }
506
Steven Moreland58a20c72018-10-09 12:30:51 -0700507 out << "::android::hardware::Status _hidl_error = ::android::hardware::Status::ok();\n";
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700508 out << "auto _hidl_return = ";
Steven Moreland69e7c702016-09-09 11:16:32 -0700509
510 if (method->isOneway()) {
Steven Moreland836cb312017-06-05 17:25:55 -0700511 out << "addOnewayTask([mImpl = this->mImpl\n"
512 << "#ifdef __ANDROID_DEBUGGABLE__\n"
513 ", mEnableInstrumentation = this->mEnableInstrumentation, "
514 "mInstrumentationCallbacks = this->mInstrumentationCallbacks\n"
515 << "#endif // __ANDROID_DEBUGGABLE__\n";
Steven Moreland58a20c72018-10-09 12:30:51 -0700516 for (const std::string& arg : wrappedArgNames) {
517 out << ", " << arg;
Steven Moreland69e7c702016-09-09 11:16:32 -0700518 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700519 out << "] {\n";
520 out.indent();
Steven Moreland69e7c702016-09-09 11:16:32 -0700521 }
522
523 out << "mImpl->"
524 << method->name()
525 << "(";
526
Yifan Hong932464e2017-03-30 15:40:22 -0700527 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800528 out << (arg->type().isInterface() ? "_hidl_wrapped_" : "") << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -0700529 });
Steven Moreland58a20c72018-10-09 12:30:51 -0700530
531 std::function<void(void)> kHandlePassthroughError = [&] {
532 out << "_hidl_error = ::android::hardware::Status::fromExceptionCode(\n";
533 out.indent(2, [&] {
534 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
535 << "\"Cannot wrap passthrough interface.\");\n";
536 });
537 };
538
Steven Moreland69e7c702016-09-09 11:16:32 -0700539 if (returnsValue && elidedReturn == nullptr) {
Steven Moreland340c8822017-05-02 14:41:49 -0700540 // never true if oneway since oneway methods don't return values
541
Steven Moreland69e7c702016-09-09 11:16:32 -0700542 if (!method->args().empty()) {
543 out << ", ";
544 }
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800545 out << "[&](";
Yifan Hong932464e2017-03-30 15:40:22 -0700546 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800547 out << "const auto &_hidl_out_"
548 << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -0700549 });
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800550
551 out << ") {\n";
552 out.indent();
Steven Moreland92a08a72017-07-31 14:57:37 -0700553 generateCppInstrumentationCall(
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800554 out,
555 InstrumentationEvent::PASSTHROUGH_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700556 method,
557 superInterface);
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800558
Steven Moreland58a20c72018-10-09 12:30:51 -0700559 std::vector<std::string> wrappedOutNames;
Yifan Hong7a118f52016-12-07 11:21:15 -0800560 for (const auto &arg : method->results()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700561 wrappedOutNames.push_back(
562 wrapPassthroughArg(out, arg, "_hidl_out_" + arg->name(), kHandlePassthroughError));
Yifan Hong7a118f52016-12-07 11:21:15 -0800563 }
564
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800565 out << "_hidl_cb(";
Steven Moreland58a20c72018-10-09 12:30:51 -0700566 out.join(wrappedOutNames.begin(), wrappedOutNames.end(), ", ",
567 [&](const std::string& arg) { out << arg; });
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800568 out << ");\n";
569 out.unindent();
570 out << "});\n\n";
571 } else {
572 out << ");\n\n";
Steven Moreland30b76e92017-06-02 18:52:24 -0700573
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800574 if (elidedReturn != nullptr) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700575 const std::string outName = "_hidl_out_" + elidedReturn->name();
576
577 out << elidedReturn->type().getCppResultType() << " " << outName
578 << " = _hidl_return;\n";
579 out << "(void) " << outName << ";\n";
580
581 const std::string wrappedName =
582 wrapPassthroughArg(out, elidedReturn, outName, kHandlePassthroughError);
583
584 if (outName != wrappedName) {
585 // update the original value since it is used by generateCppInstrumentationCall
586 out << outName << " = " << wrappedName << ";\n\n";
587
588 // update the value to be returned
589 out << "_hidl_return = " << outName << "\n;";
590 }
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800591 }
Steven Moreland92a08a72017-07-31 14:57:37 -0700592 generateCppInstrumentationCall(
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800593 out,
594 InstrumentationEvent::PASSTHROUGH_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700595 method,
596 superInterface);
Steven Moreland69e7c702016-09-09 11:16:32 -0700597 }
Steven Moreland69e7c702016-09-09 11:16:32 -0700598
599 if (method->isOneway()) {
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700600 out.unindent();
601 out << "});\n";
Steven Moreland58a20c72018-10-09 12:30:51 -0700602 } else {
603 out << "if (!_hidl_error.isOk()) return _hidl_error;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700604 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700605
606 out << "return _hidl_return;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700607
608 out.unindent();
609 out << "}\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700610}
611
Steven Moreland368e4602018-02-16 14:21:49 -0800612void AST::generateMethods(Formatter& out, const MethodGenerator& gen, bool includeParent) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700613 const Interface* iface = mRootScope.getInterface();
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700614
Yifan Hong10fe0b52016-10-19 14:20:17 -0700615 const Interface *prevIterface = nullptr;
616 for (const auto &tuple : iface->allMethodsFromRoot()) {
617 const Method *method = tuple.method();
618 const Interface *superInterface = tuple.interface();
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700619
Steven Morelandf16c5c02017-07-31 16:50:06 -0700620 if (!includeParent && superInterface != iface) {
621 continue;
622 }
623
Yifan Hong10fe0b52016-10-19 14:20:17 -0700624 if(prevIterface != superInterface) {
625 if (prevIterface != nullptr) {
626 out << "\n";
627 }
628 out << "// Methods from "
629 << superInterface->fullName()
630 << " follow.\n";
631 prevIterface = superInterface;
632 }
Steven Moreland368e4602018-02-16 14:21:49 -0800633 gen(method, superInterface);
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700634 }
635
Yifan Hong10fe0b52016-10-19 14:20:17 -0700636 out << "\n";
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700637}
638
Steven Moreland0b843772017-06-23 16:33:38 -0700639void AST::generateTemplatizationLink(Formatter& out) const {
Neel Mehta291d02e2019-06-06 17:51:07 -0700640 DocComment("The pure class is what this class wraps.", HIDL_LOCATION_HERE).emit(out);
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700641 out << "typedef " << mRootScope.getInterface()->localName() << " Pure;\n\n";
Steven Moreland0b843772017-06-23 16:33:38 -0700642}
643
Steven Moreland1a52e822017-07-27 13:56:29 -0700644void AST::generateCppTag(Formatter& out, const std::string& tag) const {
645 out << "typedef " << tag << " _hidl_tag;\n\n";
646}
647
Steven Moreland368e4602018-02-16 14:21:49 -0800648void AST::generateStubHeader(Formatter& out) const {
Steven Moreland5abcf012018-02-08 18:50:18 -0800649 CHECK(AST::isInterface());
Andreas Huber881227d2016-08-02 14:20:21 -0700650
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700651 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800652 const std::string klassName = iface->getStubName();
Steven Moreland40786312016-08-16 10:29:40 -0700653 const std::string guard = makeHeaderGuard(klassName);
Andreas Huber881227d2016-08-02 14:20:21 -0700654
655 out << "#ifndef " << guard << "\n";
656 out << "#define " << guard << "\n\n";
657
Yifan Hongeefe4f22017-01-04 15:32:42 -0800658 generateCppPackageInclude(out, mPackage, iface->getHwName());
Steven Moreland1a52e822017-07-27 13:56:29 -0700659
Steven Morelandee88eed2016-10-31 17:49:00 -0700660 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700661
662 enterLeaveNamespace(out, true /* enter */);
663 out << "\n";
664
665 out << "struct "
Yifan Hongeefe4f22017-01-04 15:32:42 -0800666 << klassName;
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100667 if (iface->isIBase()) {
Yifan Hong96a79e22017-01-12 14:22:05 -0800668 out << " : public ::android::hardware::BHwBinder";
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +0000669 out << ", public ::android::hardware::details::HidlInstrumentor {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100670 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800671 out << " : public "
672 << gIBaseFqName.getInterfaceStubFqName().cppName()
673 << " {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100674 }
Andreas Huber881227d2016-08-02 14:20:21 -0700675
676 out.indent();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800677 out << "explicit "
678 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -0700679 << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl);"
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100680 << "\n";
Yifan Hongeefe4f22017-01-04 15:32:42 -0800681 out << "explicit "
682 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -0700683 << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl,"
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -0800684 << " const std::string& HidlInstrumentor_package,"
685 << " const std::string& HidlInstrumentor_interface);"
Steven Moreland40786312016-08-16 10:29:40 -0700686 << "\n\n";
Steven Moreland57a89362017-07-21 19:29:54 +0000687 out << "virtual ~" << klassName << "();\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700688 out << "::android::status_t onTransact(\n";
689 out.indent();
690 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -0700691 out << "uint32_t _hidl_code,\n";
692 out << "const ::android::hardware::Parcel &_hidl_data,\n";
693 out << "::android::hardware::Parcel *_hidl_reply,\n";
694 out << "uint32_t _hidl_flags = 0,\n";
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700695 out << "TransactCallback _hidl_cb = nullptr) override;\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700696 out.unindent();
697 out.unindent();
698
Steven Moreland0b843772017-06-23 16:33:38 -0700699 out.endl();
700 generateTemplatizationLink(out);
Neel Mehta291d02e2019-06-06 17:51:07 -0700701 DocComment("Type tag for use in template logic that indicates this is a 'native' class.",
702 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700703 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700704 generateCppTag(out, "android::hardware::details::bnhw_tag");
Steven Moreland0b843772017-06-23 16:33:38 -0700705
Steven Morelandcbcf9f72017-11-20 10:04:15 -0800706 out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; }\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700707
Steven Moreland368e4602018-02-16 14:21:49 -0800708 generateMethods(out,
709 [&](const Method* method, const Interface*) {
710 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
711 return;
712 }
Steven Morelandf16c5c02017-07-31 16:50:06 -0700713
Steven Moreland368e4602018-02-16 14:21:49 -0800714 out << "static ::android::status_t _hidl_" << method->name() << "(\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700715
Steven Moreland368e4602018-02-16 14:21:49 -0800716 out.indent(2,
717 [&] {
718 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
719 << "const ::android::hardware::Parcel &_hidl_data,\n"
720 << "::android::hardware::Parcel *_hidl_reply,\n"
721 << "TransactCallback _hidl_cb);\n";
722 })
723 .endl()
724 .endl();
725 },
726 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -0700727
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100728 out.unindent();
729 out << "private:\n";
730 out.indent();
Yifan Hongcd2ae452017-01-31 14:33:40 -0800731
Steven Moreland368e4602018-02-16 14:21:49 -0800732 generateMethods(out, [&](const Method* method, const Interface* iface) {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800733 if (!method->isHidlReserved() || !method->overridesCppImpl(IMPL_STUB_IMPL)) {
Steven Moreland368e4602018-02-16 14:21:49 -0800734 return;
Yifan Hongcd2ae452017-01-31 14:33:40 -0800735 }
736 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700737 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Yifan Hongcd2ae452017-01-31 14:33:40 -0800738
739 if (elidedReturn == nullptr && returnsValue) {
740 out << "using " << method->name() << "_cb = "
741 << iface->fqName().cppName()
742 << "::" << method->name() << "_cb;\n";
743 }
744 method->generateCppSignature(out);
Yifan Hongbcffce22017-02-01 15:52:06 -0800745 out << ";\n";
Yifan Hongcd2ae452017-01-31 14:33:40 -0800746 });
Yifan Hongcd2ae452017-01-31 14:33:40 -0800747
Steven Moreland19f11b52017-05-12 18:22:21 -0700748 out << "::android::sp<" << iface->localName() << "> _hidl_mImpl;\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700749 out.unindent();
Andreas Huber881227d2016-08-02 14:20:21 -0700750 out << "};\n\n";
751
752 enterLeaveNamespace(out, false /* enter */);
753
754 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700755}
756
Steven Moreland368e4602018-02-16 14:21:49 -0800757void AST::generateProxyHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700758 if (!AST::isInterface()) {
Andreas Huber881227d2016-08-02 14:20:21 -0700759 // types.hal does not get a proxy header.
Steven Moreland368e4602018-02-16 14:21:49 -0800760 return;
Andreas Huber881227d2016-08-02 14:20:21 -0700761 }
762
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700763 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800764 const std::string proxyName = iface->getProxyName();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800765 const std::string guard = makeHeaderGuard(proxyName);
Andreas Huber881227d2016-08-02 14:20:21 -0700766
767 out << "#ifndef " << guard << "\n";
768 out << "#define " << guard << "\n\n";
769
Martijn Coenen115d4282016-12-19 05:14:04 +0100770 out << "#include <hidl/HidlTransportSupport.h>\n\n";
771
Andreas Huber881227d2016-08-02 14:20:21 -0700772 std::vector<std::string> packageComponents;
773 getPackageAndVersionComponents(
774 &packageComponents, false /* cpp_compatible */);
775
Yifan Hongeefe4f22017-01-04 15:32:42 -0800776 generateCppPackageInclude(out, mPackage, iface->getHwName());
Steven Morelandee88eed2016-10-31 17:49:00 -0700777 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700778
779 enterLeaveNamespace(out, true /* enter */);
780 out << "\n";
781
782 out << "struct "
Yifan Hongeefe4f22017-01-04 15:32:42 -0800783 << proxyName
784 << " : public ::android::hardware::BpInterface<"
785 << iface->localName()
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +0000786 << ">, public ::android::hardware::details::HidlInstrumentor {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700787
788 out.indent();
789
Yifan Hongeefe4f22017-01-04 15:32:42 -0800790 out << "explicit "
791 << proxyName
Iliyan Malchev549e2592016-08-10 08:59:12 -0700792 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl);"
Andreas Huber881227d2016-08-02 14:20:21 -0700793 << "\n\n";
794
Steven Moreland0b843772017-06-23 16:33:38 -0700795 generateTemplatizationLink(out);
Neel Mehta291d02e2019-06-06 17:51:07 -0700796 DocComment("Type tag for use in template logic that indicates this is a 'proxy' class.",
797 HIDL_LOCATION_HERE)
Steven Moreland7645fbd2019-03-12 18:49:28 -0700798 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700799 generateCppTag(out, "android::hardware::details::bphw_tag");
Steven Moreland0b843772017-06-23 16:33:38 -0700800
Yifan Hong10fe0b52016-10-19 14:20:17 -0700801 out << "virtual bool isRemote() const override { return true; }\n\n";
Steven Moreland40786312016-08-16 10:29:40 -0700802
Steven Moreland368e4602018-02-16 14:21:49 -0800803 generateMethods(
804 out,
805 [&](const Method* method, const Interface*) {
806 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
807 return;
808 }
Steven Morelandf16c5c02017-07-31 16:50:06 -0700809
Steven Moreland368e4602018-02-16 14:21:49 -0800810 out << "static ";
811 method->generateCppReturnType(out);
812 out << " _hidl_" << method->name() << "("
813 << "::android::hardware::IInterface* _hidl_this, "
814 << "::android::hardware::details::HidlInstrumentor *_hidl_this_instrumentor";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700815
Steven Moreland368e4602018-02-16 14:21:49 -0800816 if (!method->hasEmptyCppArgSignature()) {
817 out << ", ";
818 }
819 method->emitCppArgSignature(out);
820 out << ");\n";
821 },
822 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -0700823
Steven Moreland368e4602018-02-16 14:21:49 -0800824 generateMethods(out, [&](const Method* method, const Interface*) {
Yifan Hong068c5522016-10-31 14:07:25 -0700825 method->generateCppSignature(out);
826 out << " override;\n";
Yifan Hong068c5522016-10-31 14:07:25 -0700827 });
Steven Moreland9c387612016-09-07 09:54:26 -0700828
Andreas Huber881227d2016-08-02 14:20:21 -0700829 out.unindent();
Martijn Coenen115d4282016-12-19 05:14:04 +0100830 out << "private:\n";
831 out.indent();
832 out << "std::mutex _hidl_mMutex;\n"
833 << "std::vector<::android::sp<::android::hardware::hidl_binder_death_recipient>>"
834 << " _hidl_mDeathRecipients;\n";
835 out.unindent();
Andreas Huber881227d2016-08-02 14:20:21 -0700836 out << "};\n\n";
837
838 enterLeaveNamespace(out, false /* enter */);
839
840 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700841}
842
Steven Moreland368e4602018-02-16 14:21:49 -0800843void AST::generateCppSource(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700844 std::string baseName = getBaseName();
845 const Interface *iface = getInterface();
Andreas Huber881227d2016-08-02 14:20:21 -0700846
Steven Morelanda885d252017-09-25 18:44:43 -0700847 const std::string klassName = baseName + (baseName == "types" ? "" : "All");
Andreas Huber881227d2016-08-02 14:20:21 -0700848
Steven Moreland623c0042017-01-13 14:42:29 -0800849 out << "#define LOG_TAG \""
850 << mPackage.string() << "::" << baseName
851 << "\"\n\n";
852
Steven Moreland5add34d2018-11-08 16:31:30 -0800853 out << "#include <log/log.h>\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100854 out << "#include <cutils/trace.h>\n";
855 out << "#include <hidl/HidlTransportSupport.h>\n\n";
Steven Moreland26896a92018-07-31 15:31:01 -0700856 out << "#include <hidl/Static.h>\n";
857 out << "#include <hwbinder/ProcessState.h>\n";
Steven Moreland4607ef52018-05-09 10:52:47 -0700858 out << "#include <utils/Trace.h>\n";
Steven Moreland19f11b52017-05-12 18:22:21 -0700859 if (iface) {
Steven Moreland19d5c172016-10-20 19:20:25 -0700860 // This is a no-op for IServiceManager itself.
861 out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n";
862
Yifan Hongeefe4f22017-01-04 15:32:42 -0800863 generateCppPackageInclude(out, mPackage, iface->getProxyName());
864 generateCppPackageInclude(out, mPackage, iface->getStubName());
865 generateCppPackageInclude(out, mPackage, iface->getPassthroughName());
Yifan Hongfe95aa22016-10-19 17:26:45 -0700866
867 for (const Interface *superType : iface->superTypeChain()) {
Steven Morelandee88eed2016-10-31 17:49:00 -0700868 generateCppPackageInclude(out,
869 superType->fqName(),
Yifan Hongeefe4f22017-01-04 15:32:42 -0800870 superType->fqName().getInterfaceProxyName());
Yifan Hongfe95aa22016-10-19 17:26:45 -0700871 }
Yifan Hong2cbbdf92016-12-05 15:20:50 -0800872
873 out << "#include <hidl/ServiceManagement.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700874 } else {
Steven Morelandee88eed2016-10-31 17:49:00 -0700875 generateCppPackageInclude(out, mPackage, "types");
Yifan Hong244e82d2016-11-11 11:13:57 -0800876 generateCppPackageInclude(out, mPackage, "hwtypes");
Andreas Huber881227d2016-08-02 14:20:21 -0700877 }
878
879 out << "\n";
880
881 enterLeaveNamespace(out, true /* enter */);
882 out << "\n";
883
Steven Moreland368e4602018-02-16 14:21:49 -0800884 generateTypeSource(out, iface ? iface->localName() : "");
Andreas Huber881227d2016-08-02 14:20:21 -0700885
Steven Moreland368e4602018-02-16 14:21:49 -0800886 if (iface) {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700887 const Interface* iface = mRootScope.getInterface();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700888
889 // need to be put here, generateStubSource is using this.
Yifan Hongeefe4f22017-01-04 15:32:42 -0800890 out << "const char* "
891 << iface->localName()
Yifan Hong10fe0b52016-10-19 14:20:17 -0700892 << "::descriptor(\""
893 << iface->fqName().string()
894 << "\");\n\n";
Yifan Hong91977fd2017-11-09 16:07:37 -0800895 out << "__attribute__((constructor)) ";
Martijn Coenen8adcb652017-02-03 17:37:36 +0100896 out << "static void static_constructor() {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800897 out.indent([&] {
Yifan Hong91977fd2017-11-09 16:07:37 -0800898 out << "::android::hardware::details::getBnConstructorMap().set("
Yifan Hongeefe4f22017-01-04 15:32:42 -0800899 << iface->localName()
Yifan Hongb04de382017-02-06 15:31:52 -0800900 << "::descriptor,\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800901 out.indent(2, [&] {
Yifan Hongb04de382017-02-06 15:31:52 -0800902 out << "[](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800903 out.indent([&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800904 out << "return new "
905 << iface->getStubName()
Yifan Hong341112d2017-04-20 18:12:05 -0700906 << "(static_cast<"
Yifan Hongeefe4f22017-01-04 15:32:42 -0800907 << iface->localName()
Yifan Hong158655a2016-11-08 12:34:07 -0800908 << " *>(iIntf));\n";
909 });
Yifan Hongb04de382017-02-06 15:31:52 -0800910 out << "});\n";
Yifan Hong158655a2016-11-08 12:34:07 -0800911 });
Yifan Hong91977fd2017-11-09 16:07:37 -0800912 out << "::android::hardware::details::getBsConstructorMap().set("
Yifan Hongeefe4f22017-01-04 15:32:42 -0800913 << iface->localName()
Yifan Hongb04de382017-02-06 15:31:52 -0800914 << "::descriptor,\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800915 out.indent(2, [&] {
Yifan Hongb04de382017-02-06 15:31:52 -0800916 out << "[](void *iIntf) -> ::android::sp<"
Yifan Hong7a118f52016-12-07 11:21:15 -0800917 << gIBaseFqName.cppName()
918 << "> {\n";
919 out.indent([&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800920 out << "return new "
921 << iface->getPassthroughName()
Yifan Hong341112d2017-04-20 18:12:05 -0700922 << "(static_cast<"
Yifan Hongeefe4f22017-01-04 15:32:42 -0800923 << iface->localName()
Yifan Hong7a118f52016-12-07 11:21:15 -0800924 << " *>(iIntf));\n";
925 });
Yifan Hongb04de382017-02-06 15:31:52 -0800926 out << "});\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800927 });
Yifan Hong158655a2016-11-08 12:34:07 -0800928 });
Martijn Coenen8adcb652017-02-03 17:37:36 +0100929 out << "};\n\n";
930 out << "__attribute__((destructor))";
931 out << "static void static_destructor() {\n";
932 out.indent([&] {
Yifan Hong91977fd2017-11-09 16:07:37 -0800933 out << "::android::hardware::details::getBnConstructorMap().erase("
Martijn Coenen8adcb652017-02-03 17:37:36 +0100934 << iface->localName()
935 << "::descriptor);\n";
Yifan Hong91977fd2017-11-09 16:07:37 -0800936 out << "::android::hardware::details::getBsConstructorMap().erase("
Martijn Coenen8adcb652017-02-03 17:37:36 +0100937 << iface->localName()
938 << "::descriptor);\n";
939 });
940 out << "};\n\n";
Yifan Hong158655a2016-11-08 12:34:07 -0800941
Steven Moreland368e4602018-02-16 14:21:49 -0800942 generateInterfaceSource(out);
943 generateProxySource(out, iface->fqName());
944 generateStubSource(out, iface);
945 generatePassthroughSource(out);
Steven Moreland9c387612016-09-07 09:54:26 -0700946
Yifan Hongc8934042016-11-17 17:10:52 -0800947 if (isIBase()) {
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800948 out << "// skipped getService, registerAsService, registerForNotifications\n";
Yifan Hongc8934042016-11-17 17:10:52 -0800949 } else {
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800950 std::string package = iface->fqName().package()
951 + iface->fqName().atVersion();
952
Yifan Hongeefe4f22017-01-04 15:32:42 -0800953 implementServiceManagerInteractions(out, iface->fqName(), package);
Yifan Hongc8934042016-11-17 17:10:52 -0800954 }
Steven Moreland40786312016-08-16 10:29:40 -0700955 }
956
Andreas Huber6755e9d2017-04-06 11:09:07 -0700957 HidlTypeAssertion::EmitAll(out);
958 out << "\n";
959
Andreas Huber881227d2016-08-02 14:20:21 -0700960 enterLeaveNamespace(out, false /* enter */);
Andreas Huber881227d2016-08-02 14:20:21 -0700961}
962
Steven Moreland368e4602018-02-16 14:21:49 -0800963void AST::generateTypeSource(Formatter& out, const std::string& ifaceName) const {
964 mRootScope.emitTypeDefinitions(out, ifaceName);
Andreas Huber881227d2016-08-02 14:20:21 -0700965}
966
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700967void AST::declareCppReaderLocals(Formatter& out, const std::vector<NamedReference<Type>*>& args,
968 bool forResults) const {
Andreas Hubere7ff2282016-08-16 13:50:03 -0700969 if (args.empty()) {
970 return;
971 }
972
973 for (const auto &arg : args) {
974 const Type &type = arg->type();
975
Yifan Hong3b320f82016-11-01 15:15:54 -0700976 out << type.getCppResultType()
Andreas Hubere7ff2282016-08-16 13:50:03 -0700977 << " "
Yifan Hong3b320f82016-11-01 15:15:54 -0700978 << (forResults ? "_hidl_out_" : "") + arg->name()
Andreas Hubere7ff2282016-08-16 13:50:03 -0700979 << ";\n";
980 }
981
982 out << "\n";
983}
984
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700985void AST::emitCppReaderWriter(Formatter& out, const std::string& parcelObj, bool parcelObjIsPointer,
986 const NamedReference<Type>* arg, bool isReader, Type::ErrorMode mode,
987 bool addPrefixToName) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700988 const Type &type = arg->type();
989
Andreas Huber881227d2016-08-02 14:20:21 -0700990 type.emitReaderWriter(
991 out,
Andreas Huber5e44a292016-09-27 14:52:39 -0700992 addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(),
Andreas Huber881227d2016-08-02 14:20:21 -0700993 parcelObj,
994 parcelObjIsPointer,
995 isReader,
996 mode);
997}
998
Steven Moreland368e4602018-02-16 14:21:49 -0800999void AST::generateProxyMethodSource(Formatter& out, const std::string& klassName,
1000 const Method* method, const Interface* superInterface) const {
Yifan Hong068c5522016-10-31 14:07:25 -07001001 method->generateCppSignature(out,
1002 klassName,
1003 true /* specify namespaces */);
1004
Martijn Coenen115d4282016-12-19 05:14:04 +01001005 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
Steven Morelandf16c5c02017-07-31 16:50:06 -07001006 out.block([&] {
1007 method->cppImpl(IMPL_PROXY, out);
1008 }).endl().endl();
Steven Moreland368e4602018-02-16 14:21:49 -08001009 return;
Martijn Coenen115d4282016-12-19 05:14:04 +01001010 }
1011
Steven Morelandf16c5c02017-07-31 16:50:06 -07001012 out.block([&] {
1013 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001014 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001015
1016 method->generateCppReturnType(out);
1017
1018 out << " _hidl_out = "
1019 << superInterface->fqName().cppNamespace()
1020 << "::"
1021 << superInterface->getProxyName()
1022 << "::_hidl_"
1023 << method->name()
1024 << "(this, this";
1025
1026 if (!method->hasEmptyCppArgSignature()) {
1027 out << ", ";
1028 }
1029
1030 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
1031 out << arg->name();
1032 });
1033
1034 if (returnsValue && elidedReturn == nullptr) {
1035 if (!method->args().empty()) {
1036 out << ", ";
1037 }
1038 out << "_hidl_cb";
1039 }
1040
1041 out << ");\n\n";
1042
1043 out << "return _hidl_out;\n";
1044 }).endl().endl();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001045}
1046
Steven Moreland368e4602018-02-16 14:21:49 -08001047void AST::generateStaticProxyMethodSource(Formatter& out, const std::string& klassName,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001048 const Method* method, const Interface* superInterface) const {
Steven Morelandf16c5c02017-07-31 16:50:06 -07001049 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001050 return;
Steven Morelandf16c5c02017-07-31 16:50:06 -07001051 }
1052
1053 method->generateCppReturnType(out);
1054
1055 out << klassName
1056 << "::_hidl_"
1057 << method->name()
1058 << "("
1059 << "::android::hardware::IInterface *_hidl_this, "
1060 << "::android::hardware::details::HidlInstrumentor *_hidl_this_instrumentor";
1061
1062 if (!method->hasEmptyCppArgSignature()) {
1063 out << ", ";
1064 }
1065
1066 method->emitCppArgSignature(out);
1067 out << ") {\n";
1068
1069 out.indent();
1070
1071 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1072 out << "bool mEnableInstrumentation = _hidl_this_instrumentor->isInstrumentationEnabled();\n";
1073 out << "const auto &mInstrumentationCallbacks = _hidl_this_instrumentor->getInstrumentationCallbacks();\n";
1074 out << "#else\n";
1075 out << "(void) _hidl_this_instrumentor;\n";
1076 out << "#endif // __ANDROID_DEBUGGABLE__\n";
1077
1078 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001079 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland48cc6042019-04-30 11:28:56 -07001080 const bool hasCallback = returnsValue && elidedReturn == nullptr;
1081
Steven Moreland92a08a72017-07-31 14:57:37 -07001082 generateCppInstrumentationCall(
Yifan Hong068c5522016-10-31 14:07:25 -07001083 out,
1084 InstrumentationEvent::CLIENT_API_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001085 method,
1086 superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001087
1088 out << "::android::hardware::Parcel _hidl_data;\n";
1089 out << "::android::hardware::Parcel _hidl_reply;\n";
1090 out << "::android::status_t _hidl_err;\n";
Steven Moreland48cc6042019-04-30 11:28:56 -07001091 out << "::android::status_t _hidl_transact_err;\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001092 out << "::android::hardware::Status _hidl_status;\n\n";
1093
Steven Moreland48cc6042019-04-30 11:28:56 -07001094 if (!hasCallback) {
1095 declareCppReaderLocals(
1096 out, method->results(), true /* forResults */);
1097 }
Yifan Hong068c5522016-10-31 14:07:25 -07001098
1099 out << "_hidl_err = _hidl_data.writeInterfaceToken(";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001100 out << klassName;
Yifan Hong068c5522016-10-31 14:07:25 -07001101 out << "::descriptor);\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001102 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
1103
Martijn Coenenfff73352017-01-04 16:36:31 +01001104 bool hasInterfaceArgument = false;
Steven Moreland8249f0a2019-05-28 17:25:27 -07001105
Yifan Hong068c5522016-10-31 14:07:25 -07001106 for (const auto &arg : method->args()) {
Martijn Coenenfa55d6e2016-12-20 06:08:31 +01001107 if (arg->type().isInterface()) {
1108 hasInterfaceArgument = true;
1109 }
Yifan Hong068c5522016-10-31 14:07:25 -07001110 emitCppReaderWriter(
1111 out,
1112 "_hidl_data",
1113 false /* parcelObjIsPointer */,
1114 arg,
1115 false /* reader */,
1116 Type::ErrorMode_Goto,
1117 false /* addPrefixToName */);
1118 }
1119
Martijn Coenenfa55d6e2016-12-20 06:08:31 +01001120 if (hasInterfaceArgument) {
1121 // Start binder threadpool to handle incoming transactions
1122 out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
1123 }
Steven Moreland48cc6042019-04-30 11:28:56 -07001124 out << "_hidl_transact_err = ::android::hardware::IInterface::asBinder(_hidl_this)->transact("
Yifan Hong068c5522016-10-31 14:07:25 -07001125 << method->getSerialId()
1126 << " /* "
1127 << method->name()
1128 << " */, _hidl_data, &_hidl_reply";
1129
1130 if (method->isOneway()) {
Steven Moreland77943692018-08-09 12:53:42 -07001131 out << ", " << Interface::FLAG_ONE_WAY->cppValue();
Steven Moreland48cc6042019-04-30 11:28:56 -07001132 } else {
1133 out << ", 0";
Yifan Hong068c5522016-10-31 14:07:25 -07001134 }
Yifan Hong068c5522016-10-31 14:07:25 -07001135
Steven Moreland48cc6042019-04-30 11:28:56 -07001136 if (hasCallback) {
1137 out << ", [&] (::android::hardware::Parcel& _hidl_reply) {\n";
1138 out.indent();
1139 declareCppReaderLocals(
1140 out, method->results(), true /* forResults */);
1141 out.endl();
1142 } else {
1143 out << ");\n";
1144 out << "if (_hidl_transact_err != ::android::OK) \n";
1145 out.block([&] {
1146 out << "_hidl_err = _hidl_transact_err;\n";
1147 out << "goto _hidl_error;\n";
1148 }).endl().endl();
1149 }
Yifan Hong068c5522016-10-31 14:07:25 -07001150
1151 if (!method->isOneway()) {
Steven Moreland48cc6042019-04-30 11:28:56 -07001152 Type::ErrorMode errorMode = hasCallback ? Type::ErrorMode_ReturnNothing : Type::ErrorMode_Goto;
Yifan Hong068c5522016-10-31 14:07:25 -07001153
Steven Moreland48cc6042019-04-30 11:28:56 -07001154 out << "_hidl_err = ::android::hardware::readFromParcel(&_hidl_status, _hidl_reply);\n";
1155 Type::handleError(out, errorMode);
1156
1157 if (hasCallback) {
1158 out << "if (!_hidl_status.isOk()) { return; }\n\n";
1159 } else {
1160 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n";
1161 }
Yifan Hong068c5522016-10-31 14:07:25 -07001162
Yifan Hong068c5522016-10-31 14:07:25 -07001163 for (const auto &arg : method->results()) {
1164 emitCppReaderWriter(
1165 out,
1166 "_hidl_reply",
1167 false /* parcelObjIsPointer */,
1168 arg,
1169 true /* reader */,
Steven Moreland48cc6042019-04-30 11:28:56 -07001170 errorMode,
Yifan Hong068c5522016-10-31 14:07:25 -07001171 true /* addPrefixToName */);
1172 }
1173
Yifan Hong068c5522016-10-31 14:07:25 -07001174 if (returnsValue && elidedReturn == nullptr) {
1175 out << "_hidl_cb(";
1176
Yifan Hong932464e2017-03-30 15:40:22 -07001177 out.join(method->results().begin(), method->results().end(), ", ", [&] (const auto &arg) {
Yifan Hong068c5522016-10-31 14:07:25 -07001178 if (arg->type().resultNeedsDeref()) {
1179 out << "*";
1180 }
1181 out << "_hidl_out_" << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001182 });
Yifan Hong068c5522016-10-31 14:07:25 -07001183
1184 out << ");\n\n";
1185 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001186 }
Steven Morelandf16c5c02017-07-31 16:50:06 -07001187
Steven Moreland92a08a72017-07-31 14:57:37 -07001188 generateCppInstrumentationCall(
Martijn Coenen7b295242016-11-04 16:52:56 +01001189 out,
1190 InstrumentationEvent::CLIENT_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001191 method,
1192 superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001193
Steven Moreland48cc6042019-04-30 11:28:56 -07001194 if (hasCallback) {
1195 out.unindent();
1196 out << "});\n";
1197 out << "if (_hidl_transact_err != ::android::OK) ";
1198 out.block([&] {
1199 out << "_hidl_err = _hidl_transact_err;\n";
1200 out << "goto _hidl_error;\n";
1201 }).endl().endl();
1202 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n";
1203 }
1204
Yifan Hong068c5522016-10-31 14:07:25 -07001205 if (elidedReturn != nullptr) {
Yifan Hong068c5522016-10-31 14:07:25 -07001206 out << "return ::android::hardware::Return<";
Yifan Hong3b320f82016-11-01 15:15:54 -07001207 out << elidedReturn->type().getCppResultType()
Yifan Hong068c5522016-10-31 14:07:25 -07001208 << ">(_hidl_out_" << elidedReturn->name() << ");\n\n";
1209 } else {
Yifan Hong068c5522016-10-31 14:07:25 -07001210 out << "return ::android::hardware::Return<void>();\n\n";
1211 }
1212
1213 out.unindent();
1214 out << "_hidl_error:\n";
1215 out.indent();
1216 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
1217 out << "return ::android::hardware::Return<";
1218 if (elidedReturn != nullptr) {
Yifan Hong3b320f82016-11-01 15:15:54 -07001219 out << method->results().at(0)->type().getCppResultType();
Yifan Hong068c5522016-10-31 14:07:25 -07001220 } else {
1221 out << "void";
1222 }
1223 out << ">(_hidl_status);\n";
1224
1225 out.unindent();
1226 out << "}\n\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001227}
1228
Steven Moreland368e4602018-02-16 14:21:49 -08001229void AST::generateProxySource(Formatter& out, const FQName& fqName) const {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001230 const std::string klassName = fqName.getInterfaceProxyName();
Andreas Huber881227d2016-08-02 14:20:21 -07001231
1232 out << klassName
1233 << "::"
1234 << klassName
Iliyan Malchev549e2592016-08-10 08:59:12 -07001235 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001236
1237 out.indent();
1238 out.indent();
1239
1240 out << ": BpInterface"
Yifan Hongeefe4f22017-01-04 15:32:42 -08001241 << "<"
1242 << fqName.getInterfaceName()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001243 << ">(_hidl_impl),\n"
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001244 << " ::android::hardware::details::HidlInstrumentor(\""
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001245 << mPackage.string()
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001246 << "\", \""
Yifan Hongeefe4f22017-01-04 15:32:42 -08001247 << fqName.getInterfaceName()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001248 << "\") {\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001249
Andreas Huber881227d2016-08-02 14:20:21 -07001250 out.unindent();
1251 out.unindent();
1252 out << "}\n\n";
1253
Steven Moreland368e4602018-02-16 14:21:49 -08001254 generateMethods(out,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001255 [&](const Method* method, const Interface* superInterface) {
1256 generateStaticProxyMethodSource(out, klassName, method, superInterface);
Steven Moreland368e4602018-02-16 14:21:49 -08001257 },
1258 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -07001259
Steven Moreland368e4602018-02-16 14:21:49 -08001260 generateMethods(out, [&](const Method* method, const Interface* superInterface) {
1261 generateProxyMethodSource(out, klassName, method, superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001262 });
Andreas Huber881227d2016-08-02 14:20:21 -07001263}
1264
Steven Moreland368e4602018-02-16 14:21:49 -08001265void AST::generateStubSource(Formatter& out, const Interface* iface) const {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001266 const std::string interfaceName = iface->localName();
1267 const std::string klassName = iface->getStubName();
Andreas Huber881227d2016-08-02 14:20:21 -07001268
Steven Moreland40786312016-08-16 10:29:40 -07001269 out << klassName
1270 << "::"
1271 << klassName
Yifan Hongeefe4f22017-01-04 15:32:42 -08001272 << "(const ::android::sp<" << interfaceName <<"> &_hidl_impl)\n";
Steven Moreland40786312016-08-16 10:29:40 -07001273
1274 out.indent();
1275 out.indent();
1276
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001277 if (iface->isIBase()) {
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001278 out << ": ::android::hardware::details::HidlInstrumentor(\"";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001279 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001280 out << ": "
1281 << gIBaseFqName.getInterfaceStubFqName().cppName()
1282 << "(_hidl_impl, \"";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001283 }
1284
1285 out << mPackage.string()
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001286 << "\", \""
Yifan Hongeefe4f22017-01-04 15:32:42 -08001287 << interfaceName
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001288 << "\") { \n";
1289 out.indent();
1290 out << "_hidl_mImpl = _hidl_impl;\n";
Steven Morelandbd984412019-04-22 10:25:46 -07001291 out << "auto prio = ::android::hardware::details::gServicePrioMap->get("
Martijn Coenenb4d77952017-05-03 13:44:29 -07001292 << "_hidl_impl, {SCHED_NORMAL, 0});\n";
1293 out << "mSchedPolicy = prio.sched_policy;\n";
1294 out << "mSchedPriority = prio.prio;\n";
Steven Morelandbd984412019-04-22 10:25:46 -07001295 out << "setRequestingSid(::android::hardware::details::gServiceSidMap->get(_hidl_impl, "
1296 "false));\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001297 out.unindent();
Steven Moreland40786312016-08-16 10:29:40 -07001298
1299 out.unindent();
1300 out.unindent();
1301 out << "}\n\n";
1302
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001303 if (iface->isIBase()) {
Yifan Hong01e7cde2017-01-09 17:45:45 -08001304 // BnHwBase has a constructor to initialize the HidlInstrumentor
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001305 // class properly.
1306 out << klassName
1307 << "::"
1308 << klassName
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001309 << "(const ::android::sp<" << interfaceName << "> &_hidl_impl,"
1310 << " const std::string &HidlInstrumentor_package,"
1311 << " const std::string &HidlInstrumentor_interface)\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001312
1313 out.indent();
1314 out.indent();
1315
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001316 out << ": ::android::hardware::details::HidlInstrumentor("
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001317 << "HidlInstrumentor_package, HidlInstrumentor_interface) {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001318 out.indent();
1319 out << "_hidl_mImpl = _hidl_impl;\n";
1320 out.unindent();
1321
1322 out.unindent();
1323 out.unindent();
1324 out << "}\n\n";
1325 }
1326
Steven Moreland57a89362017-07-21 19:29:54 +00001327 out << klassName << "::~" << klassName << "() ";
1328 out.block([&]() {
Steven Morelandbd984412019-04-22 10:25:46 -07001329 out << "::android::hardware::details::gBnMap->eraseIfEqual(_hidl_mImpl.get(), this);\n";
1330 })
1331 .endl()
1332 .endl();
Steven Moreland57a89362017-07-21 19:29:54 +00001333
Steven Moreland368e4602018-02-16 14:21:49 -08001334 generateMethods(out,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001335 [&](const Method* method, const Interface* superInterface) {
1336 return generateStaticStubMethodSource(out, iface->fqName(), method, superInterface);
Steven Moreland368e4602018-02-16 14:21:49 -08001337 },
1338 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -07001339
Steven Moreland368e4602018-02-16 14:21:49 -08001340 generateMethods(out, [&](const Method* method, const Interface*) {
Yifan Hongbcffce22017-02-01 15:52:06 -08001341 if (!method->isHidlReserved() || !method->overridesCppImpl(IMPL_STUB_IMPL)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001342 return;
Yifan Hongbcffce22017-02-01 15:52:06 -08001343 }
1344 method->generateCppSignature(out, iface->getStubName());
1345 out << " ";
1346 out.block([&] {
1347 method->cppImpl(IMPL_STUB_IMPL, out);
1348 }).endl();
Yifan Hongbcffce22017-02-01 15:52:06 -08001349 });
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001350
Andreas Huber881227d2016-08-02 14:20:21 -07001351 out << "::android::status_t " << klassName << "::onTransact(\n";
1352
1353 out.indent();
1354 out.indent();
1355
Iliyan Malchev549e2592016-08-10 08:59:12 -07001356 out << "uint32_t _hidl_code,\n"
1357 << "const ::android::hardware::Parcel &_hidl_data,\n"
1358 << "::android::hardware::Parcel *_hidl_reply,\n"
1359 << "uint32_t _hidl_flags,\n"
1360 << "TransactCallback _hidl_cb) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001361
1362 out.unindent();
1363
Iliyan Malchev549e2592016-08-10 08:59:12 -07001364 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
Iliyan Malchev549e2592016-08-10 08:59:12 -07001365 out << "switch (_hidl_code) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001366 out.indent();
1367
Yifan Hong10fe0b52016-10-19 14:20:17 -07001368 for (const auto &tuple : iface->allMethodsFromRoot()) {
1369 const Method *method = tuple.method();
1370 const Interface *superInterface = tuple.interface();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001371
Howard Chen71f289f2017-08-29 17:35:01 +08001372 if (!isIBase() && method->isHidlReserved()) {
1373 continue;
1374 }
Yifan Hong10fe0b52016-10-19 14:20:17 -07001375 out << "case "
1376 << method->getSerialId()
1377 << " /* "
1378 << method->name()
1379 << " */:\n{\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001380
Yifan Hong10fe0b52016-10-19 14:20:17 -07001381 out.indent();
Andreas Huber881227d2016-08-02 14:20:21 -07001382
Steven Moreland368e4602018-02-16 14:21:49 -08001383 generateStubSourceForMethod(out, method, superInterface);
Yifan Hong10fe0b52016-10-19 14:20:17 -07001384
1385 out.unindent();
1386 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001387 }
1388
1389 out << "default:\n{\n";
1390 out.indent();
1391
Martijn Coenen225bc922017-06-27 14:39:46 -07001392 if (iface->isIBase()) {
1393 out << "(void)_hidl_flags;\n";
1394 out << "return ::android::UNKNOWN_TRANSACTION;\n";
1395 } else {
1396 out << "return ";
1397 out << gIBaseFqName.getInterfaceStubFqName().cppName();
1398 out << "::onTransact(\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001399
Martijn Coenen225bc922017-06-27 14:39:46 -07001400 out.indent();
1401 out.indent();
Andreas Huber881227d2016-08-02 14:20:21 -07001402
Martijn Coenen225bc922017-06-27 14:39:46 -07001403 out << "_hidl_code, _hidl_data, _hidl_reply, "
1404 << "_hidl_flags, _hidl_cb);\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001405
Martijn Coenen225bc922017-06-27 14:39:46 -07001406 out.unindent();
1407 out.unindent();
1408 }
Andreas Huber881227d2016-08-02 14:20:21 -07001409
1410 out.unindent();
1411 out << "}\n";
1412
1413 out.unindent();
1414 out << "}\n\n";
1415
Yifan Honga018ed52016-12-13 16:35:08 -08001416 out.sIf("_hidl_err == ::android::UNEXPECTED_NULL", [&] {
1417 out << "_hidl_err = ::android::hardware::writeToParcel(\n";
1418 out.indent(2, [&] {
1419 out << "::android::hardware::Status::fromExceptionCode(::android::hardware::Status::EX_NULL_POINTER),\n";
1420 out << "_hidl_reply);\n";
1421 });
1422 });
Andreas Huber881227d2016-08-02 14:20:21 -07001423
Iliyan Malchev549e2592016-08-10 08:59:12 -07001424 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001425
1426 out.unindent();
1427 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001428}
1429
Steven Moreland368e4602018-02-16 14:21:49 -08001430void AST::generateStubSourceForMethod(Formatter& out, const Method* method,
1431 const Interface* superInterface) const {
Martijn Coenen115d4282016-12-19 05:14:04 +01001432 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB)) {
1433 method->cppImpl(IMPL_STUB, out);
1434 out << "break;\n";
Steven Moreland368e4602018-02-16 14:21:49 -08001435 return;
Martijn Coenen115d4282016-12-19 05:14:04 +01001436 }
1437
Steven Morelandf16c5c02017-07-31 16:50:06 -07001438 out << "_hidl_err = "
1439 << superInterface->fqName().cppNamespace()
1440 << "::"
1441 << superInterface->getStubName()
1442 << "::_hidl_"
1443 << method->name()
1444 << "(this, _hidl_data, _hidl_reply, _hidl_cb);\n";
1445 out << "break;\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001446}
1447
Steven Moreland368e4602018-02-16 14:21:49 -08001448void AST::generateStaticStubMethodSource(Formatter& out, const FQName& fqName,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001449 const Method* method, const Interface* superInterface) const {
Steven Morelandf16c5c02017-07-31 16:50:06 -07001450 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001451 return;
Steven Morelandf16c5c02017-07-31 16:50:06 -07001452 }
1453
Steven Morelandf8197902018-01-30 15:38:37 -08001454 const std::string& klassName = fqName.getInterfaceStubName();
1455
Steven Morelandf16c5c02017-07-31 16:50:06 -07001456 out << "::android::status_t " << klassName << "::_hidl_" << method->name() << "(\n";
1457
1458 out.indent();
1459 out.indent();
1460
1461 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
1462 << "const ::android::hardware::Parcel &_hidl_data,\n"
1463 << "::android::hardware::Parcel *_hidl_reply,\n"
1464 << "TransactCallback _hidl_cb) {\n";
1465
1466 out.unindent();
1467
1468 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1469 out << "bool mEnableInstrumentation = _hidl_this->isInstrumentationEnabled();\n";
1470 out << "const auto &mInstrumentationCallbacks = _hidl_this->getInstrumentationCallbacks();\n";
1471 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";
1472
1473 out << "::android::status_t _hidl_err = ::android::OK;\n";
1474
Yifan Hongeefe4f22017-01-04 15:32:42 -08001475 out << "if (!_hidl_data.enforceInterface("
Steven Morelandf16c5c02017-07-31 16:50:06 -07001476 << klassName
1477 << "::Pure::descriptor)) {\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -07001478
Andreas Huber881227d2016-08-02 14:20:21 -07001479 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -07001480 out << "_hidl_err = ::android::BAD_TYPE;\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001481 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001482 out.unindent();
1483 out << "}\n\n";
1484
Andreas Huber5e44a292016-09-27 14:52:39 -07001485 declareCppReaderLocals(out, method->args(), false /* forResults */);
Andreas Hubere7ff2282016-08-16 13:50:03 -07001486
Andreas Huber881227d2016-08-02 14:20:21 -07001487 for (const auto &arg : method->args()) {
1488 emitCppReaderWriter(
1489 out,
Iliyan Malchev549e2592016-08-10 08:59:12 -07001490 "_hidl_data",
Andreas Huber881227d2016-08-02 14:20:21 -07001491 false /* parcelObjIsPointer */,
1492 arg,
1493 true /* reader */,
Steven Morelandf16c5c02017-07-31 16:50:06 -07001494 Type::ErrorMode_Return,
Andreas Huber5e44a292016-09-27 14:52:39 -07001495 false /* addPrefixToName */);
Andreas Huber881227d2016-08-02 14:20:21 -07001496 }
1497
Steven Moreland92a08a72017-07-31 14:57:37 -07001498 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001499 out,
1500 InstrumentationEvent::SERVER_API_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001501 method,
1502 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001503
Andreas Huber881227d2016-08-02 14:20:21 -07001504 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001505 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland3e787002017-08-16 14:59:54 -07001506
1507 std::string callee;
1508
1509 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB_IMPL)) {
1510 callee = "_hidl_this";
1511 } else {
Steven Morelandf8197902018-01-30 15:38:37 -08001512 callee = "static_cast<" + fqName.getInterfaceName() + "*>(_hidl_this->getImpl().get())";
Steven Moreland3e787002017-08-16 14:59:54 -07001513 }
Andreas Huber881227d2016-08-02 14:20:21 -07001514
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001515 if (elidedReturn != nullptr) {
Yifan Hong3b320f82016-11-01 15:15:54 -07001516 out << elidedReturn->type().getCppResultType()
Yifan Honga47eef32016-12-12 10:38:54 -08001517 << " _hidl_out_"
Yifan Hong3b320f82016-11-01 15:15:54 -07001518 << elidedReturn->name()
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001519 << " = "
Yifan Hongcd2ae452017-01-31 14:33:40 -08001520 << callee << "->" << method->name()
Yifan Hong3b320f82016-11-01 15:15:54 -07001521 << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001522
Yifan Hong932464e2017-03-30 15:40:22 -07001523 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001524 if (arg->type().resultNeedsDeref()) {
1525 out << "*";
1526 }
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001527 out << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001528 });
Andreas Huber881227d2016-08-02 14:20:21 -07001529
Steven Moreland2ae5bca2016-12-01 05:56:49 +00001530 out << ");\n\n";
Steven Moreland30232dc2019-03-05 19:39:10 -08001531
Yifan Hong859e53f2016-11-14 19:08:24 -08001532 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1533 << "_hidl_reply);\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001534
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001535 elidedReturn->type().emitReaderWriter(
1536 out,
Yifan Honga47eef32016-12-12 10:38:54 -08001537 "_hidl_out_" + elidedReturn->name(),
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001538 "_hidl_reply",
1539 true, /* parcelObjIsPointer */
1540 false, /* isReader */
1541 Type::ErrorMode_Ignore);
Andreas Huber881227d2016-08-02 14:20:21 -07001542
Steven Moreland92a08a72017-07-31 14:57:37 -07001543 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001544 out,
1545 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001546 method,
1547 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001548
Iliyan Malchev549e2592016-08-10 08:59:12 -07001549 out << "_hidl_cb(*_hidl_reply);\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001550 } else {
1551 if (returnsValue) {
1552 out << "bool _hidl_callbackCalled = false;\n\n";
1553 }
Andreas Huber881227d2016-08-02 14:20:21 -07001554
Steven Moreland30232dc2019-03-05 19:39:10 -08001555 out << "::android::hardware::Return<void> _hidl_ret = " << callee << "->" << method->name()
1556 << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001557
Yifan Hong932464e2017-03-30 15:40:22 -07001558 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001559 if (arg->type().resultNeedsDeref()) {
1560 out << "*";
1561 }
1562
1563 out << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001564 });
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001565
1566 if (returnsValue) {
Yifan Hong932464e2017-03-30 15:40:22 -07001567 if (!method->args().empty()) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001568 out << ", ";
1569 }
1570
1571 out << "[&](";
1572
Yifan Hong932464e2017-03-30 15:40:22 -07001573 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
Yifan Honga47eef32016-12-12 10:38:54 -08001574 out << "const auto &_hidl_out_" << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001575 });
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001576
1577 out << ") {\n";
1578 out.indent();
Steven Moreland05cd4232016-11-21 16:01:12 -08001579 out << "if (_hidl_callbackCalled) {\n";
1580 out.indent();
1581 out << "LOG_ALWAYS_FATAL(\""
1582 << method->name()
1583 << ": _hidl_cb called a second time, but must be called once.\");\n";
1584 out.unindent();
1585 out << "}\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001586 out << "_hidl_callbackCalled = true;\n\n";
1587
Yifan Hong859e53f2016-11-14 19:08:24 -08001588 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1589 << "_hidl_reply);\n\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001590
1591 for (const auto &arg : method->results()) {
1592 emitCppReaderWriter(
1593 out,
1594 "_hidl_reply",
1595 true /* parcelObjIsPointer */,
1596 arg,
1597 false /* reader */,
Andreas Huber5e44a292016-09-27 14:52:39 -07001598 Type::ErrorMode_Ignore,
Yifan Honga47eef32016-12-12 10:38:54 -08001599 true /* addPrefixToName */);
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001600 }
1601
Steven Moreland92a08a72017-07-31 14:57:37 -07001602 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001603 out,
1604 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001605 method,
1606 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001607
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001608 out << "_hidl_cb(*_hidl_reply);\n";
1609
1610 out.unindent();
Martijn Coenen8e4fc842017-01-09 16:28:59 +01001611 out << "});\n\n";
1612 } else {
1613 out << ");\n\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001614 out << "(void) _hidl_cb;\n\n";
Steven Moreland92a08a72017-07-31 14:57:37 -07001615 generateCppInstrumentationCall(
Martijn Coenen8e4fc842017-01-09 16:28:59 +01001616 out,
1617 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001618 method,
1619 superInterface);
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001620 }
Iliyan Malchevd57066f2016-09-08 13:59:38 -07001621
Steven Moreland30232dc2019-03-05 19:39:10 -08001622 out << "_hidl_ret.assertOk();\n";
1623
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001624 if (returnsValue) {
1625 out << "if (!_hidl_callbackCalled) {\n";
1626 out.indent();
Steven Moreland05cd4232016-11-21 16:01:12 -08001627 out << "LOG_ALWAYS_FATAL(\""
1628 << method->name()
1629 << ": _hidl_cb not called, but must be called once.\");\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001630 out.unindent();
1631 out << "}\n\n";
Steven Moreland05cd4232016-11-21 16:01:12 -08001632 } else {
1633 out << "::android::hardware::writeToParcel("
1634 << "::android::hardware::Status::ok(), "
1635 << "_hidl_reply);\n\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001636 }
Andreas Huber881227d2016-08-02 14:20:21 -07001637 }
1638
Steven Morelandf16c5c02017-07-31 16:50:06 -07001639 out << "return _hidl_err;\n";
1640 out.unindent();
1641 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001642}
1643
Steven Moreland368e4602018-02-16 14:21:49 -08001644void AST::generatePassthroughHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -07001645 if (!AST::isInterface()) {
Steven Moreland69e7c702016-09-09 11:16:32 -07001646 // types.hal does not get a stub header.
Steven Moreland368e4602018-02-16 14:21:49 -08001647 return;
Steven Moreland69e7c702016-09-09 11:16:32 -07001648 }
1649
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001650 const Interface* iface = mRootScope.getInterface();
Steven Moreland19f11b52017-05-12 18:22:21 -07001651 CHECK(iface != nullptr);
Steven Moreland69e7c702016-09-09 11:16:32 -07001652
Yifan Hongeefe4f22017-01-04 15:32:42 -08001653 const std::string klassName = iface->getPassthroughName();
Steven Moreland69e7c702016-09-09 11:16:32 -07001654
Steven Moreland69e7c702016-09-09 11:16:32 -07001655 const std::string guard = makeHeaderGuard(klassName);
1656
1657 out << "#ifndef " << guard << "\n";
1658 out << "#define " << guard << "\n\n";
1659
1660 std::vector<std::string> packageComponents;
1661 getPackageAndVersionComponents(
1662 &packageComponents, false /* cpp_compatible */);
1663
Steven Moreland61d3f4b2017-04-28 17:30:38 -07001664 out << "#include <android-base/macros.h>\n";
Yifan Hongb0949432016-12-15 15:32:24 -08001665 out << "#include <cutils/trace.h>\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001666 out << "#include <future>\n";
Steven Morelandee88eed2016-10-31 17:49:00 -07001667
Steven Moreland19f11b52017-05-12 18:22:21 -07001668 generateCppPackageInclude(out, mPackage, iface->localName());
Steven Morelandee88eed2016-10-31 17:49:00 -07001669 out << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001670
Yifan Hong7a118f52016-12-07 11:21:15 -08001671 out << "#include <hidl/HidlPassthroughSupport.h>\n";
Neel Mehta19f79792019-05-21 13:39:32 -07001672 out << "#include <hidl/TaskRunner.h>\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001673
1674 enterLeaveNamespace(out, true /* enter */);
1675 out << "\n";
1676
1677 out << "struct "
1678 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -07001679 << " : " << iface->localName()
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001680 << ", ::android::hardware::details::HidlInstrumentor {\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001681
1682 out.indent();
1683 out << "explicit "
1684 << klassName
Steven Morelandc46e9842016-11-02 13:21:26 -07001685 << "(const ::android::sp<"
Steven Moreland19f11b52017-05-12 18:22:21 -07001686 << iface->localName()
Steven Moreland69e7c702016-09-09 11:16:32 -07001687 << "> impl);\n";
1688
Steven Moreland0b843772017-06-23 16:33:38 -07001689 out.endl();
1690 generateTemplatizationLink(out);
Steven Moreland1a52e822017-07-27 13:56:29 -07001691 generateCppTag(out, "android::hardware::details::bs_tag");
Steven Moreland0b843772017-06-23 16:33:38 -07001692
Steven Moreland616cf4d2018-10-02 13:52:18 -07001693 generateMethods(out, [&](const Method* method, const Interface* superInterface) {
1694 generatePassthroughMethod(out, method, superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001695 });
Steven Moreland69e7c702016-09-09 11:16:32 -07001696
Steven Moreland69e7c702016-09-09 11:16:32 -07001697 out.unindent();
1698 out << "private:\n";
1699 out.indent();
Steven Moreland19f11b52017-05-12 18:22:21 -07001700 out << "const ::android::sp<" << iface->localName() << "> mImpl;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001701
Neel Mehta19f79792019-05-21 13:39:32 -07001702 out << "::android::hardware::details::TaskRunner mOnewayQueue;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001703
Neel Mehta19f79792019-05-21 13:39:32 -07001704 out << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001705
Neel Mehta19f79792019-05-21 13:39:32 -07001706 out << "::android::hardware::Return<void> addOnewayTask("
1707 "std::function<void(void)>);\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001708
1709 out.unindent();
1710
1711 out << "};\n\n";
1712
1713 enterLeaveNamespace(out, false /* enter */);
1714
1715 out << "\n#endif // " << guard << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001716}
1717
Steven Moreland368e4602018-02-16 14:21:49 -08001718void AST::generateInterfaceSource(Formatter& out) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001719 const Interface* iface = mRootScope.getInterface();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001720
Yifan Hong2d7126b2016-10-20 15:12:57 -07001721 // generate castFrom functions
Yifan Hong3d746092016-12-07 14:26:33 -08001722 std::string childTypeResult = iface->getCppResultType();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001723
Steven Moreland368e4602018-02-16 14:21:49 -08001724 generateMethods(out, [&](const Method* method, const Interface*) {
Steven Morelandd4b068a2017-03-20 06:30:51 -07001725 bool reserved = method->isHidlReserved();
1726
1727 if (!reserved) {
1728 out << "// no default implementation for: ";
1729 }
1730 method->generateCppSignature(out, iface->localName());
1731 if (reserved) {
1732 out.block([&]() {
Steven Moreland937408a2017-03-20 09:54:18 -07001733 method->cppImpl(IMPL_INTERFACE, out);
Steven Morelandd4b068a2017-03-20 06:30:51 -07001734 }).endl();
1735 }
1736
1737 out << "\n";
1738
Steven Moreland368e4602018-02-16 14:21:49 -08001739 return;
Steven Morelandd4b068a2017-03-20 06:30:51 -07001740 });
Steven Morelandd4b068a2017-03-20 06:30:51 -07001741
Yifan Hong3d746092016-12-07 14:26:33 -08001742 for (const Interface *superType : iface->typeChain()) {
Steven Moreland23cc5fa2018-05-09 10:48:48 -07001743 out << "::android::hardware::Return<"
Yifan Hong3d746092016-12-07 14:26:33 -08001744 << childTypeResult
Yifan Hong200209c2017-03-29 03:39:09 -07001745 << "> "
Yifan Hongeefe4f22017-01-04 15:32:42 -08001746 << iface->localName()
Yifan Hong3d746092016-12-07 14:26:33 -08001747 << "::castFrom("
1748 << superType->getCppArgumentType()
Yifan Hong200209c2017-03-29 03:39:09 -07001749 << " parent, bool "
1750 << (iface == superType ? "/* emitError */" : "emitError")
1751 << ") {\n";
Yifan Hong3d746092016-12-07 14:26:33 -08001752 out.indent();
1753 if (iface == superType) {
1754 out << "return parent;\n";
1755 } else {
Yifan Hong33e78012017-03-13 17:46:33 -07001756 out << "return ::android::hardware::details::castInterface<";
Yifan Hongeefe4f22017-01-04 15:32:42 -08001757 out << iface->localName() << ", "
Yifan Hongfe95aa22016-10-19 17:26:45 -07001758 << superType->fqName().cppName() << ", "
Steven Moreland57a89362017-07-21 19:29:54 +00001759 << iface->getProxyName()
Yifan Hongfe95aa22016-10-19 17:26:45 -07001760 << ">(\n";
1761 out.indent();
1762 out.indent();
1763 out << "parent, \""
1764 << iface->fqName().string()
Yifan Hong200209c2017-03-29 03:39:09 -07001765 << "\", emitError);\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -07001766 out.unindent();
1767 out.unindent();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001768 }
Yifan Hong3d746092016-12-07 14:26:33 -08001769 out.unindent();
1770 out << "}\n\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -07001771 }
Yifan Hongfe95aa22016-10-19 17:26:45 -07001772}
1773
Steven Moreland368e4602018-02-16 14:21:49 -08001774void AST::generatePassthroughSource(Formatter& out) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001775 const Interface* iface = mRootScope.getInterface();
Steven Moreland69e7c702016-09-09 11:16:32 -07001776
Yifan Hongeefe4f22017-01-04 15:32:42 -08001777 const std::string klassName = iface->getPassthroughName();
Steven Moreland69e7c702016-09-09 11:16:32 -07001778
Neel Mehta19f79792019-05-21 13:39:32 -07001779 out << klassName << "::" << klassName << "(const ::android::sp<" << iface->fullName()
1780 << "> impl) : ::android::hardware::details::HidlInstrumentor(\"" << mPackage.string()
1781 << "\", \"" << iface->localName() << "\"), mImpl(impl) {\n";
1782
1783 out.indent([&] { out << "mOnewayQueue.start(3000 /* similar limit to binderized */);\n"; });
1784
Yifan Hong2cbc1472016-10-25 19:02:40 -07001785 out << "}\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001786
Neel Mehta19f79792019-05-21 13:39:32 -07001787 out << "::android::hardware::Return<void> " << klassName
1788 << "::addOnewayTask(std::function<void(void)> fun) {\n";
1789 out.indent();
1790 out << "if (!mOnewayQueue.push(fun)) {\n";
1791 out.indent();
1792 out << "return ::android::hardware::Status::fromExceptionCode(\n";
1793 out.indent();
1794 out.indent();
1795 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
1796 << "\"Passthrough oneway function queue exceeds maximum size.\");\n";
1797 out.unindent();
1798 out.unindent();
1799 out.unindent();
1800 out << "}\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001801
Neel Mehta19f79792019-05-21 13:39:32 -07001802 out << "return ::android::hardware::Status();\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001803
Neel Mehta19f79792019-05-21 13:39:32 -07001804 out.unindent();
1805 out << "}\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001806}
1807
Steven Moreland92a08a72017-07-31 14:57:37 -07001808void AST::generateCppAtraceCall(Formatter &out,
Martijn Coenen7b295242016-11-04 16:52:56 +01001809 InstrumentationEvent event,
1810 const Method *method) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001811 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -08001812 std::string baseString = "HIDL::" + iface->localName() + "::" + method->name();
Martijn Coenen7b295242016-11-04 16:52:56 +01001813 switch (event) {
1814 case SERVER_API_ENTRY:
1815 {
1816 out << "atrace_begin(ATRACE_TAG_HAL, \""
1817 << baseString + "::server\");\n";
1818 break;
1819 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001820 case PASSTHROUGH_ENTRY:
1821 {
1822 out << "atrace_begin(ATRACE_TAG_HAL, \""
1823 << baseString + "::passthrough\");\n";
1824 break;
1825 }
1826 case SERVER_API_EXIT:
Martijn Coenen7b295242016-11-04 16:52:56 +01001827 case PASSTHROUGH_EXIT:
1828 {
1829 out << "atrace_end(ATRACE_TAG_HAL);\n";
1830 break;
1831 }
Steven Moreland4607ef52018-05-09 10:52:47 -07001832 // client uses scope because of gotos
1833 // this isn't done for server because the profiled code isn't alone in its scope
1834 // this isn't done for passthrough becuase the profiled boundary isn't even in the same code
1835 case CLIENT_API_ENTRY: {
Michael Butler0a3d99a2018-07-26 13:47:10 -07001836 out << "::android::ScopedTrace PASTE(___tracer, __LINE__) (ATRACE_TAG_HAL, \""
1837 << baseString + "::client\");\n";
Steven Moreland4607ef52018-05-09 10:52:47 -07001838 break;
1839 }
1840 case CLIENT_API_EXIT:
1841 break;
Martijn Coenen7b295242016-11-04 16:52:56 +01001842 default:
1843 {
Steven Morelandcbff5612017-10-11 17:01:54 -07001844 CHECK(false) << "Unsupported instrumentation event: " << event;
Martijn Coenen7b295242016-11-04 16:52:56 +01001845 }
1846 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001847}
1848
Steven Moreland92a08a72017-07-31 14:57:37 -07001849void AST::generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001850 Formatter &out,
1851 InstrumentationEvent event,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001852 const Method *method,
1853 const Interface* superInterface) const {
Steven Moreland92a08a72017-07-31 14:57:37 -07001854 generateCppAtraceCall(out, event, method);
Martijn Coenen7b295242016-11-04 16:52:56 +01001855
Steven Moreland30b76e92017-06-02 18:52:24 -07001856 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001857 out << "if (UNLIKELY(mEnableInstrumentation)) {\n";
1858 out.indent();
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001859 out << "std::vector<void *> _hidl_args;\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001860 std::string event_str = "";
1861 switch (event) {
1862 case SERVER_API_ENTRY:
1863 {
1864 event_str = "InstrumentationEvent::SERVER_API_ENTRY";
1865 for (const auto &arg : method->args()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001866 out << "_hidl_args.push_back((void *)"
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001867 << (arg->type().resultNeedsDeref() ? "" : "&")
1868 << arg->name()
1869 << ");\n";
1870 }
1871 break;
1872 }
1873 case SERVER_API_EXIT:
1874 {
1875 event_str = "InstrumentationEvent::SERVER_API_EXIT";
Steven Moreland031ccf12016-10-31 15:54:38 -07001876 for (const auto &arg : method->results()) {
Yifan Honga47eef32016-12-12 10:38:54 -08001877 out << "_hidl_args.push_back((void *)&_hidl_out_"
Steven Moreland031ccf12016-10-31 15:54:38 -07001878 << arg->name()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001879 << ");\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001880 }
1881 break;
1882 }
1883 case CLIENT_API_ENTRY:
1884 {
1885 event_str = "InstrumentationEvent::CLIENT_API_ENTRY";
1886 for (const auto &arg : method->args()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001887 out << "_hidl_args.push_back((void *)&"
1888 << arg->name()
1889 << ");\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001890 }
1891 break;
1892 }
1893 case CLIENT_API_EXIT:
1894 {
1895 event_str = "InstrumentationEvent::CLIENT_API_EXIT";
1896 for (const auto &arg : method->results()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001897 out << "_hidl_args.push_back((void *)"
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001898 << (arg->type().resultNeedsDeref() ? "" : "&")
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001899 << "_hidl_out_"
1900 << arg->name()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001901 << ");\n";
1902 }
1903 break;
1904 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -07001905 case PASSTHROUGH_ENTRY:
1906 {
1907 event_str = "InstrumentationEvent::PASSTHROUGH_ENTRY";
1908 for (const auto &arg : method->args()) {
1909 out << "_hidl_args.push_back((void *)&"
1910 << arg->name()
1911 << ");\n";
1912 }
1913 break;
1914 }
1915 case PASSTHROUGH_EXIT:
1916 {
1917 event_str = "InstrumentationEvent::PASSTHROUGH_EXIT";
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -08001918 for (const auto &arg : method->results()) {
Yifan Honga47eef32016-12-12 10:38:54 -08001919 out << "_hidl_args.push_back((void *)&_hidl_out_"
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -08001920 << arg->name()
1921 << ");\n";
1922 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -07001923 break;
1924 }
Steven Moreland031ccf12016-10-31 15:54:38 -07001925 default:
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001926 {
Steven Morelandcbff5612017-10-11 17:01:54 -07001927 CHECK(false) << "Unsupported instrumentation event: " << event;
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001928 }
1929 }
1930
Steven Moreland1ab31442016-11-03 18:37:51 -07001931 out << "for (const auto &callback: mInstrumentationCallbacks) {\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001932 out.indent();
1933 out << "callback("
1934 << event_str
1935 << ", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001936 << superInterface->fqName().package()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001937 << "\", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001938 << superInterface->fqName().version()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001939 << "\", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001940 << superInterface->localName()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001941 << "\", \""
1942 << method->name()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001943 << "\", &_hidl_args);\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001944 out.unindent();
1945 out << "}\n";
1946 out.unindent();
Steven Moreland30b76e92017-06-02 18:52:24 -07001947 out << "}\n";
1948 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001949}
1950
Andreas Huber881227d2016-08-02 14:20:21 -07001951} // namespace android