1 /*
2  * Copyright (c) 2021-2023 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 OHOS_DISTRIBUTED_HARDWARE_CAPABILITY_INFO_H
17 #define OHOS_DISTRIBUTED_HARDWARE_CAPABILITY_INFO_H
18 
19 #include <list>
20 #include <memory>
21 #include <map>
22 
23 #include "cJSON.h"
24 
25 #include "device_type.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class CapabilityInfo {
30 public:
CapabilityInfo()31     CapabilityInfo()
32         : dhId_(""),
33           deviceId_(""),
34           deviceName_(""),
35           deviceType_(0),
36           dhType_(DHType::UNKNOWN),
37           dhAttrs_(""),
38           dhSubtype_("")
39     {}
40 
CapabilityInfo(std::string dhId,std::string devId,std::string devName,uint16_t devType,DHType dhType,std::string dhAttrs,std::string dhSubtype)41     CapabilityInfo(std::string dhId, std::string devId, std::string devName, uint16_t devType, DHType dhType,
42                    std::string dhAttrs, std::string dhSubtype)
43         : dhId_(dhId), deviceId_(devId), deviceName_(devName), deviceType_(devType), dhType_(dhType), dhAttrs_(dhAttrs),
44           dhSubtype_(dhSubtype)
45     {}
46 
~CapabilityInfo()47     virtual ~CapabilityInfo() {}
48 
49     std::string GetDHId() const;
50 
51     void SetDHId(const std::string &dhId);
52 
53     std::string GetDeviceId() const;
54 
55     void SetDeviceId(const std::string &deviceId);
56 
57     std::string GetDeviceName() const;
58 
59     void SetDeviceName(const std::string &deviceName);
60 
61     uint16_t GetDeviceType() const;
62 
63     void SetDeviceType(uint16_t deviceType);
64 
65     DHType GetDHType() const;
66 
67     void SetDHType(const DHType dhType);
68 
69     std::string GetDHAttrs() const;
70 
71     void SetDHAttrs(const std::string &dhAttrs);
72 
73     std::string GetDHSubtype() const;
74 
75     void SetDHSubtype(const std::string &dhSubtype);
76 
77     virtual std::string GetKey() const;
78     virtual std::string GetAnonymousKey() const;
79     virtual int32_t FromJsonString(const std::string &jsonStr);
80     virtual std::string ToJsonString();
81     bool Compare(const CapabilityInfo& capInfo);
82 
83 private:
84     std::string dhId_;
85     std::string deviceId_;
86     std::string deviceName_;
87     uint16_t deviceType_;
88     DHType dhType_;
89     std::string dhAttrs_;
90     std::string dhSubtype_;
91 };
92 
93 void ToJson(cJSON *jsonObject, const CapabilityInfo &capability);
94 void FromJson(const cJSON *jsonObject, CapabilityInfo &capability);
95 
96 using CapabilityInfoMap = std::map<std::string, std::shared_ptr<CapabilityInfo>>;
97 } // namespace DistributedHardware
98 } // namespace OHOS
99 #endif
100