1/*
2 * Copyright (c) 2022-2024 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 <linux/input.h>
23#include "nlohmann/json.hpp"
24
25#include "dinput_log.h"
26
27namespace OHOS {
28namespace DistributedHardware {
29namespace DistributedInput {
30struct DevInfo {
31    std::string networkId;
32    std::string deviceName;
33    uint16_t deviceType;
34};
35
36DevInfo GetLocalDeviceInfo();
37std::string GetLocalNetworkId();
38std::string GetUUIDBySoftBus(const std::string &networkId);
39uint64_t GetCurrentTimeUs();
40std::string SetAnonyId(const std::string &message);
41/* IsString, IsUInt32 and IsUInt64 are used to valid json key */
42bool IsBoolean(const nlohmann::json &jsonObj, const std::string &key);
43bool IsString(const nlohmann::json &jsonObj, const std::string &key);
44bool IsInt32(const nlohmann::json &jsonObj, const std::string &key);
45bool IsInt64(const nlohmann::json &jsonObj, const std::string &key);
46bool IsUInt16(const nlohmann::json &jsonObj, const std::string &key);
47bool IsUInt32(const nlohmann::json &jsonObj, const std::string &key);
48bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key);
49bool IsArray(const nlohmann::json &jsonObj, const std::string &key);
50std::string GetNodeDesc(std::string parameters);
51std::string GetAnonyString(const std::string &value);
52std::string GetAnonyInt32(const int32_t value);
53std::string Sha256(const std::string &string);
54void CloseFd(int &fd);
55int BitIsSet(const unsigned long *array, int bit);
56void SplitStringToVector(const std::string &str, const char split, std::vector<std::string> &vecStr);
57int OpenInputDeviceFdByPath(const std::string &devicePath);
58std::string ConvertErrNo();
59void ScanInputDevicesPath(const std::string &dirName, std::vector<std::string> &vecInputDevPath);
60
61/**
62 * If we pressed the sink keyboard while mouse pass throuth from source to sink, we need reset the virtual keyboard
63 * key states at the source side.
64 */
65void ResetVirtualDevicePressedKeys(const std::vector<std::string> &nodePaths);
66
67std::string GetString(const std::vector<std::string> &vec);
68int32_t GetRandomInt32(int32_t randMin, int32_t randMax);
69std::string JointDhIds(const std::vector<std::string> &dhids);
70std::vector<std::string> SplitDhIdString(const std::string &dhIdsString);
71} // namespace DistributedInput
72} // namespace DistributedHardware
73} // namespace OHOS
74#endif // OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H