Support vts generation for fmq type in hidl-gen.

* Also did a few cleanup for Templated type.

Bug: 34385794
Test: make hidl-gen
Change-Id: I539bf8fe5a1bb65c36f6041417b34ddaf99840d7
diff --git a/FmqType.cpp b/FmqType.cpp
index 2f410f7..221a47a 100644
--- a/FmqType.cpp
+++ b/FmqType.cpp
@@ -149,5 +149,19 @@
     return (!elementType->isInterface() && !elementType->needsEmbeddedReadWrite());
 }
 
+std::string FmqType::getVtsType() const {
+    if (mName == "MQDescriptorSync") {
+        return "TYPE_FMQ_SYNC";
+    } else if (mName == "MQDescriptorUnsync") {
+        return "TYPE_FMQ_UNSYNC";
+    } else {
+        LOG(ERROR) << "Invalid fmq type name.\n";
+    }
+    return "";
+}
+
+std::string FmqType::getVtsValueName() const {
+    return "fmq_value";
+}
 }  // namespace android
 
diff --git a/FmqType.h b/FmqType.h
index 054a25e..d243e55 100644
--- a/FmqType.h
+++ b/FmqType.h
@@ -59,7 +59,10 @@
     bool needsEmbeddedReadWrite() const override;
     bool resultNeedsDeref() const override;
     bool isCompatibleElementType(Type *elementType) const override;
-private:
+
+    std::string getVtsType() const override;
+    std::string getVtsValueName() const override;
+ private:
     std::string mNamespace;
     std::string mName;
 
diff --git a/RefType.cpp b/RefType.cpp
index 546325b..34aa224 100644
--- a/RefType.cpp
+++ b/RefType.cpp
@@ -31,6 +31,14 @@
     return "ref" + (mElementType == nullptr ? "" : (" of " + mElementType->typeName()));
 }
 
+std::string RefType::getVtsType() const {
+    return "TYPE_REF";
+}
+
+std::string RefType::getVtsValueName() const {
+    return "ref_value";
+}
+
 bool RefType::isCompatibleElementType(Type *elementType) const {
     if (elementType->isScalar()) {
         return true;
@@ -233,30 +241,6 @@
     return false;
 }
 
-status_t RefType::emitVtsTypeDeclarations(Formatter &out) const {
-    out << "type: TYPE_REF\n" << "ref_value: {\n";
-    out.indent();
-    status_t err = mElementType->emitVtsTypeDeclarations(out);
-    if (err != OK) {
-        return err;
-    }
-    out.unindent();
-    out << "}\n";
-    return OK;
-}
-
-status_t RefType::emitVtsAttributeType(Formatter &out) const {
-    out << "type: TYPE_REF\n" << "ref_value: {\n";
-    out.indent();
-    status_t status = mElementType->emitVtsAttributeType(out);
-    if (status != OK) {
-        return status;
-    }
-    out.unindent();
-    out << "}\n";
-    return OK;
-}
-
 bool RefType::isJavaCompatible() const {
     return false;
 }
diff --git a/RefType.h b/RefType.h
index f8176b6..3c91316 100644
--- a/RefType.h
+++ b/RefType.h
@@ -32,6 +32,9 @@
     std::string getCppType(StorageMode mode,
                            bool specifyNamespaces) const override;
 
+    std::string getVtsType() const override;
+    std::string getVtsValueName() const override;
+
     void emitReaderWriter(
             Formatter &out,
             const std::string &name,
@@ -66,9 +69,6 @@
     bool needsResolveReferences() const override;
     bool resultNeedsDeref() const override;
 
-    status_t emitVtsTypeDeclarations(Formatter &out) const override;
-    status_t emitVtsAttributeType(Formatter &out) const override;
-
     bool isJavaCompatible() const override;
 
  private:
diff --git a/Type.cpp b/Type.cpp
index f155816..71279c0 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -153,6 +153,11 @@
     return std::string();
 }
 
+std::string Type::getVtsValueName() const {
+    CHECK(!"Should not be here");
+    return std::string();
+}
+
 void Type::emitReaderWriter(
         Formatter &,
         const std::string &,
@@ -470,5 +475,30 @@
     return true;
 }
 
+status_t TemplatedType::emitVtsTypeDeclarations(Formatter &out) const {
+    out << "type: " << getVtsType() << "\n";
+    out << getVtsValueName() << ": {\n";
+    out.indent();
+    status_t err = mElementType->emitVtsTypeDeclarations(out);
+    if (err != OK) {
+        return err;
+    }
+    out.unindent();
+    out << "}\n";
+    return OK;
+}
+
+status_t TemplatedType::emitVtsAttributeType(Formatter &out) const {
+    out << "type: " << getVtsType() << "\n";
+    out << getVtsValueName() << ": {\n";
+    out.indent();
+    status_t status = mElementType->emitVtsAttributeType(out);
+    if (status != OK) {
+        return status;
+    }
+    out.unindent();
+    out << "}\n";
+    return OK;
+}
 }  // namespace android
 
diff --git a/Type.h b/Type.h
index 79a44bf..f926ed2 100644
--- a/Type.h
+++ b/Type.h
@@ -102,6 +102,7 @@
     virtual std::string getJavaSuffix() const;
 
     virtual std::string getVtsType() const;
+    virtual std::string getVtsValueName() const;
 
     enum ErrorMode {
         ErrorMode_Ignore,
@@ -263,6 +264,8 @@
     Type *getElementType() const;
     bool isTemplatedType() const override;
     virtual bool isCompatibleElementType(Type *elementType) const = 0;
+    status_t emitVtsTypeDeclarations(Formatter &out) const override;
+    status_t emitVtsAttributeType(Formatter &out) const override;
 protected:
     TemplatedType();
     Type *mElementType;
diff --git a/VectorType.cpp b/VectorType.cpp
index a58ea2c..b6267c6 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -125,6 +125,10 @@
     return "TYPE_VECTOR";
 }
 
+std::string VectorType::getVtsValueName() const {
+    return "vector_value";
+}
+
 void VectorType::emitReaderWriter(
         Formatter &out,
         const std::string &name,
@@ -712,31 +716,6 @@
     return !isVectorOfBinders();
 }
 
-status_t VectorType::emitVtsTypeDeclarations(Formatter &out) const {
-    out << "type: " << getVtsType() << "\n";
-    out << "vector_value: {\n";
-    out.indent();
-    status_t err = mElementType->emitVtsTypeDeclarations(out);
-    if (err != OK) {
-        return err;
-    }
-    out.unindent();
-    out << "}\n";
-    return OK;
-}
-
-status_t VectorType::emitVtsAttributeType(Formatter &out) const {
-    out << "type: TYPE_VECTOR\n" << "vector_value: {\n";
-    out.indent();
-    status_t status = mElementType->emitVtsAttributeType(out);
-    if (status != OK) {
-        return status;
-    }
-    out.unindent();
-    out << "}\n";
-    return OK;
-}
-
 bool VectorType::isJavaCompatible() const {
     if (!mElementType->isJavaCompatible()) {
         return false;
diff --git a/VectorType.h b/VectorType.h
index a301a76..c267ba9 100644
--- a/VectorType.h
+++ b/VectorType.h
@@ -41,6 +41,7 @@
     std::string getJavaType(bool forInitializer) const override;
 
     std::string getVtsType() const override;
+    std::string getVtsValueName() const override;
 
     void emitReaderWriter(
             Formatter &out,
@@ -119,9 +120,6 @@
     bool needsResolveReferences() const override;
     bool resultNeedsDeref() const override;
 
-    status_t emitVtsTypeDeclarations(Formatter &out) const override;
-    status_t emitVtsAttributeType(Formatter &out) const override;
-
     bool isJavaCompatible() const override;
 
     void getAlignmentAndSize(size_t *align, size_t *size) const override;