SerializeFlags.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2017 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. #ifndef ANDROID_VINTF_SERIALIZE_FLAGS_H
  17. #define ANDROID_VINTF_SERIALIZE_FLAGS_H
  18. #include <stdint.h>
  19. namespace android {
  20. namespace vintf {
  21. namespace SerializeFlags {
  22. class Type {
  23. public:
  24. explicit constexpr Type(uint32_t value) : mValue(value) {}
  25. #define VINTF_SERIALIZE_FLAGS_FIELD(name, bit) \
  26. constexpr Type enable##name() const { return Type(mValue | (1 << bit)); } \
  27. constexpr Type disable##name() const { return Type(mValue & ~(1 << bit)); } \
  28. constexpr bool is##name##Enabled() const { return mValue & (1 << bit); }
  29. VINTF_SERIALIZE_FLAGS_FIELD(Hals, 0)
  30. VINTF_SERIALIZE_FLAGS_FIELD(Avb, 1)
  31. VINTF_SERIALIZE_FLAGS_FIELD(Sepolicy, 2)
  32. VINTF_SERIALIZE_FLAGS_FIELD(Vndk, 3)
  33. VINTF_SERIALIZE_FLAGS_FIELD(Kernel, 4)
  34. VINTF_SERIALIZE_FLAGS_FIELD(XmlFiles, 5)
  35. VINTF_SERIALIZE_FLAGS_FIELD(Ssdk, 6)
  36. VINTF_SERIALIZE_FLAGS_FIELD(Fqname, 7)
  37. VINTF_SERIALIZE_FLAGS_FIELD(KernelConfigs, 8)
  38. VINTF_SERIALIZE_FLAGS_FIELD(KernelMinorRevision, 9)
  39. VINTF_SERIALIZE_FLAGS_FIELD(MetaVersion, 10)
  40. VINTF_SERIALIZE_FLAGS_FIELD(SchemaType, 11)
  41. #undef VINTF_SERIALIZE_FLAGS_FIELD
  42. private:
  43. uint32_t mValue;
  44. };
  45. constexpr Type EVERYTHING = Type(~0);
  46. constexpr Type NO_HALS = EVERYTHING.disableHals();
  47. constexpr Type NO_AVB = EVERYTHING.disableAvb();
  48. constexpr Type NO_SEPOLICY = EVERYTHING.disableSepolicy();
  49. constexpr Type NO_VNDK = EVERYTHING.disableVndk();
  50. constexpr Type NO_KERNEL = EVERYTHING.disableKernel();
  51. constexpr Type NO_XMLFILES = EVERYTHING.disableXmlFiles();
  52. constexpr Type NO_SSDK = EVERYTHING.disableSsdk();
  53. constexpr Type NO_FQNAME = EVERYTHING.disableFqname();
  54. constexpr Type NO_KERNEL_CONFIGS = EVERYTHING.disableKernelConfigs();
  55. constexpr Type NO_KERNEL_MINOR_REVISION = EVERYTHING.disableKernelMinorRevision();
  56. constexpr Type NO_TAGS = Type(0).enableMetaVersion().enableSchemaType();
  57. constexpr Type HALS_ONLY = NO_TAGS.enableHals().enableFqname(); // <hal> with <fqname>
  58. constexpr Type XMLFILES_ONLY = NO_TAGS.enableXmlFiles();
  59. constexpr Type SEPOLICY_ONLY = NO_TAGS.enableSepolicy();
  60. constexpr Type VNDK_ONLY = NO_TAGS.enableVndk();
  61. constexpr Type HALS_NO_FQNAME = NO_TAGS.enableHals(); // <hal> without <fqname>
  62. constexpr Type SSDK_ONLY = NO_TAGS.enableSsdk();
  63. // tests
  64. static_assert(EVERYTHING.isHalsEnabled(), "");
  65. static_assert(EVERYTHING.isMetaVersionEnabled(), "");
  66. static_assert(!NO_HALS.isHalsEnabled(), "");
  67. static_assert(NO_HALS.isAvbEnabled(), "");
  68. static_assert(NO_HALS.isMetaVersionEnabled(), "");
  69. static_assert(!NO_TAGS.isHalsEnabled(), "");
  70. static_assert(NO_TAGS.isMetaVersionEnabled(), "");
  71. static_assert(HALS_ONLY.isHalsEnabled(), "");
  72. static_assert(!HALS_ONLY.isAvbEnabled(), "");
  73. static_assert(HALS_ONLY.isMetaVersionEnabled(), "");
  74. } // namespace SerializeFlags
  75. } // namespace vintf
  76. } // namespace android
  77. #endif // ANDROID_VINTF_SERIALIZE_FLAGS_H