1 #ifndef ANDROID_AUDIO_POLICY_ENGINE_CONFIGURATION_H 2 #define ANDROID_AUDIO_POLICY_ENGINE_CONFIGURATION_H 3 4 #include <array> 5 #include <map> 6 #include <optional> 7 #include <string> 8 #include <vector> 9 #include <sstream> 10 11 #if __has_include(<libxml/parser.h>) 12 #include <libxml/parser.h> 13 #include <libxml/xinclude.h> 14 #else 15 #error Require libxml2 library. Please add libxml2 to shared_libs or static_libs 16 #endif 17 18 #include "android_audio_policy_engine_configuration_enums.h" 19 20 namespace android { 21 namespace audio { 22 namespace policy { 23 namespace engine { 24 namespace configuration { 25 class ProductStrategies; 26 class AttributesGroup; 27 class VolumeGroupsType; 28 class VolumesType; 29 class AttributesRef; 30 class CriteriaType; 31 class CriterionType; 32 class CriterionTypesType; 33 class CriterionTypeType; 34 class ValuesType; 35 class ValueType; 36 class AttributesRefType; 37 class AttributesType; 38 class ContentTypeType; 39 class UsageType; 40 class SourceType; 41 class FlagsType; 42 class BundleType; 43 class Volume; 44 class VolumeRef; 45 class Configuration; 46 std::optional<Configuration> read(const char* configFile); 47 48 std::optional<Configuration> parse(const char* xml); 49 50 class ProductStrategies { 51 public: 52 class ProductStrategy { 53 private: 54 const std::vector<AttributesGroup> attributesGroup_; 55 const std::string name_; 56 const int id_; 57 public: 58 ProductStrategy(std::vector<AttributesGroup> attributesGroup, std::string name, int id); 59 const std::vector<AttributesGroup>& getAttributesGroup() const; 60 bool hasAttributesGroup() const; 61 const AttributesGroup* getFirstAttributesGroup() const; 62 const std::string& getName() const; 63 bool hasName() const; 64 const int& getId() const; 65 bool hasId() const; 66 static ProductStrategies::ProductStrategy read(xmlNode *root); 67 }; 68 69 70 private: 71 const std::vector<ProductStrategies::ProductStrategy> productStrategy_; 72 public: 73 explicit ProductStrategies(std::vector<ProductStrategy> productStrategy); 74 const std::vector<ProductStrategies::ProductStrategy>& getProductStrategy() const; 75 bool hasProductStrategy() const; 76 const ProductStrategies::ProductStrategy* getFirstProductStrategy() const; 77 static ProductStrategies read(xmlNode *root); 78 }; 79 80 class AttributesGroup { 81 private: 82 const std::vector<AttributesType> attributes_optional_; 83 const std::vector<ContentTypeType> contentType_optional_; 84 const std::vector<UsageType> usage_optional_; 85 const std::vector<SourceType> source_optional_; 86 const std::vector<FlagsType> flags_optional_; 87 const std::vector<BundleType> bundle_optional_; 88 const std::optional<Stream> streamType_; 89 const std::optional<std::string> volumeGroup_; 90 public: 91 AttributesGroup(std::vector<AttributesType> attributes_optional, std::vector<ContentTypeType> contentType_optional, std::vector<UsageType> usage_optional, std::vector<SourceType> source_optional, std::vector<FlagsType> flags_optional, std::vector<BundleType> bundle_optional, std::optional<Stream> streamType, std::optional<std::string> volumeGroup); 92 const std::vector<AttributesType>& getAttributes_optional() const; 93 bool hasAttributes_optional() const; 94 const AttributesType* getFirstAttributes_optional() const; 95 const std::vector<ContentTypeType>& getContentType_optional() const; 96 bool hasContentType_optional() const; 97 const ContentTypeType* getFirstContentType_optional() const; 98 const std::vector<UsageType>& getUsage_optional() const; 99 bool hasUsage_optional() const; 100 const UsageType* getFirstUsage_optional() const; 101 const std::vector<SourceType>& getSource_optional() const; 102 bool hasSource_optional() const; 103 const SourceType* getFirstSource_optional() const; 104 const std::vector<FlagsType>& getFlags_optional() const; 105 bool hasFlags_optional() const; 106 const FlagsType* getFirstFlags_optional() const; 107 const std::vector<BundleType>& getBundle_optional() const; 108 bool hasBundle_optional() const; 109 const BundleType* getFirstBundle_optional() const; 110 const Stream& getStreamType() const; 111 bool hasStreamType() const; 112 const std::string& getVolumeGroup() const; 113 bool hasVolumeGroup() const; 114 static AttributesGroup read(xmlNode *root); 115 }; 116 117 class VolumeGroupsType { 118 public: 119 class VolumeGroup { 120 private: 121 const std::optional<std::string> name_; 122 const std::optional<int> indexMin_; 123 const std::optional<int> indexMax_; 124 const std::vector<Volume> volume_; 125 public: 126 VolumeGroup(std::optional<std::string> name, std::optional<int> indexMin, std::optional<int> indexMax, std::vector<Volume> volume); 127 const std::string& getName() const; 128 bool hasName() const; 129 const int& getIndexMin() const; 130 bool hasIndexMin() const; 131 const int& getIndexMax() const; 132 bool hasIndexMax() const; 133 const std::vector<Volume>& getVolume() const; 134 bool hasVolume() const; 135 const Volume* getFirstVolume() const; 136 static VolumeGroupsType::VolumeGroup read(xmlNode *root); 137 }; 138 139 140 private: 141 const std::vector<VolumeGroupsType::VolumeGroup> volumeGroup_; 142 public: 143 explicit VolumeGroupsType(std::vector<VolumeGroup> volumeGroup); 144 const std::vector<VolumeGroupsType::VolumeGroup>& getVolumeGroup() const; 145 bool hasVolumeGroup() const; 146 const VolumeGroupsType::VolumeGroup* getFirstVolumeGroup() const; 147 static VolumeGroupsType read(xmlNode *root); 148 }; 149 150 class VolumesType { 151 private: 152 const std::vector<VolumeRef> reference_; 153 public: 154 explicit VolumesType(std::vector<VolumeRef> reference); 155 const std::vector<VolumeRef>& getReference() const; 156 bool hasReference() const; 157 const VolumeRef* getFirstReference() const; 158 static VolumesType read(xmlNode *root); 159 }; 160 161 class AttributesRef { 162 private: 163 const std::vector<AttributesRefType> reference_; 164 public: 165 explicit AttributesRef(std::vector<AttributesRefType> reference); 166 const std::vector<AttributesRefType>& getReference() const; 167 bool hasReference() const; 168 const AttributesRefType* getFirstReference() const; 169 static AttributesRef read(xmlNode *root); 170 }; 171 172 class CriteriaType { 173 private: 174 const std::vector<CriterionType> criterion_; 175 public: 176 explicit CriteriaType(std::vector<CriterionType> criterion); 177 const std::vector<CriterionType>& getCriterion() const; 178 bool hasCriterion() const; 179 const CriterionType* getFirstCriterion() const; 180 static CriteriaType read(xmlNode *root); 181 }; 182 183 class CriterionType { 184 private: 185 const std::string name_; 186 const std::string type_; 187 const std::optional<std::string> _default_; 188 public: 189 CriterionType(std::string name, std::string type, std::optional<std::string> _default); 190 const std::string& getName() const; 191 bool hasName() const; 192 const std::string& getType() const; 193 bool hasType() const; 194 const std::string& get_default() const; 195 bool has_default() const; 196 static CriterionType read(xmlNode *root); 197 }; 198 199 class CriterionTypesType { 200 private: 201 const std::vector<CriterionTypeType> criterion_type_; 202 public: 203 explicit CriterionTypesType(std::vector<CriterionTypeType> criterion_type); 204 const std::vector<CriterionTypeType>& getCriterion_type() const; 205 bool hasCriterion_type() const; 206 const CriterionTypeType* getFirstCriterion_type() const; 207 static CriterionTypesType read(xmlNode *root); 208 }; 209 210 class CriterionTypeType { 211 private: 212 const std::vector<ValuesType> values_; 213 const std::string name_; 214 const PfwCriterionTypeEnum type_; 215 public: 216 CriterionTypeType(std::vector<ValuesType> values, std::string name, PfwCriterionTypeEnum type); 217 const std::vector<ValuesType>& getValues() const; 218 bool hasValues() const; 219 const ValuesType* getFirstValues() const; 220 const std::string& getName() const; 221 bool hasName() const; 222 const PfwCriterionTypeEnum& getType() const; 223 bool hasType() const; 224 static CriterionTypeType read(xmlNode *root); 225 }; 226 227 class ValuesType { 228 private: 229 const std::vector<ValueType> value_; 230 public: 231 explicit ValuesType(std::vector<ValueType> value); 232 const std::vector<ValueType>& getValue() const; 233 bool hasValue() const; 234 const ValueType* getFirstValue() const; 235 static ValuesType read(xmlNode *root); 236 }; 237 238 class ValueType { 239 private: 240 const std::string literal_; 241 const std::optional<std::string> android_type_; 242 public: 243 ValueType(std::string literal, std::optional<std::string> android_type); 244 const std::string& getLiteral() const; 245 bool hasLiteral() const; 246 const std::string& getAndroid_type() const; 247 bool hasAndroid_type() const; 248 static ValueType read(xmlNode *root); 249 }; 250 251 class AttributesRefType { 252 private: 253 const std::vector<AttributesType> attributes_; 254 const std::string name_; 255 public: 256 AttributesRefType(std::vector<AttributesType> attributes, std::string name); 257 const std::vector<AttributesType>& getAttributes() const; 258 bool hasAttributes() const; 259 const AttributesType* getFirstAttributes() const; 260 const std::string& getName() const; 261 bool hasName() const; 262 static AttributesRefType read(xmlNode *root); 263 }; 264 265 class AttributesType { 266 private: 267 const std::vector<ContentTypeType> contentType_; 268 const std::vector<UsageType> usage_; 269 const std::vector<SourceType> source_; 270 const std::vector<FlagsType> flags_; 271 const std::vector<BundleType> bundle_; 272 const std::optional<std::string> attributesRef_; 273 public: 274 AttributesType(std::vector<ContentTypeType> contentType, std::vector<UsageType> usage, std::vector<SourceType> source, std::vector<FlagsType> flags, std::vector<BundleType> bundle, std::optional<std::string> attributesRef); 275 const std::vector<ContentTypeType>& getContentType() const; 276 bool hasContentType() const; 277 const ContentTypeType* getFirstContentType() const; 278 const std::vector<UsageType>& getUsage() const; 279 bool hasUsage() const; 280 const UsageType* getFirstUsage() const; 281 const std::vector<SourceType>& getSource() const; 282 bool hasSource() const; 283 const SourceType* getFirstSource() const; 284 const std::vector<FlagsType>& getFlags() const; 285 bool hasFlags() const; 286 const FlagsType* getFirstFlags() const; 287 const std::vector<BundleType>& getBundle() const; 288 bool hasBundle() const; 289 const BundleType* getFirstBundle() const; 290 const std::string& getAttributesRef() const; 291 bool hasAttributesRef() const; 292 static AttributesType read(xmlNode *root); 293 }; 294 295 class ContentTypeType { 296 private: 297 const ContentType value_; 298 public: 299 explicit ContentTypeType(ContentType value); 300 const ContentType& getValue() const; 301 bool hasValue() const; 302 static ContentTypeType read(xmlNode *root); 303 }; 304 305 class UsageType { 306 private: 307 const UsageEnumType value_; 308 public: 309 explicit UsageType(UsageEnumType value); 310 const UsageEnumType& getValue() const; 311 bool hasValue() const; 312 static UsageType read(xmlNode *root); 313 }; 314 315 class SourceType { 316 private: 317 const SourceEnumType value_; 318 public: 319 explicit SourceType(SourceEnumType value); 320 const SourceEnumType& getValue() const; 321 bool hasValue() const; 322 static SourceType read(xmlNode *root); 323 }; 324 325 class FlagsType { 326 private: 327 const std::vector<FlagType> value_; 328 public: 329 explicit FlagsType(std::vector<FlagType> value); 330 const std::vector<FlagType>& getValue() const; 331 bool hasValue() const; 332 static FlagsType read(xmlNode *root); 333 }; 334 335 class BundleType { 336 private: 337 const std::string key_; 338 const std::string value_; 339 public: 340 BundleType(std::string key, std::string value); 341 const std::string& getKey() const; 342 bool hasKey() const; 343 const std::string& getValue() const; 344 bool hasValue() const; 345 static BundleType read(xmlNode *root); 346 }; 347 348 class Volume { 349 private: 350 const std::vector<std::string> point_; 351 const std::optional<DeviceCategory> deviceCategory_; 352 const std::optional<std::string> ref_; 353 public: 354 Volume(std::vector<std::string> point, std::optional<DeviceCategory> deviceCategory, std::optional<std::string> ref); 355 const std::vector<std::string>& getPoint() const; 356 bool hasPoint() const; 357 const std::string* getFirstPoint() const; 358 const DeviceCategory& getDeviceCategory() const; 359 bool hasDeviceCategory() const; 360 const std::string& getRef() const; 361 bool hasRef() const; 362 static Volume read(xmlNode *root); 363 }; 364 365 class VolumeRef { 366 private: 367 const std::vector<std::string> point_; 368 const std::string name_; 369 public: 370 VolumeRef(std::vector<std::string> point, std::string name); 371 const std::vector<std::string>& getPoint() const; 372 bool hasPoint() const; 373 const std::string* getFirstPoint() const; 374 const std::string& getName() const; 375 bool hasName() const; 376 static VolumeRef read(xmlNode *root); 377 }; 378 379 class Configuration { 380 private: 381 const std::vector<ProductStrategies> productStrategies_; 382 const std::vector<CriterionTypesType> criterion_types_; 383 const std::vector<CriteriaType> criteria_; 384 const std::vector<VolumeGroupsType> volumeGroups_; 385 const std::vector<VolumesType> volumes_; 386 const std::vector<AttributesRef> attributesRef_; 387 const Version version_; 388 public: 389 Configuration(std::vector<ProductStrategies> productStrategies, std::vector<CriterionTypesType> criterion_types, std::vector<CriteriaType> criteria, std::vector<VolumeGroupsType> volumeGroups, std::vector<VolumesType> volumes, std::vector<AttributesRef> attributesRef, Version version); 390 const std::vector<ProductStrategies>& getProductStrategies() const; 391 bool hasProductStrategies() const; 392 const ProductStrategies* getFirstProductStrategies() const; 393 const std::vector<CriterionTypesType>& getCriterion_types() const; 394 bool hasCriterion_types() const; 395 const CriterionTypesType* getFirstCriterion_types() const; 396 const std::vector<CriteriaType>& getCriteria() const; 397 bool hasCriteria() const; 398 const CriteriaType* getFirstCriteria() const; 399 const std::vector<VolumeGroupsType>& getVolumeGroups() const; 400 bool hasVolumeGroups() const; 401 const VolumeGroupsType* getFirstVolumeGroups() const; 402 const std::vector<VolumesType>& getVolumes() const; 403 bool hasVolumes() const; 404 const VolumesType* getFirstVolumes() const; 405 const std::vector<AttributesRef>& getAttributesRef() const; 406 bool hasAttributesRef() const; 407 const AttributesRef* getFirstAttributesRef() const; 408 const Version& getVersion() const; 409 bool hasVersion() const; 410 static Configuration read(xmlNode *root); 411 }; 412 413 } // configuration 414 } // engine 415 } // policy 416 } // audio 417 } // android 418 #endif // ANDROID_AUDIO_POLICY_ENGINE_CONFIGURATION_H 419