François Gaffie | a56b5c2 | 2018-02-21 18:04:39 +0100 | [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 | #pragma once |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | #include <utils/Errors.h> |
| 23 | |
| 24 | struct _xmlNode; |
| 25 | struct _xmlDoc; |
| 26 | |
| 27 | namespace android { |
| 28 | namespace audio_policy { |
| 29 | namespace wrapper_config { |
| 30 | |
| 31 | /** Default path of audio policy usages configuration file. */ |
| 32 | constexpr char DEFAULT_PATH[] = "/vendor/etc/policy_wrapper_configuration.xml"; |
| 33 | |
| 34 | /** Directories where the effect libraries will be search for. */ |
| 35 | constexpr const char* POLICY_USAGE_LIBRARY_PATH[] = {"/odm/etc/", "/vendor/etc/", "/system/etc/"}; |
| 36 | |
| 37 | using ValuePair = std::pair<uint32_t, std::string>; |
| 38 | using ValuePairs = std::vector<ValuePair>; |
| 39 | |
| 40 | struct CriterionType |
| 41 | { |
| 42 | std::string name; |
| 43 | bool isInclusive; |
| 44 | ValuePairs valuePairs; |
| 45 | }; |
| 46 | |
| 47 | using CriterionTypes = std::vector<CriterionType>; |
| 48 | |
| 49 | struct Criterion |
| 50 | { |
| 51 | std::string name; |
| 52 | std::string typeName; |
| 53 | std::string defaultLiteralValue; |
| 54 | }; |
| 55 | |
| 56 | using Criteria = std::vector<Criterion>; |
| 57 | |
| 58 | struct Config { |
| 59 | float version; |
| 60 | Criteria criteria; |
| 61 | CriterionTypes criterionTypes; |
| 62 | }; |
| 63 | |
| 64 | namespace detail |
| 65 | { |
| 66 | struct ValueTraits |
| 67 | { |
| 68 | static const char *const tag; |
| 69 | static const char *const collectionTag; |
| 70 | |
| 71 | struct Attributes |
| 72 | { |
| 73 | static const char literal[]; |
| 74 | static const char numerical[]; |
| 75 | }; |
| 76 | |
| 77 | typedef ValuePair Element; |
| 78 | typedef ValuePair *PtrElement; |
| 79 | typedef ValuePairs Collection; |
| 80 | |
| 81 | static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root, |
| 82 | Collection &collection); |
| 83 | }; |
| 84 | |
| 85 | struct CriterionTypeTraits |
| 86 | { |
| 87 | static const char *const tag; |
| 88 | static const char *const collectionTag; |
| 89 | |
| 90 | struct Attributes |
| 91 | { |
| 92 | static const char name[]; |
| 93 | static const char type[]; |
| 94 | }; |
| 95 | |
| 96 | typedef CriterionType Element; |
| 97 | typedef CriterionType *PtrElement; |
| 98 | typedef CriterionTypes Collection; |
| 99 | |
| 100 | static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root, |
| 101 | Collection &collection); |
| 102 | }; |
| 103 | |
| 104 | struct CriterionTraits |
| 105 | { |
| 106 | static const char *const tag; |
| 107 | static const char *const collectionTag; |
| 108 | |
| 109 | struct Attributes |
| 110 | { |
| 111 | static const char name[]; |
| 112 | static const char type[]; |
| 113 | static const char defaultVal[]; |
| 114 | }; |
| 115 | |
| 116 | typedef Criterion Element; |
| 117 | typedef Criterion *PtrElement; |
| 118 | typedef Criteria Collection; |
| 119 | |
| 120 | static android::status_t deserialize(_xmlDoc *doc, const _xmlNode *root, |
| 121 | Collection &collection); |
| 122 | }; |
| 123 | } // namespace detail |
| 124 | |
| 125 | /** Result of `parse(const char*)` */ |
| 126 | struct ParsingResult { |
| 127 | /** Parsed config, nullptr if the xml lib could not load the file */ |
| 128 | std::unique_ptr<Config> parsedConfig; |
| 129 | size_t nbSkippedElement; //< Number of skipped invalid product strategies |
| 130 | }; |
| 131 | |
| 132 | /** Parses the provided audio policy usage configuration. |
| 133 | * @return audio policy usage @see Config |
| 134 | */ |
| 135 | ParsingResult parse(const char* path = DEFAULT_PATH); |
| 136 | |
| 137 | } // namespace wrapper_config |
| 138 | } // namespace audio_policy |
| 139 | } // android |