blob: 9e9b34889bf13bab57c303a237bc9b3728179ce7 [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"
Andreas Huber881227d2016-08-02 14:20:21 -070023#include "Method.h"
Timur Iskhakov7fa79f62017-08-09 11:04:54 -070024#include "Reference.h"
Iliyan Malchev40d474a2016-08-16 06:20:17 -070025#include "ScalarType.h"
Andreas Huber881227d2016-08-02 14:20:21 -070026#include "Scope.h"
27
Andreas Huberdca261f2016-08-04 13:47:51 -070028#include <algorithm>
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070029#include <hidl-util/Formatter.h>
Steven Moreland5708edf2016-11-04 15:33:31 +000030#include <hidl-util/StringHelper.h>
Andreas Huber881227d2016-08-02 14:20:21 -070031#include <android-base/logging.h>
Andreas Huberdca261f2016-08-04 13:47:51 -070032#include <string>
Andreas Huber881227d2016-08-02 14:20:21 -070033#include <vector>
34
35namespace android {
36
Andreas Huber737080b2016-08-02 15:38:04 -070037void AST::getPackageComponents(
38 std::vector<std::string> *components) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070039 mPackage.getPackageComponents(components);
Andreas Huber737080b2016-08-02 15:38:04 -070040}
41
42void AST::getPackageAndVersionComponents(
43 std::vector<std::string> *components, bool cpp_compatible) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070044 mPackage.getPackageAndVersionComponents(components, cpp_compatible);
Andreas Huber737080b2016-08-02 15:38:04 -070045}
46
Steven Moreland5708edf2016-11-04 15:33:31 +000047std::string AST::makeHeaderGuard(const std::string &baseName,
48 bool indicateGenerated) const {
49 std::string guard;
Andreas Huber881227d2016-08-02 14:20:21 -070050
Steven Moreland5708edf2016-11-04 15:33:31 +000051 if (indicateGenerated) {
52 guard += "HIDL_GENERATED_";
53 }
54
55 guard += StringHelper::Uppercase(mPackage.tokenName());
Andreas Huber881227d2016-08-02 14:20:21 -070056 guard += "_";
Steven Moreland5708edf2016-11-04 15:33:31 +000057 guard += StringHelper::Uppercase(baseName);
58 guard += "_H";
Andreas Huber881227d2016-08-02 14:20:21 -070059
60 return guard;
61}
62
Steven Morelandee88eed2016-10-31 17:49:00 -070063void AST::generateCppPackageInclude(
64 Formatter &out,
65 const FQName &package,
66 const std::string &klass) {
67
68 out << "#include <";
69
70 std::vector<std::string> components;
71 package.getPackageAndVersionComponents(&components, false /* cpp_compatible */);
72
73 for (const auto &component : components) {
74 out << component << "/";
75 }
76
77 out << klass
78 << ".h>\n";
79}
80
Andreas Huber881227d2016-08-02 14:20:21 -070081void AST::enterLeaveNamespace(Formatter &out, bool enter) const {
82 std::vector<std::string> packageComponents;
83 getPackageAndVersionComponents(
84 &packageComponents, true /* cpp_compatible */);
85
86 if (enter) {
87 for (const auto &component : packageComponents) {
88 out << "namespace " << component << " {\n";
89 }
Andreas Huber0e00de42016-08-03 09:56:02 -070090
Andreas Huber2831d512016-08-15 09:33:47 -070091 out.setNamespace(mPackage.cppNamespace() + "::");
Andreas Huber881227d2016-08-02 14:20:21 -070092 } else {
Andreas Huber0e00de42016-08-03 09:56:02 -070093 out.setNamespace(std::string());
94
Andreas Huber881227d2016-08-02 14:20:21 -070095 for (auto it = packageComponents.rbegin();
96 it != packageComponents.rend();
97 ++it) {
98 out << "} // namespace " << *it << "\n";
99 }
100 }
101}
102
Steven Moreland038903b2017-03-30 12:11:24 -0700103static void declareGetService(Formatter &out, const std::string &interfaceName, bool isTry) {
104 const std::string functionName = isTry ? "tryGetService" : "getService";
105
Steven Moreland7645fbd2019-03-12 18:49:28 -0700106 if (isTry) {
107 DocComment(
108 "This gets the service of this type with the specified instance name. If the\n"
109 "service is currently not available or not in the VINTF manifest on a Trebilized\n"
110 "device, this will return nullptr. This is useful when you don't want to block\n"
111 "during device boot. If getStub is true, this will try to return an unwrapped\n"
112 "passthrough implementation in the same process. This is useful when getting an\n"
113 "implementation from the same partition/compilation group.\n\n"
114 "In general, prefer getService(std::string,bool)")
115 .emit(out);
116 } else {
117 DocComment(
118 "This gets the service of this type with the specified instance name. If the\n"
119 "service is not in the VINTF manifest on a Trebilized device, this will return\n"
120 "nullptr. If the service is not available, this will wait for the service to\n"
121 "become available. If the service is a lazy service, this will start the service\n"
122 "and return when it becomes available. If getStub is true, this will try to\n"
123 "return an unwrapped passthrough implementation in the same process. This is\n"
124 "useful when getting an implementation from the same partition/compilation group.")
125 .emit(out);
126 }
Steven Moreland038903b2017-03-30 12:11:24 -0700127 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
Chris Phoenixdb0d6342017-01-11 16:10:00 -0800128 << "const std::string &serviceName=\"default\", bool getStub=false);\n";
Steven Moreland7645fbd2019-03-12 18:49:28 -0700129 DocComment("Deprecated. See " + functionName + "(std::string, bool)").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";
Steven Moreland7645fbd2019-03-12 18:49:28 -0700134 DocComment("Deprecated. See " + functionName + "(std::string, bool)").emit(out);
Steven Moreland038903b2017-03-30 12:11:24 -0700135 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
Chris Phoenixdb0d6342017-01-11 16:10:00 -0800136 << "const ::android::hardware::hidl_string& serviceName, bool getStub=false)"
137 // without c_str the std::string constructor is ambiguous
138 << " { std::string str(serviceName.c_str());"
Steven Moreland038903b2017-03-30 12:11:24 -0700139 << " return " << functionName << "(str, getStub); }\n";
Steven Moreland7645fbd2019-03-12 18:49:28 -0700140 DocComment("Calls " + functionName +
141 "(\"default\", bool). This is the recommended instance name for singleton services.")
142 .emit(out);
Steven Moreland038903b2017-03-30 12:11:24 -0700143 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
144 << "bool getStub) { return " << functionName << "(\"default\", getStub); }\n";
145}
146
147static void declareServiceManagerInteractions(Formatter &out, const std::string &interfaceName) {
148 declareGetService(out, interfaceName, true /* isTry */);
149 declareGetService(out, interfaceName, false /* isTry */);
150
Steven Moreland7645fbd2019-03-12 18:49:28 -0700151 DocComment(
152 "Registers a service with the service manager. For Trebilized devices, the service\n"
153 "must also be in the VINTF manifest.")
154 .emit(out);
Steven Moreland90831502017-03-27 12:08:40 -0700155 out << "__attribute__ ((warn_unused_result))"
156 << "::android::status_t registerAsService(const std::string &serviceName=\"default\");\n";
Steven Moreland7645fbd2019-03-12 18:49:28 -0700157 DocComment("Registers for notifications for when a service is registered.").emit(out);
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800158 out << "static bool registerForNotifications(\n";
159 out.indent(2, [&] {
160 out << "const std::string &serviceName,\n"
161 << "const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> "
162 << "&notification);\n";
163 });
164
165}
166
Steven Moreland038903b2017-03-30 12:11:24 -0700167static void implementGetService(Formatter &out,
168 const FQName &fqName,
169 bool isTry) {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800170
171 const std::string interfaceName = fqName.getInterfaceName();
Steven Moreland038903b2017-03-30 12:11:24 -0700172 const std::string functionName = isTry ? "tryGetService" : "getService";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800173
Steven Moreland23cc5fa2018-05-09 10:48:48 -0700174 out << "::android::sp<" << interfaceName << "> " << interfaceName << "::" << functionName << "("
Yifan Hong31f07ff2017-03-21 18:56:35 +0000175 << "const std::string &serviceName, const bool getStub) ";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800176 out.block([&] {
Steven Moreland78f95f92017-10-06 17:07:40 -0700177 out << "return ::android::hardware::details::getServiceInternal<"
178 << fqName.getInterfaceProxyName()
179 << ">(serviceName, "
180 << (!isTry ? "true" : "false") // retry
181 << ", getStub);\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800182 }).endl().endl();
Steven Moreland038903b2017-03-30 12:11:24 -0700183}
184
185static void implementServiceManagerInteractions(Formatter &out,
186 const FQName &fqName, const std::string &package) {
187
188 const std::string interfaceName = fqName.getInterfaceName();
189
190 implementGetService(out, fqName, true /* isTry */);
191 implementGetService(out, fqName, false /* isTry */);
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800192
Yifan Hongeefe4f22017-01-04 15:32:42 -0800193 out << "::android::status_t " << interfaceName << "::registerAsService("
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800194 << "const std::string &serviceName) ";
195 out.block([&] {
Steven Moreland5f84b382018-10-11 12:10:35 -0700196 out << "return ::android::hardware::details::registerAsServiceInternal(this, serviceName);\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800197 }).endl().endl();
198
Yifan Hongeefe4f22017-01-04 15:32:42 -0800199 out << "bool " << interfaceName << "::registerForNotifications(\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800200 out.indent(2, [&] {
201 out << "const std::string &serviceName,\n"
202 << "const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> "
203 << "&notification) ";
204 });
205 out.block([&] {
206 out << "const ::android::sp<::android::hidl::manager::V1_0::IServiceManager> sm\n";
207 out.indent(2, [&] {
208 out << "= ::android::hardware::defaultServiceManager();\n";
209 });
210 out.sIf("sm == nullptr", [&] {
211 out << "return false;\n";
212 }).endl();
213 out << "::android::hardware::Return<bool> success =\n";
214 out.indent(2, [&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800215 out << "sm->registerForNotifications(\"" << package << "::" << interfaceName << "\",\n";
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800216 out.indent(2, [&] {
217 out << "serviceName, notification);\n";
218 });
219 });
220 out << "return success.isOk() && success;\n";
221 }).endl().endl();
222}
223
Steven Moreland368e4602018-02-16 14:21:49 -0800224void AST::generateInterfaceHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700225 const Interface *iface = getInterface();
226 std::string ifaceName = iface ? iface->localName() : "types";
Andreas Huber881227d2016-08-02 14:20:21 -0700227 const std::string guard = makeHeaderGuard(ifaceName);
228
229 out << "#ifndef " << guard << "\n";
230 out << "#define " << guard << "\n\n";
231
Andreas Huber737080b2016-08-02 15:38:04 -0700232 for (const auto &item : mImportedNames) {
Steven Morelandee88eed2016-10-31 17:49:00 -0700233 generateCppPackageInclude(out, item, item.name());
Andreas Huber737080b2016-08-02 15:38:04 -0700234 }
235
236 if (!mImportedNames.empty()) {
237 out << "\n";
238 }
239
Steven Moreland19f11b52017-05-12 18:22:21 -0700240 if (iface) {
Yifan Hongc8934042016-11-17 17:10:52 -0800241 if (isIBase()) {
242 out << "// skipped #include IServiceNotification.h\n\n";
243 } else {
244 out << "#include <android/hidl/manager/1.0/IServiceNotification.h>\n\n";
245 }
Steven Moreland0693f312016-11-09 15:06:14 -0800246 }
247
Yifan Hongc8934042016-11-17 17:10:52 -0800248 out << "#include <hidl/HidlSupport.h>\n";
Andreas Huber4bcf97d2016-08-30 11:27:49 -0700249 out << "#include <hidl/MQDescriptor.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700250
Steven Moreland19f11b52017-05-12 18:22:21 -0700251 if (iface) {
Martijn Coenen93915102016-09-01 01:35:52 +0200252 out << "#include <hidl/Status.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700253 }
254
Martijn Coenenaf712c02016-11-16 15:26:27 +0100255 out << "#include <utils/NativeHandle.h>\n";
256 out << "#include <utils/misc.h>\n\n"; /* for report_sysprop_change() */
Andreas Huber881227d2016-08-02 14:20:21 -0700257
258 enterLeaveNamespace(out, true /* enter */);
259 out << "\n";
260
Steven Moreland19f11b52017-05-12 18:22:21 -0700261 if (iface) {
Steven Moreland70cb55e2019-03-12 17:20:54 -0700262 iface->emitDocComment(out);
263
Andreas Huber881227d2016-08-02 14:20:21 -0700264 out << "struct "
Steven Moreland40786312016-08-16 10:29:40 -0700265 << ifaceName;
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700266
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700267 const Interface *superType = iface->superType();
268
Yi Kong56758da2018-07-24 16:21:37 -0700269 if (superType == nullptr) {
Yifan Hongc8934042016-11-17 17:10:52 -0800270 out << " : virtual public ::android::RefBase";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700271 } else {
Steven Morelandd916a702016-10-26 22:23:09 +0000272 out << " : public "
Steven Moreland40786312016-08-16 10:29:40 -0700273 << superType->fullName();
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700274 }
275
276 out << " {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700277
278 out.indent();
279
Steven Moreland7645fbd2019-03-12 18:49:28 -0700280 DocComment("Type tag for use in template logic that indicates this is a 'pure' class.")
281 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700282 generateCppTag(out, "android::hardware::details::i_tag");
Andreas Huber881227d2016-08-02 14:20:21 -0700283
Steven Moreland7645fbd2019-03-12 18:49:28 -0700284 DocComment("Fully qualified interface name: \"" + iface->fqName().string() + "\"")
285 .emit(out);
286 out << "static const char* descriptor;\n\n";
287
Steven Moreland70cb55e2019-03-12 17:20:54 -0700288 iface->emitTypeDeclarations(out);
289 } else {
290 mRootScope.emitTypeDeclarations(out);
291 }
Andreas Huber881227d2016-08-02 14:20:21 -0700292
Steven Moreland19f11b52017-05-12 18:22:21 -0700293 if (iface) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700294 DocComment(
295 "Returns whether this object's implementation is outside of the current process.")
296 .emit(out);
Yifan Hongc8934042016-11-17 17:10:52 -0800297 out << "virtual bool isRemote() const ";
298 if (!isIBase()) {
299 out << "override ";
300 }
Steven Moreland7645fbd2019-03-12 18:49:28 -0700301 out << "{ return false; }\n";
Steven Morelandd732ea12016-11-08 17:12:06 -0800302
Steven Morelandf7f2a9a2017-07-21 18:05:38 -0700303 for (const auto& tuple : iface->allMethodsFromRoot()) {
304 const Method* method = tuple.method();
305
Andreas Huber881227d2016-08-02 14:20:21 -0700306 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700307
Andreas Huber881227d2016-08-02 14:20:21 -0700308 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700309 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Morelandd732ea12016-11-08 17:12:06 -0800310
311 if (elidedReturn == nullptr && returnsValue) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700312 DocComment("Return callback for " + method->name()).emit(out);
Steven Morelandd732ea12016-11-08 17:12:06 -0800313 out << "using "
314 << method->name()
Yifan Hong932464e2017-03-30 15:40:22 -0700315 << "_cb = std::function<void(";
316 method->emitCppResultSignature(out, true /* specify namespaces */);
317 out << ")>;\n";
Steven Morelandd732ea12016-11-08 17:12:06 -0800318 }
Andreas Huber881227d2016-08-02 14:20:21 -0700319
Andreas Huber3599d922016-08-09 10:42:57 -0700320 method->dumpAnnotations(out);
321
Steven Moreland49bad8d2018-05-17 15:45:26 -0700322 method->emitDocComment(out);
323
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700324 if (elidedReturn) {
Iliyan Malchev2b6591b2016-08-18 19:15:19 -0700325 out << "virtual ::android::hardware::Return<";
Yifan Hong3b320f82016-11-01 15:15:54 -0700326 out << elidedReturn->type().getCppResultType() << "> ";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700327 } else {
Iliyan Malchevd57066f2016-09-08 13:59:38 -0700328 out << "virtual ::android::hardware::Return<void> ";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700329 }
330
331 out << method->name()
Yifan Hong932464e2017-03-30 15:40:22 -0700332 << "(";
333 method->emitCppArgSignature(out, true /* specify namespaces */);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700334 out << ")";
335 if (method->isHidlReserved()) {
Yifan Hongc8934042016-11-17 17:10:52 -0800336 if (!isIBase()) {
337 out << " override";
338 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700339 } else {
Steven Morelandd4b068a2017-03-20 06:30:51 -0700340 out << " = 0";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700341 }
Steven Morelandd4b068a2017-03-20 06:30:51 -0700342 out << ";\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700343 }
Steven Moreland40786312016-08-16 10:29:40 -0700344
Steven Moreland7645fbd2019-03-12 18:49:28 -0700345 out << "\n// cast static functions\n";
Yifan Hong3d746092016-12-07 14:26:33 -0800346 std::string childTypeResult = iface->getCppResultType();
Yifan Hongfe95aa22016-10-19 17:26:45 -0700347
Yifan Hong3d746092016-12-07 14:26:33 -0800348 for (const Interface *superType : iface->typeChain()) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700349 DocComment(
350 "This performs a checked cast based on what the underlying implementation "
351 "actually is.")
352 .emit(out);
Yifan Hong200209c2017-03-29 03:39:09 -0700353 out << "static ::android::hardware::Return<"
Yifan Hong3d746092016-12-07 14:26:33 -0800354 << childTypeResult
Yifan Hong200209c2017-03-29 03:39:09 -0700355 << "> castFrom("
Yifan Hong3d746092016-12-07 14:26:33 -0800356 << superType->getCppArgumentType()
357 << " parent"
Yifan Hong200209c2017-03-29 03:39:09 -0700358 << ", bool emitError = false);\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -0700359 }
360
Yifan Hongc8934042016-11-17 17:10:52 -0800361 if (isIBase()) {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700362 out << "\n// skipped getService, registerAsService, registerForNotifications\n\n";
Yifan Hongc8934042016-11-17 17:10:52 -0800363 } else {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700364 out << "\n// helper methods for interactions with the hwservicemanager\n";
Yifan Hongeefe4f22017-01-04 15:32:42 -0800365 declareServiceManagerInteractions(out, iface->localName());
Yifan Hongc8934042016-11-17 17:10:52 -0800366 }
Andreas Huber881227d2016-08-02 14:20:21 -0700367 }
368
Steven Moreland19f11b52017-05-12 18:22:21 -0700369 if (iface) {
Andreas Huber881227d2016-08-02 14:20:21 -0700370 out.unindent();
371
Andreas Hubere3f769a2016-10-10 10:54:44 -0700372 out << "};\n\n";
373 }
374
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700375 out << "//\n";
376 out << "// type declarations for package\n";
377 out << "//\n\n";
Steven Moreland368e4602018-02-16 14:21:49 -0800378 mRootScope.emitPackageTypeDeclarations(out);
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700379 out << "//\n";
380 out << "// type header definitions for package\n";
381 out << "//\n\n";
382 mRootScope.emitPackageTypeHeaderDefinitions(out);
Andreas Huber881227d2016-08-02 14:20:21 -0700383
384 out << "\n";
385 enterLeaveNamespace(out, false /* enter */);
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700386 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700387
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700388 out << "//\n";
389 out << "// global type declarations for package\n";
390 out << "//\n\n";
Steven Moreland8e61c5a2017-11-17 15:55:28 -0800391 mRootScope.emitGlobalTypeDeclarations(out);
392
Andreas Huber881227d2016-08-02 14:20:21 -0700393 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700394}
395
Steven Moreland368e4602018-02-16 14:21:49 -0800396void AST::generateHwBinderHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700397 const Interface *iface = getInterface();
398 std::string klassName = iface ? iface->getHwName() : "hwtypes";
Steven Moreland40786312016-08-16 10:29:40 -0700399
Steven Moreland40786312016-08-16 10:29:40 -0700400 const std::string guard = makeHeaderGuard(klassName);
401
402 out << "#ifndef " << guard << "\n";
403 out << "#define " << guard << "\n\n";
404
Steven Moreland19f11b52017-05-12 18:22:21 -0700405 generateCppPackageInclude(out, mPackage, iface ? iface->localName() : "types");
Steven Moreland40786312016-08-16 10:29:40 -0700406
Steven Morelandee88eed2016-10-31 17:49:00 -0700407 out << "\n";
Steven Moreland40786312016-08-16 10:29:40 -0700408
409 for (const auto &item : mImportedNames) {
410 if (item.name() == "types") {
Yifan Hong244e82d2016-11-11 11:13:57 -0800411 generateCppPackageInclude(out, item, "hwtypes");
412 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800413 generateCppPackageInclude(out, item, item.getInterfaceStubName());
414 generateCppPackageInclude(out, item, item.getInterfaceProxyName());
Steven Moreland40786312016-08-16 10:29:40 -0700415 }
Steven Moreland40786312016-08-16 10:29:40 -0700416 }
417
418 out << "\n";
419
Martijn Coenen93915102016-09-01 01:35:52 +0200420 out << "#include <hidl/Status.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700421 out << "#include <hwbinder/IBinder.h>\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100422 out << "#include <hwbinder/Parcel.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700423
424 out << "\n";
425
426 enterLeaveNamespace(out, true /* enter */);
Steven Moreland40786312016-08-16 10:29:40 -0700427
Steven Moreland368e4602018-02-16 14:21:49 -0800428 mRootScope.emitPackageHwDeclarations(out);
Steven Moreland40786312016-08-16 10:29:40 -0700429
430 enterLeaveNamespace(out, false /* enter */);
431
432 out << "\n#endif // " << guard << "\n";
Steven Moreland40786312016-08-16 10:29:40 -0700433}
434
Steven Moreland58a20c72018-10-09 12:30:51 -0700435static std::string wrapPassthroughArg(Formatter& out, const NamedReference<Type>* arg,
436 std::string name, std::function<void(void)> handleError) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800437 if (!arg->type().isInterface()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700438 return name;
Yifan Hong7a118f52016-12-07 11:21:15 -0800439 }
Steven Moreland58a20c72018-10-09 12:30:51 -0700440 std::string wrappedName = "_hidl_wrapped_" + name;
Yifan Hong7a118f52016-12-07 11:21:15 -0800441 const Interface &iface = static_cast<const Interface &>(arg->type());
442 out << iface.getCppStackType() << " " << wrappedName << ";\n";
443 // TODO(elsk): b/33754152 Should not wrap this if object is Bs*
444 out.sIf(name + " != nullptr && !" + name + "->isRemote()", [&] {
445 out << wrappedName
446 << " = "
Steven Morelandbff4bd22017-10-02 14:46:06 -0700447 << "::android::hardware::details::wrapPassthrough("
448 << name
449 << ");\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800450 out.sIf(wrappedName + " == nullptr", [&] {
451 // Fatal error. Happens when the BsFoo class is not found in the binary
452 // or any dynamic libraries.
453 handleError();
454 }).endl();
455 }).sElse([&] {
456 out << wrappedName << " = " << name << ";\n";
457 }).endl().endl();
Steven Moreland58a20c72018-10-09 12:30:51 -0700458
459 return wrappedName;
Yifan Hong7a118f52016-12-07 11:21:15 -0800460}
461
Steven Moreland616cf4d2018-10-02 13:52:18 -0700462void AST::generatePassthroughMethod(Formatter& out, const Method* method, const Interface* superInterface) const {
Yifan Hong068c5522016-10-31 14:07:25 -0700463 method->generateCppSignature(out);
Steven Moreland69e7c702016-09-09 11:16:32 -0700464
Steven Moreland58a20c72018-10-09 12:30:51 -0700465 out << " override {\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700466 out.indent();
467
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800468 if (method->isHidlReserved()
469 && method->overridesCppImpl(IMPL_PASSTHROUGH)) {
470 method->cppImpl(IMPL_PASSTHROUGH, out);
471 out.unindent();
472 out << "}\n\n";
Steven Moreland368e4602018-02-16 14:21:49 -0800473 return;
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800474 }
475
Steven Moreland69e7c702016-09-09 11:16:32 -0700476 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700477 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland69e7c702016-09-09 11:16:32 -0700478
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700479 generateCppInstrumentationCall(
480 out,
481 InstrumentationEvent::PASSTHROUGH_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700482 method,
483 superInterface);
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700484
Steven Moreland58a20c72018-10-09 12:30:51 -0700485 std::vector<std::string> wrappedArgNames;
Yifan Hong7a118f52016-12-07 11:21:15 -0800486 for (const auto &arg : method->args()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700487 std::string name = wrapPassthroughArg(out, arg, arg->name(), [&] {
Yifan Hong7a118f52016-12-07 11:21:15 -0800488 out << "return ::android::hardware::Status::fromExceptionCode(\n";
489 out.indent(2, [&] {
490 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
Yifan Hong0abd7392016-12-20 16:43:26 -0800491 << "\"Cannot wrap passthrough interface.\");\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800492 });
493 });
Steven Moreland58a20c72018-10-09 12:30:51 -0700494
495 wrappedArgNames.push_back(name);
Yifan Hong7a118f52016-12-07 11:21:15 -0800496 }
497
Steven Moreland58a20c72018-10-09 12:30:51 -0700498 out << "::android::hardware::Status _hidl_error = ::android::hardware::Status::ok();\n";
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700499 out << "auto _hidl_return = ";
Steven Moreland69e7c702016-09-09 11:16:32 -0700500
501 if (method->isOneway()) {
Steven Moreland836cb312017-06-05 17:25:55 -0700502 out << "addOnewayTask([mImpl = this->mImpl\n"
503 << "#ifdef __ANDROID_DEBUGGABLE__\n"
504 ", mEnableInstrumentation = this->mEnableInstrumentation, "
505 "mInstrumentationCallbacks = this->mInstrumentationCallbacks\n"
506 << "#endif // __ANDROID_DEBUGGABLE__\n";
Steven Moreland58a20c72018-10-09 12:30:51 -0700507 for (const std::string& arg : wrappedArgNames) {
508 out << ", " << arg;
Steven Moreland69e7c702016-09-09 11:16:32 -0700509 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700510 out << "] {\n";
511 out.indent();
Steven Moreland69e7c702016-09-09 11:16:32 -0700512 }
513
514 out << "mImpl->"
515 << method->name()
516 << "(";
517
Yifan Hong932464e2017-03-30 15:40:22 -0700518 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800519 out << (arg->type().isInterface() ? "_hidl_wrapped_" : "") << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -0700520 });
Steven Moreland58a20c72018-10-09 12:30:51 -0700521
522 std::function<void(void)> kHandlePassthroughError = [&] {
523 out << "_hidl_error = ::android::hardware::Status::fromExceptionCode(\n";
524 out.indent(2, [&] {
525 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
526 << "\"Cannot wrap passthrough interface.\");\n";
527 });
528 };
529
Steven Moreland69e7c702016-09-09 11:16:32 -0700530 if (returnsValue && elidedReturn == nullptr) {
Steven Moreland340c8822017-05-02 14:41:49 -0700531 // never true if oneway since oneway methods don't return values
532
Steven Moreland69e7c702016-09-09 11:16:32 -0700533 if (!method->args().empty()) {
534 out << ", ";
535 }
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800536 out << "[&](";
Yifan Hong932464e2017-03-30 15:40:22 -0700537 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
Yifan Hong7a118f52016-12-07 11:21:15 -0800538 out << "const auto &_hidl_out_"
539 << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -0700540 });
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800541
542 out << ") {\n";
543 out.indent();
Steven Moreland92a08a72017-07-31 14:57:37 -0700544 generateCppInstrumentationCall(
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800545 out,
546 InstrumentationEvent::PASSTHROUGH_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700547 method,
548 superInterface);
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800549
Steven Moreland58a20c72018-10-09 12:30:51 -0700550 std::vector<std::string> wrappedOutNames;
Yifan Hong7a118f52016-12-07 11:21:15 -0800551 for (const auto &arg : method->results()) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700552 wrappedOutNames.push_back(
553 wrapPassthroughArg(out, arg, "_hidl_out_" + arg->name(), kHandlePassthroughError));
Yifan Hong7a118f52016-12-07 11:21:15 -0800554 }
555
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800556 out << "_hidl_cb(";
Steven Moreland58a20c72018-10-09 12:30:51 -0700557 out.join(wrappedOutNames.begin(), wrappedOutNames.end(), ", ",
558 [&](const std::string& arg) { out << arg; });
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800559 out << ");\n";
560 out.unindent();
561 out << "});\n\n";
562 } else {
563 out << ");\n\n";
Steven Moreland30b76e92017-06-02 18:52:24 -0700564
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800565 if (elidedReturn != nullptr) {
Steven Moreland58a20c72018-10-09 12:30:51 -0700566 const std::string outName = "_hidl_out_" + elidedReturn->name();
567
568 out << elidedReturn->type().getCppResultType() << " " << outName
569 << " = _hidl_return;\n";
570 out << "(void) " << outName << ";\n";
571
572 const std::string wrappedName =
573 wrapPassthroughArg(out, elidedReturn, outName, kHandlePassthroughError);
574
575 if (outName != wrappedName) {
576 // update the original value since it is used by generateCppInstrumentationCall
577 out << outName << " = " << wrappedName << ";\n\n";
578
579 // update the value to be returned
580 out << "_hidl_return = " << outName << "\n;";
581 }
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800582 }
Steven Moreland92a08a72017-07-31 14:57:37 -0700583 generateCppInstrumentationCall(
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -0800584 out,
585 InstrumentationEvent::PASSTHROUGH_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -0700586 method,
587 superInterface);
Steven Moreland69e7c702016-09-09 11:16:32 -0700588 }
Steven Moreland69e7c702016-09-09 11:16:32 -0700589
590 if (method->isOneway()) {
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700591 out.unindent();
592 out << "});\n";
Steven Moreland58a20c72018-10-09 12:30:51 -0700593 } else {
594 out << "if (!_hidl_error.isOk()) return _hidl_error;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700595 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -0700596
597 out << "return _hidl_return;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700598
599 out.unindent();
600 out << "}\n";
Steven Moreland69e7c702016-09-09 11:16:32 -0700601}
602
Steven Moreland368e4602018-02-16 14:21:49 -0800603void AST::generateMethods(Formatter& out, const MethodGenerator& gen, bool includeParent) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700604 const Interface* iface = mRootScope.getInterface();
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700605
Yifan Hong10fe0b52016-10-19 14:20:17 -0700606 const Interface *prevIterface = nullptr;
607 for (const auto &tuple : iface->allMethodsFromRoot()) {
608 const Method *method = tuple.method();
609 const Interface *superInterface = tuple.interface();
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700610
Steven Morelandf16c5c02017-07-31 16:50:06 -0700611 if (!includeParent && superInterface != iface) {
612 continue;
613 }
614
Yifan Hong10fe0b52016-10-19 14:20:17 -0700615 if(prevIterface != superInterface) {
616 if (prevIterface != nullptr) {
617 out << "\n";
618 }
619 out << "// Methods from "
620 << superInterface->fullName()
621 << " follow.\n";
622 prevIterface = superInterface;
623 }
Steven Moreland368e4602018-02-16 14:21:49 -0800624 gen(method, superInterface);
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700625 }
626
Yifan Hong10fe0b52016-10-19 14:20:17 -0700627 out << "\n";
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700628}
629
Steven Moreland0b843772017-06-23 16:33:38 -0700630void AST::generateTemplatizationLink(Formatter& out) const {
Steven Moreland7645fbd2019-03-12 18:49:28 -0700631 DocComment("The pure class is what this class wraps.").emit(out);
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700632 out << "typedef " << mRootScope.getInterface()->localName() << " Pure;\n\n";
Steven Moreland0b843772017-06-23 16:33:38 -0700633}
634
Steven Moreland1a52e822017-07-27 13:56:29 -0700635void AST::generateCppTag(Formatter& out, const std::string& tag) const {
636 out << "typedef " << tag << " _hidl_tag;\n\n";
637}
638
Steven Moreland368e4602018-02-16 14:21:49 -0800639void AST::generateStubHeader(Formatter& out) const {
Steven Moreland5abcf012018-02-08 18:50:18 -0800640 CHECK(AST::isInterface());
Andreas Huber881227d2016-08-02 14:20:21 -0700641
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700642 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800643 const std::string klassName = iface->getStubName();
Steven Moreland40786312016-08-16 10:29:40 -0700644 const std::string guard = makeHeaderGuard(klassName);
Andreas Huber881227d2016-08-02 14:20:21 -0700645
646 out << "#ifndef " << guard << "\n";
647 out << "#define " << guard << "\n\n";
648
Yifan Hongeefe4f22017-01-04 15:32:42 -0800649 generateCppPackageInclude(out, mPackage, iface->getHwName());
Steven Moreland1a52e822017-07-27 13:56:29 -0700650
Steven Morelandee88eed2016-10-31 17:49:00 -0700651 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700652
653 enterLeaveNamespace(out, true /* enter */);
654 out << "\n";
655
656 out << "struct "
Yifan Hongeefe4f22017-01-04 15:32:42 -0800657 << klassName;
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100658 if (iface->isIBase()) {
Yifan Hong96a79e22017-01-12 14:22:05 -0800659 out << " : public ::android::hardware::BHwBinder";
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +0000660 out << ", public ::android::hardware::details::HidlInstrumentor {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100661 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800662 out << " : public "
663 << gIBaseFqName.getInterfaceStubFqName().cppName()
664 << " {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100665 }
Andreas Huber881227d2016-08-02 14:20:21 -0700666
667 out.indent();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800668 out << "explicit "
669 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -0700670 << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl);"
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100671 << "\n";
Yifan Hongeefe4f22017-01-04 15:32:42 -0800672 out << "explicit "
673 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -0700674 << "(const ::android::sp<" << iface->localName() << "> &_hidl_impl,"
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -0800675 << " const std::string& HidlInstrumentor_package,"
676 << " const std::string& HidlInstrumentor_interface);"
Steven Moreland40786312016-08-16 10:29:40 -0700677 << "\n\n";
Steven Moreland57a89362017-07-21 19:29:54 +0000678 out << "virtual ~" << klassName << "();\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700679 out << "::android::status_t onTransact(\n";
680 out.indent();
681 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -0700682 out << "uint32_t _hidl_code,\n";
683 out << "const ::android::hardware::Parcel &_hidl_data,\n";
684 out << "::android::hardware::Parcel *_hidl_reply,\n";
685 out << "uint32_t _hidl_flags = 0,\n";
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700686 out << "TransactCallback _hidl_cb = nullptr) override;\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700687 out.unindent();
688 out.unindent();
689
Steven Moreland0b843772017-06-23 16:33:38 -0700690 out.endl();
691 generateTemplatizationLink(out);
Steven Moreland7645fbd2019-03-12 18:49:28 -0700692 DocComment("Type tag for use in template logic that indicates this is a 'native' class.")
693 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700694 generateCppTag(out, "android::hardware::details::bnhw_tag");
Steven Moreland0b843772017-06-23 16:33:38 -0700695
Steven Morelandcbcf9f72017-11-20 10:04:15 -0800696 out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; }\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700697
Steven Moreland368e4602018-02-16 14:21:49 -0800698 generateMethods(out,
699 [&](const Method* method, const Interface*) {
700 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
701 return;
702 }
Steven Morelandf16c5c02017-07-31 16:50:06 -0700703
Steven Moreland368e4602018-02-16 14:21:49 -0800704 out << "static ::android::status_t _hidl_" << method->name() << "(\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700705
Steven Moreland368e4602018-02-16 14:21:49 -0800706 out.indent(2,
707 [&] {
708 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
709 << "const ::android::hardware::Parcel &_hidl_data,\n"
710 << "::android::hardware::Parcel *_hidl_reply,\n"
711 << "TransactCallback _hidl_cb);\n";
712 })
713 .endl()
714 .endl();
715 },
716 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -0700717
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100718 out.unindent();
719 out << "private:\n";
720 out.indent();
Yifan Hongcd2ae452017-01-31 14:33:40 -0800721
Steven Moreland368e4602018-02-16 14:21:49 -0800722 generateMethods(out, [&](const Method* method, const Interface* iface) {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800723 if (!method->isHidlReserved() || !method->overridesCppImpl(IMPL_STUB_IMPL)) {
Steven Moreland368e4602018-02-16 14:21:49 -0800724 return;
Yifan Hongcd2ae452017-01-31 14:33:40 -0800725 }
726 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700727 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Yifan Hongcd2ae452017-01-31 14:33:40 -0800728
729 if (elidedReturn == nullptr && returnsValue) {
730 out << "using " << method->name() << "_cb = "
731 << iface->fqName().cppName()
732 << "::" << method->name() << "_cb;\n";
733 }
734 method->generateCppSignature(out);
Yifan Hongbcffce22017-02-01 15:52:06 -0800735 out << ";\n";
Yifan Hongcd2ae452017-01-31 14:33:40 -0800736 });
Yifan Hongcd2ae452017-01-31 14:33:40 -0800737
Steven Moreland19f11b52017-05-12 18:22:21 -0700738 out << "::android::sp<" << iface->localName() << "> _hidl_mImpl;\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700739 out.unindent();
Andreas Huber881227d2016-08-02 14:20:21 -0700740 out << "};\n\n";
741
742 enterLeaveNamespace(out, false /* enter */);
743
744 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700745}
746
Steven Moreland368e4602018-02-16 14:21:49 -0800747void AST::generateProxyHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700748 if (!AST::isInterface()) {
Andreas Huber881227d2016-08-02 14:20:21 -0700749 // types.hal does not get a proxy header.
Steven Moreland368e4602018-02-16 14:21:49 -0800750 return;
Andreas Huber881227d2016-08-02 14:20:21 -0700751 }
752
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700753 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800754 const std::string proxyName = iface->getProxyName();
Yifan Hongeefe4f22017-01-04 15:32:42 -0800755 const std::string guard = makeHeaderGuard(proxyName);
Andreas Huber881227d2016-08-02 14:20:21 -0700756
757 out << "#ifndef " << guard << "\n";
758 out << "#define " << guard << "\n\n";
759
Martijn Coenen115d4282016-12-19 05:14:04 +0100760 out << "#include <hidl/HidlTransportSupport.h>\n\n";
761
Andreas Huber881227d2016-08-02 14:20:21 -0700762 std::vector<std::string> packageComponents;
763 getPackageAndVersionComponents(
764 &packageComponents, false /* cpp_compatible */);
765
Yifan Hongeefe4f22017-01-04 15:32:42 -0800766 generateCppPackageInclude(out, mPackage, iface->getHwName());
Steven Morelandee88eed2016-10-31 17:49:00 -0700767 out << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700768
769 enterLeaveNamespace(out, true /* enter */);
770 out << "\n";
771
772 out << "struct "
Yifan Hongeefe4f22017-01-04 15:32:42 -0800773 << proxyName
774 << " : public ::android::hardware::BpInterface<"
775 << iface->localName()
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +0000776 << ">, public ::android::hardware::details::HidlInstrumentor {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700777
778 out.indent();
779
Yifan Hongeefe4f22017-01-04 15:32:42 -0800780 out << "explicit "
781 << proxyName
Iliyan Malchev549e2592016-08-10 08:59:12 -0700782 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl);"
Andreas Huber881227d2016-08-02 14:20:21 -0700783 << "\n\n";
784
Steven Moreland0b843772017-06-23 16:33:38 -0700785 generateTemplatizationLink(out);
Steven Moreland7645fbd2019-03-12 18:49:28 -0700786 DocComment("Type tag for use in template logic that indicates this is a 'proxy' class.")
787 .emit(out);
Steven Moreland1a52e822017-07-27 13:56:29 -0700788 generateCppTag(out, "android::hardware::details::bphw_tag");
Steven Moreland0b843772017-06-23 16:33:38 -0700789
Yifan Hong10fe0b52016-10-19 14:20:17 -0700790 out << "virtual bool isRemote() const override { return true; }\n\n";
Steven Moreland40786312016-08-16 10:29:40 -0700791
Steven Moreland596d20e2019-06-07 11:52:21 -0700792 out << "void onLastStrongRef(const void* id) override;\n\n";
793
Steven Moreland368e4602018-02-16 14:21:49 -0800794 generateMethods(
795 out,
796 [&](const Method* method, const Interface*) {
797 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
798 return;
799 }
Steven Morelandf16c5c02017-07-31 16:50:06 -0700800
Steven Moreland368e4602018-02-16 14:21:49 -0800801 out << "static ";
802 method->generateCppReturnType(out);
803 out << " _hidl_" << method->name() << "("
804 << "::android::hardware::IInterface* _hidl_this, "
805 << "::android::hardware::details::HidlInstrumentor *_hidl_this_instrumentor";
Steven Morelandf16c5c02017-07-31 16:50:06 -0700806
Steven Moreland368e4602018-02-16 14:21:49 -0800807 if (!method->hasEmptyCppArgSignature()) {
808 out << ", ";
809 }
810 method->emitCppArgSignature(out);
811 out << ");\n";
812 },
813 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -0700814
Steven Moreland368e4602018-02-16 14:21:49 -0800815 generateMethods(out, [&](const Method* method, const Interface*) {
Yifan Hong068c5522016-10-31 14:07:25 -0700816 method->generateCppSignature(out);
817 out << " override;\n";
Yifan Hong068c5522016-10-31 14:07:25 -0700818 });
Steven Moreland9c387612016-09-07 09:54:26 -0700819
Andreas Huber881227d2016-08-02 14:20:21 -0700820 out.unindent();
Martijn Coenen115d4282016-12-19 05:14:04 +0100821 out << "private:\n";
822 out.indent();
823 out << "std::mutex _hidl_mMutex;\n"
824 << "std::vector<::android::sp<::android::hardware::hidl_binder_death_recipient>>"
825 << " _hidl_mDeathRecipients;\n";
826 out.unindent();
Andreas Huber881227d2016-08-02 14:20:21 -0700827 out << "};\n\n";
828
829 enterLeaveNamespace(out, false /* enter */);
830
831 out << "\n#endif // " << guard << "\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700832}
833
Steven Moreland368e4602018-02-16 14:21:49 -0800834void AST::generateCppSource(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -0700835 std::string baseName = getBaseName();
836 const Interface *iface = getInterface();
Andreas Huber881227d2016-08-02 14:20:21 -0700837
Steven Morelanda885d252017-09-25 18:44:43 -0700838 const std::string klassName = baseName + (baseName == "types" ? "" : "All");
Andreas Huber881227d2016-08-02 14:20:21 -0700839
Steven Moreland623c0042017-01-13 14:42:29 -0800840 out << "#define LOG_TAG \""
841 << mPackage.string() << "::" << baseName
842 << "\"\n\n";
843
Steven Moreland5add34d2018-11-08 16:31:30 -0800844 out << "#include <log/log.h>\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +0100845 out << "#include <cutils/trace.h>\n";
846 out << "#include <hidl/HidlTransportSupport.h>\n\n";
Steven Moreland26896a92018-07-31 15:31:01 -0700847 out << "#include <hidl/Static.h>\n";
848 out << "#include <hwbinder/ProcessState.h>\n";
Steven Moreland4607ef52018-05-09 10:52:47 -0700849 out << "#include <utils/Trace.h>\n";
Steven Moreland19f11b52017-05-12 18:22:21 -0700850 if (iface) {
Steven Moreland19d5c172016-10-20 19:20:25 -0700851 // This is a no-op for IServiceManager itself.
852 out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n";
853
Yifan Hongeefe4f22017-01-04 15:32:42 -0800854 generateCppPackageInclude(out, mPackage, iface->getProxyName());
855 generateCppPackageInclude(out, mPackage, iface->getStubName());
856 generateCppPackageInclude(out, mPackage, iface->getPassthroughName());
Yifan Hongfe95aa22016-10-19 17:26:45 -0700857
858 for (const Interface *superType : iface->superTypeChain()) {
Steven Morelandee88eed2016-10-31 17:49:00 -0700859 generateCppPackageInclude(out,
860 superType->fqName(),
Yifan Hongeefe4f22017-01-04 15:32:42 -0800861 superType->fqName().getInterfaceProxyName());
Yifan Hongfe95aa22016-10-19 17:26:45 -0700862 }
Yifan Hong2cbbdf92016-12-05 15:20:50 -0800863
864 out << "#include <hidl/ServiceManagement.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700865 } else {
Steven Morelandee88eed2016-10-31 17:49:00 -0700866 generateCppPackageInclude(out, mPackage, "types");
Yifan Hong244e82d2016-11-11 11:13:57 -0800867 generateCppPackageInclude(out, mPackage, "hwtypes");
Andreas Huber881227d2016-08-02 14:20:21 -0700868 }
869
870 out << "\n";
871
872 enterLeaveNamespace(out, true /* enter */);
873 out << "\n";
874
Steven Moreland368e4602018-02-16 14:21:49 -0800875 generateTypeSource(out, iface ? iface->localName() : "");
Andreas Huber881227d2016-08-02 14:20:21 -0700876
Steven Moreland368e4602018-02-16 14:21:49 -0800877 if (iface) {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -0700878 const Interface* iface = mRootScope.getInterface();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700879
880 // need to be put here, generateStubSource is using this.
Yifan Hongeefe4f22017-01-04 15:32:42 -0800881 out << "const char* "
882 << iface->localName()
Yifan Hong10fe0b52016-10-19 14:20:17 -0700883 << "::descriptor(\""
884 << iface->fqName().string()
885 << "\");\n\n";
Yifan Hong91977fd2017-11-09 16:07:37 -0800886 out << "__attribute__((constructor)) ";
Martijn Coenen8adcb652017-02-03 17:37:36 +0100887 out << "static void static_constructor() {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800888 out.indent([&] {
Yifan Hong91977fd2017-11-09 16:07:37 -0800889 out << "::android::hardware::details::getBnConstructorMap().set("
Yifan Hongeefe4f22017-01-04 15:32:42 -0800890 << iface->localName()
Yifan Hongb04de382017-02-06 15:31:52 -0800891 << "::descriptor,\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800892 out.indent(2, [&] {
Yifan Hongb04de382017-02-06 15:31:52 -0800893 out << "[](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800894 out.indent([&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800895 out << "return new "
896 << iface->getStubName()
Yifan Hong341112d2017-04-20 18:12:05 -0700897 << "(static_cast<"
Yifan Hongeefe4f22017-01-04 15:32:42 -0800898 << iface->localName()
Yifan Hong158655a2016-11-08 12:34:07 -0800899 << " *>(iIntf));\n";
900 });
Yifan Hongb04de382017-02-06 15:31:52 -0800901 out << "});\n";
Yifan Hong158655a2016-11-08 12:34:07 -0800902 });
Yifan Hong91977fd2017-11-09 16:07:37 -0800903 out << "::android::hardware::details::getBsConstructorMap().set("
Yifan Hongeefe4f22017-01-04 15:32:42 -0800904 << iface->localName()
Yifan Hongb04de382017-02-06 15:31:52 -0800905 << "::descriptor,\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800906 out.indent(2, [&] {
Yifan Hongb04de382017-02-06 15:31:52 -0800907 out << "[](void *iIntf) -> ::android::sp<"
Yifan Hong7a118f52016-12-07 11:21:15 -0800908 << gIBaseFqName.cppName()
909 << "> {\n";
910 out.indent([&] {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800911 out << "return new "
912 << iface->getPassthroughName()
Yifan Hong341112d2017-04-20 18:12:05 -0700913 << "(static_cast<"
Yifan Hongeefe4f22017-01-04 15:32:42 -0800914 << iface->localName()
Yifan Hong7a118f52016-12-07 11:21:15 -0800915 << " *>(iIntf));\n";
916 });
Yifan Hongb04de382017-02-06 15:31:52 -0800917 out << "});\n";
Yifan Hong7a118f52016-12-07 11:21:15 -0800918 });
Yifan Hong158655a2016-11-08 12:34:07 -0800919 });
Martijn Coenen8adcb652017-02-03 17:37:36 +0100920 out << "};\n\n";
921 out << "__attribute__((destructor))";
922 out << "static void static_destructor() {\n";
923 out.indent([&] {
Yifan Hong91977fd2017-11-09 16:07:37 -0800924 out << "::android::hardware::details::getBnConstructorMap().erase("
Martijn Coenen8adcb652017-02-03 17:37:36 +0100925 << iface->localName()
926 << "::descriptor);\n";
Yifan Hong91977fd2017-11-09 16:07:37 -0800927 out << "::android::hardware::details::getBsConstructorMap().erase("
Martijn Coenen8adcb652017-02-03 17:37:36 +0100928 << iface->localName()
929 << "::descriptor);\n";
930 });
931 out << "};\n\n";
Yifan Hong158655a2016-11-08 12:34:07 -0800932
Steven Moreland368e4602018-02-16 14:21:49 -0800933 generateInterfaceSource(out);
934 generateProxySource(out, iface->fqName());
935 generateStubSource(out, iface);
936 generatePassthroughSource(out);
Steven Moreland9c387612016-09-07 09:54:26 -0700937
Yifan Hongc8934042016-11-17 17:10:52 -0800938 if (isIBase()) {
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800939 out << "// skipped getService, registerAsService, registerForNotifications\n";
Yifan Hongc8934042016-11-17 17:10:52 -0800940 } else {
Yifan Hong83c8e5f2016-12-13 14:33:53 -0800941 std::string package = iface->fqName().package()
942 + iface->fqName().atVersion();
943
Yifan Hongeefe4f22017-01-04 15:32:42 -0800944 implementServiceManagerInteractions(out, iface->fqName(), package);
Yifan Hongc8934042016-11-17 17:10:52 -0800945 }
Steven Moreland40786312016-08-16 10:29:40 -0700946 }
947
Andreas Huber6755e9d2017-04-06 11:09:07 -0700948 HidlTypeAssertion::EmitAll(out);
949 out << "\n";
950
Andreas Huber881227d2016-08-02 14:20:21 -0700951 enterLeaveNamespace(out, false /* enter */);
Andreas Huber881227d2016-08-02 14:20:21 -0700952}
953
Steven Moreland368e4602018-02-16 14:21:49 -0800954void AST::generateTypeSource(Formatter& out, const std::string& ifaceName) const {
955 mRootScope.emitTypeDefinitions(out, ifaceName);
Andreas Huber881227d2016-08-02 14:20:21 -0700956}
957
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700958void AST::declareCppReaderLocals(Formatter& out, const std::vector<NamedReference<Type>*>& args,
959 bool forResults) const {
Andreas Hubere7ff2282016-08-16 13:50:03 -0700960 if (args.empty()) {
961 return;
962 }
963
964 for (const auto &arg : args) {
965 const Type &type = arg->type();
966
Yifan Hong3b320f82016-11-01 15:15:54 -0700967 out << type.getCppResultType()
Andreas Hubere7ff2282016-08-16 13:50:03 -0700968 << " "
Yifan Hong3b320f82016-11-01 15:15:54 -0700969 << (forResults ? "_hidl_out_" : "") + arg->name()
Andreas Hubere7ff2282016-08-16 13:50:03 -0700970 << ";\n";
971 }
972
973 out << "\n";
974}
975
Timur Iskhakov7fa79f62017-08-09 11:04:54 -0700976void AST::emitCppReaderWriter(Formatter& out, const std::string& parcelObj, bool parcelObjIsPointer,
977 const NamedReference<Type>* arg, bool isReader, Type::ErrorMode mode,
978 bool addPrefixToName) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700979 const Type &type = arg->type();
980
Andreas Huber881227d2016-08-02 14:20:21 -0700981 type.emitReaderWriter(
982 out,
Andreas Huber5e44a292016-09-27 14:52:39 -0700983 addPrefixToName ? ("_hidl_out_" + arg->name()) : arg->name(),
Andreas Huber881227d2016-08-02 14:20:21 -0700984 parcelObj,
985 parcelObjIsPointer,
986 isReader,
987 mode);
988}
989
Steven Moreland368e4602018-02-16 14:21:49 -0800990void AST::generateProxyMethodSource(Formatter& out, const std::string& klassName,
991 const Method* method, const Interface* superInterface) const {
Yifan Hong068c5522016-10-31 14:07:25 -0700992 method->generateCppSignature(out,
993 klassName,
994 true /* specify namespaces */);
995
Martijn Coenen115d4282016-12-19 05:14:04 +0100996 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
Steven Morelandf16c5c02017-07-31 16:50:06 -0700997 out.block([&] {
998 method->cppImpl(IMPL_PROXY, out);
999 }).endl().endl();
Steven Moreland368e4602018-02-16 14:21:49 -08001000 return;
Martijn Coenen115d4282016-12-19 05:14:04 +01001001 }
1002
Steven Morelandf16c5c02017-07-31 16:50:06 -07001003 out.block([&] {
1004 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001005 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001006
1007 method->generateCppReturnType(out);
1008
1009 out << " _hidl_out = "
1010 << superInterface->fqName().cppNamespace()
1011 << "::"
1012 << superInterface->getProxyName()
1013 << "::_hidl_"
1014 << method->name()
1015 << "(this, this";
1016
1017 if (!method->hasEmptyCppArgSignature()) {
1018 out << ", ";
1019 }
1020
1021 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
1022 out << arg->name();
1023 });
1024
1025 if (returnsValue && elidedReturn == nullptr) {
1026 if (!method->args().empty()) {
1027 out << ", ";
1028 }
1029 out << "_hidl_cb";
1030 }
1031
1032 out << ");\n\n";
1033
1034 out << "return _hidl_out;\n";
1035 }).endl().endl();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001036}
1037
Steven Moreland368e4602018-02-16 14:21:49 -08001038void AST::generateStaticProxyMethodSource(Formatter& out, const std::string& klassName,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001039 const Method* method, const Interface* superInterface) const {
Steven Morelandf16c5c02017-07-31 16:50:06 -07001040 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001041 return;
Steven Morelandf16c5c02017-07-31 16:50:06 -07001042 }
1043
1044 method->generateCppReturnType(out);
1045
1046 out << klassName
1047 << "::_hidl_"
1048 << method->name()
1049 << "("
1050 << "::android::hardware::IInterface *_hidl_this, "
1051 << "::android::hardware::details::HidlInstrumentor *_hidl_this_instrumentor";
1052
1053 if (!method->hasEmptyCppArgSignature()) {
1054 out << ", ";
1055 }
1056
1057 method->emitCppArgSignature(out);
1058 out << ") {\n";
1059
1060 out.indent();
1061
1062 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1063 out << "bool mEnableInstrumentation = _hidl_this_instrumentor->isInstrumentationEnabled();\n";
1064 out << "const auto &mInstrumentationCallbacks = _hidl_this_instrumentor->getInstrumentationCallbacks();\n";
1065 out << "#else\n";
1066 out << "(void) _hidl_this_instrumentor;\n";
1067 out << "#endif // __ANDROID_DEBUGGABLE__\n";
1068
1069 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001070 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland48cc6042019-04-30 11:28:56 -07001071 const bool hasCallback = returnsValue && elidedReturn == nullptr;
1072
Steven Moreland92a08a72017-07-31 14:57:37 -07001073 generateCppInstrumentationCall(
Yifan Hong068c5522016-10-31 14:07:25 -07001074 out,
1075 InstrumentationEvent::CLIENT_API_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001076 method,
1077 superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001078
1079 out << "::android::hardware::Parcel _hidl_data;\n";
1080 out << "::android::hardware::Parcel _hidl_reply;\n";
1081 out << "::android::status_t _hidl_err;\n";
Steven Moreland48cc6042019-04-30 11:28:56 -07001082 out << "::android::status_t _hidl_transact_err;\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001083 out << "::android::hardware::Status _hidl_status;\n\n";
1084
Steven Moreland48cc6042019-04-30 11:28:56 -07001085 if (!hasCallback) {
1086 declareCppReaderLocals(
1087 out, method->results(), true /* forResults */);
1088 }
Yifan Hong068c5522016-10-31 14:07:25 -07001089
1090 out << "_hidl_err = _hidl_data.writeInterfaceToken(";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001091 out << klassName;
Yifan Hong068c5522016-10-31 14:07:25 -07001092 out << "::descriptor);\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001093 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
1094
Martijn Coenenfff73352017-01-04 16:36:31 +01001095 bool hasInterfaceArgument = false;
Steven Moreland8249f0a2019-05-28 17:25:27 -07001096
Yifan Hong068c5522016-10-31 14:07:25 -07001097 for (const auto &arg : method->args()) {
Martijn Coenenfa55d6e2016-12-20 06:08:31 +01001098 if (arg->type().isInterface()) {
1099 hasInterfaceArgument = true;
1100 }
Yifan Hong068c5522016-10-31 14:07:25 -07001101 emitCppReaderWriter(
1102 out,
1103 "_hidl_data",
1104 false /* parcelObjIsPointer */,
1105 arg,
1106 false /* reader */,
1107 Type::ErrorMode_Goto,
1108 false /* addPrefixToName */);
1109 }
1110
Martijn Coenenfa55d6e2016-12-20 06:08:31 +01001111 if (hasInterfaceArgument) {
1112 // Start binder threadpool to handle incoming transactions
1113 out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
1114 }
Steven Moreland48cc6042019-04-30 11:28:56 -07001115 out << "_hidl_transact_err = ::android::hardware::IInterface::asBinder(_hidl_this)->transact("
Yifan Hong068c5522016-10-31 14:07:25 -07001116 << method->getSerialId()
1117 << " /* "
1118 << method->name()
1119 << " */, _hidl_data, &_hidl_reply";
1120
1121 if (method->isOneway()) {
Steven Moreland77943692018-08-09 12:53:42 -07001122 out << ", " << Interface::FLAG_ONE_WAY->cppValue();
Steven Moreland48cc6042019-04-30 11:28:56 -07001123 } else {
1124 out << ", 0";
Yifan Hong068c5522016-10-31 14:07:25 -07001125 }
Yifan Hong068c5522016-10-31 14:07:25 -07001126
Steven Moreland48cc6042019-04-30 11:28:56 -07001127 if (hasCallback) {
1128 out << ", [&] (::android::hardware::Parcel& _hidl_reply) {\n";
1129 out.indent();
1130 declareCppReaderLocals(
1131 out, method->results(), true /* forResults */);
1132 out.endl();
1133 } else {
1134 out << ");\n";
1135 out << "if (_hidl_transact_err != ::android::OK) \n";
1136 out.block([&] {
1137 out << "_hidl_err = _hidl_transact_err;\n";
1138 out << "goto _hidl_error;\n";
1139 }).endl().endl();
1140 }
Yifan Hong068c5522016-10-31 14:07:25 -07001141
1142 if (!method->isOneway()) {
Steven Moreland48cc6042019-04-30 11:28:56 -07001143 Type::ErrorMode errorMode = hasCallback ? Type::ErrorMode_ReturnNothing : Type::ErrorMode_Goto;
Yifan Hong068c5522016-10-31 14:07:25 -07001144
Steven Moreland48cc6042019-04-30 11:28:56 -07001145 out << "_hidl_err = ::android::hardware::readFromParcel(&_hidl_status, _hidl_reply);\n";
1146 Type::handleError(out, errorMode);
1147
1148 if (hasCallback) {
1149 out << "if (!_hidl_status.isOk()) { return; }\n\n";
1150 } else {
1151 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n";
1152 }
Yifan Hong068c5522016-10-31 14:07:25 -07001153
Yifan Hong068c5522016-10-31 14:07:25 -07001154 for (const auto &arg : method->results()) {
1155 emitCppReaderWriter(
1156 out,
1157 "_hidl_reply",
1158 false /* parcelObjIsPointer */,
1159 arg,
1160 true /* reader */,
Steven Moreland48cc6042019-04-30 11:28:56 -07001161 errorMode,
Yifan Hong068c5522016-10-31 14:07:25 -07001162 true /* addPrefixToName */);
1163 }
1164
Yifan Hong068c5522016-10-31 14:07:25 -07001165 if (returnsValue && elidedReturn == nullptr) {
1166 out << "_hidl_cb(";
1167
Yifan Hong932464e2017-03-30 15:40:22 -07001168 out.join(method->results().begin(), method->results().end(), ", ", [&] (const auto &arg) {
Yifan Hong068c5522016-10-31 14:07:25 -07001169 if (arg->type().resultNeedsDeref()) {
1170 out << "*";
1171 }
1172 out << "_hidl_out_" << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001173 });
Yifan Hong068c5522016-10-31 14:07:25 -07001174
1175 out << ");\n\n";
1176 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001177 }
Steven Morelandf16c5c02017-07-31 16:50:06 -07001178
Steven Moreland92a08a72017-07-31 14:57:37 -07001179 generateCppInstrumentationCall(
Martijn Coenen7b295242016-11-04 16:52:56 +01001180 out,
1181 InstrumentationEvent::CLIENT_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001182 method,
1183 superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001184
Steven Moreland48cc6042019-04-30 11:28:56 -07001185 if (hasCallback) {
1186 out.unindent();
1187 out << "});\n";
1188 out << "if (_hidl_transact_err != ::android::OK) ";
1189 out.block([&] {
1190 out << "_hidl_err = _hidl_transact_err;\n";
1191 out << "goto _hidl_error;\n";
1192 }).endl().endl();
1193 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n";
1194 }
1195
Yifan Hong068c5522016-10-31 14:07:25 -07001196 if (elidedReturn != nullptr) {
Yifan Hong068c5522016-10-31 14:07:25 -07001197 out << "return ::android::hardware::Return<";
Yifan Hong3b320f82016-11-01 15:15:54 -07001198 out << elidedReturn->type().getCppResultType()
Yifan Hong068c5522016-10-31 14:07:25 -07001199 << ">(_hidl_out_" << elidedReturn->name() << ");\n\n";
1200 } else {
Yifan Hong068c5522016-10-31 14:07:25 -07001201 out << "return ::android::hardware::Return<void>();\n\n";
1202 }
1203
1204 out.unindent();
1205 out << "_hidl_error:\n";
1206 out.indent();
1207 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
1208 out << "return ::android::hardware::Return<";
1209 if (elidedReturn != nullptr) {
Yifan Hong3b320f82016-11-01 15:15:54 -07001210 out << method->results().at(0)->type().getCppResultType();
Yifan Hong068c5522016-10-31 14:07:25 -07001211 } else {
1212 out << "void";
1213 }
1214 out << ">(_hidl_status);\n";
1215
1216 out.unindent();
1217 out << "}\n\n";
Yifan Hong068c5522016-10-31 14:07:25 -07001218}
1219
Steven Moreland368e4602018-02-16 14:21:49 -08001220void AST::generateProxySource(Formatter& out, const FQName& fqName) const {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001221 const std::string klassName = fqName.getInterfaceProxyName();
Andreas Huber881227d2016-08-02 14:20:21 -07001222
1223 out << klassName
1224 << "::"
1225 << klassName
Iliyan Malchev549e2592016-08-10 08:59:12 -07001226 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001227
1228 out.indent();
1229 out.indent();
1230
1231 out << ": BpInterface"
Yifan Hongeefe4f22017-01-04 15:32:42 -08001232 << "<"
1233 << fqName.getInterfaceName()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001234 << ">(_hidl_impl),\n"
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001235 << " ::android::hardware::details::HidlInstrumentor(\""
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001236 << mPackage.string()
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001237 << "\", \""
Yifan Hongeefe4f22017-01-04 15:32:42 -08001238 << fqName.getInterfaceName()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001239 << "\") {\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001240
Andreas Huber881227d2016-08-02 14:20:21 -07001241 out.unindent();
1242 out.unindent();
1243 out << "}\n\n";
1244
Steven Moreland596d20e2019-06-07 11:52:21 -07001245 out << "void " << klassName << "::onLastStrongRef(const void* id) ";
1246 out.block([&] {
1247 out.block([&] {
1248 // if unlinkToDeath is not used, remove strong cycle between
1249 // this and hidl_binder_death_recipient
1250 out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n";
1251 out << "_hidl_mDeathRecipients.clear();\n";
1252 }).endl().endl();
1253
1254 out << "BpInterface<" << fqName.getInterfaceName() << ">::onLastStrongRef(id);\n";
1255 }).endl();
1256
Steven Moreland368e4602018-02-16 14:21:49 -08001257 generateMethods(out,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001258 [&](const Method* method, const Interface* superInterface) {
1259 generateStaticProxyMethodSource(out, klassName, method, superInterface);
Steven Moreland368e4602018-02-16 14:21:49 -08001260 },
1261 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -07001262
Steven Moreland368e4602018-02-16 14:21:49 -08001263 generateMethods(out, [&](const Method* method, const Interface* superInterface) {
1264 generateProxyMethodSource(out, klassName, method, superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001265 });
Andreas Huber881227d2016-08-02 14:20:21 -07001266}
1267
Steven Moreland368e4602018-02-16 14:21:49 -08001268void AST::generateStubSource(Formatter& out, const Interface* iface) const {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001269 const std::string interfaceName = iface->localName();
1270 const std::string klassName = iface->getStubName();
Andreas Huber881227d2016-08-02 14:20:21 -07001271
Steven Moreland40786312016-08-16 10:29:40 -07001272 out << klassName
1273 << "::"
1274 << klassName
Yifan Hongeefe4f22017-01-04 15:32:42 -08001275 << "(const ::android::sp<" << interfaceName <<"> &_hidl_impl)\n";
Steven Moreland40786312016-08-16 10:29:40 -07001276
1277 out.indent();
1278 out.indent();
1279
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001280 if (iface->isIBase()) {
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001281 out << ": ::android::hardware::details::HidlInstrumentor(\"";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001282 } else {
Yifan Hongeefe4f22017-01-04 15:32:42 -08001283 out << ": "
1284 << gIBaseFqName.getInterfaceStubFqName().cppName()
1285 << "(_hidl_impl, \"";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001286 }
1287
1288 out << mPackage.string()
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001289 << "\", \""
Yifan Hongeefe4f22017-01-04 15:32:42 -08001290 << interfaceName
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001291 << "\") { \n";
1292 out.indent();
1293 out << "_hidl_mImpl = _hidl_impl;\n";
Steven Morelandbd984412019-04-22 10:25:46 -07001294 out << "auto prio = ::android::hardware::details::gServicePrioMap->get("
Martijn Coenenb4d77952017-05-03 13:44:29 -07001295 << "_hidl_impl, {SCHED_NORMAL, 0});\n";
1296 out << "mSchedPolicy = prio.sched_policy;\n";
1297 out << "mSchedPriority = prio.prio;\n";
Steven Morelandbd984412019-04-22 10:25:46 -07001298 out << "setRequestingSid(::android::hardware::details::gServiceSidMap->get(_hidl_impl, "
1299 "false));\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001300 out.unindent();
Steven Moreland40786312016-08-16 10:29:40 -07001301
1302 out.unindent();
1303 out.unindent();
1304 out << "}\n\n";
1305
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001306 if (iface->isIBase()) {
Yifan Hong01e7cde2017-01-09 17:45:45 -08001307 // BnHwBase has a constructor to initialize the HidlInstrumentor
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001308 // class properly.
1309 out << klassName
1310 << "::"
1311 << klassName
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001312 << "(const ::android::sp<" << interfaceName << "> &_hidl_impl,"
1313 << " const std::string &HidlInstrumentor_package,"
1314 << " const std::string &HidlInstrumentor_interface)\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001315
1316 out.indent();
1317 out.indent();
1318
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001319 out << ": ::android::hardware::details::HidlInstrumentor("
Zhuoyao Zhangd10feea2017-01-23 17:29:58 -08001320 << "HidlInstrumentor_package, HidlInstrumentor_interface) {\n";
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001321 out.indent();
1322 out << "_hidl_mImpl = _hidl_impl;\n";
1323 out.unindent();
1324
1325 out.unindent();
1326 out.unindent();
1327 out << "}\n\n";
1328 }
1329
Steven Moreland57a89362017-07-21 19:29:54 +00001330 out << klassName << "::~" << klassName << "() ";
1331 out.block([&]() {
Steven Morelandbd984412019-04-22 10:25:46 -07001332 out << "::android::hardware::details::gBnMap->eraseIfEqual(_hidl_mImpl.get(), this);\n";
1333 })
1334 .endl()
1335 .endl();
Steven Moreland57a89362017-07-21 19:29:54 +00001336
Steven Moreland368e4602018-02-16 14:21:49 -08001337 generateMethods(out,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001338 [&](const Method* method, const Interface* superInterface) {
1339 return generateStaticStubMethodSource(out, iface->fqName(), method, superInterface);
Steven Moreland368e4602018-02-16 14:21:49 -08001340 },
1341 false /* include parents */);
Steven Morelandf16c5c02017-07-31 16:50:06 -07001342
Steven Moreland368e4602018-02-16 14:21:49 -08001343 generateMethods(out, [&](const Method* method, const Interface*) {
Yifan Hongbcffce22017-02-01 15:52:06 -08001344 if (!method->isHidlReserved() || !method->overridesCppImpl(IMPL_STUB_IMPL)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001345 return;
Yifan Hongbcffce22017-02-01 15:52:06 -08001346 }
1347 method->generateCppSignature(out, iface->getStubName());
1348 out << " ";
1349 out.block([&] {
1350 method->cppImpl(IMPL_STUB_IMPL, out);
1351 }).endl();
Yifan Hongbcffce22017-02-01 15:52:06 -08001352 });
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001353
Andreas Huber881227d2016-08-02 14:20:21 -07001354 out << "::android::status_t " << klassName << "::onTransact(\n";
1355
1356 out.indent();
1357 out.indent();
1358
Iliyan Malchev549e2592016-08-10 08:59:12 -07001359 out << "uint32_t _hidl_code,\n"
1360 << "const ::android::hardware::Parcel &_hidl_data,\n"
1361 << "::android::hardware::Parcel *_hidl_reply,\n"
1362 << "uint32_t _hidl_flags,\n"
1363 << "TransactCallback _hidl_cb) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001364
1365 out.unindent();
1366
Iliyan Malchev549e2592016-08-10 08:59:12 -07001367 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
Iliyan Malchev549e2592016-08-10 08:59:12 -07001368 out << "switch (_hidl_code) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001369 out.indent();
1370
Yifan Hong10fe0b52016-10-19 14:20:17 -07001371 for (const auto &tuple : iface->allMethodsFromRoot()) {
1372 const Method *method = tuple.method();
1373 const Interface *superInterface = tuple.interface();
Steven Morelandf16c5c02017-07-31 16:50:06 -07001374
Howard Chen71f289f2017-08-29 17:35:01 +08001375 if (!isIBase() && method->isHidlReserved()) {
1376 continue;
1377 }
Yifan Hong10fe0b52016-10-19 14:20:17 -07001378 out << "case "
1379 << method->getSerialId()
1380 << " /* "
1381 << method->name()
1382 << " */:\n{\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001383
Yifan Hong10fe0b52016-10-19 14:20:17 -07001384 out.indent();
Andreas Huber881227d2016-08-02 14:20:21 -07001385
Steven Moreland368e4602018-02-16 14:21:49 -08001386 generateStubSourceForMethod(out, method, superInterface);
Yifan Hong10fe0b52016-10-19 14:20:17 -07001387
1388 out.unindent();
1389 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001390 }
1391
1392 out << "default:\n{\n";
1393 out.indent();
1394
Martijn Coenen225bc922017-06-27 14:39:46 -07001395 if (iface->isIBase()) {
1396 out << "(void)_hidl_flags;\n";
1397 out << "return ::android::UNKNOWN_TRANSACTION;\n";
1398 } else {
1399 out << "return ";
1400 out << gIBaseFqName.getInterfaceStubFqName().cppName();
1401 out << "::onTransact(\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001402
Martijn Coenen225bc922017-06-27 14:39:46 -07001403 out.indent();
1404 out.indent();
Andreas Huber881227d2016-08-02 14:20:21 -07001405
Martijn Coenen225bc922017-06-27 14:39:46 -07001406 out << "_hidl_code, _hidl_data, _hidl_reply, "
1407 << "_hidl_flags, _hidl_cb);\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001408
Martijn Coenen225bc922017-06-27 14:39:46 -07001409 out.unindent();
1410 out.unindent();
1411 }
Andreas Huber881227d2016-08-02 14:20:21 -07001412
1413 out.unindent();
1414 out << "}\n";
1415
1416 out.unindent();
1417 out << "}\n\n";
1418
Yifan Honga018ed52016-12-13 16:35:08 -08001419 out.sIf("_hidl_err == ::android::UNEXPECTED_NULL", [&] {
1420 out << "_hidl_err = ::android::hardware::writeToParcel(\n";
1421 out.indent(2, [&] {
1422 out << "::android::hardware::Status::fromExceptionCode(::android::hardware::Status::EX_NULL_POINTER),\n";
1423 out << "_hidl_reply);\n";
1424 });
1425 });
Andreas Huber881227d2016-08-02 14:20:21 -07001426
Iliyan Malchev549e2592016-08-10 08:59:12 -07001427 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001428
1429 out.unindent();
1430 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001431}
1432
Steven Moreland368e4602018-02-16 14:21:49 -08001433void AST::generateStubSourceForMethod(Formatter& out, const Method* method,
1434 const Interface* superInterface) const {
Martijn Coenen115d4282016-12-19 05:14:04 +01001435 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB)) {
1436 method->cppImpl(IMPL_STUB, out);
1437 out << "break;\n";
Steven Moreland368e4602018-02-16 14:21:49 -08001438 return;
Martijn Coenen115d4282016-12-19 05:14:04 +01001439 }
1440
Steven Morelandf16c5c02017-07-31 16:50:06 -07001441 out << "_hidl_err = "
1442 << superInterface->fqName().cppNamespace()
1443 << "::"
1444 << superInterface->getStubName()
1445 << "::_hidl_"
1446 << method->name()
1447 << "(this, _hidl_data, _hidl_reply, _hidl_cb);\n";
1448 out << "break;\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001449}
1450
Steven Moreland368e4602018-02-16 14:21:49 -08001451void AST::generateStaticStubMethodSource(Formatter& out, const FQName& fqName,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001452 const Method* method, const Interface* superInterface) const {
Steven Morelandf16c5c02017-07-31 16:50:06 -07001453 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB)) {
Steven Moreland368e4602018-02-16 14:21:49 -08001454 return;
Steven Morelandf16c5c02017-07-31 16:50:06 -07001455 }
1456
Steven Morelandf8197902018-01-30 15:38:37 -08001457 const std::string& klassName = fqName.getInterfaceStubName();
1458
Steven Morelandf16c5c02017-07-31 16:50:06 -07001459 out << "::android::status_t " << klassName << "::_hidl_" << method->name() << "(\n";
1460
1461 out.indent();
1462 out.indent();
1463
1464 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
1465 << "const ::android::hardware::Parcel &_hidl_data,\n"
1466 << "::android::hardware::Parcel *_hidl_reply,\n"
1467 << "TransactCallback _hidl_cb) {\n";
1468
1469 out.unindent();
1470
1471 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1472 out << "bool mEnableInstrumentation = _hidl_this->isInstrumentationEnabled();\n";
1473 out << "const auto &mInstrumentationCallbacks = _hidl_this->getInstrumentationCallbacks();\n";
1474 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";
1475
1476 out << "::android::status_t _hidl_err = ::android::OK;\n";
1477
Yifan Hongeefe4f22017-01-04 15:32:42 -08001478 out << "if (!_hidl_data.enforceInterface("
Steven Morelandf16c5c02017-07-31 16:50:06 -07001479 << klassName
1480 << "::Pure::descriptor)) {\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -07001481
Andreas Huber881227d2016-08-02 14:20:21 -07001482 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -07001483 out << "_hidl_err = ::android::BAD_TYPE;\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001484 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001485 out.unindent();
1486 out << "}\n\n";
1487
Andreas Huber5e44a292016-09-27 14:52:39 -07001488 declareCppReaderLocals(out, method->args(), false /* forResults */);
Andreas Hubere7ff2282016-08-16 13:50:03 -07001489
Andreas Huber881227d2016-08-02 14:20:21 -07001490 for (const auto &arg : method->args()) {
1491 emitCppReaderWriter(
1492 out,
Iliyan Malchev549e2592016-08-10 08:59:12 -07001493 "_hidl_data",
Andreas Huber881227d2016-08-02 14:20:21 -07001494 false /* parcelObjIsPointer */,
1495 arg,
1496 true /* reader */,
Steven Morelandf16c5c02017-07-31 16:50:06 -07001497 Type::ErrorMode_Return,
Andreas Huber5e44a292016-09-27 14:52:39 -07001498 false /* addPrefixToName */);
Andreas Huber881227d2016-08-02 14:20:21 -07001499 }
1500
Steven Moreland92a08a72017-07-31 14:57:37 -07001501 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001502 out,
1503 InstrumentationEvent::SERVER_API_ENTRY,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001504 method,
1505 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001506
Andreas Huber881227d2016-08-02 14:20:21 -07001507 const bool returnsValue = !method->results().empty();
Timur Iskhakov7fa79f62017-08-09 11:04:54 -07001508 const NamedReference<Type>* elidedReturn = method->canElideCallback();
Steven Moreland3e787002017-08-16 14:59:54 -07001509
1510 std::string callee;
1511
1512 if (method->isHidlReserved() && method->overridesCppImpl(IMPL_STUB_IMPL)) {
1513 callee = "_hidl_this";
1514 } else {
Steven Morelandf8197902018-01-30 15:38:37 -08001515 callee = "static_cast<" + fqName.getInterfaceName() + "*>(_hidl_this->getImpl().get())";
Steven Moreland3e787002017-08-16 14:59:54 -07001516 }
Andreas Huber881227d2016-08-02 14:20:21 -07001517
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001518 if (elidedReturn != nullptr) {
Yifan Hong3b320f82016-11-01 15:15:54 -07001519 out << elidedReturn->type().getCppResultType()
Yifan Honga47eef32016-12-12 10:38:54 -08001520 << " _hidl_out_"
Yifan Hong3b320f82016-11-01 15:15:54 -07001521 << elidedReturn->name()
Martijn Coenen6ec2f0b2016-12-11 01:04:55 +01001522 << " = "
Yifan Hongcd2ae452017-01-31 14:33:40 -08001523 << callee << "->" << method->name()
Yifan Hong3b320f82016-11-01 15:15:54 -07001524 << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001525
Yifan Hong932464e2017-03-30 15:40:22 -07001526 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001527 if (arg->type().resultNeedsDeref()) {
1528 out << "*";
1529 }
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001530 out << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001531 });
Andreas Huber881227d2016-08-02 14:20:21 -07001532
Steven Moreland2ae5bca2016-12-01 05:56:49 +00001533 out << ");\n\n";
Steven Moreland30232dc2019-03-05 19:39:10 -08001534
Yifan Hong859e53f2016-11-14 19:08:24 -08001535 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1536 << "_hidl_reply);\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001537
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001538 elidedReturn->type().emitReaderWriter(
1539 out,
Yifan Honga47eef32016-12-12 10:38:54 -08001540 "_hidl_out_" + elidedReturn->name(),
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001541 "_hidl_reply",
1542 true, /* parcelObjIsPointer */
1543 false, /* isReader */
1544 Type::ErrorMode_Ignore);
Andreas Huber881227d2016-08-02 14:20:21 -07001545
Steven Moreland92a08a72017-07-31 14:57:37 -07001546 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001547 out,
1548 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001549 method,
1550 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001551
Iliyan Malchev549e2592016-08-10 08:59:12 -07001552 out << "_hidl_cb(*_hidl_reply);\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001553 } else {
1554 if (returnsValue) {
1555 out << "bool _hidl_callbackCalled = false;\n\n";
1556 }
Andreas Huber881227d2016-08-02 14:20:21 -07001557
Steven Moreland30232dc2019-03-05 19:39:10 -08001558 out << "::android::hardware::Return<void> _hidl_ret = " << callee << "->" << method->name()
1559 << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001560
Yifan Hong932464e2017-03-30 15:40:22 -07001561 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001562 if (arg->type().resultNeedsDeref()) {
1563 out << "*";
1564 }
1565
1566 out << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001567 });
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001568
1569 if (returnsValue) {
Yifan Hong932464e2017-03-30 15:40:22 -07001570 if (!method->args().empty()) {
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001571 out << ", ";
1572 }
1573
1574 out << "[&](";
1575
Yifan Hong932464e2017-03-30 15:40:22 -07001576 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
Yifan Honga47eef32016-12-12 10:38:54 -08001577 out << "const auto &_hidl_out_" << arg->name();
Yifan Hong932464e2017-03-30 15:40:22 -07001578 });
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001579
1580 out << ") {\n";
1581 out.indent();
Steven Moreland05cd4232016-11-21 16:01:12 -08001582 out << "if (_hidl_callbackCalled) {\n";
1583 out.indent();
1584 out << "LOG_ALWAYS_FATAL(\""
1585 << method->name()
1586 << ": _hidl_cb called a second time, but must be called once.\");\n";
1587 out.unindent();
1588 out << "}\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001589 out << "_hidl_callbackCalled = true;\n\n";
1590
Yifan Hong859e53f2016-11-14 19:08:24 -08001591 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1592 << "_hidl_reply);\n\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001593
1594 for (const auto &arg : method->results()) {
1595 emitCppReaderWriter(
1596 out,
1597 "_hidl_reply",
1598 true /* parcelObjIsPointer */,
1599 arg,
1600 false /* reader */,
Andreas Huber5e44a292016-09-27 14:52:39 -07001601 Type::ErrorMode_Ignore,
Yifan Honga47eef32016-12-12 10:38:54 -08001602 true /* addPrefixToName */);
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001603 }
1604
Steven Moreland92a08a72017-07-31 14:57:37 -07001605 generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001606 out,
1607 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001608 method,
1609 superInterface);
Zhuoyao Zhangde578002016-09-07 18:24:17 -07001610
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001611 out << "_hidl_cb(*_hidl_reply);\n";
1612
1613 out.unindent();
Martijn Coenen8e4fc842017-01-09 16:28:59 +01001614 out << "});\n\n";
1615 } else {
1616 out << ");\n\n";
Steven Morelandf16c5c02017-07-31 16:50:06 -07001617 out << "(void) _hidl_cb;\n\n";
Steven Moreland92a08a72017-07-31 14:57:37 -07001618 generateCppInstrumentationCall(
Martijn Coenen8e4fc842017-01-09 16:28:59 +01001619 out,
1620 InstrumentationEvent::SERVER_API_EXIT,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001621 method,
1622 superInterface);
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001623 }
Iliyan Malchevd57066f2016-09-08 13:59:38 -07001624
Steven Moreland30232dc2019-03-05 19:39:10 -08001625 out << "_hidl_ret.assertOk();\n";
1626
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001627 if (returnsValue) {
1628 out << "if (!_hidl_callbackCalled) {\n";
1629 out.indent();
Steven Moreland05cd4232016-11-21 16:01:12 -08001630 out << "LOG_ALWAYS_FATAL(\""
1631 << method->name()
1632 << ": _hidl_cb not called, but must be called once.\");\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001633 out.unindent();
1634 out << "}\n\n";
Steven Moreland05cd4232016-11-21 16:01:12 -08001635 } else {
1636 out << "::android::hardware::writeToParcel("
1637 << "::android::hardware::Status::ok(), "
1638 << "_hidl_reply);\n\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001639 }
Andreas Huber881227d2016-08-02 14:20:21 -07001640 }
1641
Steven Morelandf16c5c02017-07-31 16:50:06 -07001642 out << "return _hidl_err;\n";
1643 out.unindent();
1644 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001645}
1646
Steven Moreland368e4602018-02-16 14:21:49 -08001647void AST::generatePassthroughHeader(Formatter& out) const {
Steven Moreland19f11b52017-05-12 18:22:21 -07001648 if (!AST::isInterface()) {
Steven Moreland69e7c702016-09-09 11:16:32 -07001649 // types.hal does not get a stub header.
Steven Moreland368e4602018-02-16 14:21:49 -08001650 return;
Steven Moreland69e7c702016-09-09 11:16:32 -07001651 }
1652
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001653 const Interface* iface = mRootScope.getInterface();
Steven Moreland19f11b52017-05-12 18:22:21 -07001654 CHECK(iface != nullptr);
Steven Moreland69e7c702016-09-09 11:16:32 -07001655
Yifan Hongeefe4f22017-01-04 15:32:42 -08001656 const std::string klassName = iface->getPassthroughName();
Steven Moreland69e7c702016-09-09 11:16:32 -07001657
Steven Moreland69e7c702016-09-09 11:16:32 -07001658 const std::string guard = makeHeaderGuard(klassName);
1659
1660 out << "#ifndef " << guard << "\n";
1661 out << "#define " << guard << "\n\n";
1662
1663 std::vector<std::string> packageComponents;
1664 getPackageAndVersionComponents(
1665 &packageComponents, false /* cpp_compatible */);
1666
Steven Moreland61d3f4b2017-04-28 17:30:38 -07001667 out << "#include <android-base/macros.h>\n";
Yifan Hongb0949432016-12-15 15:32:24 -08001668 out << "#include <cutils/trace.h>\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001669 out << "#include <future>\n";
Steven Morelandee88eed2016-10-31 17:49:00 -07001670
Steven Moreland19f11b52017-05-12 18:22:21 -07001671 generateCppPackageInclude(out, mPackage, iface->localName());
Steven Morelandee88eed2016-10-31 17:49:00 -07001672 out << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001673
Yifan Hong7a118f52016-12-07 11:21:15 -08001674 out << "#include <hidl/HidlPassthroughSupport.h>\n";
Neel Mehta19f79792019-05-21 13:39:32 -07001675 out << "#include <hidl/TaskRunner.h>\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001676
1677 enterLeaveNamespace(out, true /* enter */);
1678 out << "\n";
1679
1680 out << "struct "
1681 << klassName
Steven Moreland19f11b52017-05-12 18:22:21 -07001682 << " : " << iface->localName()
Zhuoyao Zhang7d3ac802017-02-15 21:05:49 +00001683 << ", ::android::hardware::details::HidlInstrumentor {\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001684
1685 out.indent();
1686 out << "explicit "
1687 << klassName
Steven Morelandc46e9842016-11-02 13:21:26 -07001688 << "(const ::android::sp<"
Steven Moreland19f11b52017-05-12 18:22:21 -07001689 << iface->localName()
Steven Moreland69e7c702016-09-09 11:16:32 -07001690 << "> impl);\n";
1691
Steven Moreland0b843772017-06-23 16:33:38 -07001692 out.endl();
1693 generateTemplatizationLink(out);
Steven Moreland1a52e822017-07-27 13:56:29 -07001694 generateCppTag(out, "android::hardware::details::bs_tag");
Steven Moreland0b843772017-06-23 16:33:38 -07001695
Steven Moreland616cf4d2018-10-02 13:52:18 -07001696 generateMethods(out, [&](const Method* method, const Interface* superInterface) {
1697 generatePassthroughMethod(out, method, superInterface);
Yifan Hong068c5522016-10-31 14:07:25 -07001698 });
Steven Moreland69e7c702016-09-09 11:16:32 -07001699
Steven Moreland69e7c702016-09-09 11:16:32 -07001700 out.unindent();
1701 out << "private:\n";
1702 out.indent();
Steven Moreland19f11b52017-05-12 18:22:21 -07001703 out << "const ::android::sp<" << iface->localName() << "> mImpl;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001704
Neel Mehta19f79792019-05-21 13:39:32 -07001705 out << "::android::hardware::details::TaskRunner mOnewayQueue;\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001706
Neel Mehta19f79792019-05-21 13:39:32 -07001707 out << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001708
Neel Mehta19f79792019-05-21 13:39:32 -07001709 out << "::android::hardware::Return<void> addOnewayTask("
1710 "std::function<void(void)>);\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001711
1712 out.unindent();
1713
1714 out << "};\n\n";
1715
1716 enterLeaveNamespace(out, false /* enter */);
1717
1718 out << "\n#endif // " << guard << "\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001719}
1720
Steven Moreland368e4602018-02-16 14:21:49 -08001721void AST::generateInterfaceSource(Formatter& out) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001722 const Interface* iface = mRootScope.getInterface();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001723
Yifan Hong2d7126b2016-10-20 15:12:57 -07001724 // generate castFrom functions
Yifan Hong3d746092016-12-07 14:26:33 -08001725 std::string childTypeResult = iface->getCppResultType();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001726
Steven Moreland368e4602018-02-16 14:21:49 -08001727 generateMethods(out, [&](const Method* method, const Interface*) {
Steven Morelandd4b068a2017-03-20 06:30:51 -07001728 bool reserved = method->isHidlReserved();
1729
1730 if (!reserved) {
1731 out << "// no default implementation for: ";
1732 }
1733 method->generateCppSignature(out, iface->localName());
1734 if (reserved) {
1735 out.block([&]() {
Steven Moreland937408a2017-03-20 09:54:18 -07001736 method->cppImpl(IMPL_INTERFACE, out);
Steven Morelandd4b068a2017-03-20 06:30:51 -07001737 }).endl();
1738 }
1739
1740 out << "\n";
1741
Steven Moreland368e4602018-02-16 14:21:49 -08001742 return;
Steven Morelandd4b068a2017-03-20 06:30:51 -07001743 });
Steven Morelandd4b068a2017-03-20 06:30:51 -07001744
Yifan Hong3d746092016-12-07 14:26:33 -08001745 for (const Interface *superType : iface->typeChain()) {
Steven Moreland23cc5fa2018-05-09 10:48:48 -07001746 out << "::android::hardware::Return<"
Yifan Hong3d746092016-12-07 14:26:33 -08001747 << childTypeResult
Yifan Hong200209c2017-03-29 03:39:09 -07001748 << "> "
Yifan Hongeefe4f22017-01-04 15:32:42 -08001749 << iface->localName()
Yifan Hong3d746092016-12-07 14:26:33 -08001750 << "::castFrom("
1751 << superType->getCppArgumentType()
Yifan Hong200209c2017-03-29 03:39:09 -07001752 << " parent, bool "
1753 << (iface == superType ? "/* emitError */" : "emitError")
1754 << ") {\n";
Yifan Hong3d746092016-12-07 14:26:33 -08001755 out.indent();
1756 if (iface == superType) {
1757 out << "return parent;\n";
1758 } else {
Yifan Hong33e78012017-03-13 17:46:33 -07001759 out << "return ::android::hardware::details::castInterface<";
Yifan Hongeefe4f22017-01-04 15:32:42 -08001760 out << iface->localName() << ", "
Yifan Hongfe95aa22016-10-19 17:26:45 -07001761 << superType->fqName().cppName() << ", "
Steven Moreland57a89362017-07-21 19:29:54 +00001762 << iface->getProxyName()
Yifan Hongfe95aa22016-10-19 17:26:45 -07001763 << ">(\n";
1764 out.indent();
1765 out.indent();
1766 out << "parent, \""
1767 << iface->fqName().string()
Yifan Hong200209c2017-03-29 03:39:09 -07001768 << "\", emitError);\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -07001769 out.unindent();
1770 out.unindent();
Yifan Hongfe95aa22016-10-19 17:26:45 -07001771 }
Yifan Hong3d746092016-12-07 14:26:33 -08001772 out.unindent();
1773 out << "}\n\n";
Yifan Hongfe95aa22016-10-19 17:26:45 -07001774 }
Yifan Hongfe95aa22016-10-19 17:26:45 -07001775}
1776
Steven Moreland368e4602018-02-16 14:21:49 -08001777void AST::generatePassthroughSource(Formatter& out) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001778 const Interface* iface = mRootScope.getInterface();
Steven Moreland69e7c702016-09-09 11:16:32 -07001779
Yifan Hongeefe4f22017-01-04 15:32:42 -08001780 const std::string klassName = iface->getPassthroughName();
Steven Moreland69e7c702016-09-09 11:16:32 -07001781
Neel Mehta19f79792019-05-21 13:39:32 -07001782 out << klassName << "::" << klassName << "(const ::android::sp<" << iface->fullName()
1783 << "> impl) : ::android::hardware::details::HidlInstrumentor(\"" << mPackage.string()
1784 << "\", \"" << iface->localName() << "\"), mImpl(impl) {\n";
1785
1786 out.indent([&] { out << "mOnewayQueue.start(3000 /* similar limit to binderized */);\n"; });
1787
Yifan Hong2cbc1472016-10-25 19:02:40 -07001788 out << "}\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001789
Neel Mehta19f79792019-05-21 13:39:32 -07001790 out << "::android::hardware::Return<void> " << klassName
1791 << "::addOnewayTask(std::function<void(void)> fun) {\n";
1792 out.indent();
1793 out << "if (!mOnewayQueue.push(fun)) {\n";
1794 out.indent();
1795 out << "return ::android::hardware::Status::fromExceptionCode(\n";
1796 out.indent();
1797 out.indent();
1798 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
1799 << "\"Passthrough oneway function queue exceeds maximum size.\");\n";
1800 out.unindent();
1801 out.unindent();
1802 out.unindent();
1803 out << "}\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001804
Neel Mehta19f79792019-05-21 13:39:32 -07001805 out << "return ::android::hardware::Status();\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001806
Neel Mehta19f79792019-05-21 13:39:32 -07001807 out.unindent();
1808 out << "}\n\n";
Steven Moreland69e7c702016-09-09 11:16:32 -07001809}
1810
Steven Moreland92a08a72017-07-31 14:57:37 -07001811void AST::generateCppAtraceCall(Formatter &out,
Martijn Coenen7b295242016-11-04 16:52:56 +01001812 InstrumentationEvent event,
1813 const Method *method) const {
Timur Iskhakovcb0ba522017-07-17 20:01:37 -07001814 const Interface* iface = mRootScope.getInterface();
Yifan Hongeefe4f22017-01-04 15:32:42 -08001815 std::string baseString = "HIDL::" + iface->localName() + "::" + method->name();
Martijn Coenen7b295242016-11-04 16:52:56 +01001816 switch (event) {
1817 case SERVER_API_ENTRY:
1818 {
1819 out << "atrace_begin(ATRACE_TAG_HAL, \""
1820 << baseString + "::server\");\n";
1821 break;
1822 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001823 case PASSTHROUGH_ENTRY:
1824 {
1825 out << "atrace_begin(ATRACE_TAG_HAL, \""
1826 << baseString + "::passthrough\");\n";
1827 break;
1828 }
1829 case SERVER_API_EXIT:
Martijn Coenen7b295242016-11-04 16:52:56 +01001830 case PASSTHROUGH_EXIT:
1831 {
1832 out << "atrace_end(ATRACE_TAG_HAL);\n";
1833 break;
1834 }
Steven Moreland4607ef52018-05-09 10:52:47 -07001835 // client uses scope because of gotos
1836 // this isn't done for server because the profiled code isn't alone in its scope
1837 // this isn't done for passthrough becuase the profiled boundary isn't even in the same code
1838 case CLIENT_API_ENTRY: {
Michael Butler0a3d99a2018-07-26 13:47:10 -07001839 out << "::android::ScopedTrace PASTE(___tracer, __LINE__) (ATRACE_TAG_HAL, \""
1840 << baseString + "::client\");\n";
Steven Moreland4607ef52018-05-09 10:52:47 -07001841 break;
1842 }
1843 case CLIENT_API_EXIT:
1844 break;
Martijn Coenen7b295242016-11-04 16:52:56 +01001845 default:
1846 {
Steven Morelandcbff5612017-10-11 17:01:54 -07001847 CHECK(false) << "Unsupported instrumentation event: " << event;
Martijn Coenen7b295242016-11-04 16:52:56 +01001848 }
1849 }
Martijn Coenen7b295242016-11-04 16:52:56 +01001850}
1851
Steven Moreland92a08a72017-07-31 14:57:37 -07001852void AST::generateCppInstrumentationCall(
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001853 Formatter &out,
1854 InstrumentationEvent event,
Steven Moreland616cf4d2018-10-02 13:52:18 -07001855 const Method *method,
1856 const Interface* superInterface) const {
Steven Moreland92a08a72017-07-31 14:57:37 -07001857 generateCppAtraceCall(out, event, method);
Martijn Coenen7b295242016-11-04 16:52:56 +01001858
Steven Moreland30b76e92017-06-02 18:52:24 -07001859 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001860 out << "if (UNLIKELY(mEnableInstrumentation)) {\n";
1861 out.indent();
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001862 out << "std::vector<void *> _hidl_args;\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001863 std::string event_str = "";
1864 switch (event) {
1865 case SERVER_API_ENTRY:
1866 {
1867 event_str = "InstrumentationEvent::SERVER_API_ENTRY";
1868 for (const auto &arg : method->args()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001869 out << "_hidl_args.push_back((void *)"
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001870 << (arg->type().resultNeedsDeref() ? "" : "&")
1871 << arg->name()
1872 << ");\n";
1873 }
1874 break;
1875 }
1876 case SERVER_API_EXIT:
1877 {
1878 event_str = "InstrumentationEvent::SERVER_API_EXIT";
Steven Moreland031ccf12016-10-31 15:54:38 -07001879 for (const auto &arg : method->results()) {
Yifan Honga47eef32016-12-12 10:38:54 -08001880 out << "_hidl_args.push_back((void *)&_hidl_out_"
Steven Moreland031ccf12016-10-31 15:54:38 -07001881 << arg->name()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001882 << ");\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001883 }
1884 break;
1885 }
1886 case CLIENT_API_ENTRY:
1887 {
1888 event_str = "InstrumentationEvent::CLIENT_API_ENTRY";
1889 for (const auto &arg : method->args()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001890 out << "_hidl_args.push_back((void *)&"
1891 << arg->name()
1892 << ");\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001893 }
1894 break;
1895 }
1896 case CLIENT_API_EXIT:
1897 {
1898 event_str = "InstrumentationEvent::CLIENT_API_EXIT";
1899 for (const auto &arg : method->results()) {
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001900 out << "_hidl_args.push_back((void *)"
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001901 << (arg->type().resultNeedsDeref() ? "" : "&")
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001902 << "_hidl_out_"
1903 << arg->name()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001904 << ");\n";
1905 }
1906 break;
1907 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -07001908 case PASSTHROUGH_ENTRY:
1909 {
1910 event_str = "InstrumentationEvent::PASSTHROUGH_ENTRY";
1911 for (const auto &arg : method->args()) {
1912 out << "_hidl_args.push_back((void *)&"
1913 << arg->name()
1914 << ");\n";
1915 }
1916 break;
1917 }
1918 case PASSTHROUGH_EXIT:
1919 {
1920 event_str = "InstrumentationEvent::PASSTHROUGH_EXIT";
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -08001921 for (const auto &arg : method->results()) {
Yifan Honga47eef32016-12-12 10:38:54 -08001922 out << "_hidl_args.push_back((void *)&_hidl_out_"
Zhuoyao Zhang085a8c32016-11-17 15:35:49 -08001923 << arg->name()
1924 << ");\n";
1925 }
Steven Moreland9b1cbdf2016-11-01 12:23:27 -07001926 break;
1927 }
Steven Moreland031ccf12016-10-31 15:54:38 -07001928 default:
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001929 {
Steven Morelandcbff5612017-10-11 17:01:54 -07001930 CHECK(false) << "Unsupported instrumentation event: " << event;
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001931 }
1932 }
1933
Steven Moreland1ab31442016-11-03 18:37:51 -07001934 out << "for (const auto &callback: mInstrumentationCallbacks) {\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001935 out.indent();
1936 out << "callback("
1937 << event_str
1938 << ", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001939 << superInterface->fqName().package()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001940 << "\", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001941 << superInterface->fqName().version()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001942 << "\", \""
Steven Moreland616cf4d2018-10-02 13:52:18 -07001943 << superInterface->localName()
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001944 << "\", \""
1945 << method->name()
Zhuoyao Zhang964f72f2016-10-21 11:12:03 -07001946 << "\", &_hidl_args);\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001947 out.unindent();
1948 out << "}\n";
1949 out.unindent();
Steven Moreland30b76e92017-06-02 18:52:24 -07001950 out << "}\n";
1951 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";
Zhuoyao Zhang8f492942016-09-28 14:27:56 -07001952}
1953
Andreas Huber881227d2016-08-02 14:20:21 -07001954} // namespace android