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 #ifndef ANDROID_HARDWARE_VERSION_MACRO_H
18 #define ANDROID_HARDWARE_VERSION_MACRO_H
19 
20 #if !defined(MAJOR_VERSION) || !defined(MINOR_VERSION)
21 #error "MAJOR_VERSION and MINOR_VERSION must be defined"
22 #endif
23 
24 #ifndef COMMON_TYPES_MINOR_VERSION
25 #define COMMON_TYPES_MINOR_VERSION MINOR_VERSION
26 #endif
27 
28 #ifndef CORE_TYPES_MINOR_VERSION
29 #define CORE_TYPES_MINOR_VERSION MINOR_VERSION
30 #endif
31 
32 /** Allows macro expansion for x and add surrounding `<>`.
33  * Is intended to be used for version dependant includes as
34  * `#include` do not macro expand if starting with < or "
35  * Example usage:
36  *      #include PATH(path/to/FILE_VERSION/file)
37  * @note: uses the implementation-define "Computed Includes" feature.
38  */
39 #define PATH(x) <x>
40 
41 #define CONCAT_3(a, b, c) a##b##c
42 #define EXPAND_CONCAT_3(a, b, c) CONCAT_3(a, b, c)
43 /** The directory name of the version: <major>.<minor> */
44 #define FILE_VERSION EXPAND_CONCAT_3(MAJOR_VERSION, ., MINOR_VERSION)
45 #define COMMON_TYPES_FILE_VERSION EXPAND_CONCAT_3(MAJOR_VERSION, ., COMMON_TYPES_MINOR_VERSION)
46 #define CORE_TYPES_FILE_VERSION EXPAND_CONCAT_3(MAJOR_VERSION, ., CORE_TYPES_MINOR_VERSION)
47 
48 #define CONCAT_4(a, b, c, d) a##b##c##d
49 #define EXPAND_CONCAT_4(a, b, c, d) CONCAT_4(a, b, c, d)
50 /** The c++ namespace of the version: V<major>_<minor> */
51 #define CPP_VERSION EXPAND_CONCAT_4(V, MAJOR_VERSION, _, MINOR_VERSION)
52 #define COMMON_TYPES_CPP_VERSION EXPAND_CONCAT_4(V, MAJOR_VERSION, _, COMMON_TYPES_MINOR_VERSION)
53 #define CORE_TYPES_CPP_VERSION EXPAND_CONCAT_4(V, MAJOR_VERSION, _, CORE_TYPES_MINOR_VERSION)
54 
55 /* Gluing these file names from macros is non-trivial due to "illegal tokens"
56    occurring during expansion. The XSD and enums always use the minor version. */
57 // clang-format off
58 #if MAJOR_VERSION >= 7
59 #if MINOR_VERSION == 0
60 #define APM_XSD_H_FILENAME android_audio_policy_configuration_V7_0.h
61 #define APM_XSD_ENUMS_H_FILENAME android_audio_policy_configuration_V7_0-enums.h
62 #elif MINOR_VERSION == 1
63 #define APM_XSD_H_FILENAME android_audio_policy_configuration_V7_1.h
64 #define APM_XSD_ENUMS_H_FILENAME android_audio_policy_configuration_V7_1-enums.h
65 #else
66 #error "Unsupported minor version"
67 #endif
68 #endif
69 // clang-format on
70 
71 #endif  // ANDROID_HARDWARE_VERSION_MACRO_H
72