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 "capability_info.h"
19 #include "constants.h"
20 #include "dh_utils_tool.h"
21 #include "distributed_hardware_errno.h"
22
23 namespace OHOS {
24 namespace DistributedHardware {
25 #undef DH_LOG_TAG
26 #define DH_LOG_TAG "CapabilityUtils"
27
GetCapabilityKey(const std::string & deviceId,const std::string & dhId)28 std::string GetCapabilityKey(const std::string &deviceId, const std::string &dhId)
29 {
30 return deviceId + RESOURCE_SEPARATOR + dhId;
31 }
32
IsCapKeyMatchDeviceId(const std::string & key,const std::string & deviceId)33 bool IsCapKeyMatchDeviceId(const std::string &key, const std::string &deviceId)
34 {
35 if (!IsIdLengthValid(key) || !IsIdLengthValid(deviceId)) {
36 return false;
37 }
38 std::size_t separatorPos = key.find(RESOURCE_SEPARATOR);
39 if (separatorPos == std::string::npos) {
40 return false;
41 }
42 std::string keyDevId = key.substr(0, separatorPos);
43 return keyDevId.compare(deviceId) == 0;
44 }
45 } // namespace DistributedHardware
46 } // namespace OHOS
47