• 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 #include "capability_utils.h"
17 
18 #include "nlohmann/json.hpp"
19 
20 #include "capability_info.h"
21 #include "constants.h"
22 #include "distributed_hardware_log.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 #undef DH_LOG_TAG
27 #define DH_LOG_TAG "CapabilityUtils"
28 
GetCapabilityByValue(const std::string & value,std::shared_ptr<CapabilityInfo> & capPtr)29 int32_t CapabilityUtils::GetCapabilityByValue(const std::string &value, std::shared_ptr<CapabilityInfo> &capPtr)
30 {
31     capPtr = std::make_shared<CapabilityInfo>();
32     return capPtr->FromJsonString(value);
33 }
34 
GetCapabilityKey(const std::string & deviceId,const std::string & dhId)35 std::string CapabilityUtils::GetCapabilityKey(const std::string &deviceId, const std::string &dhId)
36 {
37     return deviceId + RESOURCE_SEPARATOR + dhId;
38 }
39 
IsCapKeyMatchDeviceId(const std::string & key,const std::string & deviceId)40 bool CapabilityUtils::IsCapKeyMatchDeviceId(const std::string &key, const std::string &deviceId)
41 {
42     std::size_t separatorPos = key.find(RESOURCE_SEPARATOR);
43     if (separatorPos == std::string::npos) {
44         return false;
45     }
46     std::string keyDevId = key.substr(0, separatorPos);
47     return keyDevId.compare(deviceId) == 0;
48 }
49 }
50 }