blob: 0d680cfb207476261d560cb97f06745c47c2a8a3 [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 Huber881227d2016-08-02 14:20:21 -070021#include "Formatter.h"
22#include "Interface.h"
23#include "Method.h"
Iliyan Malchev40d474a2016-08-16 06:20:17 -070024#include "ScalarType.h"
Andreas Huber881227d2016-08-02 14:20:21 -070025#include "Scope.h"
26
Andreas Huberdca261f2016-08-04 13:47:51 -070027#include <algorithm>
Andreas Huber881227d2016-08-02 14:20:21 -070028#include <android-base/logging.h>
Andreas Huberdca261f2016-08-04 13:47:51 -070029#include <string>
Andreas Huber881227d2016-08-02 14:20:21 -070030#include <vector>
31
32namespace android {
33
Andreas Huber881227d2016-08-02 14:20:21 -070034static std::string upcase(const std::string in) {
35 std::string out{in};
36
37 for (auto &ch : out) {
38 ch = toupper(ch);
39 }
40
41 return out;
42}
43
Andreas Huberb82318c2016-08-02 14:45:54 -070044status_t AST::generateCpp(const std::string &outputPath) const {
45 status_t err = generateInterfaceHeader(outputPath);
Andreas Huber881227d2016-08-02 14:20:21 -070046
47 if (err == OK) {
Andreas Huberb82318c2016-08-02 14:45:54 -070048 err = generateStubHeader(outputPath);
Andreas Huber881227d2016-08-02 14:20:21 -070049 }
50
51 if (err == OK) {
Steven Moreland40786312016-08-16 10:29:40 -070052 err = generateHwBinderHeader(outputPath);
53 }
54
55 if (err == OK) {
Andreas Huberb82318c2016-08-02 14:45:54 -070056 err = generateProxyHeader(outputPath);
Andreas Huber881227d2016-08-02 14:20:21 -070057 }
58
59 if (err == OK) {
Andreas Huberb82318c2016-08-02 14:45:54 -070060 err = generateAllSource(outputPath);
Andreas Huber881227d2016-08-02 14:20:21 -070061 }
62
63 return err;
64}
65
Andreas Huber737080b2016-08-02 15:38:04 -070066void AST::getPackageComponents(
67 std::vector<std::string> *components) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070068 mPackage.getPackageComponents(components);
Andreas Huber737080b2016-08-02 15:38:04 -070069}
70
71void AST::getPackageAndVersionComponents(
72 std::vector<std::string> *components, bool cpp_compatible) const {
Andreas Huber0e00de42016-08-03 09:56:02 -070073 mPackage.getPackageAndVersionComponents(components, cpp_compatible);
Andreas Huber737080b2016-08-02 15:38:04 -070074}
75
Andreas Huber881227d2016-08-02 14:20:21 -070076std::string AST::makeHeaderGuard(const std::string &baseName) const {
77 std::vector<std::string> packageComponents;
78 getPackageAndVersionComponents(
79 &packageComponents, true /* cpp_compatible */);
80
81 std::string guard = "HIDL_GENERATED";
82 for (const auto &component : packageComponents) {
83 guard += "_";
84 guard += component;
85 }
86
87 guard += "_";
88 guard += baseName;
89 guard += "_H_";
90
91 return guard;
92}
93
94void AST::enterLeaveNamespace(Formatter &out, bool enter) const {
95 std::vector<std::string> packageComponents;
96 getPackageAndVersionComponents(
97 &packageComponents, true /* cpp_compatible */);
98
99 if (enter) {
100 for (const auto &component : packageComponents) {
101 out << "namespace " << component << " {\n";
102 }
Andreas Huber0e00de42016-08-03 09:56:02 -0700103
Andreas Huber2831d512016-08-15 09:33:47 -0700104 out.setNamespace(mPackage.cppNamespace() + "::");
Andreas Huber881227d2016-08-02 14:20:21 -0700105 } else {
Andreas Huber0e00de42016-08-03 09:56:02 -0700106 out.setNamespace(std::string());
107
Andreas Huber881227d2016-08-02 14:20:21 -0700108 for (auto it = packageComponents.rbegin();
109 it != packageComponents.rend();
110 ++it) {
111 out << "} // namespace " << *it << "\n";
112 }
113 }
114}
115
Andreas Huberb82318c2016-08-02 14:45:54 -0700116status_t AST::generateInterfaceHeader(const std::string &outputPath) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700117
Andreas Huberb82318c2016-08-02 14:45:54 -0700118 std::string path = outputPath;
Andreas Huberd2943e12016-08-05 11:59:31 -0700119 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Andreas Huberdca261f2016-08-04 13:47:51 -0700120 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
Andreas Huber881227d2016-08-02 14:20:21 -0700121
122 std::string ifaceName;
123 bool isInterface = true;
124 if (!AST::isInterface(&ifaceName)) {
125 ifaceName = "types";
126 isInterface = false;
127 }
128 path.append(ifaceName);
129 path.append(".h");
130
Andreas Huberd2943e12016-08-05 11:59:31 -0700131 CHECK(Coordinator::MakeParentHierarchy(path));
Andreas Huber881227d2016-08-02 14:20:21 -0700132 FILE *file = fopen(path.c_str(), "w");
133
134 if (file == NULL) {
135 return -errno;
136 }
137
138 Formatter out(file);
139
140 const std::string guard = makeHeaderGuard(ifaceName);
141
142 out << "#ifndef " << guard << "\n";
143 out << "#define " << guard << "\n\n";
144
Andreas Huber737080b2016-08-02 15:38:04 -0700145 for (const auto &item : mImportedNames) {
146 out << "#include <";
147
148 std::vector<std::string> components;
Andreas Huber0e00de42016-08-03 09:56:02 -0700149 item.getPackageAndVersionComponents(
150 &components, false /* cpp_compatible */);
Andreas Huber737080b2016-08-02 15:38:04 -0700151
152 for (const auto &component : components) {
153 out << component << "/";
154 }
155
156 out << item.name()
157 << ".h>\n";
158 }
159
160 if (!mImportedNames.empty()) {
161 out << "\n";
162 }
163
Martijn Coenen7473fab2016-08-19 14:05:40 +0200164 out << "#include <hidl/HidlSupport.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700165 out << "#include <hidl/IServiceManager.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700166
167 if (isInterface) {
Martijn Coenen93915102016-09-01 01:35:52 +0200168 out << "#include <hidl/Status.h>\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700169 }
170
171 out << "#include <utils/NativeHandle.h>\n\n";
172
173 enterLeaveNamespace(out, true /* enter */);
174 out << "\n";
175
Steven Moreland40786312016-08-16 10:29:40 -0700176 // cut off the leading 'I'.
177 const std::string baseName = ifaceName.substr(1);
178
Andreas Huber881227d2016-08-02 14:20:21 -0700179 if (isInterface) {
180 out << "struct "
Steven Moreland40786312016-08-16 10:29:40 -0700181 << ifaceName;
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700182
183 const Interface *iface = mRootScope->getInterface();
184 const Interface *superType = iface->superType();
185
Steven Moreland40786312016-08-16 10:29:40 -0700186 if (superType == NULL) {
187 out << " : virtual public RefBase";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700188 } else {
Steven Moreland40786312016-08-16 10:29:40 -0700189 out << " : public "
190 << superType->fullName();
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700191 }
192
193 out << " {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700194
195 out.indent();
196
Andreas Huber881227d2016-08-02 14:20:21 -0700197 }
198
199 status_t err = emitTypeDeclarations(out);
200
201 if (err != OK) {
202 return err;
203 }
204
205 if (isInterface) {
206 const Interface *iface = mRootScope->getInterface();
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700207 const Interface *superType = iface->superType();
Andreas Huber881227d2016-08-02 14:20:21 -0700208
Iliyan Malchev795dd432016-09-02 11:48:26 -0700209 out << "virtual bool isRemote() const { return false; }\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700210 bool haveCallbacks = false;
211 for (const auto &method : iface->methods()) {
212 const bool returnsValue = !method->results().empty();
213
214 if (!returnsValue) {
215 continue;
216 }
217
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700218 if (method->canElideCallback() != nullptr) {
219 continue;
220 }
221
Andreas Huber881227d2016-08-02 14:20:21 -0700222 haveCallbacks = true;
223
224 out << "using "
225 << method->name()
226 << "_cb = std::function<void("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700227 << Method::GetArgSignature(method->results())
Andreas Huber881227d2016-08-02 14:20:21 -0700228 << ")>;\n";
229 }
230
231 if (haveCallbacks) {
232 out << "\n";
233 }
234
235 for (const auto &method : iface->methods()) {
236 const bool returnsValue = !method->results().empty();
237
Andreas Huber3599d922016-08-09 10:42:57 -0700238 method->dumpAnnotations(out);
239
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700240 const TypedVar *elidedReturn = method->canElideCallback();
241 if (elidedReturn) {
242 std::string extra;
Iliyan Malchev2b6591b2016-08-18 19:15:19 -0700243 out << "virtual ::android::hardware::Return<";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700244 out << elidedReturn->type().getCppResultType(&extra) << "> ";
245 } else {
246 out << "virtual ::android::hardware::Status ";
247 }
248
249 out << method->name()
Andreas Huber881227d2016-08-02 14:20:21 -0700250 << "("
Steven Morelanda7a421a2016-09-07 08:35:18 -0700251 << Method::GetArgSignature(method->args());
Andreas Huber881227d2016-08-02 14:20:21 -0700252
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700253 if (returnsValue && elidedReturn == nullptr) {
Andreas Huber881227d2016-08-02 14:20:21 -0700254 if (!method->args().empty()) {
255 out << ", ";
256 }
257
Iliyan Malchev549e2592016-08-10 08:59:12 -0700258 out << method->name() << "_cb _hidl_cb = nullptr";
Andreas Huber881227d2016-08-02 14:20:21 -0700259 }
260
261 out << ") = 0;\n";
262 }
Steven Moreland40786312016-08-16 10:29:40 -0700263
264 out << "DECLARE_REGISTER_AND_GET_SERVICE(" << baseName << ")\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700265 }
266
267 if (isInterface) {
268 out.unindent();
269
270 out << "};\n";
271 }
272
273 out << "\n";
274 enterLeaveNamespace(out, false /* enter */);
275
276 out << "\n#endif // " << guard << "\n";
277
278 return OK;
279}
280
Steven Moreland40786312016-08-16 10:29:40 -0700281status_t AST::generateHwBinderHeader(const std::string &outputPath) const {
282 std::string ifaceName;
283 if(!AST::isInterface(&ifaceName)) {
284 // types.hal does not get an HwBinder header.
285 return OK;
286 }
287
288 // cut off the leading 'I'.
289 const std::string baseName = ifaceName.substr(1);
290
291 const std::string klassName = "IHw" + baseName;
292
293 std::string path = outputPath;
294 path.append(mCoordinator->convertPackageRootToPath(mPackage));
295 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
296 path.append(klassName + ".h");
297
298 FILE* file = fopen(path.c_str(), "w");
299
300 if (file == NULL) {
301 return -errno;
302 }
303
304 Formatter out(file);
305
306 const std::string guard = makeHeaderGuard(klassName);
307
308 out << "#ifndef " << guard << "\n";
309 out << "#define " << guard << "\n\n";
310
311 std::vector<std::string> packageComponents;
312 getPackageAndVersionComponents(
313 &packageComponents, false /* cpp_compatible */);
314
315 out << "#include <";
316 for (const auto &component : packageComponents) {
317 out << component << "/";
318 }
319 out << ifaceName << ".h>\n\n";
320
321 for (const auto &item : mImportedNames) {
322 if (item.name() == "types") {
323 continue;
324 }
325
326 out << "#include <";
327
328 std::vector<std::string> components;
329 item.getPackageAndVersionComponents(
330 &components, false /* cpp_compatible */);
331
332 for (const auto &component : components) {
333 out << component << "/";
334 }
335
336 // cut off the leading I
337 const std::string itemBaseName = item.name().substr(1);
338
339 out << "Bn"
340 << itemBaseName
341 << ".h>\n";
342 }
343
344 out << "\n";
345
346 out << "#include <hidl/HidlSupport.h>\n";
Martijn Coenen93915102016-09-01 01:35:52 +0200347 out << "#include <hidl/Status.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700348 out << "#include <hwbinder/IBinder.h>\n";
349 out << "#include <hwbinder/IInterface.h>\n";
Steven Moreland40786312016-08-16 10:29:40 -0700350
351 out << "\n";
352
353 enterLeaveNamespace(out, true /* enter */);
354 out << "\n";
355
356 out << "struct "
357 << klassName
358 << " : public "
359 << ifaceName;
360
361 const Interface *iface = mRootScope->getInterface();
362 const Interface *superType = iface->superType();
363
364 out << ", public ::android::hardware::IInterface";
365
366 out << " {\n";
367
368 out.indent();
369
370 out << "DECLARE_HWBINDER_META_INTERFACE(" << baseName << ");\n\n";
371
372 out << "enum Call {\n";
373 out.indent();
374
375 bool first = true;
376 for (const auto &method : iface->methods()) {
377 out << upcase(method->name());
378
379 if (first) {
380 out << " = ";
381 if (superType != NULL) {
382 out << superType->fqName().cppNamespace()
383 << "::IHw"
384 << superType->getBaseName()
385 << "::Call::CallCount";
386 } else {
387 out << "::android::hardware::IBinder::FIRST_CALL_TRANSACTION";
388 }
389
390 first = false;
391 }
392
393 out << ",\n";
394 }
395
396 out << "CallCount\n";
397
398 out.unindent();
399 out << "};\n\n";
400
401 out.unindent();
402
403 out << "};\n\n";
404
405 enterLeaveNamespace(out, false /* enter */);
406
407 out << "\n#endif // " << guard << "\n";
408
409 return OK;
410}
411
Andreas Huber881227d2016-08-02 14:20:21 -0700412status_t AST::emitTypeDeclarations(Formatter &out) const {
413 return mRootScope->emitTypeDeclarations(out);
414}
415
Steven Morelanda7a421a2016-09-07 08:35:18 -0700416status_t AST::generateStubMethod(Formatter &out,
417 const std::string &className,
418 const Method *method) const {
419 out << "inline ";
420
421 method->generateCppSignature(out, className);
422
423 const bool returnsValue = !method->results().empty();
424 const TypedVar *elidedReturn = method->canElideCallback();
425 out << " {\n";
426 out.indent();
427 out << "return mImpl->"
428 << method->name()
429 << "(";
430 bool first = true;
431 for (const auto &arg : method->args()) {
432 if (!first) {
433 out << ", ";
434 }
435 first = false;
436 out << arg->name();
437 }
438 if (returnsValue && elidedReturn == nullptr) {
439 if (!method->args().empty()) {
440 out << ", ";
441 }
442
443 out << "_hidl_cb";
444 }
445 out << ");\n";
446 out.unindent();
447 out << "}";
448
449 out << ";\n";
450
451 return OK;
452}
453
454status_t AST::generateProxyMethod(Formatter &out,
455 const std::string &className,
456 const Method *method) const {
457
458 method->generateCppSignature(out, className);
459 out << " override;\n";
460
461 return OK;
462}
463
464status_t AST::generateMethods(
465 Formatter &out,
466 const std::string &className,
467 MethodLocation type) const {
468
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700469 const Interface *iface = mRootScope->getInterface();
470
471 std::vector<const Interface *> chain;
472 while (iface != NULL) {
473 chain.push_back(iface);
474 iface = iface->superType();
475 }
476
477 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
478 const Interface *superInterface = *it;
479
480 out << "// Methods from "
481 << superInterface->fullName()
482 << " follow.\n";
483
484 for (const auto &method : superInterface->methods()) {
Steven Morelanda7a421a2016-09-07 08:35:18 -0700485 status_t err;
486 switch(type) {
487 case STUB_HEADER:
488 err = generateStubMethod(out,
489 className,
490 method);
491 break;
492 case PROXY_HEADER:
493 err = generateProxyMethod(out,
494 className,
495 method);
496 break;
497 default:
498 err = UNKNOWN_ERROR;
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700499 }
500
Steven Morelanda7a421a2016-09-07 08:35:18 -0700501 if (err != OK) {
502 return err;
Steven Moreland40786312016-08-16 10:29:40 -0700503 }
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700504 }
505
506 out << "\n";
507 }
508
509 return OK;
510}
511
Andreas Huberb82318c2016-08-02 14:45:54 -0700512status_t AST::generateStubHeader(const std::string &outputPath) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700513 std::string ifaceName;
514 if (!AST::isInterface(&ifaceName)) {
515 // types.hal does not get a stub header.
516 return OK;
517 }
518
Andreas Huber881227d2016-08-02 14:20:21 -0700519 // cut off the leading 'I'.
520 const std::string baseName = ifaceName.substr(1);
Steven Moreland40786312016-08-16 10:29:40 -0700521 const std::string klassName = "Bn" + baseName;
Andreas Huber881227d2016-08-02 14:20:21 -0700522
Andreas Huberb82318c2016-08-02 14:45:54 -0700523 std::string path = outputPath;
Andreas Huberd2943e12016-08-05 11:59:31 -0700524 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Andreas Huberdca261f2016-08-04 13:47:51 -0700525 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
Steven Moreland40786312016-08-16 10:29:40 -0700526 path.append(klassName);
Andreas Huber881227d2016-08-02 14:20:21 -0700527 path.append(".h");
528
Andreas Huberd2943e12016-08-05 11:59:31 -0700529 CHECK(Coordinator::MakeParentHierarchy(path));
Andreas Huber881227d2016-08-02 14:20:21 -0700530 FILE *file = fopen(path.c_str(), "w");
531
532 if (file == NULL) {
533 return -errno;
534 }
535
536 Formatter out(file);
537
Steven Moreland40786312016-08-16 10:29:40 -0700538 const std::string guard = makeHeaderGuard(klassName);
Andreas Huber881227d2016-08-02 14:20:21 -0700539
540 out << "#ifndef " << guard << "\n";
541 out << "#define " << guard << "\n\n";
542
543 std::vector<std::string> packageComponents;
544 getPackageAndVersionComponents(
545 &packageComponents, false /* cpp_compatible */);
546
547 out << "#include <";
548 for (const auto &component : packageComponents) {
549 out << component << "/";
550 }
Steven Moreland40786312016-08-16 10:29:40 -0700551 out << "IHw" << baseName << ".h>\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700552
553 enterLeaveNamespace(out, true /* enter */);
554 out << "\n";
555
556 out << "struct "
557 << "Bn"
558 << baseName
Steven Moreland40786312016-08-16 10:29:40 -0700559 << " : public ::android::hardware::BnInterface<I"
560 << baseName << ", IHw" << baseName
Andreas Huber881227d2016-08-02 14:20:21 -0700561 << "> {\n";
562
563 out.indent();
Steven Moreland40786312016-08-16 10:29:40 -0700564 out << "explicit Bn"
565 << baseName
566 << "(const ::android::sp<" << ifaceName << "> &_hidl_impl);"
567 << "\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700568 out << "::android::status_t onTransact(\n";
569 out.indent();
570 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -0700571 out << "uint32_t _hidl_code,\n";
572 out << "const ::android::hardware::Parcel &_hidl_data,\n";
573 out << "::android::hardware::Parcel *_hidl_reply,\n";
574 out << "uint32_t _hidl_flags = 0,\n";
Iliyan Malchev62c3d182016-08-16 20:33:39 -0700575 out << "TransactCallback _hidl_cb = nullptr) override;\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700576 out.unindent();
577 out.unindent();
578
Steven Morelanda7a421a2016-09-07 08:35:18 -0700579 generateMethods(out,
580 "" /* class name */,
581 MethodLocation::STUB_HEADER);
Andreas Huber881227d2016-08-02 14:20:21 -0700582 out.unindent();
583
584 out << "};\n\n";
585
586 enterLeaveNamespace(out, false /* enter */);
587
588 out << "\n#endif // " << guard << "\n";
589
590 return OK;
591}
592
Andreas Huberb82318c2016-08-02 14:45:54 -0700593status_t AST::generateProxyHeader(const std::string &outputPath) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700594 std::string ifaceName;
595 if (!AST::isInterface(&ifaceName)) {
596 // types.hal does not get a proxy header.
597 return OK;
598 }
599
Andreas Huber881227d2016-08-02 14:20:21 -0700600 // cut off the leading 'I'.
601 const std::string baseName = ifaceName.substr(1);
602
Andreas Huberb82318c2016-08-02 14:45:54 -0700603 std::string path = outputPath;
Andreas Huberd2943e12016-08-05 11:59:31 -0700604 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Andreas Huberdca261f2016-08-04 13:47:51 -0700605 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
Andreas Huber881227d2016-08-02 14:20:21 -0700606 path.append("Bp");
607 path.append(baseName);
608 path.append(".h");
609
Andreas Huberd2943e12016-08-05 11:59:31 -0700610 CHECK(Coordinator::MakeParentHierarchy(path));
Andreas Huber881227d2016-08-02 14:20:21 -0700611 FILE *file = fopen(path.c_str(), "w");
612
613 if (file == NULL) {
614 return -errno;
615 }
616
617 Formatter out(file);
618
619 const std::string guard = makeHeaderGuard("Bp" + baseName);
620
621 out << "#ifndef " << guard << "\n";
622 out << "#define " << guard << "\n\n";
623
624 std::vector<std::string> packageComponents;
625 getPackageAndVersionComponents(
626 &packageComponents, false /* cpp_compatible */);
627
628 out << "#include <";
629 for (const auto &component : packageComponents) {
630 out << component << "/";
631 }
Steven Moreland40786312016-08-16 10:29:40 -0700632 out << "IHw" << baseName << ".h>\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700633
634 enterLeaveNamespace(out, true /* enter */);
635 out << "\n";
636
637 out << "struct "
638 << "Bp"
639 << baseName
Steven Moreland40786312016-08-16 10:29:40 -0700640 << " : public ::android::hardware::BpInterface<IHw"
641 << baseName
Andreas Huber881227d2016-08-02 14:20:21 -0700642 << "> {\n";
643
644 out.indent();
645
646 out << "explicit Bp"
647 << baseName
Iliyan Malchev549e2592016-08-10 08:59:12 -0700648 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl);"
Andreas Huber881227d2016-08-02 14:20:21 -0700649 << "\n\n";
650
Iliyan Malchev795dd432016-09-02 11:48:26 -0700651 out << "virtual bool isRemote() const { return true; }\n\n";
Steven Moreland40786312016-08-16 10:29:40 -0700652
Steven Morelanda7a421a2016-09-07 08:35:18 -0700653 generateMethods(out,
654 "" /* class name */,
655 MethodLocation::PROXY_HEADER);
Andreas Huber881227d2016-08-02 14:20:21 -0700656
657 out.unindent();
658
659 out << "};\n\n";
660
661 enterLeaveNamespace(out, false /* enter */);
662
663 out << "\n#endif // " << guard << "\n";
664
665 return OK;
666}
667
Andreas Huberb82318c2016-08-02 14:45:54 -0700668status_t AST::generateAllSource(const std::string &outputPath) const {
Andreas Huber881227d2016-08-02 14:20:21 -0700669
Andreas Huberb82318c2016-08-02 14:45:54 -0700670 std::string path = outputPath;
Andreas Huberd2943e12016-08-05 11:59:31 -0700671 path.append(mCoordinator->convertPackageRootToPath(mPackage));
Andreas Huberdca261f2016-08-04 13:47:51 -0700672 path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
Andreas Huber881227d2016-08-02 14:20:21 -0700673
674 std::string ifaceName;
675 std::string baseName;
676
677 bool isInterface = true;
678 if (!AST::isInterface(&ifaceName)) {
679 baseName = "types";
680 isInterface = false;
681 } else {
682 baseName = ifaceName.substr(1); // cut off the leading 'I'.
683 }
684
685 path.append(baseName);
686
687 if (baseName != "types") {
688 path.append("All");
689 }
690
691 path.append(".cpp");
692
Andreas Huberd2943e12016-08-05 11:59:31 -0700693 CHECK(Coordinator::MakeParentHierarchy(path));
Andreas Huber881227d2016-08-02 14:20:21 -0700694 FILE *file = fopen(path.c_str(), "w");
695
696 if (file == NULL) {
697 return -errno;
698 }
699
700 Formatter out(file);
701
702 std::vector<std::string> packageComponents;
703 getPackageAndVersionComponents(
704 &packageComponents, false /* cpp_compatible */);
705
706 std::string prefix;
707 for (const auto &component : packageComponents) {
708 prefix += component;
709 prefix += "/";
710 }
711
712 if (isInterface) {
713 out << "#include <" << prefix << "/Bp" << baseName << ".h>\n";
714 out << "#include <" << prefix << "/Bn" << baseName << ".h>\n";
715 } else {
716 out << "#include <" << prefix << "types.h>\n";
717 }
718
719 out << "\n";
720
721 enterLeaveNamespace(out, true /* enter */);
722 out << "\n";
723
724 status_t err = generateTypeSource(out, ifaceName);
725
726 if (err == OK && isInterface) {
727 err = generateProxySource(out, baseName);
728 }
729
730 if (err == OK && isInterface) {
731 err = generateStubSource(out, baseName);
732 }
733
Steven Moreland40786312016-08-16 10:29:40 -0700734 if (err == OK && isInterface) {
735 out << "IMPLEMENT_REGISTER_AND_GET_SERVICE(" << baseName << ")\n";
736 }
737
Andreas Huber881227d2016-08-02 14:20:21 -0700738 enterLeaveNamespace(out, false /* enter */);
739
740 return err;
741}
742
743status_t AST::generateTypeSource(
744 Formatter &out, const std::string &ifaceName) const {
745 return mRootScope->emitTypeDefinitions(out, ifaceName);
746}
747
Andreas Hubere7ff2282016-08-16 13:50:03 -0700748void AST::declareCppReaderLocals(
749 Formatter &out, const std::vector<TypedVar *> &args) const {
750 if (args.empty()) {
751 return;
752 }
753
754 for (const auto &arg : args) {
755 const Type &type = arg->type();
756
757 std::string extra;
758 out << type.getCppResultType(&extra)
759 << " "
760 << arg->name()
761 << extra
762 << ";\n";
763 }
764
765 out << "\n";
766}
767
Andreas Huber881227d2016-08-02 14:20:21 -0700768void AST::emitCppReaderWriter(
769 Formatter &out,
770 const std::string &parcelObj,
771 bool parcelObjIsPointer,
772 const TypedVar *arg,
773 bool isReader,
774 Type::ErrorMode mode) const {
775 const Type &type = arg->type();
776
Andreas Huber881227d2016-08-02 14:20:21 -0700777 type.emitReaderWriter(
778 out,
779 arg->name(),
780 parcelObj,
781 parcelObjIsPointer,
782 isReader,
783 mode);
784}
785
786status_t AST::generateProxySource(
787 Formatter &out, const std::string &baseName) const {
788 const std::string klassName = "Bp" + baseName;
789
790 out << klassName
791 << "::"
792 << klassName
Iliyan Malchev549e2592016-08-10 08:59:12 -0700793 << "(const ::android::sp<::android::hardware::IBinder> &_hidl_impl)\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700794
795 out.indent();
796 out.indent();
797
798 out << ": BpInterface"
Steven Moreland40786312016-08-16 10:29:40 -0700799 << "<IHw"
Andreas Huber881227d2016-08-02 14:20:21 -0700800 << baseName
Iliyan Malchev549e2592016-08-10 08:59:12 -0700801 << ">(_hidl_impl) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700802
803 out.unindent();
804 out.unindent();
805 out << "}\n\n";
806
807 const Interface *iface = mRootScope->getInterface();
808
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700809 std::vector<const Interface *> chain;
810 while (iface != NULL) {
811 chain.push_back(iface);
812 iface = iface->superType();
813 }
Andreas Huber881227d2016-08-02 14:20:21 -0700814
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700815 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
816 const Interface *superInterface = *it;
Andreas Huber881227d2016-08-02 14:20:21 -0700817
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700818 for (const auto &method : superInterface->methods()) {
Steven Morelanda7a421a2016-09-07 08:35:18 -0700819 method->generateCppSignature(out, klassName);
820
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700821 const bool returnsValue = !method->results().empty();
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700822 const TypedVar *elidedReturn = method->canElideCallback();
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700823
Steven Morelanda7a421a2016-09-07 08:35:18 -0700824 out << "{\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700825
826 out.indent();
827
Iliyan Malchev549e2592016-08-10 08:59:12 -0700828 out << "::android::hardware::Parcel _hidl_data;\n";
829 out << "::android::hardware::Parcel _hidl_reply;\n";
Andreas Hubere7ff2282016-08-16 13:50:03 -0700830 out << "::android::status_t _hidl_err;\n";
831 out << "::android::hardware::Status _hidl_status;\n\n";
Andreas Hubere7ff2282016-08-16 13:50:03 -0700832 declareCppReaderLocals(out, method->results());
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700833
Iliyan Malchev549e2592016-08-10 08:59:12 -0700834 out << "_hidl_err = _hidl_data.writeInterfaceToken("
Steven Moreland40786312016-08-16 10:29:40 -0700835 << superInterface->fqName().cppNamespace()
836 << "::IHw"
837 << superInterface->getBaseName()
838 << "::descriptor);\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700839
Iliyan Malchev549e2592016-08-10 08:59:12 -0700840 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700841
842 for (const auto &arg : method->args()) {
843 emitCppReaderWriter(
844 out,
Iliyan Malchev549e2592016-08-10 08:59:12 -0700845 "_hidl_data",
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700846 false /* parcelObjIsPointer */,
847 arg,
848 false /* reader */,
849 Type::ErrorMode_Goto);
850 }
851
Steven Moreland40786312016-08-16 10:29:40 -0700852 out << "_hidl_err = remote()->transact("
853 << superInterface->fqName().cppNamespace()
854 << "::IHw"
855 << superInterface->getBaseName()
856 << "::Call::"
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700857 << upcase(method->name())
Iliyan Malchev639bff82016-08-13 14:24:11 -0700858 << ", _hidl_data, &_hidl_reply";
859 if (method->isOneway()) {
860 out << ", ::android::hardware::IBinder::FLAG_ONEWAY";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700861 }
Iliyan Malchev639bff82016-08-13 14:24:11 -0700862 out << ");\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700863
Iliyan Malchev639bff82016-08-13 14:24:11 -0700864 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700865
Iliyan Malchev639bff82016-08-13 14:24:11 -0700866 if (!method->isOneway()) {
867 out << "_hidl_err = _hidl_status.readFromParcel(_hidl_reply);\n";
868 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
Iliyan Malchev639bff82016-08-13 14:24:11 -0700869 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n";
870
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700871 for (const auto &arg : method->results()) {
Iliyan Malchev639bff82016-08-13 14:24:11 -0700872 emitCppReaderWriter(
873 out,
874 "_hidl_reply",
875 false /* parcelObjIsPointer */,
876 arg,
877 true /* reader */,
878 Type::ErrorMode_Goto);
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700879 }
880
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700881 if (returnsValue && elidedReturn == nullptr) {
Iliyan Malchev639bff82016-08-13 14:24:11 -0700882 out << "if (_hidl_cb != nullptr) {\n";
883 out.indent();
884 out << "_hidl_cb(";
885
886 bool first = true;
887 for (const auto &arg : method->results()) {
888 if (!first) {
889 out << ", ";
890 }
891
892 if (arg->type().resultNeedsDeref()) {
893 out << "*";
894 }
895 out << arg->name();
896
897 first = false;
898 }
899
900 out << ");\n";
901 out.unindent();
902 out << "}\n\n";
903 }
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700904 }
905
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700906 if (elidedReturn != nullptr) {
907 std::string extra;
908
909 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
Iliyan Malchev2b6591b2016-08-18 19:15:19 -0700910 out << "return ::android::hardware::Return<";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700911 out << elidedReturn->type().getCppResultType(&extra)
912 << ">(" << elidedReturn->name() << ");\n\n";
913
914 out.unindent();
915 out << "_hidl_error:\n";
916 out.indent();
917 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
Iliyan Malchev2b6591b2016-08-18 19:15:19 -0700918 out << "return ::android::hardware::Return<";
Iliyan Malchev40d474a2016-08-16 06:20:17 -0700919 out << method->results().at(0)->type().getCppResultType(&extra)
920 << ">(_hidl_status);\n";
921 } else {
922 out.unindent();
923 out << "_hidl_error:\n";
924 out.indent();
925 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
926 out << "return _hidl_status;\n";
927 }
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700928
Andreas Huber881227d2016-08-02 14:20:21 -0700929 out.unindent();
930 out << "}\n\n";
931 }
Andreas Huber881227d2016-08-02 14:20:21 -0700932 }
933
934 return OK;
935}
936
937status_t AST::generateStubSource(
938 Formatter &out, const std::string &baseName) const {
939 out << "IMPLEMENT_HWBINDER_META_INTERFACE("
940 << baseName
941 << ", \""
942 << mPackage.string()
943 << "::I"
944 << baseName
945 << "\");\n\n";
946
947 const std::string klassName = "Bn" + baseName;
948
Steven Moreland40786312016-08-16 10:29:40 -0700949 out << klassName
950 << "::"
951 << klassName
952 << "(const ::android::sp<I" << baseName <<"> &_hidl_impl)\n";
953
954 out.indent();
955 out.indent();
956
957 out << ": BnInterface"
958 << "<I"
959 << baseName
960 << ", IHw"
961 << baseName
962 << ">(_hidl_impl) {\n";
963
964 out.unindent();
965 out.unindent();
966 out << "}\n\n";
967
Andreas Huber881227d2016-08-02 14:20:21 -0700968 out << "::android::status_t " << klassName << "::onTransact(\n";
969
970 out.indent();
971 out.indent();
972
Iliyan Malchev549e2592016-08-10 08:59:12 -0700973 out << "uint32_t _hidl_code,\n"
974 << "const ::android::hardware::Parcel &_hidl_data,\n"
975 << "::android::hardware::Parcel *_hidl_reply,\n"
976 << "uint32_t _hidl_flags,\n"
977 << "TransactCallback _hidl_cb) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700978
979 out.unindent();
980
Iliyan Malchev549e2592016-08-10 08:59:12 -0700981 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
Iliyan Malchev549e2592016-08-10 08:59:12 -0700982 out << "switch (_hidl_code) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700983 out.indent();
984
985 const Interface *iface = mRootScope->getInterface();
986
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700987 std::vector<const Interface *> chain;
988 while (iface != NULL) {
989 chain.push_back(iface);
990 iface = iface->superType();
991 }
Andreas Huber881227d2016-08-02 14:20:21 -0700992
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700993 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
994 const Interface *superInterface = *it;
Andreas Huber881227d2016-08-02 14:20:21 -0700995
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700996 for (const auto &method : superInterface->methods()) {
997 out << "case "
Steven Moreland40786312016-08-16 10:29:40 -0700998 << superInterface->fqName().cppNamespace()
999 << "::IHw"
1000 << superInterface->getBaseName()
Andreas Huber6cb08cf2016-08-03 15:44:51 -07001001 << "::Call::"
1002 << upcase(method->name())
1003 << ":\n{\n";
1004
1005 out.indent();
1006
1007 status_t err =
1008 generateStubSourceForMethod(out, superInterface, method);
1009
1010 if (err != OK) {
1011 return err;
1012 }
1013
1014 out.unindent();
1015 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001016 }
Andreas Huber881227d2016-08-02 14:20:21 -07001017 }
1018
1019 out << "default:\n{\n";
1020 out.indent();
1021
Andreas Huber8a82ff72016-08-04 10:29:39 -07001022 out << "return ::android::hardware::BnInterface<I"
Steven Moreland40786312016-08-16 10:29:40 -07001023 << baseName << ", IHw" << baseName
Andreas Huber881227d2016-08-02 14:20:21 -07001024 << ">::onTransact(\n";
1025
1026 out.indent();
1027 out.indent();
1028
Iliyan Malchev549e2592016-08-10 08:59:12 -07001029 out << "_hidl_code, _hidl_data, _hidl_reply, "
1030 << "_hidl_flags, _hidl_cb);\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001031
1032 out.unindent();
1033 out.unindent();
1034
1035 out.unindent();
1036 out << "}\n";
1037
1038 out.unindent();
1039 out << "}\n\n";
1040
Iliyan Malchev549e2592016-08-10 08:59:12 -07001041 out << "if (_hidl_err == ::android::UNEXPECTED_NULL) {\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001042 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -07001043 out << "_hidl_err = ::android::hardware::Status::fromExceptionCode(\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001044 out.indent();
1045 out.indent();
Andreas Huber8a82ff72016-08-04 10:29:39 -07001046 out << "::android::hardware::Status::EX_NULL_POINTER)\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001047 out.indent();
1048 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -07001049 out << ".writeToParcel(_hidl_reply);\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001050 out.unindent();
1051 out.unindent();
1052 out.unindent();
1053 out.unindent();
1054
1055 out.unindent();
1056 out << "}\n\n";
1057
Iliyan Malchev549e2592016-08-10 08:59:12 -07001058 out << "return _hidl_err;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001059
1060 out.unindent();
1061 out << "}\n\n";
1062
1063 return OK;
1064}
1065
1066status_t AST::generateStubSourceForMethod(
Andreas Huber6cb08cf2016-08-03 15:44:51 -07001067 Formatter &out, const Interface *iface, const Method *method) const {
Iliyan Malchev549e2592016-08-10 08:59:12 -07001068 out << "if (!_hidl_data.enforceInterface("
Steven Moreland40786312016-08-16 10:29:40 -07001069 << iface->fqName().cppNamespace()
1070 << "::IHw"
1071 << iface->getBaseName()
1072 << "::descriptor)) {\n";
Andreas Huber6cb08cf2016-08-03 15:44:51 -07001073
Andreas Huber881227d2016-08-02 14:20:21 -07001074 out.indent();
Iliyan Malchev549e2592016-08-10 08:59:12 -07001075 out << "_hidl_err = ::android::BAD_TYPE;\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001076 out << "break;\n";
1077 out.unindent();
1078 out << "}\n\n";
1079
Andreas Hubere7ff2282016-08-16 13:50:03 -07001080 declareCppReaderLocals(out, method->args());
1081
Andreas Huber881227d2016-08-02 14:20:21 -07001082 for (const auto &arg : method->args()) {
1083 emitCppReaderWriter(
1084 out,
Iliyan Malchev549e2592016-08-10 08:59:12 -07001085 "_hidl_data",
Andreas Huber881227d2016-08-02 14:20:21 -07001086 false /* parcelObjIsPointer */,
1087 arg,
1088 true /* reader */,
1089 Type::ErrorMode_Break);
1090 }
1091
1092 const bool returnsValue = !method->results().empty();
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001093 const TypedVar *elidedReturn = method->canElideCallback();
Andreas Huber881227d2016-08-02 14:20:21 -07001094
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001095 if (elidedReturn != nullptr) {
1096 std::string extra;
Andreas Huber881227d2016-08-02 14:20:21 -07001097
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001098 out << elidedReturn->type().getCppResultType(&extra) << " ";
1099 out << elidedReturn->name() << " = ";
1100 out << method->name() << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001101
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001102 bool first = true;
1103 for (const auto &arg : method->args()) {
Andreas Huber881227d2016-08-02 14:20:21 -07001104 if (!first) {
1105 out << ", ";
1106 }
1107
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001108 if (arg->type().resultNeedsDeref()) {
1109 out << "*";
1110 }
1111
1112 out << arg->name();
Andreas Huber881227d2016-08-02 14:20:21 -07001113
1114 first = false;
1115 }
1116
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001117 out << ");\n\n";
Andreas Huber8a82ff72016-08-04 10:29:39 -07001118 out << "::android::hardware::Status::ok()"
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001119 << ".writeToParcel(_hidl_reply);\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001120
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001121 elidedReturn->type().emitReaderWriter(
1122 out,
1123 elidedReturn->name(),
1124 "_hidl_reply",
1125 true, /* parcelObjIsPointer */
1126 false, /* isReader */
1127 Type::ErrorMode_Ignore);
Andreas Huber881227d2016-08-02 14:20:21 -07001128
Iliyan Malchev549e2592016-08-10 08:59:12 -07001129 out << "_hidl_cb(*_hidl_reply);\n";
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001130 } else {
1131 if (returnsValue) {
1132 out << "bool _hidl_callbackCalled = false;\n\n";
1133 }
Andreas Huber881227d2016-08-02 14:20:21 -07001134
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001135 out << "::android::hardware::Status _hidl_status(\n";
Andreas Huber881227d2016-08-02 14:20:21 -07001136 out.indent();
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001137 out.indent();
1138 out << method->name() << "(";
Andreas Huber881227d2016-08-02 14:20:21 -07001139
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001140 bool first = true;
1141 for (const auto &arg : method->args()) {
1142 if (!first) {
1143 out << ", ";
1144 }
Andreas Huber881227d2016-08-02 14:20:21 -07001145
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001146 if (arg->type().resultNeedsDeref()) {
1147 out << "*";
1148 }
1149
1150 out << arg->name();
1151
1152 first = false;
1153 }
1154
1155 if (returnsValue) {
1156 if (!first) {
1157 out << ", ";
1158 }
1159
1160 out << "[&](";
1161
1162 first = true;
1163 for (const auto &arg : method->results()) {
1164 if (!first) {
1165 out << ", ";
1166 }
1167
1168 out << "const auto &" << arg->name();
1169
1170 first = false;
1171 }
1172
1173 out << ") {\n";
1174 out.indent();
1175 out << "_hidl_callbackCalled = true;\n\n";
1176
1177 out << "::android::hardware::Status::ok()"
1178 << ".writeToParcel(_hidl_reply);\n\n";
1179
1180 for (const auto &arg : method->results()) {
1181 emitCppReaderWriter(
1182 out,
1183 "_hidl_reply",
1184 true /* parcelObjIsPointer */,
1185 arg,
1186 false /* reader */,
1187 Type::ErrorMode_Ignore);
1188 }
1189
1190 out << "_hidl_cb(*_hidl_reply);\n";
1191
1192 out.unindent();
1193 out << "}\n";
1194 }
1195
Andreas Huber881227d2016-08-02 14:20:21 -07001196 out.unindent();
Iliyan Malchev40d474a2016-08-16 06:20:17 -07001197 out.unindent();
1198 out << "));\n\n";
1199
1200 if (returnsValue) {
1201 out << "if (!_hidl_callbackCalled) {\n";
1202 out.indent();
1203 }
1204
1205 out << "_hidl_err = _hidl_status.writeToParcel(_hidl_reply);\n";
1206
1207 if (returnsValue) {
1208 out.unindent();
1209 out << "}\n\n";
1210 }
Andreas Huber881227d2016-08-02 14:20:21 -07001211 }
1212
1213 out << "break;\n";
1214
1215 return OK;
1216}
1217
1218} // namespace android
1219