blob: 467d0e11fb1b66388ef1de6f0bb1ae2eecf7b3bb [file] [log] [blame]
François Gaffiea56b5c22018-02-21 18:04:39 +01001/*
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
24struct _xmlNode;
25struct _xmlDoc;
26
27namespace android {
28namespace audio_policy {
29namespace wrapper_config {
30
31/** Default path of audio policy usages configuration file. */
32constexpr char DEFAULT_PATH[] = "/vendor/etc/policy_wrapper_configuration.xml";
33
34/** Directories where the effect libraries will be search for. */
35constexpr const char* POLICY_USAGE_LIBRARY_PATH[] = {"/odm/etc/", "/vendor/etc/", "/system/etc/"};
36
37using ValuePair = std::pair<uint32_t, std::string>;
38using ValuePairs = std::vector<ValuePair>;
39
40struct CriterionType
41{
42 std::string name;
43 bool isInclusive;
44 ValuePairs valuePairs;
45};
46
47using CriterionTypes = std::vector<CriterionType>;
48
49struct Criterion
50{
51 std::string name;
52 std::string typeName;
53 std::string defaultLiteralValue;
54};
55
56using Criteria = std::vector<Criterion>;
57
58struct Config {
59 float version;
60 Criteria criteria;
61 CriterionTypes criterionTypes;
62};
63
64namespace detail
65{
66struct 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
85struct 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
104struct 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*)` */
126struct 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 */
135ParsingResult parse(const char* path = DEFAULT_PATH);
136
137} // namespace wrapper_config
138} // namespace audio_policy
139} // android