Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "generate_ndk.h" |
| 18 | |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 19 | #include "aidl.h" |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 20 | #include "aidl_language.h" |
| 21 | #include "aidl_to_cpp_common.h" |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 22 | #include "aidl_to_ndk.h" |
Jiyong Park | 2a7c92b | 2020-07-22 19:12:36 +0900 | [diff] [blame] | 23 | #include "logging.h" |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 24 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 25 | #include <android-base/stringprintf.h> |
| 26 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace aidl { |
| 29 | namespace ndk { |
| 30 | |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 31 | static constexpr const char* kClazz = "_g_aidl_clazz"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 32 | static constexpr const char* kDescriptor = "descriptor"; |
| 33 | static constexpr const char* kVersion = "version"; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 34 | static constexpr const char* kHash = "hash"; |
| 35 | static constexpr const char* kCachedVersion = "_aidl_cached_version"; |
| 36 | static constexpr const char* kCachedHash = "_aidl_cached_hash"; |
| 37 | static constexpr const char* kCachedHashMutex = "_aidl_cached_hash_mutex"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 38 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 39 | using namespace internals; |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 40 | namespace internals { |
| 41 | void GenerateParcelHeader(CodeWriter& out, const AidlTypenames& types, |
| 42 | const AidlStructuredParcelable& defined_type, const Options& options); |
| 43 | void GenerateParcelSource(CodeWriter& out, const AidlTypenames& types, |
| 44 | const AidlStructuredParcelable& defined_type, const Options& options); |
| 45 | void GenerateParcelHeader(CodeWriter& out, const AidlTypenames& types, |
| 46 | const AidlUnionDecl& defined_type, const Options& options); |
| 47 | void GenerateParcelSource(CodeWriter& out, const AidlTypenames& types, |
| 48 | const AidlUnionDecl& defined_type, const Options& options); |
| 49 | } // namespace internals |
| 50 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 51 | using cpp::ClassNames; |
| 52 | |
| 53 | void GenerateNdkInterface(const string& output_file, const Options& options, |
| 54 | const AidlTypenames& types, const AidlInterface& defined_type, |
| 55 | const IoDelegate& io_delegate) { |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 56 | const string i_header = options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 57 | unique_ptr<CodeWriter> i_writer(io_delegate.GetCodeWriter(i_header)); |
| 58 | GenerateInterfaceHeader(*i_writer, types, defined_type, options); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 59 | AIDL_FATAL_IF(!i_writer->Close(), i_header); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 60 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 61 | const string bp_header = |
| 62 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 63 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 64 | GenerateClientHeader(*bp_writer, types, defined_type, options); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 65 | AIDL_FATAL_IF(!bp_writer->Close(), bp_header); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 66 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 67 | const string bn_header = |
| 68 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 69 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 70 | GenerateServerHeader(*bn_writer, types, defined_type, options); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 71 | AIDL_FATAL_IF(!bn_writer->Close(), bn_header); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 72 | |
| 73 | unique_ptr<CodeWriter> source_writer = io_delegate.GetCodeWriter(output_file); |
| 74 | GenerateSource(*source_writer, types, defined_type, options); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 75 | AIDL_FATAL_IF(!source_writer->Close(), output_file); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 78 | template <typename ParcelableType> |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 79 | void GenerateNdkParcel(const string& output_file, const Options& options, |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 80 | const AidlTypenames& types, const ParcelableType& defined_type, |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 81 | const IoDelegate& io_delegate) { |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 82 | const string header_path = |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 83 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 84 | unique_ptr<CodeWriter> header_writer(io_delegate.GetCodeWriter(header_path)); |
| 85 | GenerateParcelHeader(*header_writer, types, defined_type, options); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 86 | |
| 87 | unique_ptr<CodeWriter> source_writer(io_delegate.GetCodeWriter(output_file)); |
| 88 | if (defined_type.IsGeneric()) { |
| 89 | // Need to write source to header if this is a template |
| 90 | GenerateParcelSource(*header_writer, types, defined_type, options); |
| 91 | } else { |
| 92 | GenerateParcelSource(*source_writer, types, defined_type, options); |
| 93 | } |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 94 | (source_writer->Close()); |
| 95 | AIDL_FATAL_IF(!header_writer->Close(), header_path); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 96 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 97 | const string bp_header = |
| 98 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 99 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 100 | *bp_writer << "#error TODO(b/111362593) defined_types do not have bp classes\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 101 | AIDL_FATAL_IF(!bp_writer->Close(), bp_header); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 102 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 103 | const string bn_header = |
| 104 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 105 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 106 | *bn_writer << "#error TODO(b/111362593) defined_types do not have bn classes\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 107 | AIDL_FATAL_IF(!bn_writer->Close(), bn_header); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 110 | void GenerateNdkParcelDeclaration(const std::string& filename, const IoDelegate& io_delegate) { |
| 111 | CodeWriterPtr code_writer = io_delegate.GetCodeWriter(filename); |
| 112 | *code_writer |
| 113 | << "// This file is intentionally left blank as placeholder for parcel declaration.\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 114 | AIDL_FATAL_IF(!code_writer->Close(), filename); |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 117 | void GenerateNdkEnumDeclaration(const string& output_file, const Options& options, |
| 118 | const AidlTypenames& types, const AidlEnumDeclaration& defined_type, |
| 119 | const IoDelegate& io_delegate) { |
| 120 | const string header_path = |
| 121 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
| 122 | unique_ptr<CodeWriter> header_writer(io_delegate.GetCodeWriter(header_path)); |
| 123 | GenerateEnumHeader(*header_writer, types, defined_type, options); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 124 | AIDL_FATAL_IF(!header_writer->Close(), header_path); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 125 | |
| 126 | const string bp_header = |
| 127 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
| 128 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 129 | *bp_writer << "#error TODO(b/111362593) enums do not have bp classes\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 130 | AIDL_FATAL_IF(!bp_writer->Close(), bp_header); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 131 | |
| 132 | const string bn_header = |
| 133 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
| 134 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 135 | *bn_writer << "#error TODO(b/111362593) enums do not have bn classes\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 136 | AIDL_FATAL_IF(!bn_writer->Close(), bn_header); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 137 | |
| 138 | unique_ptr<CodeWriter> source_writer = io_delegate.GetCodeWriter(output_file); |
| 139 | *source_writer |
| 140 | << "// This file is intentionally left blank as placeholder for enum declaration.\n"; |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 141 | AIDL_FATAL_IF(!source_writer->Close(), output_file); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 144 | void GenerateNdk(const string& output_file, const Options& options, const AidlTypenames& types, |
| 145 | const AidlDefinedType& defined_type, const IoDelegate& io_delegate) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 146 | if (const AidlStructuredParcelable* parcelable = defined_type.AsStructuredParcelable(); |
| 147 | parcelable != nullptr) { |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 148 | GenerateNdkParcel<AidlStructuredParcelable>(output_file, options, types, *parcelable, |
| 149 | io_delegate); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | if (const AidlUnionDecl* union_decl = defined_type.AsUnionDeclaration(); union_decl != nullptr) { |
| 154 | GenerateNdkParcel<AidlUnionDecl>(output_file, options, types, *union_decl, io_delegate); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 158 | if (const AidlParcelable* parcelable_decl = defined_type.AsParcelable(); |
| 159 | parcelable_decl != nullptr) { |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 160 | GenerateNdkParcelDeclaration(output_file, io_delegate); |
| 161 | return; |
| 162 | } |
| 163 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 164 | if (const AidlEnumDeclaration* enum_decl = defined_type.AsEnumDeclaration(); |
| 165 | enum_decl != nullptr) { |
| 166 | GenerateNdkEnumDeclaration(output_file, options, types, *enum_decl, io_delegate); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | if (const AidlInterface* interface = defined_type.AsInterface(); interface != nullptr) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 171 | GenerateNdkInterface(output_file, options, types, *interface, io_delegate); |
| 172 | return; |
| 173 | } |
| 174 | |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 175 | AIDL_FATAL(defined_type) << "Unrecognized type sent for NDK cpp generation."; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 176 | } |
| 177 | namespace internals { |
| 178 | |
| 179 | void EnterNdkNamespace(CodeWriter& out, const AidlDefinedType& defined_type) { |
| 180 | out << "namespace aidl {\n"; |
| 181 | cpp::EnterNamespace(out, defined_type); |
| 182 | } |
| 183 | void LeaveNdkNamespace(CodeWriter& out, const AidlDefinedType& defined_type) { |
| 184 | cpp::LeaveNamespace(out, defined_type); |
| 185 | out << "} // namespace aidl\n"; |
| 186 | } |
| 187 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 188 | static void StatusCheckGoto(CodeWriter& out) { |
| 189 | out << "if (_aidl_ret_status != STATUS_OK) goto _aidl_error;\n\n"; |
| 190 | } |
| 191 | static void StatusCheckBreak(CodeWriter& out) { |
| 192 | out << "if (_aidl_ret_status != STATUS_OK) break;\n\n"; |
| 193 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 194 | static void StatusCheckReturn(CodeWriter& out) { |
| 195 | out << "if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;\n\n"; |
| 196 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 197 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 198 | static void GenerateHeaderIncludes(CodeWriter& out, const AidlTypenames& types, |
| 199 | const AidlDefinedType& defined_type) { |
Steven Moreland | 8769f93 | 2019-10-30 15:38:10 -0700 | [diff] [blame] | 200 | out << "#include <cstdint>\n"; |
| 201 | out << "#include <memory>\n"; |
| 202 | out << "#include <optional>\n"; |
| 203 | out << "#include <string>\n"; |
| 204 | out << "#include <vector>\n"; |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 205 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 206 | out << "#include <android/binder_stability.h>\n"; |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 207 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 208 | |
Steven Moreland | a7764e5 | 2020-10-27 17:29:29 +0000 | [diff] [blame] | 209 | if (defined_type.IsSensitiveData()) { |
| 210 | out << "#include <android/binder_parcel_platform.h>\n"; |
| 211 | out << "#include <android/binder_ibinder_platform.h>\n"; |
| 212 | } |
| 213 | |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 214 | auto headerFilePath = [&types](const AidlTypeSpecifier& typespec) -> std::string { |
| 215 | const AidlDefinedType* type = types.TryGetDefinedType(typespec.GetName()); |
| 216 | if (type == nullptr) { |
| 217 | // could be a primitive type. |
| 218 | return ""; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 219 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 220 | |
| 221 | if (type->AsInterface() != nullptr) { |
| 222 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
| 223 | } else if (type->AsStructuredParcelable() != nullptr) { |
| 224 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 225 | } else if (type->AsUnionDeclaration() != nullptr) { |
| 226 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 227 | } else if (type->AsParcelable() != nullptr) { |
| 228 | return type->AsParcelable()->GetCppHeader(); |
| 229 | } else if (type->AsEnumDeclaration() != nullptr) { |
| 230 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
| 231 | } else { |
| 232 | AIDL_FATAL(*type) << "Unrecognized type."; |
| 233 | return ""; |
| 234 | } |
| 235 | }; |
| 236 | |
| 237 | std::set<std::string> includes; |
| 238 | |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 239 | // visit a type and collect all reference types' headers |
| 240 | std::function<void(const AidlTypeSpecifier& type)> visit = [&](const AidlTypeSpecifier& type) { |
| 241 | includes.insert(headerFilePath(type)); |
| 242 | if (type.IsGeneric()) { |
| 243 | for (const auto& param : type.GetTypeParameters()) { |
| 244 | visit(*param); |
| 245 | } |
| 246 | } |
| 247 | }; |
| 248 | |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 249 | const AidlInterface* interface = defined_type.AsInterface(); |
| 250 | if (interface != nullptr) { |
| 251 | for (const auto& method : interface->GetMethods()) { |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 252 | visit(method->GetType()); |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 253 | for (const auto& argument : method->GetArguments()) { |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 254 | visit(argument->GetType()); |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 259 | auto visit_parcelable = [&](const auto& parcelable) { |
| 260 | for (const auto& field : parcelable.GetFields()) { |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 261 | visit(field->GetType()); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 262 | // Check the fields for generic type arguments |
| 263 | if (field->GetType().IsGeneric()) { |
| 264 | for (const auto& type_argument : field->GetType().GetTypeParameters()) { |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 265 | visit(*type_argument); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 268 | } |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | const AidlStructuredParcelable* parcelable = defined_type.AsStructuredParcelable(); |
| 272 | if (parcelable != nullptr) { |
| 273 | visit_parcelable(*parcelable); |
| 274 | } |
| 275 | |
| 276 | const AidlUnionDecl* union_decl = defined_type.AsUnionDeclaration(); |
| 277 | if (union_decl != nullptr) { |
| 278 | visit_parcelable(*union_decl); |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | const AidlEnumDeclaration* enum_decl = defined_type.AsEnumDeclaration(); |
| 282 | if (enum_decl != nullptr) { |
Jooyung Han | 14004ed | 2020-10-16 03:49:57 +0900 | [diff] [blame] | 283 | visit(enum_decl->GetBackingType()); |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | for (const auto& path : includes) { |
| 287 | if (path == "") { |
| 288 | continue; |
| 289 | } |
| 290 | out << "#include <" << path << ">\n"; |
| 291 | } |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 292 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 293 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 294 | static void GenerateSourceIncludes(CodeWriter& out, const AidlTypenames& types, |
| 295 | const AidlDefinedType& /*defined_type*/) { |
Steven Moreland | 8769f93 | 2019-10-30 15:38:10 -0700 | [diff] [blame] | 296 | out << "#include <android/binder_parcel_utils.h>\n"; |
| 297 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 298 | types.IterateTypes([&](const AidlDefinedType& a_defined_type) { |
| 299 | if (a_defined_type.AsInterface() != nullptr) { |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 300 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::CLIENT, false /*use_os_sep*/) |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 301 | << ">\n"; |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 302 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::SERVER, false /*use_os_sep*/) |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 303 | << ">\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 304 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::RAW, false /*use_os_sep*/) |
| 305 | << ">\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 306 | } |
| 307 | }); |
| 308 | } |
| 309 | |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 310 | template <typename TypeWithConstants> |
Steven Moreland | e689da2 | 2020-11-10 02:06:30 +0000 | [diff] [blame] | 311 | static void GenerateConstantDeclarations(CodeWriter& out, const AidlTypenames& types, |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 312 | const TypeWithConstants& type) { |
| 313 | for (const auto& constant : type.GetConstantDeclarations()) { |
Steven Moreland | e689da2 | 2020-11-10 02:06:30 +0000 | [diff] [blame] | 314 | const AidlTypeSpecifier& type = constant->GetType(); |
| 315 | |
Jooyung Han | 965e31d | 2020-11-27 12:30:16 +0900 | [diff] [blame] | 316 | if (type.Signature() == "String") { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 317 | out << "static const char*"; |
| 318 | cpp::GenerateDeprecated(out, *constant); |
| 319 | out << " " << constant->GetName() << ";\n"; |
Steven Moreland | e689da2 | 2020-11-10 02:06:30 +0000 | [diff] [blame] | 320 | } else { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 321 | out << "enum : " << NdkNameOf(types, type, StorageMode::STACK) << " { "; |
| 322 | out << constant->GetName(); |
| 323 | cpp::GenerateDeprecated(out, *constant); |
| 324 | out << " = " << constant->ValueString(ConstantValueDecorator) << " };\n"; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 327 | } |
Steven Moreland | e689da2 | 2020-11-10 02:06:30 +0000 | [diff] [blame] | 328 | |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 329 | template <typename TypeWithConstants> |
| 330 | static void GenerateConstantDefinitions(CodeWriter& out, const TypeWithConstants& interface, |
| 331 | const std::string& clazz, |
| 332 | const std::string& tmpl_decl = "") { |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 333 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 334 | const AidlConstantValue& value = constant->GetValue(); |
Steven Moreland | 2178081 | 2020-09-11 01:29:45 +0000 | [diff] [blame] | 335 | AIDL_FATAL_IF(value.GetType() == AidlConstantValue::Type::UNARY || |
| 336 | value.GetType() == AidlConstantValue::Type::BINARY, |
| 337 | value); |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 338 | if (value.GetType() == AidlConstantValue::Type::STRING) { |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 339 | out << tmpl_decl; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 340 | out << "const char* " << clazz << "::" << constant->GetName() << " = " |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 341 | << constant->ValueString(ConstantValueDecorator) << ";\n"; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 346 | void GenerateSource(CodeWriter& out, const AidlTypenames& types, const AidlInterface& defined_type, |
| 347 | const Options& options) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 348 | GenerateSourceIncludes(out, types, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 349 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 350 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 351 | EnterNdkNamespace(out, defined_type); |
Jooyung Han | b8e01b9 | 2020-11-01 16:49:13 +0900 | [diff] [blame] | 352 | if (options.GenLog()) { |
| 353 | out << cpp::kToStringHelper; |
| 354 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 355 | GenerateClassSource(out, types, defined_type, options); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 356 | GenerateClientSource(out, types, defined_type, options); |
| 357 | GenerateServerSource(out, types, defined_type, options); |
| 358 | GenerateInterfaceSource(out, types, defined_type, options); |
| 359 | LeaveNdkNamespace(out, defined_type); |
| 360 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 361 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 362 | static std::string MethodId(const AidlMethod& m) { |
| 363 | return "(FIRST_CALL_TRANSACTION + " + std::to_string(m.GetId()) + " /*" + m.GetName() + "*/)"; |
| 364 | } |
| 365 | |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 366 | static void GenerateClientMethodDefinition(CodeWriter& out, const AidlTypenames& types, |
| 367 | const AidlInterface& defined_type, |
| 368 | const AidlMethod& method, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 369 | const Options& options) { |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 370 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
| 371 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 372 | out << NdkMethodDecl(types, method, clazz) << " {\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 373 | out.Indent(); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 374 | out << "binder_status_t _aidl_ret_status = STATUS_OK;\n"; |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 375 | out << "::ndk::ScopedAStatus _aidl_status;\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 376 | |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 377 | if (method.GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 378 | out << "const std::lock_guard<std::mutex> lock(" << kCachedHashMutex << ");\n"; |
| 379 | out << "if (" << kCachedHash << " != \"-1\") {\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 380 | out.Indent(); |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 381 | out << "*_aidl_return = " << kCachedHash << ";\n" |
| 382 | << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n" |
| 383 | << "return _aidl_status;\n"; |
| 384 | out.Dedent(); |
| 385 | out << "}\n"; |
| 386 | } else if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 387 | out << "if (" << kCachedVersion << " != -1) {\n"; |
| 388 | out.Indent(); |
| 389 | out << "*_aidl_return = " << kCachedVersion << ";\n" |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 390 | << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n" |
| 391 | << "return _aidl_status;\n"; |
| 392 | out.Dedent(); |
| 393 | out << "}\n"; |
| 394 | } |
| 395 | out << "::ndk::ScopedAParcel _aidl_in;\n"; |
| 396 | out << "::ndk::ScopedAParcel _aidl_out;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 397 | out << "\n"; |
| 398 | |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 399 | if (options.GenLog()) { |
| 400 | out << cpp::GenLogBeforeExecute(ClassName(defined_type, ClassNames::CLIENT), method, |
| 401 | false /* isServer */, true /* isNdk */); |
| 402 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 403 | if (options.GenTraces()) { |
Jooyung Han | 9435e9a | 2021-01-06 10:16:31 +0900 | [diff] [blame] | 404 | out << "ScopedTrace _aidl_trace(\"AIDL::" << to_string(options.TargetLanguage()) |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 405 | << "::" << ClassName(defined_type, ClassNames::INTERFACE) << "::" << method.GetName() |
| 406 | << "::client\");\n"; |
| 407 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 408 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 409 | out << "_aidl_ret_status = AIBinder_prepareTransaction(asBinder().get(), _aidl_in.getR());\n"; |
Steven Moreland | a7764e5 | 2020-10-27 17:29:29 +0000 | [diff] [blame] | 410 | if (defined_type.IsSensitiveData()) { |
| 411 | out << "AParcel_markSensitive(_aidl_in.get());\n"; |
| 412 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 413 | StatusCheckGoto(out); |
| 414 | |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 415 | for (const auto& arg : method.GetArguments()) { |
| 416 | const std::string var_name = cpp::BuildVarName(*arg); |
| 417 | |
| 418 | if (arg->IsIn()) { |
| 419 | out << "_aidl_ret_status = "; |
| 420 | const std::string prefix = (arg->IsOut() ? "*" : ""); |
| 421 | WriteToParcelFor({out, types, arg->GetType(), "_aidl_in.get()", prefix + var_name}); |
| 422 | out << ";\n"; |
| 423 | StatusCheckGoto(out); |
| 424 | } else if (arg->IsOut() && arg->GetType().IsArray()) { |
| 425 | out << "_aidl_ret_status = ::ndk::AParcel_writeVectorSize(_aidl_in.get(), *" << var_name |
| 426 | << ");\n"; |
Steven Moreland | 823e4db | 2020-12-11 18:37:11 +0000 | [diff] [blame] | 427 | StatusCheckGoto(out); |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 428 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 429 | } |
| 430 | out << "_aidl_ret_status = AIBinder_transact(\n"; |
| 431 | out.Indent(); |
| 432 | out << "asBinder().get(),\n"; |
| 433 | out << MethodId(method) << ",\n"; |
| 434 | out << "_aidl_in.getR(),\n"; |
| 435 | out << "_aidl_out.getR(),\n"; |
Steven Moreland | a7764e5 | 2020-10-27 17:29:29 +0000 | [diff] [blame] | 436 | |
| 437 | std::vector<std::string> flags; |
| 438 | if (method.IsOneway()) flags.push_back("FLAG_ONEWAY"); |
| 439 | if (defined_type.IsSensitiveData()) flags.push_back("FLAG_CLEAR_BUF"); |
| 440 | out << (flags.empty() ? "0" : base::Join(flags, " | ")) << "\n"; |
| 441 | |
Steven Moreland | b72a1e7 | 2019-10-15 11:23:26 -0700 | [diff] [blame] | 442 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
| 443 | out << "| FLAG_PRIVATE_LOCAL\n"; |
| 444 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
| 445 | out << ");\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 446 | out.Dedent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 447 | |
| 448 | // If the method is not implmented in the server side but the client has |
| 449 | // provided the default implementation, call it instead of failing hard. |
| 450 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
| 451 | out << "if (_aidl_ret_status == STATUS_UNKNOWN_TRANSACTION && "; |
| 452 | out << iface << "::getDefaultImpl()) {\n"; |
| 453 | out.Indent(); |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 454 | out << "_aidl_status = " << iface << "::getDefaultImpl()->" << method.GetName() << "("; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 455 | out << NdkArgList(types, method, FormatArgNameOnly) << ");\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 456 | out << "goto _aidl_status_return;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 457 | out.Dedent(); |
| 458 | out << "}\n"; |
| 459 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 460 | StatusCheckGoto(out); |
| 461 | |
| 462 | if (!method.IsOneway()) { |
| 463 | out << "_aidl_ret_status = AParcel_readStatusHeader(_aidl_out.get(), _aidl_status.getR());\n"; |
| 464 | StatusCheckGoto(out); |
| 465 | |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 466 | out << "if (!AStatus_isOk(_aidl_status.get())) goto _aidl_status_return;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 469 | if (method.GetType().GetName() != "void") { |
| 470 | out << "_aidl_ret_status = "; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 471 | ReadFromParcelFor({out, types, method.GetType(), "_aidl_out.get()", "_aidl_return"}); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 472 | out << ";\n"; |
| 473 | StatusCheckGoto(out); |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 474 | if (method.GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 475 | out << kCachedHash << " = *_aidl_return;\n"; |
| 476 | } else if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 477 | out << kCachedVersion << " = *_aidl_return;\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 478 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 479 | } |
Steven Moreland | 7c78d5d | 2018-10-15 14:21:11 -0700 | [diff] [blame] | 480 | for (const AidlArgument* arg : method.GetOutArguments()) { |
| 481 | out << "_aidl_ret_status = "; |
| 482 | ReadFromParcelFor({out, types, arg->GetType(), "_aidl_out.get()", cpp::BuildVarName(*arg)}); |
| 483 | out << ";\n"; |
| 484 | StatusCheckGoto(out); |
| 485 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 486 | |
| 487 | out << "_aidl_error:\n"; |
| 488 | out << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 489 | out << "_aidl_status_return:\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 490 | if (options.GenLog()) { |
| 491 | out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::CLIENT), defined_type, |
| 492 | method, "_aidl_status", "_aidl_return", false /* isServer */, |
| 493 | true /* isNdk */); |
| 494 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 495 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 496 | out << "return _aidl_status;\n"; |
| 497 | out.Dedent(); |
| 498 | out << "}\n"; |
| 499 | } |
| 500 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 501 | static void GenerateServerCaseDefinition(CodeWriter& out, const AidlTypenames& types, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 502 | const AidlInterface& defined_type, |
| 503 | const AidlMethod& method, const Options& options) { |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 504 | out << "case " << MethodId(method) << ": {\n"; |
| 505 | out.Indent(); |
| 506 | for (const auto& arg : method.GetArguments()) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 507 | out << NdkNameOf(types, arg->GetType(), StorageMode::STACK) << " " << cpp::BuildVarName(*arg) |
| 508 | << ";\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 509 | } |
| 510 | if (method.GetType().GetName() != "void") { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 511 | out << NdkNameOf(types, method.GetType(), StorageMode::STACK) << " _aidl_return;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 512 | } |
| 513 | out << "\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 514 | if (options.GenTraces()) { |
Jooyung Han | 9435e9a | 2021-01-06 10:16:31 +0900 | [diff] [blame] | 515 | out << "ScopedTrace _aidl_trace(\"AIDL::" << to_string(options.TargetLanguage()) |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 516 | << "::" << ClassName(defined_type, ClassNames::INTERFACE) << "::" << method.GetName() |
| 517 | << "::server\");\n"; |
| 518 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 519 | |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 520 | for (const auto& arg : method.GetArguments()) { |
| 521 | const std::string var_name = cpp::BuildVarName(*arg); |
| 522 | |
| 523 | if (arg->IsIn()) { |
| 524 | out << "_aidl_ret_status = "; |
| 525 | ReadFromParcelFor({out, types, arg->GetType(), "_aidl_in", "&" + var_name}); |
| 526 | out << ";\n"; |
| 527 | StatusCheckBreak(out); |
| 528 | } else if (arg->IsOut() && arg->GetType().IsArray()) { |
| 529 | out << "_aidl_ret_status = ::ndk::AParcel_resizeVector(_aidl_in, &" << var_name << ");\n"; |
Steven Moreland | 823e4db | 2020-12-11 18:37:11 +0000 | [diff] [blame] | 530 | StatusCheckBreak(out); |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 531 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 532 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 533 | if (options.GenLog()) { |
| 534 | out << cpp::GenLogBeforeExecute(ClassName(defined_type, ClassNames::SERVER), method, |
| 535 | true /* isServer */, true /* isNdk */); |
| 536 | } |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 537 | out << "::ndk::ScopedAStatus _aidl_status = _aidl_impl->" << method.GetName() << "(" |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 538 | << NdkArgList(types, method, FormatArgForCall) << ");\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 539 | |
Jeongik Cha | eaf978e | 2019-05-04 00:32:35 +0900 | [diff] [blame] | 540 | if (options.GenLog()) { |
| 541 | out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::SERVER), defined_type, |
| 542 | method, "_aidl_status", "_aidl_return", true /* isServer */, |
| 543 | true /* isNdk */); |
| 544 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 545 | if (method.IsOneway()) { |
| 546 | // For a oneway transaction, the kernel will have already returned a result. This is for the |
| 547 | // in-process case when a oneway transaction is parceled/unparceled in the same process. |
| 548 | out << "_aidl_ret_status = STATUS_OK;\n"; |
| 549 | } else { |
| 550 | out << "_aidl_ret_status = AParcel_writeStatusHeader(_aidl_out, _aidl_status.get());\n"; |
| 551 | StatusCheckBreak(out); |
| 552 | |
| 553 | out << "if (!AStatus_isOk(_aidl_status.get())) break;\n\n"; |
| 554 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 555 | if (method.GetType().GetName() != "void") { |
| 556 | out << "_aidl_ret_status = "; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 557 | WriteToParcelFor({out, types, method.GetType(), "_aidl_out", "_aidl_return"}); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 558 | out << ";\n"; |
| 559 | StatusCheckBreak(out); |
| 560 | } |
Steven Moreland | 7c78d5d | 2018-10-15 14:21:11 -0700 | [diff] [blame] | 561 | for (const AidlArgument* arg : method.GetOutArguments()) { |
| 562 | out << "_aidl_ret_status = "; |
| 563 | WriteToParcelFor({out, types, arg->GetType(), "_aidl_out", cpp::BuildVarName(*arg)}); |
| 564 | out << ";\n"; |
| 565 | StatusCheckBreak(out); |
| 566 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 567 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 568 | out << "break;\n"; |
| 569 | out.Dedent(); |
| 570 | out << "}\n"; |
| 571 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 572 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 573 | void GenerateClassSource(CodeWriter& out, const AidlTypenames& types, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 574 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 575 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
| 576 | const std::string bn_clazz = ClassName(defined_type, ClassNames::SERVER); |
Devin Moore | f760087 | 2020-05-13 15:47:50 -0700 | [diff] [blame] | 577 | if (options.GenTraces()) { |
| 578 | out << "class ScopedTrace {\n"; |
| 579 | out.Indent(); |
| 580 | out << "public:\n" |
Jiyong Park | dd57f1a | 2020-11-16 20:19:55 +0900 | [diff] [blame] | 581 | << "inline explicit ScopedTrace(const char* name) {\n" |
Devin Moore | f760087 | 2020-05-13 15:47:50 -0700 | [diff] [blame] | 582 | << "ATrace_beginSection(name);\n" |
| 583 | << "}\n" |
| 584 | << "inline ~ScopedTrace() {\n" |
| 585 | << "ATrace_endSection();\n" |
| 586 | << "}\n"; |
| 587 | out.Dedent(); |
| 588 | out << "};\n"; |
| 589 | } |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 590 | bool deprecated = defined_type.IsDeprecated() || |
| 591 | std::any_of(defined_type.GetMethods().begin(), defined_type.GetMethods().end(), |
| 592 | [](const auto& m) { return m->IsDeprecated(); }); |
| 593 | if (deprecated) { |
| 594 | out << "#pragma clang diagnostic push\n"; |
| 595 | out << "#pragma clang diagnostic ignored \"-Wdeprecated\"\n"; |
| 596 | } |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 597 | out << "static binder_status_t " |
| 598 | << "_aidl_onTransact" |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 599 | << "(AIBinder* _aidl_binder, transaction_code_t _aidl_code, const AParcel* _aidl_in, " |
| 600 | "AParcel* _aidl_out) {\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 601 | out.Indent(); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 602 | out << "(void)_aidl_in;\n"; |
| 603 | out << "(void)_aidl_out;\n"; |
| 604 | out << "binder_status_t _aidl_ret_status = STATUS_UNKNOWN_TRANSACTION;\n"; |
| 605 | if (!defined_type.GetMethods().empty()) { |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 606 | // we know this cast is valid because this method is only called by the ICInterface |
| 607 | // AIBinder_Class object which is associated with this class. |
| 608 | out << "std::shared_ptr<" << bn_clazz << "> _aidl_impl = std::static_pointer_cast<" << bn_clazz |
| 609 | << ">(::ndk::ICInterface::asInterface(_aidl_binder));\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 610 | out << "switch (_aidl_code) {\n"; |
| 611 | out.Indent(); |
| 612 | for (const auto& method : defined_type.GetMethods()) { |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 613 | GenerateServerCaseDefinition(out, types, defined_type, *method, options); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 614 | } |
| 615 | out.Dedent(); |
| 616 | out << "}\n"; |
| 617 | } else { |
| 618 | out << "(void)_aidl_binder;\n"; |
| 619 | out << "(void)_aidl_code;\n"; |
| 620 | } |
| 621 | out << "return _aidl_ret_status;\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 622 | out.Dedent(); |
Steven Moreland | 73d6624 | 2019-09-26 16:03:54 -0700 | [diff] [blame] | 623 | out << "}\n\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 624 | |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 625 | out << "static AIBinder_Class* " << kClazz << " = ::ndk::ICInterface::defineClass(" << clazz |
| 626 | << "::" << kDescriptor << ", _aidl_onTransact);\n\n"; |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 627 | if (deprecated) { |
| 628 | out << "#pragma clang diagnostic pop\n"; |
| 629 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 630 | } |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 631 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 632 | void GenerateClientSource(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 633 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 634 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 635 | |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 636 | out << clazz << "::" << clazz << "(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {}\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 637 | out << clazz << "::~" << clazz << "() {}\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 638 | if (options.GenLog()) { |
Jooyung Han | 81003c3 | 2020-11-04 14:08:26 +0900 | [diff] [blame] | 639 | out << "std::function<void(const " + clazz + "::TransactionLog&)> " << clazz << "::logFunc;\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 640 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 641 | out << "\n"; |
| 642 | for (const auto& method : defined_type.GetMethods()) { |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 643 | GenerateClientMethodDefinition(out, types, defined_type, *method, options); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 644 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 645 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 646 | void GenerateServerSource(CodeWriter& out, const AidlTypenames& types, |
| 647 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 648 | const std::string clazz = ClassName(defined_type, ClassNames::SERVER); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 649 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 650 | |
| 651 | out << "// Source for " << clazz << "\n"; |
| 652 | out << clazz << "::" << clazz << "() {}\n"; |
| 653 | out << clazz << "::~" << clazz << "() {}\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 654 | if (options.GenLog()) { |
Jooyung Han | 81003c3 | 2020-11-04 14:08:26 +0900 | [diff] [blame] | 655 | out << "std::function<void(const " + clazz + "::TransactionLog&)> " << clazz << "::logFunc;\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 656 | } |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 657 | out << "::ndk::SpAIBinder " << clazz << "::createBinder() {\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 658 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 659 | out << "AIBinder* binder = AIBinder_new(" << kClazz << ", static_cast<void*>(this));\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 660 | |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 661 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 662 | if (defined_type.IsVintfStability()) { |
| 663 | out << "AIBinder_markVintfStability(binder);\n"; |
| 664 | } else { |
| 665 | out << "AIBinder_markCompilationUnitStability(binder);\n"; |
| 666 | } |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 667 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 668 | |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 669 | out << "return ::ndk::SpAIBinder(binder);\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 670 | out.Dedent(); |
| 671 | out << "}\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 672 | |
| 673 | // Implement the meta methods |
| 674 | for (const auto& method : defined_type.GetMethods()) { |
| 675 | if (method->IsUserDefined()) { |
| 676 | continue; |
| 677 | } |
| 678 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 679 | out << NdkMethodDecl(types, *method, clazz) << " {\n"; |
| 680 | out.Indent(); |
| 681 | out << "*_aidl_return = " << iface << "::" << kVersion << ";\n"; |
| 682 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 683 | out.Dedent(); |
| 684 | out << "}\n"; |
| 685 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 686 | if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 687 | out << NdkMethodDecl(types, *method, clazz) << " {\n"; |
| 688 | out.Indent(); |
| 689 | out << "*_aidl_return = " << iface << "::" << kHash << ";\n"; |
| 690 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 691 | out.Dedent(); |
| 692 | out << "}\n"; |
| 693 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 694 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 695 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 696 | void GenerateInterfaceSource(CodeWriter& out, const AidlTypenames& types, |
| 697 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 698 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 699 | const std::string bp_clazz = ClassName(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 700 | |
| 701 | out << "// Source for " << clazz << "\n"; |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 702 | out << "const char* " << clazz << "::" << kDescriptor << " = \"" << defined_type.GetDescriptor() |
| 703 | << "\";\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 704 | out << clazz << "::" << clazz << "() {}\n"; |
| 705 | out << clazz << "::~" << clazz << "() {}\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 706 | out << "\n"; |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 707 | GenerateConstantDefinitions(out, defined_type, clazz); |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 708 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 709 | |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 710 | out << "std::shared_ptr<" << clazz << "> " << clazz |
| 711 | << "::fromBinder(const ::ndk::SpAIBinder& binder) {\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 712 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 713 | out << "if (!AIBinder_associateClass(binder.get(), " << kClazz << ")) { return nullptr; }\n"; |
| 714 | out << "std::shared_ptr<::ndk::ICInterface> interface = " |
| 715 | "::ndk::ICInterface::asInterface(binder.get());\n"; |
| 716 | out << "if (interface) {\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 717 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 718 | out << "return std::static_pointer_cast<" << clazz << ">(interface);\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 719 | out.Dedent(); |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 720 | out << "}\n"; |
Steven Moreland | c09d34c | 2020-02-13 09:42:49 -0800 | [diff] [blame] | 721 | out << "return ::ndk::SharedRefBase::make<" << bp_clazz << ">(binder);\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 722 | out.Dedent(); |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 723 | out << "}\n\n"; |
| 724 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 725 | out << "binder_status_t " << clazz << "::writeToParcel(AParcel* parcel, const std::shared_ptr<" |
| 726 | << clazz << ">& instance) {\n"; |
| 727 | out.Indent(); |
| 728 | out << "return AParcel_writeStrongBinder(parcel, instance ? instance->asBinder().get() : " |
| 729 | "nullptr);\n"; |
| 730 | out.Dedent(); |
| 731 | out << "}\n"; |
| 732 | |
| 733 | out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* parcel, std::shared_ptr<" |
| 734 | << clazz << ">* instance) {\n"; |
| 735 | out.Indent(); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 736 | out << "::ndk::SpAIBinder binder;\n"; |
Steven Moreland | 055d879 | 2018-11-14 12:48:42 -0800 | [diff] [blame] | 737 | out << "binder_status_t status = AParcel_readStrongBinder(parcel, binder.getR());\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 738 | out << "if (status != STATUS_OK) return status;\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 739 | out << "*instance = " << clazz << "::fromBinder(binder);\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 740 | out << "return STATUS_OK;\n"; |
| 741 | out.Dedent(); |
| 742 | out << "}\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 743 | |
| 744 | // defintion for static member setDefaultImpl |
Jiyong Park | dd57f1a | 2020-11-16 20:19:55 +0900 | [diff] [blame] | 745 | out << "bool " << clazz << "::setDefaultImpl(const std::shared_ptr<" << clazz << ">& impl) {\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 746 | out.Indent(); |
Jooyung Han | 4a04466 | 2020-05-13 17:17:07 +0900 | [diff] [blame] | 747 | out << "// Only one user of this interface can use this function\n"; |
| 748 | out << "// at a time. This is a heuristic to detect if two different\n"; |
| 749 | out << "// users in the same process use this function.\n"; |
| 750 | out << "assert(!" << clazz << "::default_impl);\n"; |
| 751 | out << "if (impl) {\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 752 | out.Indent(); |
| 753 | out << clazz << "::default_impl = impl;\n"; |
| 754 | out << "return true;\n"; |
| 755 | out.Dedent(); |
| 756 | out << "}\n"; |
| 757 | out << "return false;\n"; |
| 758 | out.Dedent(); |
| 759 | out << "}\n"; |
| 760 | |
| 761 | // definition for static member getDefaultImpl |
| 762 | out << "const std::shared_ptr<" << clazz << ">& " << clazz << "::getDefaultImpl() {\n"; |
| 763 | out.Indent(); |
| 764 | out << "return " << clazz << "::default_impl;\n"; |
| 765 | out.Dedent(); |
| 766 | out << "}\n"; |
| 767 | |
| 768 | // definition for the static field default_impl |
| 769 | out << "std::shared_ptr<" << clazz << "> " << clazz << "::default_impl = nullptr;\n"; |
| 770 | |
| 771 | // default implementation for the <Name>Default class members |
| 772 | const std::string defaultClazz = clazz + "Default"; |
| 773 | for (const auto& method : defined_type.GetMethods()) { |
| 774 | if (method->IsUserDefined()) { |
| 775 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 776 | << NdkArgList(types, *method, FormatArgNameUnused) << ") {\n"; |
| 777 | out.Indent(); |
| 778 | out << "::ndk::ScopedAStatus _aidl_status;\n"; |
| 779 | out << "_aidl_status.set(AStatus_fromStatus(STATUS_UNKNOWN_TRANSACTION));\n"; |
| 780 | out << "return _aidl_status;\n"; |
| 781 | out.Dedent(); |
| 782 | out << "}\n"; |
| 783 | } else { |
| 784 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 785 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 786 | << "int32_t* _aidl_return) {\n"; |
| 787 | out.Indent(); |
| 788 | out << "*_aidl_return = 0;\n"; |
| 789 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 790 | out.Dedent(); |
| 791 | out << "}\n"; |
| 792 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 793 | if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 794 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 795 | << "std::string* _aidl_return) {\n"; |
| 796 | out.Indent(); |
| 797 | out << "*_aidl_return = \"\";\n"; |
| 798 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 799 | out.Dedent(); |
| 800 | out << "}\n"; |
| 801 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
| 805 | out << "::ndk::SpAIBinder " << defaultClazz << "::asBinder() {\n"; |
| 806 | out.Indent(); |
| 807 | out << "return ::ndk::SpAIBinder();\n"; |
| 808 | out.Dedent(); |
| 809 | out << "}\n"; |
| 810 | |
| 811 | out << "bool " << defaultClazz << "::isRemote() {\n"; |
| 812 | out.Indent(); |
| 813 | out << "return false;\n"; |
| 814 | out.Dedent(); |
| 815 | out << "}\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 816 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 817 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 818 | void GenerateClientHeader(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 819 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 820 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
| 821 | |
| 822 | out << "#pragma once\n\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 823 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 824 | << "\"\n"; |
| 825 | out << "\n"; |
| 826 | out << "#include <android/binder_ibinder.h>\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 827 | if (options.GenLog()) { |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 828 | out << "#include <functional>\n"; |
| 829 | out << "#include <chrono>\n"; |
| 830 | out << "#include <sstream>\n"; |
| 831 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 832 | if (options.GenTraces()) { |
| 833 | out << "#include <android/trace.h>\n"; |
| 834 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 835 | out << "\n"; |
| 836 | EnterNdkNamespace(out, defined_type); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 837 | out << "class"; |
| 838 | cpp::GenerateDeprecated(out, defined_type); |
| 839 | out << " " << clazz << " : public ::ndk::BpCInterface<" |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 840 | << ClassName(defined_type, ClassNames::INTERFACE) << "> {\n"; |
| 841 | out << "public:\n"; |
| 842 | out.Indent(); |
Jiyong Park | dd57f1a | 2020-11-16 20:19:55 +0900 | [diff] [blame] | 843 | out << "explicit " << clazz << "(const ::ndk::SpAIBinder& binder);\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 844 | out << "virtual ~" << clazz << "();\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 845 | out << "\n"; |
| 846 | for (const auto& method : defined_type.GetMethods()) { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 847 | out << NdkMethodDecl(types, *method) << " override"; |
| 848 | cpp::GenerateDeprecated(out, *method); |
| 849 | out << ";\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 850 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 851 | |
| 852 | if (options.Version() > 0) { |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 853 | out << "int32_t " << kCachedVersion << " = -1;\n"; |
| 854 | } |
| 855 | |
| 856 | if (!options.Hash().empty()) { |
| 857 | out << "std::string " << kCachedHash << " = \"-1\";\n"; |
| 858 | out << "std::mutex " << kCachedHashMutex << ";\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 859 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 860 | if (options.GenLog()) { |
Jooyung Han | 81003c3 | 2020-11-04 14:08:26 +0900 | [diff] [blame] | 861 | out << cpp::kTransactionLogStruct; |
| 862 | out << "static std::function<void(const TransactionLog&)> logFunc;\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 863 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 864 | out.Dedent(); |
| 865 | out << "};\n"; |
| 866 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 867 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 868 | void GenerateServerHeader(CodeWriter& out, const AidlTypenames& types, |
| 869 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 870 | const std::string clazz = ClassName(defined_type, ClassNames::SERVER); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 871 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 872 | |
| 873 | out << "#pragma once\n\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 874 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 875 | << "\"\n"; |
| 876 | out << "\n"; |
| 877 | out << "#include <android/binder_ibinder.h>\n"; |
| 878 | out << "\n"; |
| 879 | EnterNdkNamespace(out, defined_type); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 880 | out << "class"; |
| 881 | cpp::GenerateDeprecated(out, defined_type); |
| 882 | out << " " << clazz << " : public ::ndk::BnCInterface<" << iface << "> {\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 883 | out << "public:\n"; |
| 884 | out.Indent(); |
| 885 | out << clazz << "();\n"; |
| 886 | out << "virtual ~" << clazz << "();\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 887 | |
| 888 | // Declare the meta methods |
| 889 | for (const auto& method : defined_type.GetMethods()) { |
| 890 | if (method->IsUserDefined()) { |
| 891 | continue; |
| 892 | } |
| 893 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 894 | out << NdkMethodDecl(types, *method) << " final override;\n"; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 895 | } else if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 896 | out << NdkMethodDecl(types, *method) << " final override;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 897 | } else { |
| 898 | AIDL_FATAL(defined_type) << "Meta method '" << method->GetName() << "' is unimplemented."; |
| 899 | } |
| 900 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 901 | if (options.GenLog()) { |
Jooyung Han | 81003c3 | 2020-11-04 14:08:26 +0900 | [diff] [blame] | 902 | out << cpp::kTransactionLogStruct; |
| 903 | out << "static std::function<void(const TransactionLog&)> logFunc;\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 904 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 905 | out.Dedent(); |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 906 | out << "protected:\n"; |
| 907 | out.Indent(); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 908 | out << "::ndk::SpAIBinder createBinder() override;\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 909 | out.Dedent(); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 910 | out << "private:\n"; |
| 911 | out.Indent(); |
| 912 | out.Dedent(); |
| 913 | out << "};\n"; |
| 914 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 915 | } |
| 916 | void GenerateInterfaceHeader(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 917 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 918 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
| 919 | |
| 920 | out << "#pragma once\n\n"; |
| 921 | out << "#include <android/binder_interface_utils.h>\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 922 | if (options.GenLog()) { |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 923 | out << "#include <functional>\n"; |
| 924 | out << "#include <chrono>\n"; |
| 925 | out << "#include <sstream>\n"; |
| 926 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 927 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 928 | |
| 929 | GenerateHeaderIncludes(out, types, defined_type); |
| 930 | out << "\n"; |
| 931 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 932 | EnterNdkNamespace(out, defined_type); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 933 | out << "class"; |
| 934 | cpp::GenerateDeprecated(out, defined_type); |
| 935 | out << " " << clazz << " : public ::ndk::ICInterface {\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 936 | out << "public:\n"; |
| 937 | out.Indent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 938 | out << "static const char* " << kDescriptor << ";\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 939 | out << clazz << "();\n"; |
| 940 | out << "virtual ~" << clazz << "();\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 941 | out << "\n"; |
Steven Moreland | e689da2 | 2020-11-10 02:06:30 +0000 | [diff] [blame] | 942 | GenerateConstantDeclarations(out, types, defined_type); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 943 | if (options.Version() > 0) { |
| 944 | out << "static const int32_t " << kVersion << " = " << std::to_string(options.Version()) |
| 945 | << ";\n"; |
| 946 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 947 | if (!options.Hash().empty()) { |
| 948 | out << "static inline const std::string " << kHash << " = \"" << options.Hash() << "\";\n"; |
| 949 | } |
Jiyong Park | 717fc69 | 2020-11-25 16:31:32 +0900 | [diff] [blame] | 950 | for (const auto& method : defined_type.GetMethods()) { |
| 951 | if (!method->IsUserDefined()) { |
| 952 | continue; |
| 953 | } |
| 954 | out << "static constexpr uint32_t TRANSACTION_" << method->GetName() << " = " |
| 955 | << "FIRST_CALL_TRANSACTION + " << std::to_string(method->GetId()) << ";\n"; |
| 956 | } |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 957 | out << "\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 958 | out << "static std::shared_ptr<" << clazz << "> fromBinder(const ::ndk::SpAIBinder& binder);\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 959 | out << "static binder_status_t writeToParcel(AParcel* parcel, const std::shared_ptr<" << clazz |
| 960 | << ">& instance);"; |
Jiyong Park | 1b88cce | 2018-11-19 19:53:44 +0900 | [diff] [blame] | 961 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 962 | out << "static binder_status_t readFromParcel(const AParcel* parcel, std::shared_ptr<" << clazz |
| 963 | << ">* instance);"; |
| 964 | out << "\n"; |
Jiyong Park | dd57f1a | 2020-11-16 20:19:55 +0900 | [diff] [blame] | 965 | out << "static bool setDefaultImpl(const std::shared_ptr<" << clazz << ">& impl);"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 966 | out << "\n"; |
| 967 | out << "static const std::shared_ptr<" << clazz << ">& getDefaultImpl();"; |
| 968 | out << "\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 969 | for (const auto& method : defined_type.GetMethods()) { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 970 | out << "virtual " << NdkMethodDecl(types, *method); |
| 971 | cpp::GenerateDeprecated(out, *method); |
| 972 | out << " = 0;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 973 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 974 | out.Dedent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 975 | out << "private:\n"; |
| 976 | out.Indent(); |
| 977 | out << "static std::shared_ptr<" << clazz << "> default_impl;\n"; |
| 978 | out.Dedent(); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 979 | out << "};\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 980 | |
| 981 | const std::string defaultClazz = clazz + "Default"; |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 982 | out << "class"; |
| 983 | cpp::GenerateDeprecated(out, defined_type); |
| 984 | out << " " << defaultClazz << " : public " << clazz << " {\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 985 | out << "public:\n"; |
| 986 | out.Indent(); |
| 987 | for (const auto& method : defined_type.GetMethods()) { |
| 988 | if (method->IsUserDefined()) { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 989 | out << NdkMethodDecl(types, *method) << " override"; |
| 990 | cpp::GenerateDeprecated(out, *method); |
| 991 | out << ";\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 992 | } else if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 993 | out << NdkMethodDecl(types, *method) << " override;\n"; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 994 | } else if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 995 | out << NdkMethodDecl(types, *method) << " override;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | out << "::ndk::SpAIBinder asBinder() override;\n"; |
| 999 | out << "bool isRemote() override;\n"; |
| 1000 | out.Dedent(); |
| 1001 | out << "};\n"; |
| 1002 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1003 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1004 | } |
| 1005 | void GenerateParcelHeader(CodeWriter& out, const AidlTypenames& types, |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1006 | const AidlStructuredParcelable& defined_type, |
| 1007 | const Options& /*options*/) { |
Steven Moreland | b8df37d | 2019-11-21 12:33:24 -0800 | [diff] [blame] | 1008 | const std::string clazz = ClassName(defined_type, ClassNames::RAW); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1009 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1010 | out << "#pragma once\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1011 | out << "#include <android/binder_interface_utils.h>\n"; |
Jeongik Cha | 93741c4 | 2020-09-22 11:57:28 +0900 | [diff] [blame] | 1012 | out << "#include <android/binder_parcelable_utils.h>\n"; |
Jooyung Han | 74b1dd4 | 2020-11-01 22:17:16 +0900 | [diff] [blame] | 1013 | |
| 1014 | // used by toString() |
| 1015 | out << "#include <codecvt>\n"; |
| 1016 | out << "#include <locale>\n"; |
| 1017 | out << "#include <sstream>\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1018 | |
| 1019 | GenerateHeaderIncludes(out, types, defined_type); |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 1020 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1021 | EnterNdkNamespace(out, defined_type); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1022 | out << cpp::TemplateDecl(defined_type); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 1023 | out << "class"; |
| 1024 | cpp::GenerateDeprecated(out, defined_type); |
| 1025 | out << " " << clazz << " {\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1026 | out << "public:\n"; |
| 1027 | out.Indent(); |
Devin Moore | 369fdc0 | 2020-09-11 14:21:34 -0700 | [diff] [blame] | 1028 | if (defined_type.IsFixedSize()) { |
| 1029 | out << "typedef std::true_type fixed_size;\n"; |
| 1030 | } else { |
| 1031 | out << "typedef std::false_type fixed_size;\n"; |
| 1032 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1033 | out << "static const char* descriptor;\n"; |
| 1034 | out << "\n"; |
| 1035 | for (const auto& variable : defined_type.GetFields()) { |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 1036 | out << NdkNameOf(types, variable->GetType(), StorageMode::STACK); |
| 1037 | cpp::GenerateDeprecated(out, *variable); |
| 1038 | out << " " << variable->GetName(); |
Jeongik Cha | 8f02a53 | 2020-10-14 00:16:28 +0900 | [diff] [blame] | 1039 | if (variable->GetType().GetName() == "ParcelableHolder") { |
| 1040 | out << "{::ndk::" << (defined_type.IsVintfStability() ? "STABILITY_VINTF" : "STABILITY_LOCAL") |
| 1041 | << "}"; |
| 1042 | } |
Devin Moore | 83e7698 | 2020-09-30 09:32:35 -0700 | [diff] [blame] | 1043 | if (defined_type.IsFixedSize()) { |
| 1044 | int alignment = NdkAlignmentOf(types, variable->GetType()); |
| 1045 | if (alignment > 0) { |
| 1046 | out << " __attribute__((aligned (" << std::to_string(alignment) << ")))"; |
| 1047 | } |
| 1048 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1049 | if (variable->GetDefaultValue()) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1050 | out << " = " << variable->ValueString(ConstantValueDecorator); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1051 | } |
| 1052 | out << ";\n"; |
| 1053 | } |
| 1054 | out << "\n"; |
| 1055 | out << "binder_status_t readFromParcel(const AParcel* parcel);\n"; |
| 1056 | out << "binder_status_t writeToParcel(AParcel* parcel) const;\n"; |
Steven Moreland | f58804a | 2020-12-07 18:12:15 +0000 | [diff] [blame] | 1057 | out << "\n"; |
| 1058 | |
| 1059 | cpp::GenerateParcelableComparisonOperators(out, defined_type); |
Jeongik Cha | 92d33d0 | 2020-05-14 00:53:57 +0900 | [diff] [blame] | 1060 | |
Jeongik Cha | 93741c4 | 2020-09-22 11:57:28 +0900 | [diff] [blame] | 1061 | out << "static const ::ndk::parcelable_stability_t _aidl_stability = ::ndk::" |
| 1062 | << (defined_type.IsVintfStability() ? "STABILITY_VINTF" : "STABILITY_LOCAL") << ";\n"; |
Jooyung Han | 74b1dd4 | 2020-11-01 22:17:16 +0900 | [diff] [blame] | 1063 | |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 1064 | GenerateConstantDeclarations(out, types, defined_type); |
Jooyung Han | 74b1dd4 | 2020-11-01 22:17:16 +0900 | [diff] [blame] | 1065 | cpp::GenerateToString(out, defined_type); |
| 1066 | |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1067 | out.Dedent(); |
| 1068 | out << "};\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1069 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1070 | } |
| 1071 | void GenerateParcelSource(CodeWriter& out, const AidlTypenames& types, |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1072 | const AidlStructuredParcelable& defined_type, |
| 1073 | const Options& /*options*/) { |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1074 | std::string clazz = ClassName(defined_type, ClassNames::RAW); |
| 1075 | if (defined_type.IsGeneric()) { |
| 1076 | std::vector<std::string> template_params; |
| 1077 | for (const auto& parameter : defined_type.GetTypeParameters()) { |
| 1078 | template_params.push_back(parameter); |
| 1079 | } |
| 1080 | clazz += base::StringPrintf("<%s>", base::Join(template_params, ", ").c_str()); |
| 1081 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1082 | |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 1083 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1084 | << "\"\n"; |
| 1085 | out << "\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1086 | GenerateSourceIncludes(out, types, defined_type); |
| 1087 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1088 | EnterNdkNamespace(out, defined_type); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1089 | out << cpp::TemplateDecl(defined_type); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 1090 | out << "const char* " << clazz << "::" << kDescriptor << " = \"" |
| 1091 | << defined_type.GetCanonicalName() << "\";\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1092 | out << "\n"; |
| 1093 | |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 1094 | GenerateConstantDefinitions(out, defined_type, clazz, cpp::TemplateDecl(defined_type)); |
| 1095 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1096 | out << cpp::TemplateDecl(defined_type); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1097 | out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* parcel) {\n"; |
| 1098 | out.Indent(); |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1099 | out << "int32_t _aidl_parcelable_size;\n"; |
Steven Moreland | 4348f9a | 2019-12-16 16:33:01 -0800 | [diff] [blame] | 1100 | out << "int32_t _aidl_start_pos = AParcel_getDataPosition(parcel);\n"; |
| 1101 | out << "binder_status_t _aidl_ret_status = AParcel_readInt32(parcel, &_aidl_parcelable_size);\n"; |
Jeongik Cha | 8b32998 | 2020-09-01 20:59:36 +0900 | [diff] [blame] | 1102 | out << "if (_aidl_start_pos > INT32_MAX - _aidl_parcelable_size) return STATUS_BAD_VALUE;\n"; |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1103 | out << "if (_aidl_parcelable_size < 0) return STATUS_BAD_VALUE;\n"; |
| 1104 | StatusCheckReturn(out); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1105 | |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1106 | for (const auto& variable : defined_type.GetFields()) { |
| 1107 | out << "_aidl_ret_status = "; |
| 1108 | ReadFromParcelFor({out, types, variable->GetType(), "parcel", "&" + variable->GetName()}); |
| 1109 | out << ";\n"; |
| 1110 | StatusCheckReturn(out); |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1111 | out << "if (AParcel_getDataPosition(parcel) - _aidl_start_pos >= _aidl_parcelable_size) {\n" |
| 1112 | << " AParcel_setDataPosition(parcel, _aidl_start_pos + _aidl_parcelable_size);\n" |
| 1113 | << " return _aidl_ret_status;\n" |
| 1114 | << "}\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1115 | } |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1116 | out << "AParcel_setDataPosition(parcel, _aidl_start_pos + _aidl_parcelable_size);\n" |
| 1117 | << "return _aidl_ret_status;\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1118 | out.Dedent(); |
| 1119 | out << "}\n"; |
| 1120 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1121 | out << cpp::TemplateDecl(defined_type); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1122 | out << "binder_status_t " << clazz << "::writeToParcel(AParcel* parcel) const {\n"; |
| 1123 | out.Indent(); |
| 1124 | out << "binder_status_t _aidl_ret_status;\n"; |
| 1125 | |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1126 | out << "size_t _aidl_start_pos = AParcel_getDataPosition(parcel);\n"; |
| 1127 | out << "_aidl_ret_status = AParcel_writeInt32(parcel, 0);\n"; |
| 1128 | StatusCheckReturn(out); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1129 | |
| 1130 | for (const auto& variable : defined_type.GetFields()) { |
| 1131 | out << "_aidl_ret_status = "; |
| 1132 | WriteToParcelFor({out, types, variable->GetType(), "parcel", variable->GetName()}); |
| 1133 | out << ";\n"; |
| 1134 | StatusCheckReturn(out); |
| 1135 | } |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1136 | out << "size_t _aidl_end_pos = AParcel_getDataPosition(parcel);\n"; |
| 1137 | out << "AParcel_setDataPosition(parcel, _aidl_start_pos);\n"; |
| 1138 | out << "AParcel_writeInt32(parcel, _aidl_end_pos - _aidl_start_pos);\n"; |
| 1139 | out << "AParcel_setDataPosition(parcel, _aidl_end_pos);\n"; |
| 1140 | |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1141 | out << "return _aidl_ret_status;\n"; |
| 1142 | out.Dedent(); |
| 1143 | out << "}\n"; |
| 1144 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1145 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1146 | } |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1147 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1148 | void GenerateParcelHeader(CodeWriter& out, const AidlTypenames& types, |
| 1149 | const AidlUnionDecl& defined_type, const Options& /*options*/) { |
| 1150 | const std::string clazz = ClassName(defined_type, ClassNames::RAW); |
| 1151 | cpp::UnionWriter uw{defined_type, types, |
| 1152 | [&](const AidlTypeSpecifier& type, const AidlTypenames& types) { |
| 1153 | return NdkNameOf(types, type, StorageMode::STACK); |
| 1154 | }, |
| 1155 | &ConstantValueDecorator}; |
| 1156 | |
| 1157 | out << "#pragma once\n"; |
| 1158 | out << "#include <android/binder_interface_utils.h>\n"; |
| 1159 | out << "#include <android/binder_parcelable_utils.h>\n"; |
Jooyung Han | 74b1dd4 | 2020-11-01 22:17:16 +0900 | [diff] [blame] | 1160 | |
| 1161 | // used by toString() |
| 1162 | out << "#include <codecvt>\n"; |
| 1163 | out << "#include <locale>\n"; |
| 1164 | out << "#include <sstream>\n"; |
| 1165 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1166 | out << "\n"; |
| 1167 | |
| 1168 | for (const auto& header : cpp::UnionWriter::headers) { |
| 1169 | out << "#include <" << header << ">\n"; |
| 1170 | } |
| 1171 | GenerateHeaderIncludes(out, types, defined_type); |
| 1172 | |
Jooyung Han | df39e19 | 2020-11-23 15:59:46 +0900 | [diff] [blame] | 1173 | // TODO(b/31559095) bionic on host should define this |
| 1174 | out << "\n"; |
| 1175 | out << "#ifndef __BIONIC__\n"; |
| 1176 | out << "#define __assert2(a,b,c,d) ((void)0)\n"; |
| 1177 | out << "#endif\n"; |
| 1178 | out << "\n"; |
| 1179 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1180 | EnterNdkNamespace(out, defined_type); |
| 1181 | out << cpp::TemplateDecl(defined_type); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 1182 | out << "class"; |
| 1183 | cpp::GenerateDeprecated(out, defined_type); |
| 1184 | out << " " << clazz << " {\n"; |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1185 | out << "public:\n"; |
| 1186 | out.Indent(); |
| 1187 | if (defined_type.IsFixedSize()) { |
| 1188 | out << "typedef std::true_type fixed_size;\n"; |
| 1189 | } else { |
| 1190 | out << "typedef std::false_type fixed_size;\n"; |
| 1191 | } |
| 1192 | out << "static const char* descriptor;\n"; |
| 1193 | out << "\n"; |
| 1194 | uw.PublicFields(out); |
| 1195 | |
| 1196 | out << "binder_status_t readFromParcel(const AParcel* _parcel);\n"; |
| 1197 | out << "binder_status_t writeToParcel(AParcel* _parcel) const;\n"; |
Steven Moreland | f58804a | 2020-12-07 18:12:15 +0000 | [diff] [blame] | 1198 | out << "\n"; |
| 1199 | |
| 1200 | cpp::GenerateParcelableComparisonOperators(out, defined_type); |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1201 | |
| 1202 | out << "static const ::ndk::parcelable_stability_t _aidl_stability = ::ndk::" |
| 1203 | << (defined_type.IsVintfStability() ? "STABILITY_VINTF" : "STABILITY_LOCAL") << ";\n"; |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 1204 | GenerateConstantDeclarations(out, types, defined_type); |
Jooyung Han | 74b1dd4 | 2020-11-01 22:17:16 +0900 | [diff] [blame] | 1205 | cpp::GenerateToString(out, defined_type); |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1206 | out.Dedent(); |
| 1207 | out << "private:\n"; |
| 1208 | out.Indent(); |
| 1209 | uw.PrivateFields(out); |
| 1210 | out.Dedent(); |
| 1211 | out << "};\n"; |
| 1212 | LeaveNdkNamespace(out, defined_type); |
| 1213 | } |
| 1214 | void GenerateParcelSource(CodeWriter& out, const AidlTypenames& types, |
| 1215 | const AidlUnionDecl& defined_type, const Options& /*options*/) { |
| 1216 | std::string clazz = ClassName(defined_type, ClassNames::RAW); |
| 1217 | if (defined_type.IsGeneric()) { |
| 1218 | std::vector<std::string> template_params; |
| 1219 | for (const auto& parameter : defined_type.GetTypeParameters()) { |
| 1220 | template_params.push_back(parameter); |
| 1221 | } |
| 1222 | clazz += base::StringPrintf("<%s>", base::Join(template_params, ", ").c_str()); |
| 1223 | } |
| 1224 | |
| 1225 | cpp::UnionWriter uw{defined_type, types, |
| 1226 | [&](const AidlTypeSpecifier& type, const AidlTypenames& types) { |
| 1227 | return NdkNameOf(types, type, StorageMode::STACK); |
| 1228 | }, |
| 1229 | &ConstantValueDecorator}; |
| 1230 | cpp::ParcelWriterContext ctx{ |
| 1231 | .status_type = "binder_status_t", |
| 1232 | .status_ok = "STATUS_OK", |
| 1233 | .status_bad = "STATUS_BAD_VALUE", |
| 1234 | .read_func = |
| 1235 | [&](CodeWriter& out, const std::string& var, const AidlTypeSpecifier& type) { |
| 1236 | ReadFromParcelFor({out, types, type, "_parcel", "&" + var}); |
| 1237 | }, |
| 1238 | .write_func = |
| 1239 | [&](CodeWriter& out, const std::string& value, const AidlTypeSpecifier& type) { |
| 1240 | WriteToParcelFor({out, types, type, "_parcel", value}); |
| 1241 | }, |
| 1242 | }; |
| 1243 | |
| 1244 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
| 1245 | << "\"\n"; |
| 1246 | out << "\n"; |
| 1247 | GenerateSourceIncludes(out, types, defined_type); |
| 1248 | out << "\n"; |
| 1249 | EnterNdkNamespace(out, defined_type); |
| 1250 | out << cpp::TemplateDecl(defined_type); |
| 1251 | out << "const char* " << clazz << "::" << kDescriptor << " = \"" |
| 1252 | << defined_type.GetCanonicalName() << "\";\n"; |
| 1253 | out << "\n"; |
| 1254 | |
Jooyung Han | 3f347ca | 2020-12-01 12:41:50 +0900 | [diff] [blame] | 1255 | GenerateConstantDefinitions(out, defined_type, clazz, cpp::TemplateDecl(defined_type)); |
| 1256 | |
Jooyung Han | 6beac04 | 2020-10-17 21:59:43 +0900 | [diff] [blame] | 1257 | out << cpp::TemplateDecl(defined_type); |
| 1258 | out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* _parcel) {\n"; |
| 1259 | out.Indent(); |
| 1260 | uw.ReadFromParcel(out, ctx); |
| 1261 | out.Dedent(); |
| 1262 | out << "}\n"; |
| 1263 | |
| 1264 | out << cpp::TemplateDecl(defined_type); |
| 1265 | out << "binder_status_t " << clazz << "::writeToParcel(AParcel* _parcel) const {\n"; |
| 1266 | out.Indent(); |
| 1267 | uw.WriteToParcel(out, ctx); |
| 1268 | out.Dedent(); |
| 1269 | out << "}\n"; |
| 1270 | out << "\n"; |
| 1271 | LeaveNdkNamespace(out, defined_type); |
| 1272 | } |
| 1273 | |
Daniel Norman | 455d95c | 2019-11-19 09:55:39 -0800 | [diff] [blame] | 1274 | std::string GenerateEnumToString(const AidlTypenames& typenames, |
| 1275 | const AidlEnumDeclaration& enum_decl) { |
| 1276 | std::ostringstream code; |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 1277 | const std::string signature = |
| 1278 | "static inline std::string toString(" + enum_decl.GetName() + " val)"; |
| 1279 | if (enum_decl.IsDeprecated()) { |
| 1280 | code << signature; |
| 1281 | cpp::GenerateDeprecated(code, enum_decl); |
| 1282 | code << ";\n"; |
| 1283 | } |
| 1284 | code << signature << " {\n"; |
Daniel Norman | 455d95c | 2019-11-19 09:55:39 -0800 | [diff] [blame] | 1285 | code << " switch(val) {\n"; |
| 1286 | std::set<std::string> unique_cases; |
| 1287 | for (const auto& enumerator : enum_decl.GetEnumerators()) { |
| 1288 | std::string c = enumerator->ValueString(enum_decl.GetBackingType(), ConstantValueDecorator); |
| 1289 | // Only add a case if its value has not yet been used in the switch |
| 1290 | // statement. C++ does not allow multiple cases with the same value, but |
| 1291 | // enums does allow this. In this scenario, the first declared |
| 1292 | // enumerator with the given value is printed. |
| 1293 | if (unique_cases.count(c) == 0) { |
| 1294 | unique_cases.insert(c); |
| 1295 | code << " case " << enum_decl.GetName() << "::" << enumerator->GetName() << ":\n"; |
| 1296 | code << " return \"" << enumerator->GetName() << "\";\n"; |
| 1297 | } |
| 1298 | } |
| 1299 | code << " default:\n"; |
| 1300 | code << " return std::to_string(static_cast<" |
| 1301 | << NdkNameOf(typenames, enum_decl.GetBackingType(), StorageMode::STACK) << ">(val));\n"; |
| 1302 | code << " }\n"; |
| 1303 | code << "}\n"; |
| 1304 | return code.str(); |
| 1305 | } |
| 1306 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1307 | void GenerateEnumHeader(CodeWriter& out, const AidlTypenames& types, |
| 1308 | const AidlEnumDeclaration& enum_decl, const Options& /*options*/) { |
| 1309 | out << "#pragma once\n"; |
| 1310 | out << "\n"; |
| 1311 | |
| 1312 | GenerateHeaderIncludes(out, types, enum_decl); |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 1313 | // enum specific headers |
| 1314 | out << "#include <array>\n"; |
| 1315 | out << "#include <android/binder_enums.h>\n"; |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1316 | |
| 1317 | EnterNdkNamespace(out, enum_decl); |
Jooyung Han | 720253d | 2021-01-05 19:13:17 +0900 | [diff] [blame] | 1318 | out << "enum class"; |
| 1319 | cpp::GenerateDeprecated(out, enum_decl); |
| 1320 | out << " " << enum_decl.GetName() << " : " |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1321 | << NdkNameOf(types, enum_decl.GetBackingType(), StorageMode::STACK) << " {\n"; |
| 1322 | out.Indent(); |
| 1323 | for (const auto& enumerator : enum_decl.GetEnumerators()) { |
| 1324 | out << enumerator->GetName() << " = " |
| 1325 | << enumerator->ValueString(enum_decl.GetBackingType(), ConstantValueDecorator) << ",\n"; |
| 1326 | } |
| 1327 | out.Dedent(); |
| 1328 | out << "};\n"; |
Daniel Norman | 455d95c | 2019-11-19 09:55:39 -0800 | [diff] [blame] | 1329 | out << "\n"; |
| 1330 | out << GenerateEnumToString(types, enum_decl); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1331 | LeaveNdkNamespace(out, enum_decl); |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 1332 | |
| 1333 | out << "namespace ndk {\n"; |
| 1334 | out << "namespace internal {\n"; |
| 1335 | out << cpp::GenerateEnumValues(enum_decl, {"aidl"}); |
| 1336 | out << "} // namespace internal\n"; |
| 1337 | out << "} // namespace android\n"; |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1340 | } // namespace internals |
| 1341 | } // namespace ndk |
| 1342 | } // namespace aidl |
| 1343 | } // namespace android |