Implement getInterfaceVersion for C++
This change fixes a bug that getInterfaceVerison() is not implemented in
the stub class when --lang=cpp and --version is set.
Bug: 130195984
Test: m
Test: aidl_unittests
Change-Id: I2b107db8c47ef287ec2be736b6beb84768cb04e6
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index ca7d7d6..61552c1 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -828,6 +828,14 @@
vector<unique_ptr<Declaration>> decls;
decls.push_back(std::move(on_transact));
+ if (options.Version() > 0) {
+ std::ostringstream code;
+ code << "int32_t " << bn_name << "::" << kGetInterfaceVersion << "() {\n"
+ << " return " << ClassName(interface, ClassNames::INTERFACE) << "::VERSION;\n"
+ << "}\n";
+ decls.emplace_back(new LiteralDecl(code.str()));
+ }
+
if (options.GenLog()) {
string code;
ClassName(interface, ClassNames::SERVER);
@@ -991,6 +999,12 @@
vector<unique_ptr<Declaration>> publics;
publics.push_back(std::move(on_transact));
+ if (options.Version() > 0) {
+ std::ostringstream code;
+ code << "int32_t " << kGetInterfaceVersion << "() final override;\n";
+ publics.emplace_back(new LiteralDecl(code.str()));
+ }
+
if (options.GenLog()) {
includes.emplace_back("chrono"); // for std::chrono::steady_clock
includes.emplace_back("functional"); // for std::function
diff --git a/tests/test_data_ping_responder.cpp b/tests/test_data_ping_responder.cpp
index b2cc14f..6dec57b 100644
--- a/tests/test_data_ping_responder.cpp
+++ b/tests/test_data_ping_responder.cpp
@@ -833,6 +833,10 @@
return _aidl_ret_status;
}
+int32_t BnPingResponder::getInterfaceVersion() {
+ return IPingResponder::VERSION;
+}
+
} // namespace os
} // namespace android
@@ -930,6 +934,7 @@
class BnPingResponder : public ::android::BnInterface<IPingResponder> {
public:
::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override;
+ int32_t getInterfaceVersion() final override;
}; // class BnPingResponder
} // namespace os
diff --git a/tests/test_data_string_constants.cpp b/tests/test_data_string_constants.cpp
index e02c128..a83874c 100644
--- a/tests/test_data_string_constants.cpp
+++ b/tests/test_data_string_constants.cpp
@@ -468,6 +468,10 @@
return _aidl_ret_status;
}
+int32_t BnStringConstants::getInterfaceVersion() {
+ return IStringConstants::VERSION;
+}
+
} // namespace os
} // namespace android