12d4d9a4dSopenharmony_ci/* 22d4d9a4dSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 32d4d9a4dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42d4d9a4dSopenharmony_ci * you may not use this file except in compliance with the License. 52d4d9a4dSopenharmony_ci * You may obtain a copy of the License at 62d4d9a4dSopenharmony_ci * 72d4d9a4dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82d4d9a4dSopenharmony_ci * 92d4d9a4dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102d4d9a4dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112d4d9a4dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122d4d9a4dSopenharmony_ci * See the License for the specific language governing permissions and 132d4d9a4dSopenharmony_ci * limitations under the License. 142d4d9a4dSopenharmony_ci */ 152d4d9a4dSopenharmony_ci 162d4d9a4dSopenharmony_ci#ifndef OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H 172d4d9a4dSopenharmony_ci#define OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H 182d4d9a4dSopenharmony_ci 192d4d9a4dSopenharmony_ci#include <cstdint> 202d4d9a4dSopenharmony_ci#include <string> 212d4d9a4dSopenharmony_ci 222d4d9a4dSopenharmony_ci#include <linux/input.h> 232d4d9a4dSopenharmony_ci#include "nlohmann/json.hpp" 242d4d9a4dSopenharmony_ci 252d4d9a4dSopenharmony_ci#include "dinput_log.h" 262d4d9a4dSopenharmony_ci 272d4d9a4dSopenharmony_cinamespace OHOS { 282d4d9a4dSopenharmony_cinamespace DistributedHardware { 292d4d9a4dSopenharmony_cinamespace DistributedInput { 302d4d9a4dSopenharmony_cistruct DevInfo { 312d4d9a4dSopenharmony_ci std::string networkId; 322d4d9a4dSopenharmony_ci std::string deviceName; 332d4d9a4dSopenharmony_ci uint16_t deviceType; 342d4d9a4dSopenharmony_ci}; 352d4d9a4dSopenharmony_ci 362d4d9a4dSopenharmony_ciDevInfo GetLocalDeviceInfo(); 372d4d9a4dSopenharmony_cistd::string GetLocalNetworkId(); 382d4d9a4dSopenharmony_cistd::string GetUUIDBySoftBus(const std::string &networkId); 392d4d9a4dSopenharmony_ciuint64_t GetCurrentTimeUs(); 402d4d9a4dSopenharmony_cistd::string SetAnonyId(const std::string &message); 412d4d9a4dSopenharmony_ci/* IsString, IsUInt32 and IsUInt64 are used to valid json key */ 422d4d9a4dSopenharmony_cibool IsBoolean(const nlohmann::json &jsonObj, const std::string &key); 432d4d9a4dSopenharmony_cibool IsString(const nlohmann::json &jsonObj, const std::string &key); 442d4d9a4dSopenharmony_cibool IsInt32(const nlohmann::json &jsonObj, const std::string &key); 452d4d9a4dSopenharmony_cibool IsInt64(const nlohmann::json &jsonObj, const std::string &key); 462d4d9a4dSopenharmony_cibool IsUInt16(const nlohmann::json &jsonObj, const std::string &key); 472d4d9a4dSopenharmony_cibool IsUInt32(const nlohmann::json &jsonObj, const std::string &key); 482d4d9a4dSopenharmony_cibool IsUInt64(const nlohmann::json &jsonObj, const std::string &key); 492d4d9a4dSopenharmony_cibool IsArray(const nlohmann::json &jsonObj, const std::string &key); 502d4d9a4dSopenharmony_cistd::string GetNodeDesc(std::string parameters); 512d4d9a4dSopenharmony_cistd::string GetAnonyString(const std::string &value); 522d4d9a4dSopenharmony_cistd::string GetAnonyInt32(const int32_t value); 532d4d9a4dSopenharmony_cistd::string Sha256(const std::string &string); 542d4d9a4dSopenharmony_civoid CloseFd(int &fd); 552d4d9a4dSopenharmony_ciint BitIsSet(const unsigned long *array, int bit); 562d4d9a4dSopenharmony_civoid SplitStringToVector(const std::string &str, const char split, std::vector<std::string> &vecStr); 572d4d9a4dSopenharmony_ciint OpenInputDeviceFdByPath(const std::string &devicePath); 582d4d9a4dSopenharmony_cistd::string ConvertErrNo(); 592d4d9a4dSopenharmony_civoid ScanInputDevicesPath(const std::string &dirName, std::vector<std::string> &vecInputDevPath); 602d4d9a4dSopenharmony_ci 612d4d9a4dSopenharmony_ci/** 622d4d9a4dSopenharmony_ci * If we pressed the sink keyboard while mouse pass throuth from source to sink, we need reset the virtual keyboard 632d4d9a4dSopenharmony_ci * key states at the source side. 642d4d9a4dSopenharmony_ci */ 652d4d9a4dSopenharmony_civoid ResetVirtualDevicePressedKeys(const std::vector<std::string> &nodePaths); 662d4d9a4dSopenharmony_ci 672d4d9a4dSopenharmony_cistd::string GetString(const std::vector<std::string> &vec); 682d4d9a4dSopenharmony_ciint32_t GetRandomInt32(int32_t randMin, int32_t randMax); 692d4d9a4dSopenharmony_cistd::string JointDhIds(const std::vector<std::string> &dhids); 702d4d9a4dSopenharmony_cistd::vector<std::string> SplitDhIdString(const std::string &dhIdsString); 712d4d9a4dSopenharmony_ci} // namespace DistributedInput 722d4d9a4dSopenharmony_ci} // namespace DistributedHardware 732d4d9a4dSopenharmony_ci} // namespace OHOS 742d4d9a4dSopenharmony_ci#endif // OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H