hidl-gen: use Return<void>
C++ HIDL methods now return Return<> objects regadless of elision
status. This hides Status from auto-generated code.
b/31367910
b/31348667
b/31365311
Change-Id: Ib009d2bade022a557f51d3cd4cb3e61ece38bba2
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 0d680cf..9cfb938 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -243,7 +243,7 @@
out << "virtual ::android::hardware::Return<";
out << elidedReturn->type().getCppResultType(&extra) << "> ";
} else {
- out << "virtual ::android::hardware::Status ";
+ out << "virtual ::android::hardware::Return<void> ";
}
out << method->name()
@@ -905,28 +905,29 @@
if (elidedReturn != nullptr) {
std::string extra;
-
out << "_hidl_status.setFromStatusT(_hidl_err);\n";
out << "return ::android::hardware::Return<";
out << elidedReturn->type().getCppResultType(&extra)
<< ">(" << elidedReturn->name() << ");\n\n";
-
- out.unindent();
- out << "_hidl_error:\n";
- out.indent();
- out << "_hidl_status.setFromStatusT(_hidl_err);\n";
- out << "return ::android::hardware::Return<";
- out << method->results().at(0)->type().getCppResultType(&extra)
- << ">(_hidl_status);\n";
} else {
- out.unindent();
- out << "_hidl_error:\n";
- out.indent();
out << "_hidl_status.setFromStatusT(_hidl_err);\n";
- out << "return _hidl_status;\n";
+ out << "return ::android::hardware::Return<void>();\n\n";
}
out.unindent();
+ out << "_hidl_error:\n";
+ out.indent();
+ out << "_hidl_status.setFromStatusT(_hidl_err);\n";
+ out << "return ::android::hardware::Return<";
+ if (elidedReturn != nullptr) {
+ std::string extra;
+ out << method->results().at(0)->type().getCppResultType(&extra);
+ } else {
+ out << "void";
+ }
+ out << ">(_hidl_status);\n";
+
+ out.unindent();
out << "}\n\n";
}
}
@@ -1132,9 +1133,6 @@
out << "bool _hidl_callbackCalled = false;\n\n";
}
- out << "::android::hardware::Status _hidl_status(\n";
- out.indent();
- out.indent();
out << method->name() << "(";
bool first = true;
@@ -1193,16 +1191,22 @@
out << "}\n";
}
- out.unindent();
- out.unindent();
- out << "));\n\n";
+ out << ");\n\n";
+
+ // What to do if the stub implementation has a synchronous callback
+ // which does not get invoked? This is not a transport error but a
+ // service error of sorts. For now, return OK to the caller, as this is
+ // not a transport error.
+ //
+ // TODO(b/31365311) Figure out how to deal with this later.
if (returnsValue) {
out << "if (!_hidl_callbackCalled) {\n";
out.indent();
}
- out << "_hidl_err = _hidl_status.writeToParcel(_hidl_reply);\n";
+ out << "::android::hardware::Status::ok()"
+ << ".writeToParcel(_hidl_reply);\n";
if (returnsValue) {
out.unindent();