Lines Matching defs:out

64         Formatter &out,
68 out << "#include <";
74 out << component << "/";
77 out << klass
81 void AST::enterLeaveNamespace(Formatter &out, bool enter) const {
88 out << "namespace " << component << " {\n";
91 out.setNamespace(mPackage.cppNamespace() + "::");
93 out.setNamespace(std::string());
98 out << "} // namespace " << *it << "\n";
103 static void declareGetService(Formatter &out, const std::string &interfaceName, bool isTry) {
106 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
108 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
112 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
117 out << "static ::android::sp<" << interfaceName << "> " << functionName << "("
121 static void declareServiceManagerInteractions(Formatter &out, const std::string &interfaceName) {
122 declareGetService(out, interfaceName, true /* isTry */);
123 declareGetService(out, interfaceName, false /* isTry */);
125 out << "__attribute__ ((warn_unused_result))"
127 out << "static bool registerForNotifications(\n";
128 out.indent(2, [&] {
129 out << "const std::string &serviceName,\n"
136 static void implementGetService(Formatter &out,
143 out << "// static\n"
146 out.block([&] {
147 out << "return ::android::hardware::details::getServiceInternal<"
155 static void implementServiceManagerInteractions(Formatter &out,
160 implementGetService(out, fqName, true /* isTry */);
161 implementGetService(out, fqName, false /* isTry */);
163 out << "::android::status_t " << interfaceName << "::registerAsService("
165 out.block([&] {
166 out << "::android::hardware::details::onRegistration(\""
170 out << "const ::android::sp<::android::hidl::manager::V1_0::IServiceManager> sm\n";
171 out.indent(2, [&] {
172 out << "= ::android::hardware::defaultServiceManager();\n";
174 out.sIf("sm == nullptr", [&] {
175 out << "return ::android::INVALID_OPERATION;\n";
177 out << "::android::hardware::Return<bool> ret = "
182 out << "bool " << interfaceName << "::registerForNotifications(\n";
183 out.indent(2, [&] {
184 out << "const std::string &serviceName,\n"
188 out.block([&] {
189 out << "const ::android::sp<::android::hidl::manager::V1_0::IServiceManager> sm\n";
190 out.indent(2, [&] {
191 out << "= ::android::hardware::defaultServiceManager();\n";
193 out.sIf("sm == nullptr", [&] {
194 out << "return false;\n";
196 out << "::android::hardware::Return<bool> success =\n";
197 out.indent(2, [&] {
198 out << "sm->registerForNotifications(\"" << package << "::" << interfaceName << "\",\n";
199 out.indent(2, [&] {
200 out << "serviceName, notification);\n";
203 out << "return success.isOk() && success;\n";
207 void AST::generateInterfaceHeader(Formatter& out) const {
212 out << "#ifndef " << guard << "\n";
213 out << "#define " << guard << "\n\n";
216 generateCppPackageInclude(out, item, item.name());
220 out << "\n";
225 out << "// skipped #include IServiceNotification.h\n\n";
227 out << "#include <android/hidl/manager/1.0/IServiceNotification.h>\n\n";
231 out << "#include <hidl/HidlSupport.h>\n";
232 out << "#include <hidl/MQDescriptor.h>\n";
235 out << "#include <hidl/Status.h>\n";
238 out << "#include <utils/NativeHandle.h>\n";
239 out << "#include <utils/misc.h>\n\n"; /* for report_sysprop_change() */
241 enterLeaveNamespace(out, true /* enter */);
242 out << "\n";
245 out << "struct "
251 out << " : virtual public ::android::RefBase";
253 out << " : public "
257 out << " {\n";
259 out.indent();
261 generateCppTag(out, "android::hardware::details::i_tag");
264 emitTypeDeclarations(out);
267 out << "virtual bool isRemote() const ";
269 out << "override ";
271 out << "{ return false; }\n\n";
276 out << "\n";
282 out << "using "
285 method->emitCppResultSignature(out, true /* specify namespaces */);
286 out << ")>;\n";
289 method->dumpAnnotations(out);
291 method->emitDocComment(out);
294 out << "virtual ::android::hardware::Return<";
295 out << elidedReturn->type().getCppResultType() << "> ";
297 out << "virtual ::android::hardware::Return<void> ";
300 out << method->name()
302 method->emitCppArgSignature(out, true /* specify namespaces */);
303 out << ")";
306 out << " override";
309 out << " = 0";
311 out << ";\n";
314 out << "// cast static functions\n";
318 out << "static ::android::hardware::Return<"
326 out << "\nstatic const char* descriptor;\n\n";
329 out << "// skipped getService, registerAsService, registerForNotifications\n\n";
331 declareServiceManagerInteractions(out, iface->localName());
336 out.unindent();
338 out << "};\n\n";
341 mRootScope.emitPackageTypeDeclarations(out);
343 out << "\n";
344 enterLeaveNamespace(out, false /* enter */);
346 mRootScope.emitGlobalTypeDeclarations(out);
348 out << "\n#endif // " << guard << "\n";
351 void AST::generateHwBinderHeader(Formatter& out) const {
357 out << "#ifndef " << guard << "\n";
358 out << "#define " << guard << "\n\n";
360 generateCppPackageInclude(out, mPackage, iface ? iface->localName() : "types");
362 out << "\n";
366 generateCppPackageInclude(out, item, "hwtypes");
368 generateCppPackageInclude(out, item, item.getInterfaceStubName());
369 generateCppPackageInclude(out, item, item.getInterfaceProxyName());
373 out << "\n";
375 out << "#include <hidl/Status.h>\n";
376 out << "#include <hwbinder/IBinder.h>\n";
377 out << "#include <hwbinder/Parcel.h>\n";
379 out << "\n";
381 enterLeaveNamespace(out, true /* enter */);
383 mRootScope.emitPackageHwDeclarations(out);
385 enterLeaveNamespace(out, false /* enter */);
387 out << "\n#endif // " << guard << "\n";
390 void AST::emitTypeDeclarations(Formatter& out) const {
391 return mRootScope.emitTypeDeclarations(out);
394 static void wrapPassthroughArg(Formatter& out, const NamedReference<Type>* arg,
403 out << iface.getCppStackType() << " " << wrappedName << ";\n";
405 out.sIf(name + " != nullptr && !" + name + "->isRemote()", [&] {
406 out << wrappedName
411 out.sIf(wrappedName + " == nullptr", [&] {
417 out << wrappedName << " = " << name << ";\n";
421 void AST::generatePassthroughMethod(Formatter& out, const Method* method) const {
422 method->generateCppSignature(out);
424 out << " {\n";
425 out.indent();
429 method->cppImpl(IMPL_PASSTHROUGH, out);
430 out.unindent();
431 out << "}\n\n";
439 generateCheckNonNull(out, "_hidl_cb");
443 out,
449 wrapPassthroughArg(out, arg, false /* addPrefixToName */, [&] {
450 out << "return ::android::hardware::Status::fromExceptionCode(\n";
451 out.indent(2, [&] {
452 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
458 out << "auto _hidl_error = ::android::hardware::Void();\n";
459 out << "auto _hidl_return = ";
462 out << "addOnewayTask([mImpl = this->mImpl\n"
468 out << ", "
472 out << "] {\n";
473 out.indent();
476 out << "mImpl->"
480 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
481 out << (arg->type().isInterface() ? "_hidl_wrapped_" : "") << arg->name();
487 out << ", ";
489 out << "[&](";
490 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
491 out << "const auto &_hidl_out_"
495 out << ") {\n";
496 out.indent();
498 out,
503 wrapPassthroughArg(out, arg, true /* addPrefixToName */, [&] {
504 out << "_hidl_error = ::android::hardware::Status::fromExceptionCode(\n";
505 out.indent(2, [&] {
506 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
509 out << "return;\n";
513 out << "_hidl_cb(";
514 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
515 out << (arg->type().isInterface() ? "_hidl_out_wrapped_" : "_hidl_out_")
518 out << ");\n";
519 out.unindent();
520 out << "});\n\n";
522 out << ");\n\n";
526 out << "#ifdef __ANDROID_DEBUGGABLE__\n"
532 out,
538 out.unindent();
539 out << "});\n";
542 out << "return _hidl_return;\n";
544 out.unindent();
545 out << "}\n";
548 void AST::generateMethods(Formatter& out, const MethodGenerator& gen, bool includeParent) const {
562 out << "\n";
564 out << "// Methods from "
572 out << "\n";
575 void AST::generateTemplatizationLink(Formatter& out) const {
576 out << "typedef " << mRootScope.getInterface()->localName() << " Pure;\n\n";
579 void AST::generateCppTag(Formatter& out, const std::string& tag) const {
580 out << "typedef " << tag << " _hidl_tag;\n\n";
583 void AST::generateStubHeader(Formatter& out) const {
590 out << "#ifndef " << guard << "\n";
591 out << "#define " << guard << "\n\n";
593 generateCppPackageInclude(out, mPackage, iface->getHwName());
595 out << "\n";
597 enterLeaveNamespace(out, true /* enter */);
598 out << "\n";
600 out << "struct "
603 out << " : public ::android::hardware::BHwBinder";
604 out << ", public ::android::hardware::details::HidlInstrumentor {\n";
606 out << " : public "
611 out.indent();
612 out << "explicit "
616 out << "explicit "
622 out << "virtual ~" << klassName << "();\n\n";
623 out << "::android::status_t onTransact(\n";
624 out.indent();
625 out.indent();
626 out << "uint32_t _hidl_code,\n";
627 out << "const ::android::hardware::Parcel &_hidl_data,\n";
628 out << "::android::hardware::Parcel *_hidl_reply,\n";
629 out << "uint32_t _hidl_flags = 0,\n";
630 out << "TransactCallback _hidl_cb = nullptr) override;\n\n";
631 out.unindent();
632 out.unindent();
634 out.endl();
635 generateTemplatizationLink(out);
636 generateCppTag(out, "android::hardware::details::bnhw_tag");
638 out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; }\n";
640 generateMethods(out,
646 out << "static ::android::status_t _hidl_" << method->name() << "(\n";
648 out.indent(2,
650 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
660 out.unindent();
661 out << "private:\n";
662 out.indent();
664 generateMethods(out, [&](const Method* method, const Interface* iface) {
672 out << "using " << method->name() << "_cb = "
676 method->generateCppSignature(out);
677 out << ";\n";
680 out << "::android::sp<" << iface->localName() << "> _hidl_mImpl;\n";
681 out.unindent();
682 out << "};\n\n";
684 enterLeaveNamespace(out, false /* enter */);
686 out << "\n#endif // " << guard << "\n";
689 void AST::generateProxyHeader(Formatter& out) const {
699 out << "#ifndef " << guard << "\n";
700 out << "#define " << guard << "\n\n";
702 out << "#include <hidl/HidlTransportSupport.h>\n\n";
708 generateCppPackageInclude(out, mPackage, iface->getHwName());
709 out << "\n";
711 enterLeaveNamespace(out, true /* enter */);
712 out << "\n";
714 out << "struct "
720 out.indent();
722 out << "explicit "
727 generateTemplatizationLink(out);
728 generateCppTag(out, "android::hardware::details::bphw_tag");
730 out << "virtual bool isRemote() const override { return true; }\n\n";
733 out,
739 out << "static ";
740 method->generateCppReturnType(out);
741 out << " _hidl_" << method->name() << "("
746 out << ", ";
748 method->emitCppArgSignature(out);
749 out << ");\n";
753 generateMethods(out, [&](const Method* method, const Interface*) {
754 method->generateCppSignature(out);
755 out << " override;\n";
758 out.unindent();
759 out << "private:\n";
760 out.indent();
761 out << "std::mutex _hidl_mMutex;\n"
764 out.unindent();
765 out << "};\n\n";
767 enterLeaveNamespace(out, false /* enter */);
769 out << "\n#endif // " << guard << "\n";
772 void AST::generateCppSource(Formatter& out) const {
778 out << "#define LOG_TAG \""
782 out << "#include <android/log.h>\n";
783 out << "#include <cutils/trace.h>\n";
784 out << "#include <hidl/HidlTransportSupport.h>\n\n";
787 out << "#include <android/hidl/manager/1.0/IServiceManager.h>\n";
789 generateCppPackageInclude(out, mPackage, iface->getProxyName());
790 generateCppPackageInclude(out, mPackage, iface->getStubName());
791 generateCppPackageInclude(out, mPackage, iface->getPassthroughName());
794 generateCppPackageInclude(out,
799 out << "#include <hidl/ServiceManagement.h>\n";
801 generateCppPackageInclude(out, mPackage, "types");
802 generateCppPackageInclude(out, mPackage, "hwtypes");
805 out << "\n";
807 enterLeaveNamespace(out, true /* enter */);
808 out << "\n";
810 generateTypeSource(out, iface ? iface->localName() : "");
816 out << "const char* "
821 out << "__attribute__((constructor)) ";
822 out << "static void static_constructor() {\n";
823 out.indent([&] {
824 out << "::android::hardware::details::getBnConstructorMap().set("
827 out.indent(2, [&] {
828 out << "[](void *iIntf) -> ::android::sp<::android::hardware::IBinder> {\n";
829 out.indent([&] {
830 out << "return new "
836 out << "});\n";
838 out << "::android::hardware::details::getBsConstructorMap().set("
841 out.indent(2, [&] {
842 out << "[](void *iIntf) -> ::android::sp<"
845 out.indent([&] {
846 out << "return new "
852 out << "});\n";
855 out << "};\n\n";
856 out << "__attribute__((destructor))";
857 out << "static void static_destructor() {\n";
858 out.indent([&] {
859 out << "::android::hardware::details::getBnConstructorMap().erase("
862 out << "::android::hardware::details::getBsConstructorMap().erase("
866 out << "};\n\n";
868 generateInterfaceSource(out);
869 generateProxySource(out, iface->fqName());
870 generateStubSource(out, iface);
871 generatePassthroughSource(out);
874 out << "// skipped getService, registerAsService, registerForNotifications\n";
879 implementServiceManagerInteractions(out, iface->fqName(), package);
883 HidlTypeAssertion::EmitAll(out);
884 out << "\n";
886 enterLeaveNamespace(out, false /* enter */);
889 void AST::generateCheckNonNull(Formatter &out, const std::string &nonNull) {
890 out.sIf(nonNull + " == nullptr", [&] {
891 out << "return ::android::hardware::Status::fromExceptionCode(\n";
892 out.indent(2, [&] {
893 out << "::android::hardware::Status::EX_ILLEGAL_ARGUMENT,\n"
899 void AST::generateTypeSource(Formatter& out, const std::string& ifaceName) const {
900 mRootScope.emitTypeDefinitions(out, ifaceName);
903 void AST::declareCppReaderLocals(Formatter& out, const std::vector<NamedReference<Type>*>& args,
912 out << type.getCppResultType()
918 out << "\n";
921 void AST::emitCppReaderWriter(Formatter& out, const std::string& parcelObj, bool parcelObjIsPointer,
927 out,
935 void AST::emitCppResolveReferences(Formatter& out, const std::string& parcelObj,
942 out,
952 void AST::generateProxyMethodSource(Formatter& out, const std::string& klassName,
954 method->generateCppSignature(out,
959 out.block([&] {
960 method->cppImpl(IMPL_PROXY, out);
965 out.block([&] {
969 method->generateCppReturnType(out);
971 out << " _hidl_out = "
980 out << ", ";
983 out.join(method->args().begin(), method->args().end(), ", ", [&](const auto &arg) {
984 out << arg->name();
989 out << ", ";
991 out << "_hidl_cb";
994 out << ");\n\n";
996 out << "return _hidl_out;\n";
1000 void AST::generateStaticProxyMethodSource(Formatter& out, const std::string& klassName,
1006 method->generateCppReturnType(out);
1008 out << klassName
1016 out << ", ";
1019 method->emitCppArgSignature(out);
1020 out << ") {\n";
1022 out.indent();
1024 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1025 out << "bool mEnableInstrumentation = _hidl_this_instrumentor->isInstrumentationEnabled();\n";
1026 out << "const auto &mInstrumentationCallbacks = _hidl_this_instrumentor->getInstrumentationCallbacks();\n";
1027 out << "#else\n";
1028 out << "(void) _hidl_this_instrumentor;\n";
1029 out << "#endif // __ANDROID_DEBUGGABLE__\n";
1034 generateCheckNonNull(out, "_hidl_cb");
1038 out,
1042 out << "::android::hardware::Parcel _hidl_data;\n";
1043 out << "::android::hardware::Parcel _hidl_reply;\n";
1044 out << "::android::status_t _hidl_err;\n";
1045 out << "::android::hardware::Status _hidl_status;\n\n";
1048 out, method->results(), true /* forResults */);
1050 out << "_hidl_err = _hidl_data.writeInterfaceToken(";
1051 out << klassName;
1052 out << "::descriptor);\n";
1053 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
1062 out,
1074 out,
1085 out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
1087 out << "_hidl_err = ::android::hardware::IInterface::asBinder(_hidl_this)->transact("
1094 out << ", " << Interface::FLAG_ONEWAY << " /* oneway */";
1096 out << ");\n";
1098 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
1101 out << "_hidl_err = ::android::hardware::readFromParcel(&_hidl_status, _hidl_reply);\n";
1102 out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
1103 out << "if (!_hidl_status.isOk()) { return _hidl_status; }\n\n";
1109 out,
1121 out,
1131 out << "_hidl_cb(";
1133 out.join(method->results().begin(), method->results().end(), ", ", [&] (const auto &arg) {
1135 out << "*";
1137 out << "_hidl_out_" << arg->name();
1140 out << ");\n\n";
1145 out,
1150 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
1151 out << "return ::android::hardware::Return<";
1152 out << elidedReturn->type().getCppResultType()
1155 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
1156 out << "return ::android::hardware::Return<void>();\n\n";
1159 out.unindent();
1160 out << "_hidl_error:\n";
1161 out.indent();
1162 out << "_hidl_status.setFromStatusT(_hidl_err);\n";
1163 out << "return ::android::hardware::Return<";
1165 out << method->results().at(0)->type().getCppResultType();
1167 out << "void";
1169 out << ">(_hidl_status);\n";
1171 out.unindent();
1172 out << "}\n\n";
1175 void AST::generateProxySource(Formatter& out, const FQName& fqName) const {
1178 out << klassName
1183 out.indent();
1184 out.indent();
1186 out << ": BpInterface"
1196 out.unindent();
1197 out.unindent();
1198 out << "}\n\n";
1200 generateMethods(out,
1202 generateStaticProxyMethodSource(out, klassName, method);
1206 generateMethods(out, [&](const Method* method, const Interface* superInterface) {
1207 generateProxyMethodSource(out, klassName, method, superInterface);
1211 void AST::generateStubSource(Formatter& out, const Interface* iface) const {
1215 out << klassName
1220 out.indent();
1221 out.indent();
1224 out << ": ::android::hardware::details::HidlInstrumentor(\"";
1226 out << ": "
1231 out << mPackage.string()
1235 out.indent();
1236 out << "_hidl_mImpl = _hidl_impl;\n";
1237 out << "auto prio = ::android::hardware::details::gServicePrioMap.get("
1239 out << "mSchedPolicy = prio.sched_policy;\n";
1240 out << "mSchedPriority = prio.prio;\n";
1241 out.unindent();
1243 out.unindent();
1244 out.unindent();
1245 out << "}\n\n";
1250 out << klassName
1257 out.indent();
1258 out.indent();
1260 out << ": ::android::hardware::details::HidlInstrumentor("
1262 out.indent();
1263 out << "_hidl_mImpl = _hidl_impl;\n";
1264 out.unindent();
1266 out.unindent();
1267 out.unindent();
1268 out << "}\n\n";
1271 out << klassName << "::~" << klassName << "() ";
1272 out.block([&]() {
1273 out << "::android::hardware::details::gBnMap.eraseIfEqual(_hidl_mImpl.get(), this);\n";
1276 generateMethods(out,
1278 return generateStaticStubMethodSource(out, iface->fqName(), method);
1282 generateMethods(out, [&](const Method* method, const Interface*) {
1286 method->generateCppSignature(out, iface->getStubName());
1287 out << " ";
1288 out.block([&] {
1289 method->cppImpl(IMPL_STUB_IMPL, out);
1293 out << "::android::status_t " << klassName << "::onTransact(\n";
1295 out.indent();
1296 out.indent();
1298 out << "uint32_t _hidl_code,\n"
1304 out.unindent();
1306 out << "::android::status_t _hidl_err = ::android::OK;\n\n";
1307 out << "switch (_hidl_code) {\n";
1308 out.indent();
1317 out << "case "
1323 out.indent();
1325 out << "bool _hidl_is_oneway = _hidl_flags & " << Interface::FLAG_ONEWAY
1327 out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
1328 out.block([&] { out << "return ::android::UNKNOWN_ERROR;\n"; }).endl().endl();
1330 generateStubSourceForMethod(out, method, superInterface);
1332 out.unindent();
1333 out << "}\n\n";
1336 out << "default:\n{\n";
1337 out.indent();
1340 out << "(void)_hidl_flags;\n";
1341 out << "return ::android::UNKNOWN_TRANSACTION;\n";
1343 out << "return ";
1344 out << gIBaseFqName.getInterfaceStubFqName().cppName();
1345 out << "::onTransact(\n";
1347 out.indent();
1348 out.indent();
1350 out << "_hidl_code, _hidl_data, _hidl_reply, "
1353 out.unindent();
1354 out.unindent();
1357 out.unindent();
1358 out << "}\n";
1360 out.unindent();
1361 out << "}\n\n";
1363 out.sIf("_hidl_err == ::android::UNEXPECTED_NULL", [&] {
1364 out << "_hidl_err = ::android::hardware::writeToParcel(\n";
1365 out.indent(2, [&] {
1366 out << "::android::hardware::Status::fromExceptionCode(::android::hardware::Status::EX_NULL_POINTER),\n";
1367 out << "_hidl_reply);\n";
1371 out << "return _hidl_err;\n";
1373 out.unindent();
1374 out << "}\n\n";
1377 void AST::generateStubSourceForMethod(Formatter& out, const Method* method,
1380 method->cppImpl(IMPL_STUB, out);
1381 out << "break;\n";
1385 out << "_hidl_err = "
1392 out << "break;\n";
1395 void AST::generateStaticStubMethodSource(Formatter& out, const FQName& fqName,
1403 out << "::android::status_t " << klassName << "::_hidl_" << method->name() << "(\n";
1405 out.indent();
1406 out.indent();
1408 out << "::android::hidl::base::V1_0::BnHwBase* _hidl_this,\n"
1413 out.unindent();
1415 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1416 out << "bool mEnableInstrumentation = _hidl_this->isInstrumentationEnabled();\n";
1417 out << "const auto &mInstrumentationCallbacks = _hidl_this->getInstrumentationCallbacks();\n";
1418 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";
1420 out << "::android::status_t _hidl_err = ::android::OK;\n";
1422 out << "if (!_hidl_data.enforceInterface("
1426 out.indent();
1427 out << "_hidl_err = ::android::BAD_TYPE;\n";
1428 out << "return _hidl_err;\n";
1429 out.unindent();
1430 out << "}\n\n";
1432 declareCppReaderLocals(out, method->args(), false /* forResults */);
1437 out,
1449 out,
1459 out,
1475 out << elidedReturn->type().getCppResultType()
1482 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
1484 out << "*";
1486 out << arg->name();
1489 out << ");\n\n";
1490 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1494 out,
1502 out,
1511 out,
1515 out << "_hidl_cb(*_hidl_reply);\n";
1518 out << "bool _hidl_callbackCalled = false;\n\n";
1521 out << callee << "->" << method->name() << "(";
1523 out.join(method->args().begin(), method->args().end(), ", ", [&] (const auto &arg) {
1525 out << "*";
1528 out << arg->name();
1533 out << ", ";
1536 out << "[&](";
1538 out.join(method->results().begin(), method->results().end(), ", ", [&](const auto &arg) {
1539 out << "const auto &_hidl_out_" << arg->name();
1542 out << ") {\n";
1543 out.indent();
1544 out << "if (_hidl_callbackCalled) {\n";
1545 out.indent();
1546 out << "LOG_ALWAYS_FATAL(\""
1549 out.unindent();
1550 out << "}\n";
1551 out << "_hidl_callbackCalled = true;\n\n";
1553 out << "::android::hardware::writeToParcel(::android::hardware::Status::ok(), "
1559 out,
1571 out,
1581 out,
1585 out << "_hidl_cb(*_hidl_reply);\n";
1587 out.unindent();
1588 out << "});\n\n";
1590 out << ");\n\n";
1591 out << "(void) _hidl_cb;\n\n";
1593 out,
1599 out << "if (!_hidl_callbackCalled) {\n";
1600 out.indent();
1601 out << "LOG_ALWAYS_FATAL(\""
1604 out.unindent();
1605 out << "}\n\n";
1607 out << "::android::hardware::writeToParcel("
1613 out << "return _hidl_err;\n";
1614 out.unindent();
1615 out << "}\n\n";
1618 void AST::generatePassthroughHeader(Formatter& out) const {
1633 out << "#ifndef " << guard << "\n";
1634 out << "#define " << guard << "\n\n";
1640 out << "#include <android-base/macros.h>\n";
1641 out << "#include <cutils/trace.h>\n";
1642 out << "#include <future>\n";
1644 generateCppPackageInclude(out, mPackage, iface->localName());
1645 out << "\n";
1647 out << "#include <hidl/HidlPassthroughSupport.h>\n";
1649 out << "#include <hidl/TaskRunner.h>\n";
1652 enterLeaveNamespace(out, true /* enter */);
1653 out << "\n";
1655 out << "struct "
1660 out.indent();
1661 out << "explicit "
1667 out.endl();
1668 generateTemplatizationLink(out);
1669 generateCppTag(out, "android::hardware::details::bs_tag");
1671 generateMethods(out, [&](const Method* method, const Interface*) {
1672 generatePassthroughMethod(out, method);
1675 out.unindent();
1676 out << "private:\n";
1677 out.indent();
1678 out << "const ::android::sp<" << iface->localName() << "> mImpl;\n";
1681 out << "::android::hardware::details::TaskRunner mOnewayQueue;\n";
1683 out << "\n";
1685 out << "::android::hardware::Return<void> addOnewayTask("
1689 out.unindent();
1691 out << "};\n\n";
1693 enterLeaveNamespace(out, false /* enter */);
1695 out << "\n#endif // " << guard << "\n";
1698 void AST::generateInterfaceSource(Formatter& out) const {
1704 generateMethods(out, [&](const Method* method, const Interface*) {
1708 out << "// no default implementation for: ";
1710 method->generateCppSignature(out, iface->localName());
1712 out.block([&]() {
1713 method->cppImpl(IMPL_INTERFACE, out);
1717 out << "\n";
1723 out << "// static \n::android::hardware::Return<"
1732 out.indent();
1734 out << "return parent;\n";
1736 out << "return ::android::hardware::details::castInterface<";
1737 out << iface->localName() << ", "
1741 out.indent();
1742 out.indent();
1743 out << "parent, \""
1746 out.unindent();
1747 out.unindent();
1749 out.unindent();
1750 out << "}\n\n";
1754 void AST::generatePassthroughSource(Formatter& out) const {
1759 out << klassName
1770 out << "\n";
1771 out.indent([&] {
1772 out << "mOnewayQueue.start(3000 /* similar limit to binderized */);\n";
1775 out << "}\n\n";
1778 out << "::android::hardware::Return<void> "
1781 out.indent();
1782 out << "if (!mOnewayQueue.push(fun)) {\n";
1783 out.indent();
1784 out << "return ::android::hardware::Status::fromExceptionCode(\n";
1785 out.indent();
1786 out.indent();
1787 out << "::android::hardware::Status::EX_TRANSACTION_FAILED,\n"
1789 out.unindent();
1790 out.unindent();
1791 out.unindent();
1792 out << "}\n";
1794 out << "return ::android::hardware::Status();\n";
1796 out.unindent();
1797 out << "}\n\n";
1803 void AST::generateCppAtraceCall(Formatter &out,
1811 out << "atrace_begin(ATRACE_TAG_HAL, \""
1817 out << "atrace_begin(ATRACE_TAG_HAL, \""
1823 out << "atrace_begin(ATRACE_TAG_HAL, \""
1831 out << "atrace_end(ATRACE_TAG_HAL);\n";
1842 Formatter &out,
1845 generateCppAtraceCall(out, event, method);
1847 out << "#ifdef __ANDROID_DEBUGGABLE__\n";
1848 out << "if (UNLIKELY(mEnableInstrumentation)) {\n";
1849 out.indent();
1850 out << "std::vector<void *> _hidl_args;\n";
1857 out << "_hidl_args.push_back((void *)"
1868 out << "_hidl_args.push_back((void *)&_hidl_out_"
1878 out << "_hidl_args.push_back((void *)&"
1888 out << "_hidl_args.push_back((void *)"
1900 out << "_hidl_args.push_back((void *)&"
1910 out << "_hidl_args.push_back((void *)&_hidl_out_"
1924 out << "for (const auto &callback: mInstrumentationCallbacks) {\n";
1925 out.indent();
1926 out << "callback("
1937 out.unindent();
1938 out << "}\n";
1939 out.unindent();
1940 out << "}\n";
1941 out << "#endif // __ANDROID_DEBUGGABLE__\n\n";