aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2019-04-09 14:23:41 +0900
committerJiyong Park <jiyong@google.com>2019-04-10 02:53:33 +0900
commit0dc10177706b9dd818e2ef12a01f17eeb663cf17 (patch)
treef06d98655bd2f6b052ab300cc621033d4456508a
parent545f44dc4c6ec299b4745e74d6589ab9e7e2eec4 (diff)
downloadaidl-0dc10177706b9dd818e2ef12a01f17eeb663cf17.tar.gz
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 Merged-In: I2b107db8c47ef287ec2be736b6beb84768cb04e6 Change-Id: I2b107db8c47ef287ec2be736b6beb84768cb04e6 (cherry picked from commit 22d4cfc8fbef14080ce082e9e387ed6da2fa1321)
-rw-r--r--generate_cpp.cpp14
-rw-r--r--tests/test_data_ping_responder.cpp5
-rw-r--r--tests/test_data_string_constants.cpp4
3 files changed, 23 insertions, 0 deletions
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index ca7d7d69..61552c1b 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -828,6 +828,14 @@ unique_ptr<Document> BuildServerSource(const TypeNamespace& types, const AidlInt
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 @@ unique_ptr<Document> BuildServerHeader(const TypeNamespace& /* types */,
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 b2cc14f1..6dec57bf 100644
--- a/tests/test_data_ping_responder.cpp
+++ b/tests/test_data_ping_responder.cpp
@@ -833,6 +833,10 @@ namespace os {
return _aidl_ret_status;
}
+int32_t BnPingResponder::getInterfaceVersion() {
+ return IPingResponder::VERSION;
+}
+
} // namespace os
} // namespace android
@@ -930,6 +934,7 @@ namespace os {
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 e02c128f..a83874c1 100644
--- a/tests/test_data_string_constants.cpp
+++ b/tests/test_data_string_constants.cpp
@@ -468,6 +468,10 @@ namespace os {
return _aidl_ret_status;
}
+int32_t BnStringConstants::getInterfaceVersion() {
+ return IStringConstants::VERSION;
+}
+
} // namespace os
} // namespace android