MatrixInstance.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef ANDROID_VINTF_MATRIX_INSTANCE_H
  17. #define ANDROID_VINTF_MATRIX_INSTANCE_H
  18. #include <string>
  19. #include <hidl-util/FqInstance.h>
  20. #include "VersionRange.h"
  21. namespace android {
  22. namespace vintf {
  23. class MatrixInstance {
  24. public:
  25. MatrixInstance();
  26. MatrixInstance(const MatrixInstance&);
  27. MatrixInstance(MatrixInstance&&) noexcept;
  28. MatrixInstance& operator=(const MatrixInstance&);
  29. MatrixInstance& operator=(MatrixInstance&&) noexcept;
  30. using VersionType = VersionRange;
  31. // fqInstance.version is ignored. Version range is provided separately.
  32. MatrixInstance(FqInstance&& fqInstance, VersionRange&& range, bool optional, bool isRegex);
  33. MatrixInstance(const FqInstance fqInstance, const VersionRange& range, bool optional,
  34. bool isRegex);
  35. const std::string& package() const;
  36. const VersionRange& versionRange() const;
  37. const std::string& interface() const;
  38. bool optional() const;
  39. bool isSatisfiedBy(const FqInstance& provided) const;
  40. // If isRegex, return true if instance matches the pattern.
  41. // If !isRegex, return true if e == instance().
  42. // Follows rules of "Extended Regular Expression" (ERE).
  43. bool matchInstance(const std::string& e) const;
  44. // If isRegex, return the regex pattern. Else empty string.
  45. const std::string& regexPattern() const;
  46. // If !isRegex, return the exact instance name. Else empty string.
  47. const std::string& exactInstance() const;
  48. bool isRegex() const;
  49. private:
  50. FqInstance mFqInstance;
  51. VersionRange mRange;
  52. bool mOptional = false;
  53. bool mIsRegex = false;
  54. };
  55. } // namespace vintf
  56. } // namespace android
  57. #endif // ANDROID_VINTF_MATRIX_INSTANCE_H