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; |
| 40 | using cpp::ClassNames; |
| 41 | |
| 42 | void GenerateNdkInterface(const string& output_file, const Options& options, |
| 43 | const AidlTypenames& types, const AidlInterface& defined_type, |
| 44 | const IoDelegate& io_delegate) { |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 45 | const string i_header = options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 46 | unique_ptr<CodeWriter> i_writer(io_delegate.GetCodeWriter(i_header)); |
| 47 | GenerateInterfaceHeader(*i_writer, types, defined_type, options); |
| 48 | CHECK(i_writer->Close()); |
| 49 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 50 | const string bp_header = |
| 51 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 52 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 53 | GenerateClientHeader(*bp_writer, types, defined_type, options); |
| 54 | CHECK(bp_writer->Close()); |
| 55 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 56 | const string bn_header = |
| 57 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 58 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 59 | GenerateServerHeader(*bn_writer, types, defined_type, options); |
| 60 | CHECK(bn_writer->Close()); |
| 61 | |
| 62 | unique_ptr<CodeWriter> source_writer = io_delegate.GetCodeWriter(output_file); |
| 63 | GenerateSource(*source_writer, types, defined_type, options); |
| 64 | CHECK(source_writer->Close()); |
| 65 | } |
| 66 | |
| 67 | void GenerateNdkParcel(const string& output_file, const Options& options, |
| 68 | const AidlTypenames& types, const AidlStructuredParcelable& defined_type, |
| 69 | const IoDelegate& io_delegate) { |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 70 | const string header_path = |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 71 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 72 | unique_ptr<CodeWriter> header_writer(io_delegate.GetCodeWriter(header_path)); |
| 73 | GenerateParcelHeader(*header_writer, types, defined_type, options); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 74 | |
| 75 | unique_ptr<CodeWriter> source_writer(io_delegate.GetCodeWriter(output_file)); |
| 76 | if (defined_type.IsGeneric()) { |
| 77 | // Need to write source to header if this is a template |
| 78 | GenerateParcelSource(*header_writer, types, defined_type, options); |
| 79 | } else { |
| 80 | GenerateParcelSource(*source_writer, types, defined_type, options); |
| 81 | } |
| 82 | CHECK(source_writer->Close()); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 83 | CHECK(header_writer->Close()); |
| 84 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 85 | const string bp_header = |
| 86 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 87 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 88 | *bp_writer << "#error TODO(b/111362593) defined_types do not have bp classes\n"; |
| 89 | CHECK(bp_writer->Close()); |
| 90 | |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 91 | const string bn_header = |
| 92 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 93 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 94 | *bn_writer << "#error TODO(b/111362593) defined_types do not have bn classes\n"; |
| 95 | CHECK(bn_writer->Close()); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 98 | void GenerateNdkParcelDeclaration(const std::string& filename, const IoDelegate& io_delegate) { |
| 99 | CodeWriterPtr code_writer = io_delegate.GetCodeWriter(filename); |
| 100 | *code_writer |
| 101 | << "// This file is intentionally left blank as placeholder for parcel declaration.\n"; |
| 102 | CHECK(code_writer->Close()); |
| 103 | } |
| 104 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 105 | void GenerateNdkEnumDeclaration(const string& output_file, const Options& options, |
| 106 | const AidlTypenames& types, const AidlEnumDeclaration& defined_type, |
| 107 | const IoDelegate& io_delegate) { |
| 108 | const string header_path = |
| 109 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::RAW); |
| 110 | unique_ptr<CodeWriter> header_writer(io_delegate.GetCodeWriter(header_path)); |
| 111 | GenerateEnumHeader(*header_writer, types, defined_type, options); |
| 112 | CHECK(header_writer->Close()); |
| 113 | |
| 114 | const string bp_header = |
| 115 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::CLIENT); |
| 116 | unique_ptr<CodeWriter> bp_writer(io_delegate.GetCodeWriter(bp_header)); |
| 117 | *bp_writer << "#error TODO(b/111362593) enums do not have bp classes\n"; |
| 118 | CHECK(bp_writer->Close()); |
| 119 | |
| 120 | const string bn_header = |
| 121 | options.OutputHeaderDir() + NdkHeaderFile(defined_type, ClassNames::SERVER); |
| 122 | unique_ptr<CodeWriter> bn_writer(io_delegate.GetCodeWriter(bn_header)); |
| 123 | *bn_writer << "#error TODO(b/111362593) enums do not have bn classes\n"; |
| 124 | CHECK(bn_writer->Close()); |
| 125 | |
| 126 | unique_ptr<CodeWriter> source_writer = io_delegate.GetCodeWriter(output_file); |
| 127 | *source_writer |
| 128 | << "// This file is intentionally left blank as placeholder for enum declaration.\n"; |
| 129 | CHECK(source_writer->Close()); |
| 130 | } |
| 131 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 132 | void GenerateNdk(const string& output_file, const Options& options, const AidlTypenames& types, |
| 133 | const AidlDefinedType& defined_type, const IoDelegate& io_delegate) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 134 | if (const AidlStructuredParcelable* parcelable = defined_type.AsStructuredParcelable(); |
| 135 | parcelable != nullptr) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 136 | GenerateNdkParcel(output_file, options, types, *parcelable, io_delegate); |
| 137 | return; |
| 138 | } |
| 139 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 140 | if (const AidlParcelable* parcelable_decl = defined_type.AsParcelable(); |
| 141 | parcelable_decl != nullptr) { |
Steven Moreland | 2a9a7d6 | 2019-02-05 16:11:54 -0800 | [diff] [blame] | 142 | GenerateNdkParcelDeclaration(output_file, io_delegate); |
| 143 | return; |
| 144 | } |
| 145 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 146 | if (const AidlEnumDeclaration* enum_decl = defined_type.AsEnumDeclaration(); |
| 147 | enum_decl != nullptr) { |
| 148 | GenerateNdkEnumDeclaration(output_file, options, types, *enum_decl, io_delegate); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (const AidlInterface* interface = defined_type.AsInterface(); interface != nullptr) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 153 | GenerateNdkInterface(output_file, options, types, *interface, io_delegate); |
| 154 | return; |
| 155 | } |
| 156 | |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 157 | CHECK(false) << "Unrecognized type sent for NDK cpp generation."; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 158 | } |
| 159 | namespace internals { |
| 160 | |
| 161 | void EnterNdkNamespace(CodeWriter& out, const AidlDefinedType& defined_type) { |
| 162 | out << "namespace aidl {\n"; |
| 163 | cpp::EnterNamespace(out, defined_type); |
| 164 | } |
| 165 | void LeaveNdkNamespace(CodeWriter& out, const AidlDefinedType& defined_type) { |
| 166 | cpp::LeaveNamespace(out, defined_type); |
| 167 | out << "} // namespace aidl\n"; |
| 168 | } |
| 169 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 170 | static void StatusCheckGoto(CodeWriter& out) { |
| 171 | out << "if (_aidl_ret_status != STATUS_OK) goto _aidl_error;\n\n"; |
| 172 | } |
| 173 | static void StatusCheckBreak(CodeWriter& out) { |
| 174 | out << "if (_aidl_ret_status != STATUS_OK) break;\n\n"; |
| 175 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 176 | static void StatusCheckReturn(CodeWriter& out) { |
| 177 | out << "if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;\n\n"; |
| 178 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 179 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 180 | static void GenerateHeaderIncludes(CodeWriter& out, const AidlTypenames& types, |
| 181 | const AidlDefinedType& defined_type) { |
Steven Moreland | 8769f93 | 2019-10-30 15:38:10 -0700 | [diff] [blame] | 182 | out << "#include <cstdint>\n"; |
| 183 | out << "#include <memory>\n"; |
| 184 | out << "#include <optional>\n"; |
| 185 | out << "#include <string>\n"; |
| 186 | out << "#include <vector>\n"; |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 187 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 188 | out << "#include <android/binder_stability.h>\n"; |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 189 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 190 | |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 191 | auto headerFilePath = [&types](const AidlTypeSpecifier& typespec) -> std::string { |
| 192 | const AidlDefinedType* type = types.TryGetDefinedType(typespec.GetName()); |
| 193 | if (type == nullptr) { |
| 194 | // could be a primitive type. |
| 195 | return ""; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 196 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 197 | |
| 198 | if (type->AsInterface() != nullptr) { |
| 199 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
| 200 | } else if (type->AsStructuredParcelable() != nullptr) { |
| 201 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
| 202 | } else if (type->AsParcelable() != nullptr) { |
| 203 | return type->AsParcelable()->GetCppHeader(); |
| 204 | } else if (type->AsEnumDeclaration() != nullptr) { |
| 205 | return NdkHeaderFile(*type, ClassNames::RAW, false /*use_os_sep*/); |
| 206 | } else { |
| 207 | AIDL_FATAL(*type) << "Unrecognized type."; |
| 208 | return ""; |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | std::set<std::string> includes; |
| 213 | |
| 214 | const AidlInterface* interface = defined_type.AsInterface(); |
| 215 | if (interface != nullptr) { |
| 216 | for (const auto& method : interface->GetMethods()) { |
| 217 | includes.insert(headerFilePath(method->GetType())); |
| 218 | for (const auto& argument : method->GetArguments()) { |
| 219 | includes.insert(headerFilePath(argument->GetType())); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 220 | // Check the method arguments for generic type arguments |
| 221 | if (argument->GetType().IsGeneric()) { |
| 222 | for (const auto& type_argument : argument->GetType().GetTypeParameters()) { |
| 223 | includes.insert(headerFilePath(*type_argument)); |
| 224 | } |
| 225 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | const AidlStructuredParcelable* parcelable = defined_type.AsStructuredParcelable(); |
| 231 | if (parcelable != nullptr) { |
| 232 | for (const auto& field : parcelable->GetFields()) { |
| 233 | includes.insert(headerFilePath(field->GetType())); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 234 | // Check the fields for generic type arguments |
| 235 | if (field->GetType().IsGeneric()) { |
| 236 | for (const auto& type_argument : field->GetType().GetTypeParameters()) { |
| 237 | includes.insert(headerFilePath(*type_argument)); |
| 238 | } |
| 239 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | const AidlEnumDeclaration* enum_decl = defined_type.AsEnumDeclaration(); |
| 244 | if (enum_decl != nullptr) { |
| 245 | includes.insert(headerFilePath(enum_decl->GetBackingType())); |
| 246 | } |
| 247 | |
| 248 | for (const auto& path : includes) { |
| 249 | if (path == "") { |
| 250 | continue; |
| 251 | } |
| 252 | out << "#include <" << path << ">\n"; |
| 253 | } |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 254 | } |
Jiyong Park | f1f5c80 | 2020-05-19 17:33:00 +0900 | [diff] [blame] | 255 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 256 | static void GenerateSourceIncludes(CodeWriter& out, const AidlTypenames& types, |
| 257 | const AidlDefinedType& /*defined_type*/) { |
Steven Moreland | 8769f93 | 2019-10-30 15:38:10 -0700 | [diff] [blame] | 258 | out << "#include <android/binder_parcel_utils.h>\n"; |
| 259 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 260 | types.IterateTypes([&](const AidlDefinedType& a_defined_type) { |
| 261 | if (a_defined_type.AsInterface() != nullptr) { |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 262 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::CLIENT, false /*use_os_sep*/) |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 263 | << ">\n"; |
Steven Moreland | 7c93337 | 2018-10-11 15:20:04 -0700 | [diff] [blame] | 264 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::SERVER, false /*use_os_sep*/) |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 265 | << ">\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 266 | out << "#include <" << NdkHeaderFile(a_defined_type, ClassNames::RAW, false /*use_os_sep*/) |
| 267 | << ">\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 268 | } |
| 269 | }); |
| 270 | } |
| 271 | |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 272 | static void GenerateConstantDeclarations(CodeWriter& out, const AidlInterface& interface) { |
| 273 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 274 | const AidlConstantValue& value = constant->GetValue(); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 275 | CHECK(value.GetType() != AidlConstantValue::Type::UNARY && |
| 276 | value.GetType() != AidlConstantValue::Type::BINARY); |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 277 | if (value.GetType() == AidlConstantValue::Type::STRING) { |
| 278 | out << "static const char* " << constant->GetName() << ";\n"; |
| 279 | } |
| 280 | } |
| 281 | out << "\n"; |
| 282 | |
| 283 | bool hasIntegralConstant = false; |
| 284 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 285 | const AidlConstantValue& value = constant->GetValue(); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 286 | CHECK(value.GetType() != AidlConstantValue::Type::UNARY && |
| 287 | value.GetType() != AidlConstantValue::Type::BINARY); |
| 288 | if (value.GetType() == AidlConstantValue::Type::BOOLEAN || |
| 289 | value.GetType() == AidlConstantValue::Type::INT8 || |
| 290 | value.GetType() == AidlConstantValue::Type::INT32) { |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 291 | hasIntegralConstant = true; |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | if (hasIntegralConstant) { |
| 297 | out << "enum : int32_t {\n"; |
| 298 | out.Indent(); |
| 299 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 300 | const AidlConstantValue& value = constant->GetValue(); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 301 | if (value.GetType() == AidlConstantValue::Type::BOOLEAN || |
| 302 | value.GetType() == AidlConstantValue::Type::INT8 || |
| 303 | value.GetType() == AidlConstantValue::Type::INT32) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 304 | out << constant->GetName() << " = " << constant->ValueString(ConstantValueDecorator) |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 305 | << ",\n"; |
| 306 | } |
| 307 | } |
| 308 | out.Dedent(); |
| 309 | out << "};\n"; |
| 310 | } |
| 311 | } |
| 312 | static void GenerateConstantDefinitions(CodeWriter& out, const AidlInterface& interface) { |
| 313 | const std::string clazz = ClassName(interface, ClassNames::INTERFACE); |
| 314 | |
| 315 | for (const auto& constant : interface.GetConstantDeclarations()) { |
| 316 | const AidlConstantValue& value = constant->GetValue(); |
Will McVicker | d7d18df | 2019-09-12 13:40:50 -0700 | [diff] [blame] | 317 | CHECK(value.GetType() != AidlConstantValue::Type::UNARY && |
| 318 | value.GetType() != AidlConstantValue::Type::BINARY); |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 319 | if (value.GetType() == AidlConstantValue::Type::STRING) { |
| 320 | out << "const char* " << clazz << "::" << constant->GetName() << " = " |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 321 | << constant->ValueString(ConstantValueDecorator) << ";\n"; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 326 | void GenerateSource(CodeWriter& out, const AidlTypenames& types, const AidlInterface& defined_type, |
| 327 | const Options& options) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 328 | GenerateSourceIncludes(out, types, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 329 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 330 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 331 | EnterNdkNamespace(out, defined_type); |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 332 | GenerateClassSource(out, types, defined_type, options); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 333 | GenerateClientSource(out, types, defined_type, options); |
| 334 | GenerateServerSource(out, types, defined_type, options); |
| 335 | GenerateInterfaceSource(out, types, defined_type, options); |
| 336 | LeaveNdkNamespace(out, defined_type); |
| 337 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 338 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 339 | static std::string MethodId(const AidlMethod& m) { |
| 340 | return "(FIRST_CALL_TRANSACTION + " + std::to_string(m.GetId()) + " /*" + m.GetName() + "*/)"; |
| 341 | } |
| 342 | |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 343 | static void GenerateClientMethodDefinition(CodeWriter& out, const AidlTypenames& types, |
| 344 | const AidlInterface& defined_type, |
| 345 | const AidlMethod& method, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 346 | const Options& options) { |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 347 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
| 348 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 349 | out << NdkMethodDecl(types, method, clazz) << " {\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 350 | out.Indent(); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 351 | out << "binder_status_t _aidl_ret_status = STATUS_OK;\n"; |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 352 | out << "::ndk::ScopedAStatus _aidl_status;\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 353 | |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 354 | if (method.GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 355 | out << "const std::lock_guard<std::mutex> lock(" << kCachedHashMutex << ");\n"; |
| 356 | out << "if (" << kCachedHash << " != \"-1\") {\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 357 | out.Indent(); |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 358 | out << "*_aidl_return = " << kCachedHash << ";\n" |
| 359 | << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n" |
| 360 | << "return _aidl_status;\n"; |
| 361 | out.Dedent(); |
| 362 | out << "}\n"; |
| 363 | } else if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 364 | out << "if (" << kCachedVersion << " != -1) {\n"; |
| 365 | out.Indent(); |
| 366 | out << "*_aidl_return = " << kCachedVersion << ";\n" |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 367 | << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n" |
| 368 | << "return _aidl_status;\n"; |
| 369 | out.Dedent(); |
| 370 | out << "}\n"; |
| 371 | } |
| 372 | out << "::ndk::ScopedAParcel _aidl_in;\n"; |
| 373 | out << "::ndk::ScopedAParcel _aidl_out;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 374 | out << "\n"; |
| 375 | |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 376 | if (options.GenLog()) { |
| 377 | out << cpp::GenLogBeforeExecute(ClassName(defined_type, ClassNames::CLIENT), method, |
| 378 | false /* isServer */, true /* isNdk */); |
| 379 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 380 | if (options.GenTraces()) { |
Devin Moore | f760087 | 2020-05-13 15:47:50 -0700 | [diff] [blame] | 381 | out << "ScopedTrace _aidl_trace(\"AIDL::" << Options::LanguageToString(options.TargetLanguage()) |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 382 | << "::" << ClassName(defined_type, ClassNames::INTERFACE) << "::" << method.GetName() |
| 383 | << "::client\");\n"; |
| 384 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 385 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 386 | out << "_aidl_ret_status = AIBinder_prepareTransaction(asBinder().get(), _aidl_in.getR());\n"; |
| 387 | StatusCheckGoto(out); |
| 388 | |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 389 | for (const auto& arg : method.GetArguments()) { |
| 390 | const std::string var_name = cpp::BuildVarName(*arg); |
| 391 | |
| 392 | if (arg->IsIn()) { |
| 393 | out << "_aidl_ret_status = "; |
| 394 | const std::string prefix = (arg->IsOut() ? "*" : ""); |
| 395 | WriteToParcelFor({out, types, arg->GetType(), "_aidl_in.get()", prefix + var_name}); |
| 396 | out << ";\n"; |
| 397 | StatusCheckGoto(out); |
| 398 | } else if (arg->IsOut() && arg->GetType().IsArray()) { |
| 399 | out << "_aidl_ret_status = ::ndk::AParcel_writeVectorSize(_aidl_in.get(), *" << var_name |
| 400 | << ");\n"; |
| 401 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 402 | } |
| 403 | out << "_aidl_ret_status = AIBinder_transact(\n"; |
| 404 | out.Indent(); |
| 405 | out << "asBinder().get(),\n"; |
| 406 | out << MethodId(method) << ",\n"; |
| 407 | out << "_aidl_in.getR(),\n"; |
| 408 | out << "_aidl_out.getR(),\n"; |
Steven Moreland | b72a1e7 | 2019-10-15 11:23:26 -0700 | [diff] [blame] | 409 | out << (method.IsOneway() ? "FLAG_ONEWAY" : "0") << "\n"; |
| 410 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
| 411 | out << "| FLAG_PRIVATE_LOCAL\n"; |
| 412 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
| 413 | out << ");\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 414 | out.Dedent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 415 | |
| 416 | // If the method is not implmented in the server side but the client has |
| 417 | // provided the default implementation, call it instead of failing hard. |
| 418 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
| 419 | out << "if (_aidl_ret_status == STATUS_UNKNOWN_TRANSACTION && "; |
| 420 | out << iface << "::getDefaultImpl()) {\n"; |
| 421 | out.Indent(); |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 422 | out << "_aidl_status = " << iface << "::getDefaultImpl()->" << method.GetName() << "("; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 423 | out << NdkArgList(types, method, FormatArgNameOnly) << ");\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 424 | out << "goto _aidl_status_return;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 425 | out.Dedent(); |
| 426 | out << "}\n"; |
| 427 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 428 | StatusCheckGoto(out); |
| 429 | |
| 430 | if (!method.IsOneway()) { |
| 431 | out << "_aidl_ret_status = AParcel_readStatusHeader(_aidl_out.get(), _aidl_status.getR());\n"; |
| 432 | StatusCheckGoto(out); |
| 433 | |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 434 | out << "if (!AStatus_isOk(_aidl_status.get())) goto _aidl_status_return;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 437 | if (method.GetType().GetName() != "void") { |
| 438 | out << "_aidl_ret_status = "; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 439 | ReadFromParcelFor({out, types, method.GetType(), "_aidl_out.get()", "_aidl_return"}); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 440 | out << ";\n"; |
| 441 | StatusCheckGoto(out); |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 442 | if (method.GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 443 | out << kCachedHash << " = *_aidl_return;\n"; |
| 444 | } else if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 445 | out << kCachedVersion << " = *_aidl_return;\n"; |
Jeongik Cha | c997292 | 2019-02-11 12:41:16 +0900 | [diff] [blame] | 446 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 447 | } |
Steven Moreland | 7c78d5d | 2018-10-15 14:21:11 -0700 | [diff] [blame] | 448 | for (const AidlArgument* arg : method.GetOutArguments()) { |
| 449 | out << "_aidl_ret_status = "; |
| 450 | ReadFromParcelFor({out, types, arg->GetType(), "_aidl_out.get()", cpp::BuildVarName(*arg)}); |
| 451 | out << ";\n"; |
| 452 | StatusCheckGoto(out); |
| 453 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 454 | |
| 455 | out << "_aidl_error:\n"; |
| 456 | out << "_aidl_status.set(AStatus_fromStatus(_aidl_ret_status));\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 457 | out << "_aidl_status_return:\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 458 | if (options.GenLog()) { |
| 459 | out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::CLIENT), defined_type, |
| 460 | method, "_aidl_status", "_aidl_return", false /* isServer */, |
| 461 | true /* isNdk */); |
| 462 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 463 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 464 | out << "return _aidl_status;\n"; |
| 465 | out.Dedent(); |
| 466 | out << "}\n"; |
| 467 | } |
| 468 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 469 | static void GenerateServerCaseDefinition(CodeWriter& out, const AidlTypenames& types, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 470 | const AidlInterface& defined_type, |
| 471 | const AidlMethod& method, const Options& options) { |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 472 | out << "case " << MethodId(method) << ": {\n"; |
| 473 | out.Indent(); |
| 474 | for (const auto& arg : method.GetArguments()) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 475 | out << NdkNameOf(types, arg->GetType(), StorageMode::STACK) << " " << cpp::BuildVarName(*arg) |
| 476 | << ";\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 477 | } |
| 478 | if (method.GetType().GetName() != "void") { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 479 | out << NdkNameOf(types, method.GetType(), StorageMode::STACK) << " _aidl_return;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 480 | } |
| 481 | out << "\n"; |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 482 | if (options.GenTraces()) { |
Devin Moore | f760087 | 2020-05-13 15:47:50 -0700 | [diff] [blame] | 483 | out << "ScopedTrace _aidl_trace(\"AIDL::" << Options::LanguageToString(options.TargetLanguage()) |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 484 | << "::" << ClassName(defined_type, ClassNames::INTERFACE) << "::" << method.GetName() |
| 485 | << "::server\");\n"; |
| 486 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 487 | |
Steven Moreland | eb38ee7 | 2018-10-15 14:20:04 -0700 | [diff] [blame] | 488 | for (const auto& arg : method.GetArguments()) { |
| 489 | const std::string var_name = cpp::BuildVarName(*arg); |
| 490 | |
| 491 | if (arg->IsIn()) { |
| 492 | out << "_aidl_ret_status = "; |
| 493 | ReadFromParcelFor({out, types, arg->GetType(), "_aidl_in", "&" + var_name}); |
| 494 | out << ";\n"; |
| 495 | StatusCheckBreak(out); |
| 496 | } else if (arg->IsOut() && arg->GetType().IsArray()) { |
| 497 | out << "_aidl_ret_status = ::ndk::AParcel_resizeVector(_aidl_in, &" << var_name << ");\n"; |
| 498 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 499 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 500 | if (options.GenLog()) { |
| 501 | out << cpp::GenLogBeforeExecute(ClassName(defined_type, ClassNames::SERVER), method, |
| 502 | true /* isServer */, true /* isNdk */); |
| 503 | } |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 504 | out << "::ndk::ScopedAStatus _aidl_status = _aidl_impl->" << method.GetName() << "(" |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 505 | << NdkArgList(types, method, FormatArgForCall) << ");\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 506 | |
Jeongik Cha | eaf978e | 2019-05-04 00:32:35 +0900 | [diff] [blame] | 507 | if (options.GenLog()) { |
| 508 | out << cpp::GenLogAfterExecute(ClassName(defined_type, ClassNames::SERVER), defined_type, |
| 509 | method, "_aidl_status", "_aidl_return", true /* isServer */, |
| 510 | true /* isNdk */); |
| 511 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 512 | if (method.IsOneway()) { |
| 513 | // For a oneway transaction, the kernel will have already returned a result. This is for the |
| 514 | // in-process case when a oneway transaction is parceled/unparceled in the same process. |
| 515 | out << "_aidl_ret_status = STATUS_OK;\n"; |
| 516 | } else { |
| 517 | out << "_aidl_ret_status = AParcel_writeStatusHeader(_aidl_out, _aidl_status.get());\n"; |
| 518 | StatusCheckBreak(out); |
| 519 | |
| 520 | out << "if (!AStatus_isOk(_aidl_status.get())) break;\n\n"; |
| 521 | |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 522 | if (method.GetType().GetName() != "void") { |
| 523 | out << "_aidl_ret_status = "; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 524 | WriteToParcelFor({out, types, method.GetType(), "_aidl_out", "_aidl_return"}); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 525 | out << ";\n"; |
| 526 | StatusCheckBreak(out); |
| 527 | } |
Steven Moreland | 7c78d5d | 2018-10-15 14:21:11 -0700 | [diff] [blame] | 528 | for (const AidlArgument* arg : method.GetOutArguments()) { |
| 529 | out << "_aidl_ret_status = "; |
| 530 | WriteToParcelFor({out, types, arg->GetType(), "_aidl_out", cpp::BuildVarName(*arg)}); |
| 531 | out << ";\n"; |
| 532 | StatusCheckBreak(out); |
| 533 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 534 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 535 | out << "break;\n"; |
| 536 | out.Dedent(); |
| 537 | out << "}\n"; |
| 538 | } |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 539 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 540 | void GenerateClassSource(CodeWriter& out, const AidlTypenames& types, |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 541 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 542 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
| 543 | const std::string bn_clazz = ClassName(defined_type, ClassNames::SERVER); |
Devin Moore | f760087 | 2020-05-13 15:47:50 -0700 | [diff] [blame] | 544 | if (options.GenTraces()) { |
| 545 | out << "class ScopedTrace {\n"; |
| 546 | out.Indent(); |
| 547 | out << "public:\n" |
| 548 | << "inline ScopedTrace(const char* name) {\n" |
| 549 | << "ATrace_beginSection(name);\n" |
| 550 | << "}\n" |
| 551 | << "inline ~ScopedTrace() {\n" |
| 552 | << "ATrace_endSection();\n" |
| 553 | << "}\n"; |
| 554 | out.Dedent(); |
| 555 | out << "};\n"; |
| 556 | } |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 557 | out << "static binder_status_t " |
| 558 | << "_aidl_onTransact" |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 559 | << "(AIBinder* _aidl_binder, transaction_code_t _aidl_code, const AParcel* _aidl_in, " |
| 560 | "AParcel* _aidl_out) {\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 561 | out.Indent(); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 562 | out << "(void)_aidl_in;\n"; |
| 563 | out << "(void)_aidl_out;\n"; |
| 564 | out << "binder_status_t _aidl_ret_status = STATUS_UNKNOWN_TRANSACTION;\n"; |
| 565 | if (!defined_type.GetMethods().empty()) { |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 566 | // we know this cast is valid because this method is only called by the ICInterface |
| 567 | // AIBinder_Class object which is associated with this class. |
| 568 | out << "std::shared_ptr<" << bn_clazz << "> _aidl_impl = std::static_pointer_cast<" << bn_clazz |
| 569 | << ">(::ndk::ICInterface::asInterface(_aidl_binder));\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 570 | out << "switch (_aidl_code) {\n"; |
| 571 | out.Indent(); |
| 572 | for (const auto& method : defined_type.GetMethods()) { |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 573 | GenerateServerCaseDefinition(out, types, defined_type, *method, options); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 574 | } |
| 575 | out.Dedent(); |
| 576 | out << "}\n"; |
| 577 | } else { |
| 578 | out << "(void)_aidl_binder;\n"; |
| 579 | out << "(void)_aidl_code;\n"; |
| 580 | } |
| 581 | out << "return _aidl_ret_status;\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 582 | out.Dedent(); |
Steven Moreland | 73d6624 | 2019-09-26 16:03:54 -0700 | [diff] [blame] | 583 | out << "}\n\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 584 | |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 585 | out << "static AIBinder_Class* " << kClazz << " = ::ndk::ICInterface::defineClass(" << clazz |
| 586 | << "::" << kDescriptor << ", _aidl_onTransact);\n\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 587 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 588 | void GenerateClientSource(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 589 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 590 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 591 | |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 592 | out << clazz << "::" << clazz << "(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {}\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 593 | out << clazz << "::~" << clazz << "() {}\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 594 | if (options.GenLog()) { |
| 595 | out << "std::function<void(const Json::Value&)> " << clazz << "::logFunc;\n"; |
| 596 | } |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 597 | out << "\n"; |
| 598 | for (const auto& method : defined_type.GetMethods()) { |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 599 | GenerateClientMethodDefinition(out, types, defined_type, *method, options); |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 600 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 601 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 602 | void GenerateServerSource(CodeWriter& out, const AidlTypenames& types, |
| 603 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 604 | const std::string clazz = ClassName(defined_type, ClassNames::SERVER); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 605 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 606 | |
| 607 | out << "// Source for " << clazz << "\n"; |
| 608 | out << clazz << "::" << clazz << "() {}\n"; |
| 609 | out << clazz << "::~" << clazz << "() {}\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 610 | if (options.GenLog()) { |
| 611 | out << "std::function<void(const Json::Value&)> " << clazz << "::logFunc;\n"; |
| 612 | } |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 613 | out << "::ndk::SpAIBinder " << clazz << "::createBinder() {\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 614 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 615 | out << "AIBinder* binder = AIBinder_new(" << kClazz << ", static_cast<void*>(this));\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 616 | |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 617 | out << "#ifdef BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 618 | if (defined_type.IsVintfStability()) { |
| 619 | out << "AIBinder_markVintfStability(binder);\n"; |
| 620 | } else { |
| 621 | out << "AIBinder_markCompilationUnitStability(binder);\n"; |
| 622 | } |
Steven Moreland | 88378b1 | 2019-10-11 13:13:24 -0700 | [diff] [blame] | 623 | out << "#endif // BINDER_STABILITY_SUPPORT\n"; |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 624 | |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 625 | out << "return ::ndk::SpAIBinder(binder);\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 626 | out.Dedent(); |
| 627 | out << "}\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 628 | |
| 629 | // Implement the meta methods |
| 630 | for (const auto& method : defined_type.GetMethods()) { |
| 631 | if (method->IsUserDefined()) { |
| 632 | continue; |
| 633 | } |
| 634 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 635 | out << NdkMethodDecl(types, *method, clazz) << " {\n"; |
| 636 | out.Indent(); |
| 637 | out << "*_aidl_return = " << iface << "::" << kVersion << ";\n"; |
| 638 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 639 | out.Dedent(); |
| 640 | out << "}\n"; |
| 641 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 642 | if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 643 | out << NdkMethodDecl(types, *method, clazz) << " {\n"; |
| 644 | out.Indent(); |
| 645 | out << "*_aidl_return = " << iface << "::" << kHash << ";\n"; |
| 646 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 647 | out.Dedent(); |
| 648 | out << "}\n"; |
| 649 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 650 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 651 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 652 | void GenerateInterfaceSource(CodeWriter& out, const AidlTypenames& types, |
| 653 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 654 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 655 | const std::string bp_clazz = ClassName(defined_type, ClassNames::CLIENT); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 656 | |
| 657 | out << "// Source for " << clazz << "\n"; |
Jiyong Park | 27fd7fd | 2020-08-27 16:25:09 +0900 | [diff] [blame] | 658 | out << "const char* " << clazz << "::" << kDescriptor << " = \"" << defined_type.GetDescriptor() |
| 659 | << "\";\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 660 | out << clazz << "::" << clazz << "() {}\n"; |
| 661 | out << clazz << "::~" << clazz << "() {}\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 662 | out << "\n"; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 663 | GenerateConstantDefinitions(out, defined_type); |
| 664 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 665 | |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 666 | out << "std::shared_ptr<" << clazz << "> " << clazz |
| 667 | << "::fromBinder(const ::ndk::SpAIBinder& binder) {\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 668 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 669 | out << "if (!AIBinder_associateClass(binder.get(), " << kClazz << ")) { return nullptr; }\n"; |
| 670 | out << "std::shared_ptr<::ndk::ICInterface> interface = " |
| 671 | "::ndk::ICInterface::asInterface(binder.get());\n"; |
| 672 | out << "if (interface) {\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 673 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 674 | out << "return std::static_pointer_cast<" << clazz << ">(interface);\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 675 | out.Dedent(); |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 676 | out << "}\n"; |
Steven Moreland | c09d34c | 2020-02-13 09:42:49 -0800 | [diff] [blame] | 677 | out << "return ::ndk::SharedRefBase::make<" << bp_clazz << ">(binder);\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 678 | out.Dedent(); |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 679 | out << "}\n\n"; |
| 680 | |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 681 | out << "binder_status_t " << clazz << "::writeToParcel(AParcel* parcel, const std::shared_ptr<" |
| 682 | << clazz << ">& instance) {\n"; |
| 683 | out.Indent(); |
| 684 | out << "return AParcel_writeStrongBinder(parcel, instance ? instance->asBinder().get() : " |
| 685 | "nullptr);\n"; |
| 686 | out.Dedent(); |
| 687 | out << "}\n"; |
| 688 | |
| 689 | out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* parcel, std::shared_ptr<" |
| 690 | << clazz << ">* instance) {\n"; |
| 691 | out.Indent(); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 692 | out << "::ndk::SpAIBinder binder;\n"; |
Steven Moreland | 055d879 | 2018-11-14 12:48:42 -0800 | [diff] [blame] | 693 | out << "binder_status_t status = AParcel_readStrongBinder(parcel, binder.getR());\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 694 | out << "if (status != STATUS_OK) return status;\n"; |
Steven Moreland | 3c316ed | 2019-01-17 09:39:37 -0800 | [diff] [blame] | 695 | out << "*instance = " << clazz << "::fromBinder(binder);\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 696 | out << "return STATUS_OK;\n"; |
| 697 | out.Dedent(); |
| 698 | out << "}\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 699 | |
| 700 | // defintion for static member setDefaultImpl |
| 701 | out << "bool " << clazz << "::setDefaultImpl(std::shared_ptr<" << clazz << "> impl) {\n"; |
| 702 | out.Indent(); |
Jooyung Han | 4a04466 | 2020-05-13 17:17:07 +0900 | [diff] [blame] | 703 | out << "// Only one user of this interface can use this function\n"; |
| 704 | out << "// at a time. This is a heuristic to detect if two different\n"; |
| 705 | out << "// users in the same process use this function.\n"; |
| 706 | out << "assert(!" << clazz << "::default_impl);\n"; |
| 707 | out << "if (impl) {\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 708 | out.Indent(); |
| 709 | out << clazz << "::default_impl = impl;\n"; |
| 710 | out << "return true;\n"; |
| 711 | out.Dedent(); |
| 712 | out << "}\n"; |
| 713 | out << "return false;\n"; |
| 714 | out.Dedent(); |
| 715 | out << "}\n"; |
| 716 | |
| 717 | // definition for static member getDefaultImpl |
| 718 | out << "const std::shared_ptr<" << clazz << ">& " << clazz << "::getDefaultImpl() {\n"; |
| 719 | out.Indent(); |
| 720 | out << "return " << clazz << "::default_impl;\n"; |
| 721 | out.Dedent(); |
| 722 | out << "}\n"; |
| 723 | |
| 724 | // definition for the static field default_impl |
| 725 | out << "std::shared_ptr<" << clazz << "> " << clazz << "::default_impl = nullptr;\n"; |
| 726 | |
| 727 | // default implementation for the <Name>Default class members |
| 728 | const std::string defaultClazz = clazz + "Default"; |
| 729 | for (const auto& method : defined_type.GetMethods()) { |
| 730 | if (method->IsUserDefined()) { |
| 731 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 732 | << NdkArgList(types, *method, FormatArgNameUnused) << ") {\n"; |
| 733 | out.Indent(); |
| 734 | out << "::ndk::ScopedAStatus _aidl_status;\n"; |
| 735 | out << "_aidl_status.set(AStatus_fromStatus(STATUS_UNKNOWN_TRANSACTION));\n"; |
| 736 | out << "return _aidl_status;\n"; |
| 737 | out.Dedent(); |
| 738 | out << "}\n"; |
| 739 | } else { |
| 740 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 741 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 742 | << "int32_t* _aidl_return) {\n"; |
| 743 | out.Indent(); |
| 744 | out << "*_aidl_return = 0;\n"; |
| 745 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 746 | out.Dedent(); |
| 747 | out << "}\n"; |
| 748 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 749 | if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 750 | out << "::ndk::ScopedAStatus " << defaultClazz << "::" << method->GetName() << "(" |
| 751 | << "std::string* _aidl_return) {\n"; |
| 752 | out.Indent(); |
| 753 | out << "*_aidl_return = \"\";\n"; |
| 754 | out << "return ::ndk::ScopedAStatus(AStatus_newOk());\n"; |
| 755 | out.Dedent(); |
| 756 | out << "}\n"; |
| 757 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | out << "::ndk::SpAIBinder " << defaultClazz << "::asBinder() {\n"; |
| 762 | out.Indent(); |
| 763 | out << "return ::ndk::SpAIBinder();\n"; |
| 764 | out.Dedent(); |
| 765 | out << "}\n"; |
| 766 | |
| 767 | out << "bool " << defaultClazz << "::isRemote() {\n"; |
| 768 | out.Indent(); |
| 769 | out << "return false;\n"; |
| 770 | out.Dedent(); |
| 771 | out << "}\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 772 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 773 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 774 | void GenerateClientHeader(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 775 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 776 | const std::string clazz = ClassName(defined_type, ClassNames::CLIENT); |
| 777 | |
| 778 | out << "#pragma once\n\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 779 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 780 | << "\"\n"; |
| 781 | out << "\n"; |
| 782 | out << "#include <android/binder_ibinder.h>\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 783 | if (options.GenLog()) { |
| 784 | out << "#include <json/value.h>\n"; |
| 785 | out << "#include <functional>\n"; |
| 786 | out << "#include <chrono>\n"; |
| 787 | out << "#include <sstream>\n"; |
| 788 | } |
Devin Moore | 7d5a454 | 2020-04-29 15:37:25 -0700 | [diff] [blame] | 789 | if (options.GenTraces()) { |
| 790 | out << "#include <android/trace.h>\n"; |
| 791 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 792 | out << "\n"; |
| 793 | EnterNdkNamespace(out, defined_type); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 794 | out << "class " << clazz << " : public ::ndk::BpCInterface<" |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 795 | << ClassName(defined_type, ClassNames::INTERFACE) << "> {\n"; |
| 796 | out << "public:\n"; |
| 797 | out.Indent(); |
Steven Moreland | 15b3ba7 | 2019-03-06 13:17:08 -0800 | [diff] [blame] | 798 | out << clazz << "(const ::ndk::SpAIBinder& binder);\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 799 | out << "virtual ~" << clazz << "();\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 800 | out << "\n"; |
| 801 | for (const auto& method : defined_type.GetMethods()) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 802 | out << NdkMethodDecl(types, *method) << " override;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 803 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 804 | |
| 805 | if (options.Version() > 0) { |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 806 | out << "int32_t " << kCachedVersion << " = -1;\n"; |
| 807 | } |
| 808 | |
| 809 | if (!options.Hash().empty()) { |
| 810 | out << "std::string " << kCachedHash << " = \"-1\";\n"; |
| 811 | out << "std::mutex " << kCachedHashMutex << ";\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 812 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 813 | if (options.GenLog()) { |
| 814 | out << "static std::function<void(const Json::Value&)> logFunc;\n"; |
| 815 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 816 | out.Dedent(); |
| 817 | out << "};\n"; |
| 818 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 819 | } |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 820 | void GenerateServerHeader(CodeWriter& out, const AidlTypenames& types, |
| 821 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 822 | const std::string clazz = ClassName(defined_type, ClassNames::SERVER); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 823 | const std::string iface = ClassName(defined_type, ClassNames::INTERFACE); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 824 | |
| 825 | out << "#pragma once\n\n"; |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 826 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 827 | << "\"\n"; |
| 828 | out << "\n"; |
| 829 | out << "#include <android/binder_ibinder.h>\n"; |
| 830 | out << "\n"; |
| 831 | EnterNdkNamespace(out, defined_type); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 832 | out << "class " << clazz << " : public ::ndk::BnCInterface<" << iface << "> {\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 833 | out << "public:\n"; |
| 834 | out.Indent(); |
| 835 | out << clazz << "();\n"; |
| 836 | out << "virtual ~" << clazz << "();\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 837 | |
| 838 | // Declare the meta methods |
| 839 | for (const auto& method : defined_type.GetMethods()) { |
| 840 | if (method->IsUserDefined()) { |
| 841 | continue; |
| 842 | } |
| 843 | if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 844 | out << NdkMethodDecl(types, *method) << " final override;\n"; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 845 | } else if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 846 | out << NdkMethodDecl(types, *method) << " final override;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 847 | } else { |
| 848 | AIDL_FATAL(defined_type) << "Meta method '" << method->GetName() << "' is unimplemented."; |
| 849 | } |
| 850 | } |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 851 | if (options.GenLog()) { |
| 852 | out << "static std::function<void(const Json::Value&)> logFunc;\n"; |
| 853 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 854 | out.Dedent(); |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 855 | out << "protected:\n"; |
| 856 | out.Indent(); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 857 | out << "::ndk::SpAIBinder createBinder() override;\n"; |
Steven Moreland | 0cf3f08 | 2018-09-20 19:09:46 -0700 | [diff] [blame] | 858 | out.Dedent(); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 859 | out << "private:\n"; |
| 860 | out.Indent(); |
| 861 | out.Dedent(); |
| 862 | out << "};\n"; |
| 863 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 864 | } |
| 865 | void GenerateInterfaceHeader(CodeWriter& out, const AidlTypenames& types, |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 866 | const AidlInterface& defined_type, const Options& options) { |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 867 | const std::string clazz = ClassName(defined_type, ClassNames::INTERFACE); |
| 868 | |
| 869 | out << "#pragma once\n\n"; |
| 870 | out << "#include <android/binder_interface_utils.h>\n"; |
Jeongik Cha | 37e2ad5 | 2019-04-18 13:44:26 +0900 | [diff] [blame] | 871 | if (options.GenLog()) { |
| 872 | out << "#include <json/value.h>\n"; |
| 873 | out << "#include <functional>\n"; |
| 874 | out << "#include <chrono>\n"; |
| 875 | out << "#include <sstream>\n"; |
| 876 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 877 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 878 | |
| 879 | GenerateHeaderIncludes(out, types, defined_type); |
| 880 | out << "\n"; |
| 881 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 882 | EnterNdkNamespace(out, defined_type); |
Steven Moreland | 6340453 | 2018-10-08 14:31:00 -0700 | [diff] [blame] | 883 | out << "class " << clazz << " : public ::ndk::ICInterface {\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 884 | out << "public:\n"; |
| 885 | out.Indent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 886 | out << "static const char* " << kDescriptor << ";\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 887 | out << clazz << "();\n"; |
| 888 | out << "virtual ~" << clazz << "();\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 889 | out << "\n"; |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 890 | GenerateConstantDeclarations(out, defined_type); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 891 | if (options.Version() > 0) { |
| 892 | out << "static const int32_t " << kVersion << " = " << std::to_string(options.Version()) |
| 893 | << ";\n"; |
| 894 | } |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 895 | if (!options.Hash().empty()) { |
| 896 | out << "static inline const std::string " << kHash << " = \"" << options.Hash() << "\";\n"; |
| 897 | } |
Steven Moreland | ac8fe7f | 2018-10-04 09:58:31 -0700 | [diff] [blame] | 898 | out << "\n"; |
Steven Moreland | 4cb2e6d | 2019-01-18 14:03:43 -0800 | [diff] [blame] | 899 | out << "static std::shared_ptr<" << clazz << "> fromBinder(const ::ndk::SpAIBinder& binder);\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 900 | out << "static binder_status_t writeToParcel(AParcel* parcel, const std::shared_ptr<" << clazz |
| 901 | << ">& instance);"; |
Jiyong Park | 1b88cce | 2018-11-19 19:53:44 +0900 | [diff] [blame] | 902 | out << "\n"; |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 903 | out << "static binder_status_t readFromParcel(const AParcel* parcel, std::shared_ptr<" << clazz |
| 904 | << ">* instance);"; |
| 905 | out << "\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 906 | out << "static bool setDefaultImpl(std::shared_ptr<" << clazz << "> impl);"; |
| 907 | out << "\n"; |
| 908 | out << "static const std::shared_ptr<" << clazz << ">& getDefaultImpl();"; |
| 909 | out << "\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 910 | for (const auto& method : defined_type.GetMethods()) { |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 911 | out << "virtual " << NdkMethodDecl(types, *method) << " = 0;\n"; |
Steven Moreland | aada342 | 2018-09-20 15:55:33 -0700 | [diff] [blame] | 912 | } |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 913 | out.Dedent(); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 914 | out << "private:\n"; |
| 915 | out.Indent(); |
| 916 | out << "static std::shared_ptr<" << clazz << "> default_impl;\n"; |
| 917 | out.Dedent(); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 918 | out << "};\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 919 | |
| 920 | const std::string defaultClazz = clazz + "Default"; |
| 921 | |
| 922 | out << "class " << defaultClazz << " : public " << clazz << " {\n"; |
| 923 | out << "public:\n"; |
| 924 | out.Indent(); |
| 925 | for (const auto& method : defined_type.GetMethods()) { |
| 926 | if (method->IsUserDefined()) { |
| 927 | out << NdkMethodDecl(types, *method) << " override;\n"; |
| 928 | } else if (method->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 929 | out << NdkMethodDecl(types, *method) << " override;\n"; |
Paul Trautrim | b77048c | 2020-01-21 16:39:32 +0900 | [diff] [blame] | 930 | } else if (method->GetName() == kGetInterfaceHash && !options.Hash().empty()) { |
| 931 | out << NdkMethodDecl(types, *method) << " override;\n"; |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | out << "::ndk::SpAIBinder asBinder() override;\n"; |
| 935 | out << "bool isRemote() override;\n"; |
| 936 | out.Dedent(); |
| 937 | out << "};\n"; |
| 938 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 939 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 940 | } |
| 941 | void GenerateParcelHeader(CodeWriter& out, const AidlTypenames& types, |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 942 | const AidlStructuredParcelable& defined_type, |
| 943 | const Options& /*options*/) { |
Steven Moreland | b8df37d | 2019-11-21 12:33:24 -0800 | [diff] [blame] | 944 | const std::string clazz = ClassName(defined_type, ClassNames::RAW); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 945 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 946 | out << "#pragma once\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 947 | out << "#include <android/binder_interface_utils.h>\n"; |
| 948 | out << "\n"; |
| 949 | |
| 950 | GenerateHeaderIncludes(out, types, defined_type); |
Steven Moreland | 2bea13b | 2018-10-03 15:12:33 -0700 | [diff] [blame] | 951 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 952 | EnterNdkNamespace(out, defined_type); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 953 | out << cpp::TemplateDecl(defined_type); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 954 | out << "class " << clazz << " {\n"; |
| 955 | out << "public:\n"; |
| 956 | out.Indent(); |
| 957 | out << "static const char* descriptor;\n"; |
| 958 | out << "\n"; |
| 959 | for (const auto& variable : defined_type.GetFields()) { |
| 960 | out << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << " " << variable->GetName(); |
| 961 | if (variable->GetDefaultValue()) { |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 962 | out << " = " << variable->ValueString(ConstantValueDecorator); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 963 | } |
| 964 | out << ";\n"; |
| 965 | } |
| 966 | out << "\n"; |
| 967 | out << "binder_status_t readFromParcel(const AParcel* parcel);\n"; |
| 968 | out << "binder_status_t writeToParcel(AParcel* parcel) const;\n"; |
Jeongik Cha | 92d33d0 | 2020-05-14 00:53:57 +0900 | [diff] [blame] | 969 | |
| 970 | out << "static const bool _aidl_is_stable = " |
| 971 | << (defined_type.IsVintfStability() ? "true" : "false") << ";\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 972 | out.Dedent(); |
| 973 | out << "};\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 974 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 975 | } |
| 976 | void GenerateParcelSource(CodeWriter& out, const AidlTypenames& types, |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 977 | const AidlStructuredParcelable& defined_type, |
| 978 | const Options& /*options*/) { |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 979 | std::string clazz = ClassName(defined_type, ClassNames::RAW); |
| 980 | if (defined_type.IsGeneric()) { |
| 981 | std::vector<std::string> template_params; |
| 982 | for (const auto& parameter : defined_type.GetTypeParameters()) { |
| 983 | template_params.push_back(parameter); |
| 984 | } |
| 985 | clazz += base::StringPrintf("<%s>", base::Join(template_params, ", ").c_str()); |
| 986 | } |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 987 | |
Jiyong Park | 5b7e532 | 2019-04-03 20:05:01 +0900 | [diff] [blame] | 988 | out << "#include \"" << NdkHeaderFile(defined_type, ClassNames::RAW, false /*use_os_sep*/) |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 989 | << "\"\n"; |
| 990 | out << "\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 991 | GenerateSourceIncludes(out, types, defined_type); |
| 992 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 993 | EnterNdkNamespace(out, defined_type); |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 994 | out << cpp::TemplateDecl(defined_type); |
Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 995 | out << "const char* " << clazz << "::" << kDescriptor << " = \"" |
| 996 | << defined_type.GetCanonicalName() << "\";\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 997 | out << "\n"; |
| 998 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 999 | out << cpp::TemplateDecl(defined_type); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1000 | out << "binder_status_t " << clazz << "::readFromParcel(const AParcel* parcel) {\n"; |
| 1001 | out.Indent(); |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1002 | out << "int32_t _aidl_parcelable_size;\n"; |
Steven Moreland | 4348f9a | 2019-12-16 16:33:01 -0800 | [diff] [blame] | 1003 | out << "int32_t _aidl_start_pos = AParcel_getDataPosition(parcel);\n"; |
| 1004 | 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] | 1005 | 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] | 1006 | out << "if (_aidl_parcelable_size < 0) return STATUS_BAD_VALUE;\n"; |
| 1007 | StatusCheckReturn(out); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1008 | |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1009 | for (const auto& variable : defined_type.GetFields()) { |
| 1010 | out << "_aidl_ret_status = "; |
| 1011 | ReadFromParcelFor({out, types, variable->GetType(), "parcel", "&" + variable->GetName()}); |
| 1012 | out << ";\n"; |
| 1013 | StatusCheckReturn(out); |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1014 | out << "if (AParcel_getDataPosition(parcel) - _aidl_start_pos >= _aidl_parcelable_size) {\n" |
| 1015 | << " AParcel_setDataPosition(parcel, _aidl_start_pos + _aidl_parcelable_size);\n" |
| 1016 | << " return _aidl_ret_status;\n" |
| 1017 | << "}\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1018 | } |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1019 | out << "AParcel_setDataPosition(parcel, _aidl_start_pos + _aidl_parcelable_size);\n" |
| 1020 | << "return _aidl_ret_status;\n"; |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1021 | out.Dedent(); |
| 1022 | out << "}\n"; |
| 1023 | |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 1024 | out << cpp::TemplateDecl(defined_type); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1025 | out << "binder_status_t " << clazz << "::writeToParcel(AParcel* parcel) const {\n"; |
| 1026 | out.Indent(); |
| 1027 | out << "binder_status_t _aidl_ret_status;\n"; |
| 1028 | |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1029 | out << "size_t _aidl_start_pos = AParcel_getDataPosition(parcel);\n"; |
| 1030 | out << "_aidl_ret_status = AParcel_writeInt32(parcel, 0);\n"; |
| 1031 | StatusCheckReturn(out); |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1032 | |
| 1033 | for (const auto& variable : defined_type.GetFields()) { |
| 1034 | out << "_aidl_ret_status = "; |
| 1035 | WriteToParcelFor({out, types, variable->GetType(), "parcel", variable->GetName()}); |
| 1036 | out << ";\n"; |
| 1037 | StatusCheckReturn(out); |
| 1038 | } |
Jeongik Cha | 95eba57 | 2018-11-22 09:14:52 +0900 | [diff] [blame] | 1039 | out << "size_t _aidl_end_pos = AParcel_getDataPosition(parcel);\n"; |
| 1040 | out << "AParcel_setDataPosition(parcel, _aidl_start_pos);\n"; |
| 1041 | out << "AParcel_writeInt32(parcel, _aidl_end_pos - _aidl_start_pos);\n"; |
| 1042 | out << "AParcel_setDataPosition(parcel, _aidl_end_pos);\n"; |
| 1043 | |
Steven Moreland | bb8f46c | 2018-10-03 17:38:00 -0700 | [diff] [blame] | 1044 | out << "return _aidl_ret_status;\n"; |
| 1045 | out.Dedent(); |
| 1046 | out << "}\n"; |
| 1047 | out << "\n"; |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1048 | LeaveNdkNamespace(out, defined_type); |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1049 | } |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1050 | |
Daniel Norman | 455d95c | 2019-11-19 09:55:39 -0800 | [diff] [blame] | 1051 | std::string GenerateEnumToString(const AidlTypenames& typenames, |
| 1052 | const AidlEnumDeclaration& enum_decl) { |
| 1053 | std::ostringstream code; |
| 1054 | code << "static inline std::string toString(" << enum_decl.GetName() << " val) {\n"; |
| 1055 | code << " switch(val) {\n"; |
| 1056 | std::set<std::string> unique_cases; |
| 1057 | for (const auto& enumerator : enum_decl.GetEnumerators()) { |
| 1058 | std::string c = enumerator->ValueString(enum_decl.GetBackingType(), ConstantValueDecorator); |
| 1059 | // Only add a case if its value has not yet been used in the switch |
| 1060 | // statement. C++ does not allow multiple cases with the same value, but |
| 1061 | // enums does allow this. In this scenario, the first declared |
| 1062 | // enumerator with the given value is printed. |
| 1063 | if (unique_cases.count(c) == 0) { |
| 1064 | unique_cases.insert(c); |
| 1065 | code << " case " << enum_decl.GetName() << "::" << enumerator->GetName() << ":\n"; |
| 1066 | code << " return \"" << enumerator->GetName() << "\";\n"; |
| 1067 | } |
| 1068 | } |
| 1069 | code << " default:\n"; |
| 1070 | code << " return std::to_string(static_cast<" |
| 1071 | << NdkNameOf(typenames, enum_decl.GetBackingType(), StorageMode::STACK) << ">(val));\n"; |
| 1072 | code << " }\n"; |
| 1073 | code << "}\n"; |
| 1074 | return code.str(); |
| 1075 | } |
| 1076 | |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1077 | void GenerateEnumHeader(CodeWriter& out, const AidlTypenames& types, |
| 1078 | const AidlEnumDeclaration& enum_decl, const Options& /*options*/) { |
| 1079 | out << "#pragma once\n"; |
| 1080 | out << "\n"; |
| 1081 | |
| 1082 | GenerateHeaderIncludes(out, types, enum_decl); |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 1083 | // enum specific headers |
| 1084 | out << "#include <array>\n"; |
| 1085 | out << "#include <android/binder_enums.h>\n"; |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1086 | |
| 1087 | EnterNdkNamespace(out, enum_decl); |
| 1088 | out << "enum class " << enum_decl.GetName() << " : " |
| 1089 | << NdkNameOf(types, enum_decl.GetBackingType(), StorageMode::STACK) << " {\n"; |
| 1090 | out.Indent(); |
| 1091 | for (const auto& enumerator : enum_decl.GetEnumerators()) { |
| 1092 | out << enumerator->GetName() << " = " |
| 1093 | << enumerator->ValueString(enum_decl.GetBackingType(), ConstantValueDecorator) << ",\n"; |
| 1094 | } |
| 1095 | out.Dedent(); |
| 1096 | out << "};\n"; |
Daniel Norman | 455d95c | 2019-11-19 09:55:39 -0800 | [diff] [blame] | 1097 | out << "\n"; |
| 1098 | out << GenerateEnumToString(types, enum_decl); |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1099 | LeaveNdkNamespace(out, enum_decl); |
Jooyung Han | 7a9aceb | 2019-12-17 14:18:15 +0000 | [diff] [blame] | 1100 | |
| 1101 | out << "namespace ndk {\n"; |
| 1102 | out << "namespace internal {\n"; |
| 1103 | out << cpp::GenerateEnumValues(enum_decl, {"aidl"}); |
| 1104 | out << "} // namespace internal\n"; |
| 1105 | out << "} // namespace android\n"; |
Daniel Norman | 37d43dd | 2019-09-09 17:22:34 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Steven Moreland | b0057e7 | 2018-08-27 01:44:11 -0700 | [diff] [blame] | 1108 | } // namespace internals |
| 1109 | } // namespace ndk |
| 1110 | } // namespace aidl |
| 1111 | } // namespace android |