aidl_to_ndk.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #pragma once
  17. #include "aidl_language.h"
  18. #include "aidl_to_cpp_common.h"
  19. namespace android {
  20. namespace aidl {
  21. namespace ndk {
  22. enum class StorageMode {
  23. STACK,
  24. ARGUMENT, // Value for primitives, const& for larger types
  25. OUT_ARGUMENT, // Pointer to raw type
  26. };
  27. std::string NdkHeaderFile(const AidlDefinedType& defined_type, cpp::ClassNames name,
  28. bool use_os_sep = true);
  29. // Returns ::aidl::some_package::some_sub_package::foo::IFoo/BpFoo/BnFoo
  30. std::string NdkFullClassName(const AidlDefinedType& type, cpp::ClassNames name);
  31. // Returns the corresponding Ndk type name for an AIDL type spec including
  32. // array modifiers.
  33. std::string NdkNameOf(const AidlTypenames& types, const AidlTypeSpecifier& aidl, StorageMode mode);
  34. struct CodeGeneratorContext {
  35. CodeWriter& writer;
  36. const AidlTypenames& types;
  37. const AidlTypeSpecifier& type;
  38. const string parcel;
  39. const string var;
  40. };
  41. void WriteToParcelFor(const CodeGeneratorContext& c);
  42. void ReadFromParcelFor(const CodeGeneratorContext& c);
  43. // Returns argument list of a method where each arg is formatted by the fomatter
  44. std::string NdkArgList(
  45. const AidlTypenames& types, const AidlMethod& method,
  46. std::function<std::string(const std::string& type, const std::string& name, bool isOut)>
  47. formatter);
  48. inline std::string FormatArgForDecl(const std::string& type, const std::string& name,
  49. bool /*isOut*/) {
  50. return type + " " + name;
  51. }
  52. inline std::string FormatArgNameUnused(const std::string& type, const std::string& name,
  53. bool /*isOut*/) {
  54. return type + " /*" + name + "*/";
  55. }
  56. inline std::string FormatArgForCall(const std::string& /*type*/, const std::string& name,
  57. bool isOut) {
  58. std::string reference_prefix = isOut ? "&" : "";
  59. return reference_prefix + name;
  60. }
  61. inline std::string FormatArgNameOnly(const std::string& /*type*/, const std::string& name,
  62. bool /*isOut*/) {
  63. return name;
  64. }
  65. // -> 'status (class::)name(type name, ...)' for a method
  66. std::string NdkMethodDecl(const AidlTypenames& types, const AidlMethod& method,
  67. const std::string& clazz = "");
  68. } // namespace ndk
  69. } // namespace aidl
  70. } // namespace android