Encode hidl_version in each generated interface.

Each generated interface will have a constexpr encoding
the package version. Additionally, there's a client-facing
getInterfaceVersion() method; while for now it always returns
the static version, this is not always correct: in case this
interface has a transport that goes to a remote implementation,
the version needs to be retrieved from that implementation
instead. This depends on other changes and will be added with them.

Bug: 31297066
Change-Id: I15b7f5ccf2dbfa25acfd385c68e8ae1f3e782ade
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 2ad8019..84001cf 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -189,7 +189,14 @@
     if (isInterface) {
         const Interface *iface = mRootScope->getInterface();
         const Interface *superType = iface->superType();
-
+        out << "constexpr static hidl_version version = {"
+            << mPackage.getPackageMajorVersion() << ","
+            << mPackage.getPackageMinorVersion() << "};\n";
+        out << "virtual const hidl_version& getInterfaceVersion() const {\n";
+        out.indent();
+        out << "return version;\n";
+        out.unindent();
+        out << "}\n\n";
         out << "virtual bool isRemote() const { return false; }\n\n";
         bool haveCallbacks = false;
         for (const auto &method : iface->methods()) {
@@ -743,6 +750,7 @@
     status_t err = generateTypeSource(out, ifaceName);
 
     if (err == OK && isInterface) {
+        out << "constexpr hidl_version " << ifaceName << "::version;\n\n";
         err = generateProxySource(out, baseName);
     }