123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <set>
- #include <string>
- #include "HalInterface.h"
- namespace android {
- namespace vintf {
- bool operator==(const HalInterface& lft, const HalInterface& rgt) {
- if (lft.mName != rgt.mName) return false;
- if (lft.mInstances != rgt.mInstances) return false;
- return true;
- }
- bool HalInterface::forEachInstance(
- const std::function<bool(const std::string&, const std::string&, bool isRegex)>& func) const {
- for (const auto& instance : mInstances) {
- if (!func(mName, instance, false )) {
- return false;
- }
- }
- for (const auto& instance : mRegexes) {
- if (!func(mName, instance, true )) {
- return false;
- }
- }
- return true;
- }
- bool HalInterface::hasAnyInstance() const {
- bool found = false;
- forEachInstance([&found](const auto&, const auto&, bool) {
- found = true;
- return false;
- });
- return found;
- }
- bool HalInterface::insertInstance(const std::string& instanceOrPattern, bool isRegex) {
- if (isRegex) {
- return mRegexes.insert(instanceOrPattern).second;
- } else {
- return mInstances.insert(instanceOrPattern).second;
- }
- }
- bool HalInterface::removeInstance(const std::string& instanceOrPattern, bool isRegex) {
- if (isRegex) {
- return mRegexes.erase(instanceOrPattern) > 0;
- } else {
- return mInstances.erase(instanceOrPattern) > 0;
- }
- }
- }
- }
|