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>
3 files changed
tree: 64c82e410afca44eafc54ea2653d7512daef27dd
  1. test/
  2. Android.mk
  3. Annotation.cpp
  4. Annotation.h
  5. ArrayType.cpp
  6. ArrayType.h
  7. AST.cpp
  8. AST.h
  9. CompoundType.cpp
  10. CompoundType.h
  11. ConstantExpression.cpp
  12. ConstantExpression.h
  13. Coordinator.cpp
  14. Coordinator.h
  15. EnumType.cpp
  16. EnumType.h
  17. Formatter.cpp
  18. Formatter.h
  19. FQName.cpp
  20. FQName.h
  21. generateCpp.cpp
  22. generateJava.cpp
  23. generateVts.cpp
  24. GenericBinder.cpp
  25. GenericBinder.h
  26. HandleType.cpp
  27. HandleType.h
  28. hidl-gen_l.ll
  29. hidl-gen_y.yy
  30. Interface.cpp
  31. Interface.h
  32. main.cpp
  33. Method.cpp
  34. Method.h
  35. NamedType.cpp
  36. NamedType.h
  37. README.md
  38. ScalarType.cpp
  39. ScalarType.h
  40. Scope.cpp
  41. Scope.h
  42. StringType.cpp
  43. StringType.h
  44. Type.cpp
  45. Type.h
  46. TypeDef.cpp
  47. TypeDef.h
  48. VectorType.cpp
  49. VectorType.h
README.md

hidl-gen user guide

1. Build

croot
make hidl-gen

2. Run

hidl-gen -o output-path -L language (-r interface-root) fqname

output-path: directory to store the output files.
language: output file for given language. e.g.c++, vts..

fqname: fully qualified name of the input files.
For singe file input, follow the format: package@version::fileName
For directory input, follow the format: package@version

interface-root(optional): prefix and root path for fqname.
If not set, use the default prefix: android.hardware and default root path
defined in $TOP.

examples:

hidl-gen -o output -L c++ android.hardware.nfc@1.0::INfc.hal
hidl-gen -o output -L vts android.hardware.nfc@1.0
hild-gen -o test -L c++ -r android.hardware:/home/android/master/hardware/interfaces android.hardware.nfc@1.0