diff options
author | Steven Moreland <smoreland@google.com> | 2018-10-08 14:31:00 -0700 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2018-10-09 18:49:03 +0000 |
commit | 63404536ced57063ce08cf64e9c37d6379c336ff (patch) | |
tree | 59e78bc8c9d4feb589f7623641e9b5ce7e0f521a | |
parent | 76a6a46c4509f692ad8ed59cb8447fef6f5de2d4 (diff) | |
download | aidl-63404536ced57063ce08cf64e9c37d6379c336ff.tar.gz |
NDK Backend: rename things according to convention
C++ wrapper namespace 'android' -> 'ndk'
AutoAIBinder -> SpAIBinder (to reflect usage, disambiguate with auto_ptr)
AutoA* -> ScopedA (to reflect usage, disambiguate with auto_ptr
Bug: 112664205
Test: atest android.binder.cts
Change-Id: I257a15fa53d4d7eb007bc9de01e70ca2df48453b
-rw-r--r-- | aidl_to_ndk.cpp | 15 | ||||
-rw-r--r-- | generate_ndk.cpp | 32 |
2 files changed, 26 insertions, 21 deletions
diff --git a/aidl_to_ndk.cpp b/aidl_to_ndk.cpp index 40f34517..56473a56 100644 --- a/aidl_to_ndk.cpp +++ b/aidl_to_ndk.cpp @@ -59,11 +59,18 @@ static map<std::string, TypeInfo> kNdkTypeInfoMap = { {"long", {"int64_t", true, standardRead("Int64"), standardWrite("Int64")}}, {"float", {"float", true, standardRead("Float"), standardWrite("Float")}}, {"double", {"double", true, standardRead("Double"), standardWrite("Double")}}, - {"String", {"std::string", false, standardRead("String"), standardWrite("String")}}, + {"String", + {"std::string", false, + [](const CodeGeneratorContext& c) { + c.writer << "::ndk::AParcel_readString(" << c.parcel << ", " << c.var << ")"; + }, + [](const CodeGeneratorContext& c) { + c.writer << "::ndk::AParcel_writeString(" << c.parcel << ", " << c.var << ")"; + }}}, // TODO(b/111445392) {"List", ""}, // TODO(b/111445392) {"Map", ""}, {"IBinder", - {"::android::AutoAIBinder", false, + {"::ndk::SpAIBinder", false, [](const CodeGeneratorContext& c) { c.writer << "AParcel_readNullableStrongBinder(" << c.parcel << ", (" << c.var << ")->getR())"; @@ -76,7 +83,7 @@ static map<std::string, TypeInfo> kNdkTypeInfoMap = { }; std::string NdkFullClassName(const AidlDefinedType& type, cpp::ClassNames name) { - std::vector<std::string> pieces = {"aidl"}; + std::vector<std::string> pieces = {"::aidl"}; std::vector<std::string> package = type.GetSplitPackage(); pieces.insert(pieces.end(), package.begin(), package.end()); pieces.push_back(cpp::ClassName(type, name)); @@ -213,7 +220,7 @@ std::string NdkCallListFor(const AidlMethod& method) { std::string NdkMethodDecl(const AidlTypenames& types, const AidlMethod& method, const std::string& clazz) { std::string class_prefix = clazz.empty() ? "" : (clazz + "::"); - return "::android::AutoAStatus " + class_prefix + method.GetName() + "(" + + return "::ndk::ScopedAStatus " + class_prefix + method.GetName() + "(" + NdkArgListOf(types, method) + ")"; } diff --git a/generate_ndk.cpp b/generate_ndk.cpp index efeeab62..37936a98 100644 --- a/generate_ndk.cpp +++ b/generate_ndk.cpp @@ -220,10 +220,10 @@ static void GenerateClientMethodDefinition(CodeWriter& out, const AidlTypenames& out << NdkMethodDecl(types, method, clazz) << " {\n"; out.Indent(); - out << "::android::AutoAParcel _aidl_in;\n"; - out << "::android::AutoAParcel _aidl_out;\n"; + out << "::ndk::ScopedAParcel _aidl_in;\n"; + out << "::ndk::ScopedAParcel _aidl_out;\n"; out << "binder_status_t _aidl_ret_status = STATUS_OK;\n"; - out << "::android::AutoAStatus _aidl_status;\n"; + out << "::ndk::ScopedAStatus _aidl_status;\n"; out << "\n"; out << "_aidl_ret_status = AIBinder_prepareTransaction(asBinder().get(), _aidl_in.getR());\n"; @@ -296,7 +296,7 @@ static void GenerateServerCaseDefinition(CodeWriter& out, const AidlTypenames& t StatusCheckBreak(out); } - out << "::android::AutoAStatus _aidl_status = _aidl_impl->" << method.GetName() << "(" + out << "::ndk::ScopedAStatus _aidl_status = _aidl_impl->" << method.GetName() << "(" << NdkCallListFor(method) << ");\n"; if (method.IsOneway()) { @@ -393,7 +393,7 @@ void GenerateClientSource(CodeWriter& out, const AidlTypenames& types, out << "// Source for " << clazz << "\n"; out << "std::shared_ptr<" << clazz << "> " << clazz - << "::associate(const ::android::AutoAIBinder& binder) {\n"; + << "::associate(const ::ndk::SpAIBinder& binder) {\n"; out.Indent(); out << "if (!AIBinder_associateClass(binder.get(), " << data_clazz << "::clazz)) { return nullptr; }\n"; @@ -401,8 +401,7 @@ void GenerateClientSource(CodeWriter& out, const AidlTypenames& types, out.Dedent(); out << "}\n\n"; - out << clazz << "::" << clazz - << "(const ::android::AutoAIBinder& binder) : BpCInterface(binder) {}\n"; + out << clazz << "::" << clazz << "(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {}\n"; out << clazz << "::~" << clazz << "() {}\n"; out << "\n"; for (const auto& method : defined_type.GetMethods()) { @@ -418,11 +417,11 @@ void GenerateServerSource(CodeWriter& out, const AidlTypenames& /*types*/, out << clazz << "::" << clazz << "() {}\n"; out << clazz << "::~" << clazz << "() {}\n"; - out << "::android::AutoAIBinder " << clazz << "::createBinder() {\n"; + out << "::ndk::SpAIBinder " << clazz << "::createBinder() {\n"; out.Indent(); out << "AIBinder* binder = AIBinder_new(" << data_clazz << "::clazz, static_cast<void*>(this));\n"; - out << "return ::android::AutoAIBinder(binder);\n"; + out << "return ::ndk::SpAIBinder(binder);\n"; out.Dedent(); out << "}\n"; } @@ -451,7 +450,7 @@ void GenerateInterfaceSource(CodeWriter& out, const AidlTypenames& /*types*/, out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* parcel, std::shared_ptr<" << clazz << ">* instance) {\n"; out.Indent(); - out << "::android::AutoAIBinder binder;\n"; + out << "::ndk::SpAIBinder binder;\n"; out << "binder_status_t status = AParcel_readNullableStrongBinder(parcel, binder.getR());\n"; out << "if (status != STATUS_OK) return status;\n"; out << data_clazz << "* data = static_cast<" << data_clazz @@ -481,12 +480,11 @@ void GenerateClientHeader(CodeWriter& out, const AidlTypenames& types, out << "#include <android/binder_ibinder.h>\n"; out << "\n"; EnterNdkNamespace(out, defined_type); - out << "class " << clazz << " : public ::android::BpCInterface<" + out << "class " << clazz << " : public ::ndk::BpCInterface<" << ClassName(defined_type, ClassNames::INTERFACE) << "> {\n"; out << "public:\n"; out.Indent(); - out << "static std::shared_ptr<" << clazz - << "> associate(const ::android::AutoAIBinder& binder);\n"; + out << "static std::shared_ptr<" << clazz << "> associate(const ::ndk::SpAIBinder& binder);\n"; out << "virtual ~" << clazz << "();\n"; out << "\n"; for (const auto& method : defined_type.GetMethods()) { @@ -495,7 +493,7 @@ void GenerateClientHeader(CodeWriter& out, const AidlTypenames& types, out.Dedent(); out << "private:\n"; out.Indent(); - out << clazz << "(const ::android::AutoAIBinder& binder);\n"; + out << clazz << "(const ::ndk::SpAIBinder& binder);\n"; out.Dedent(); out << "};\n"; LeaveNdkNamespace(out, defined_type); @@ -511,7 +509,7 @@ void GenerateServerHeader(CodeWriter& out, const AidlTypenames& /*types*/, out << "#include <android/binder_ibinder.h>\n"; out << "\n"; EnterNdkNamespace(out, defined_type); - out << "class " << clazz << " : public ::android::BnCInterface<" + out << "class " << clazz << " : public ::ndk::BnCInterface<" << ClassName(defined_type, ClassNames::INTERFACE) << "> {\n"; out << "public:\n"; out.Indent(); @@ -520,7 +518,7 @@ void GenerateServerHeader(CodeWriter& out, const AidlTypenames& /*types*/, out.Dedent(); out << "protected:\n"; out.Indent(); - out << "::android::AutoAIBinder createBinder() override;\n"; + out << "::ndk::SpAIBinder createBinder() override;\n"; out.Dedent(); out << "private:\n"; out.Indent(); @@ -540,7 +538,7 @@ void GenerateInterfaceHeader(CodeWriter& out, const AidlTypenames& types, out << "\n"; EnterNdkNamespace(out, defined_type); - out << "class " << clazz << " : public ::android::ICInterface {\n"; + out << "class " << clazz << " : public ::ndk::ICInterface {\n"; out << "public:\n"; out.Indent(); out << "static AIBinder_Class* clazz;\n"; |