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/FQName.cpp b/FQName.cpp
index b031c6f..2504ef5 100644
--- a/FQName.cpp
+++ b/FQName.cpp
@@ -230,25 +230,37 @@
         bool cpp_compatible) const {
     getPackageComponents(components);
 
-    const std::string packageVersion = version();
-    CHECK(packageVersion[0] == '@');
-
     if (!cpp_compatible) {
-        components->push_back(packageVersion.substr(1));
+        components->push_back(getPackageMajorVersion() +
+                "." + getPackageMinorVersion());
         return;
     }
 
-    const size_t dotPos = packageVersion.find('.');
-
     // Form "Vmajor_minor".
     std::string versionString = "V";
-    versionString.append(packageVersion.substr(1, dotPos - 1));
+    versionString.append(getPackageMajorVersion());
     versionString.append("_");
-    versionString.append(packageVersion.substr(dotPos + 1));
+    versionString.append(getPackageMinorVersion());
 
     components->push_back(versionString);
 }
 
+std::string FQName::getPackageMajorVersion() const {
+    const std::string packageVersion = version();
+    CHECK(packageVersion[0] == '@');
+    const size_t dotPos = packageVersion.find('.');
+    CHECK(dotPos != std::string::npos);
+    return packageVersion.substr(1, dotPos - 1);
+}
+
+std::string FQName::getPackageMinorVersion() const {
+    const std::string packageVersion = version();
+    CHECK(packageVersion[0] == '@');
+    const size_t dotPos = packageVersion.find('.');
+    CHECK(dotPos != std::string::npos);
+    return packageVersion.substr(dotPos + 1);
+}
+
 bool FQName::endsWith(const FQName &other) const {
     std::string s1 = string();
     std::string s2 = other.string();