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