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