hidl-gen: callback elision for scalar returns
Suppose a HIDL method has a generates clause with a single scalar
(including an enum), for example as follows:
add(uint32_t a, uint32_t b) generates(uint32_t sum);
In this case, hidl-gen will emit the following method signature:
SimpleReturn<uint32_t> add(uint32_t a, uint32_t b);
SimpleReturn is a standard HIDL struct implementing a tuple of the
return value (in this case, uint32_t) and a HWBinder Status object. The
tuple can be used as a uint32_t, ignoring the Status value inside it, or
the status value can be extracted from it:
uint32_t tmol = ifc->add(41, 1);
or:
if (ifc->add(41, 1)) {
...
or
auto ret = ifc->add(41, 1);
if (ret.status.isOk()) {
...
With this, these methods that return a single scalar value do not have
to use the awkward synchronous-callback syntax.
b/30518487 Optimize out lamdas from HIDL C++ auto-generated code in
common cases
Change-Id: I83312e0b49d084c641c007df4a09e04a326b5245
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/Method.h b/Method.h
index 3ba9c52..84ffc03 100644
--- a/Method.h
+++ b/Method.h
@@ -11,6 +11,7 @@
struct Annotation;
struct Formatter;
+struct ScalarType;
struct Type;
struct TypedVar;
@@ -33,6 +34,8 @@
static std::string GetSignature(const std::vector<TypedVar *> &args);
static std::string GetJavaSignature(const std::vector<TypedVar *> &args);
+ const TypedVar* canElideCallback() const;
+
void dumpAnnotations(Formatter &out) const;
bool isJavaCompatible() const;