• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_INPUT_UTILS_TOOL_H
17 #define OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "nlohmann/json.hpp"
23 
24 #include "dinput_log.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 namespace DistributedInput {
29 struct DevInfo {
30     std::string networkId;
31     std::string deviceName;
32     uint16_t deviceType;
33 };
34 
35 DevInfo GetLocalDeviceInfo();
36 std::string GetLocalNetworkId();
37 std::string GetUUIDBySoftBus(const std::string &networkId);
38 uint64_t GetCurrentTime();
39 std::string SetAnonyId(const std::string &message);
40 /* IsString, IsUInt32 and IsUInt64 are used to valid json key */
41 bool IsBoolean(const nlohmann::json &jsonObj, const std::string &key);
42 bool IsString(const nlohmann::json &jsonObj, const std::string &key);
43 bool IsInt32(const nlohmann::json &jsonObj, const std::string &key);
44 bool IsInt64(const nlohmann::json &jsonObj, const std::string &key);
45 bool IsUInt16(const nlohmann::json &jsonObj, const std::string &key);
46 bool IsUInt32(const nlohmann::json &jsonObj, const std::string &key);
47 bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key);
48 bool IsArray(const nlohmann::json &jsonObj, const std::string &key);
49 std::string GetNodeDesc(std::string parameters);
50 std::string GetAnonyString(const std::string &value);
51 std::string GetAnonyInt32(const int32_t value);
52 std::string Sha256(const std::string &string);
53 void CloseFd(int &fd);
54 int BitIsSet(const unsigned long *array, int bit);
55 void StringSplitToVector(const std::string &str, const char split, std::vector<std::string> &vecStr);
56 int OpenInputDeviceFdByPath(const std::string &devicePath);
57 std::string ConvertErrNo();
58 void ScanInputDevicesPath(const std::string &dirName, std::vector<std::string> &vecInputDevPath);
59 } // namespace DistributedInput
60 } // namespace DistributedHardware
61 } // namespace OHOS
62 #endif // OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H