HalInterface.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <set>
  17. #include <string>
  18. #include "HalInterface.h"
  19. namespace android {
  20. namespace vintf {
  21. bool operator==(const HalInterface& lft, const HalInterface& rgt) {
  22. if (lft.mName != rgt.mName) return false;
  23. if (lft.mInstances != rgt.mInstances) return false;
  24. return true;
  25. }
  26. bool HalInterface::forEachInstance(
  27. const std::function<bool(const std::string&, const std::string&, bool isRegex)>& func) const {
  28. for (const auto& instance : mInstances) {
  29. if (!func(mName, instance, false /* isRegex */)) {
  30. return false;
  31. }
  32. }
  33. for (const auto& instance : mRegexes) {
  34. if (!func(mName, instance, true /* isRegex */)) {
  35. return false;
  36. }
  37. }
  38. return true;
  39. }
  40. bool HalInterface::hasAnyInstance() const {
  41. bool found = false;
  42. forEachInstance([&found](const auto&, const auto&, bool) {
  43. found = true;
  44. return false; // break;
  45. });
  46. return found;
  47. }
  48. bool HalInterface::insertInstance(const std::string& instanceOrPattern, bool isRegex) {
  49. if (isRegex) {
  50. return mRegexes.insert(instanceOrPattern).second;
  51. } else {
  52. return mInstances.insert(instanceOrPattern).second;
  53. }
  54. }
  55. bool HalInterface::removeInstance(const std::string& instanceOrPattern, bool isRegex) {
  56. if (isRegex) {
  57. return mRegexes.erase(instanceOrPattern) > 0;
  58. } else {
  59. return mInstances.erase(instanceOrPattern) > 0;
  60. }
  61. }
  62. } // namespace vintf
  63. } // namespace android