1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CAPABILITY_H
17 #define CAPABILITY_H
18 
19 #include <map>
20 #include <string>
21 #include "json.hpp"
22 #include "attr_data.h"
23 #include "plugin_errors.h"
24 
25 namespace OHOS {
26 namespace MultimediaPlugin {
27 class Capability final {
28 public:
29     Capability() = default;
30     explicit Capability(const std::map<std::string, AttrData> &caps);
31     explicit Capability(std::map<std::string, AttrData> &&caps);
32     ~Capability() = default;
33     uint32_t SetCapability(const nlohmann::json &capsInfo);
34     bool IsCompatible(const std::map<std::string, AttrData> &caps) const;
35     const AttrData *GetCapability(const std::string &key) const;
36     const std::map<std::string, AttrData> &GetCapability() const;
37 
38 private:
39     uint32_t AnalyzeAttrData(const nlohmann::json &capInfo, AttrData &attrData);
40     uint32_t AnalyzeBool(const nlohmann::json &capInfo, AttrData &attrData);
41     uint32_t AnalyzeUint32(const nlohmann::json &capInfo, AttrData &attrData);
42     uint32_t AnalyzeString(const nlohmann::json &capInfo, AttrData &attrData);
43     uint32_t AnalyzeUint32Set(const nlohmann::json &capInfo, AttrData &attrData);
44     uint32_t AnalyzeUint32Range(const nlohmann::json &capInfo, AttrData &attrData);
45     uint32_t AnalyzeStringSet(const nlohmann::json &capInfo, AttrData &attrData);
46 
47     static constexpr uint32_t SET_MIN_VALUE_NUM = 1;
48     static const std::string CAPABILITY_BOOL_TRUE;
49     static const std::string CAPABILITY_BOOL_FALSE;
50     static std::map<std::string, AttrDataType> typeMap_;
51     using CapsMap = std::map<std::string, AttrData>;
52     CapsMap caps_;
53 };
54 } // namespace MultimediaPlugin
55 } // namespace OHOS
56 
57 #endif // CAPABILITY_H
58