HalInterface.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_HAL_INTERFACE_H_
  17. #define ANDROID_VINTF_HAL_INTERFACE_H_
  18. #include <functional>
  19. #include <set>
  20. #include <string>
  21. #include "Regex.h"
  22. namespace android {
  23. namespace vintf {
  24. // manifest.hal.interface element / compatibility-matrix.hal.interface element
  25. struct HalInterface {
  26. HalInterface() = default;
  27. HalInterface(std::string&& name, std::set<std::string>&& instances)
  28. : mName(std::move(name)), mInstances(std::move(instances)) {}
  29. HalInterface(const std::string& name, const std::set<std::string>& instances)
  30. : mName(name), mInstances(instances) {}
  31. bool forEachInstance(
  32. const std::function<bool(const std::string& interface, const std::string& instance,
  33. bool isRegex)>& func) const;
  34. bool hasAnyInstance() const;
  35. // Return true if inserted, false otherwise.
  36. bool insertInstance(const std::string& instanceOrPattern, bool isRegex);
  37. // Return true if removed, false otherwise.
  38. bool removeInstance(const std::string& instanceOrPattern, bool isRegex);
  39. const std::string& name() const { return mName; }
  40. private:
  41. friend bool operator==(const HalInterface&, const HalInterface&);
  42. friend struct HalInterfaceConverter;
  43. std::string mName;
  44. std::set<std::string> mInstances;
  45. std::set<std::string> mRegexes;
  46. };
  47. } // namespace vintf
  48. } // namespace android
  49. #endif // ANDROID_VINTF_HAL_INTERFACE_H_