MatrixHal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef ANDROID_VINTF_MATRIX_HAL_H
  17. #define ANDROID_VINTF_MATRIX_HAL_H
  18. #include <map>
  19. #include <set>
  20. #include <string>
  21. #include <vector>
  22. #include "HalFormat.h"
  23. #include "HalInterface.h"
  24. #include "MatrixInstance.h"
  25. #include "VersionRange.h"
  26. namespace android {
  27. namespace vintf {
  28. // A HAL entry to a compatibility matrix
  29. struct MatrixHal {
  30. using InstanceType = MatrixInstance;
  31. bool operator==(const MatrixHal &other) const;
  32. // Check whether the MatrixHal contains the given version.
  33. bool containsVersion(const Version& version) const;
  34. HalFormat format = HalFormat::HIDL;
  35. std::string name;
  36. std::vector<VersionRange> versionRanges;
  37. bool optional = false;
  38. std::map<std::string, HalInterface> interfaces;
  39. inline const std::string& getName() const { return name; }
  40. bool forEachInstance(const std::function<bool(const MatrixInstance&)>& func) const;
  41. private:
  42. friend struct HalManifest;
  43. friend struct CompatibilityMatrix;
  44. friend std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace);
  45. friend std::vector<std::string> expandInstances(const MatrixHal& req);
  46. // Loop over interface/instance for a specific VersionRange.
  47. bool forEachInstance(const VersionRange& vr,
  48. const std::function<bool(const MatrixInstance&)>& func) const;
  49. // Loop over interface/instance. VersionRange is supplied to the function as a vector.
  50. bool forEachInstance(
  51. const std::function<bool(const std::vector<VersionRange>&, const std::string&,
  52. const std::string& instanceOrPattern, bool isRegex)>& func) const;
  53. bool isCompatible(const std::set<FqInstance>& providedInstances,
  54. const std::set<Version>& providedVersions) const;
  55. bool isCompatible(const VersionRange& vr, const std::set<FqInstance>& providedInstances,
  56. const std::set<Version>& providedVersions) const;
  57. void setOptional(bool o);
  58. void insertVersionRanges(const std::vector<VersionRange>& other);
  59. // Return size of all interface/instance pairs.
  60. size_t instancesCount() const;
  61. void insertInstance(const std::string& interface, const std::string& instance, bool isRegex);
  62. // Remove a specific interface/instances. Return true if removed, false otherwise.
  63. bool removeInstance(const std::string& interface, const std::string& instance, bool isRegex);
  64. // Remove all <interface> tags.
  65. void clearInstances();
  66. };
  67. } // namespace vintf
  68. } // namespace android
  69. #endif // ANDROID_VINTF_MATRIX_HAL_H