• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 "nlohmann/json.hpp"
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     {}
39 
CapabilityInfo(std::string dhId,std::string devId,std::string devName,uint16_t devType,DHType dhType,std::string dhAttrs)40     CapabilityInfo(std::string dhId, std::string devId, std::string devName, uint16_t devType, DHType dhType,
41                    std::string dhAttrs)
42         : dhId_(dhId), deviceId_(devId), deviceName_(devName), deviceType_(devType), dhType_(dhType), dhAttrs_(dhAttrs)
43     {}
44 
~CapabilityInfo()45     virtual ~CapabilityInfo() {}
46 
47     std::string GetDHId() const;
48 
49     void SetDHId(const std::string &dhId);
50 
51     std::string GetDeviceId() const;
52 
53     void SetDeviceId(const std::string &deviceId);
54 
55     std::string GetDeviceName() const;
56 
57     void SetDeviceName(const std::string &deviceName);
58 
59     uint16_t GetDeviceType() const;
60 
61     void SetDeviceType(uint16_t deviceType);
62 
63     DHType GetDHType() const;
64 
65     void SetDHType(const DHType dhType);
66 
67     std::string GetDHAttrs() const;
68 
69     void SetDHAttrs(const std::string &dhAttrs);
70 
71     virtual std::string GetKey() const;
72     virtual std::string GetAnonymousKey() const;
73     virtual int32_t FromJsonString(const std::string &jsonStr);
74     virtual std::string ToJsonString();
75     bool Compare(const CapabilityInfo& capInfo);
76 
77 private:
78     std::string dhId_;
79     std::string deviceId_;
80     std::string deviceName_;
81     uint16_t deviceType_;
82     DHType dhType_;
83     std::string dhAttrs_;
84 };
85 
86 void ToJson(nlohmann::json &jsonObject, const CapabilityInfo &capability);
87 void FromJson(const nlohmann::json &jsonObject, CapabilityInfo &capability);
88 
89 using CapabilityInfoMap = std::map<std::string, std::shared_ptr<CapabilityInfo>>;
90 } // namespace DistributedHardware
91 } // namespace OHOS
92 #endif
93