1e0e9324cSopenharmony_ci/* 2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License. 5e0e9324cSopenharmony_ci * You may obtain a copy of the License at 6e0e9324cSopenharmony_ci * 7e0e9324cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0e9324cSopenharmony_ci * 9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and 13e0e9324cSopenharmony_ci * limitations under the License. 14e0e9324cSopenharmony_ci */ 15e0e9324cSopenharmony_ci 16e0e9324cSopenharmony_ci#ifndef OHOS_SHARING_UTILS_H 17e0e9324cSopenharmony_ci#define OHOS_SHARING_UTILS_H 18e0e9324cSopenharmony_ci 19e0e9324cSopenharmony_ci#include <regex> 20e0e9324cSopenharmony_ci#include <string> 21e0e9324cSopenharmony_ci#include <vector> 22e0e9324cSopenharmony_ci 23e0e9324cSopenharmony_cinamespace OHOS { 24e0e9324cSopenharmony_cinamespace Sharing { 25e0e9324cSopenharmony_ci 26e0e9324cSopenharmony_ciclass RpcKeyParser { 27e0e9324cSopenharmony_cipublic: 28e0e9324cSopenharmony_ci RpcKeyParser() = default; 29e0e9324cSopenharmony_ci 30e0e9324cSopenharmony_ci std::string GetRpcKey(std::string bundleName, std::string abilityName, std::string deviceId, std::string className) 31e0e9324cSopenharmony_ci 32e0e9324cSopenharmony_ci { 33e0e9324cSopenharmony_ci bundleName_ = std::move(bundleName); 34e0e9324cSopenharmony_ci abilityName_ = std::move(abilityName); 35e0e9324cSopenharmony_ci deviceId_ = std::move(deviceId); 36e0e9324cSopenharmony_ci className_ = std::move(className); 37e0e9324cSopenharmony_ci return bundleName_ + "+" + abilityName_ + "+" + deviceId_ + "+" + className_; 38e0e9324cSopenharmony_ci } 39e0e9324cSopenharmony_ci 40e0e9324cSopenharmony_ci bool ParseKey(std::string key) 41e0e9324cSopenharmony_ci { 42e0e9324cSopenharmony_ci std::regex reg{"\\+"}; 43e0e9324cSopenharmony_ci std::vector<std::string> out{std::sregex_token_iterator(key.begin(), key.end(), reg, -1), 44e0e9324cSopenharmony_ci std::sregex_token_iterator()}; 45e0e9324cSopenharmony_ci if (out.size() != 4) { // 4: rpckey length 46e0e9324cSopenharmony_ci return false; 47e0e9324cSopenharmony_ci } 48e0e9324cSopenharmony_ci bundleName_ = std::move(out[0]); 49e0e9324cSopenharmony_ci abilityName_ = std::move(out[1]); 50e0e9324cSopenharmony_ci deviceId_ = std::move(out[2]); // 2: rpckey parse 51e0e9324cSopenharmony_ci className_ = std::move(out[3]); // 3: rpckey parse 52e0e9324cSopenharmony_ci return true; 53e0e9324cSopenharmony_ci } 54e0e9324cSopenharmony_ci 55e0e9324cSopenharmony_ci std::string GetBundleName() 56e0e9324cSopenharmony_ci { 57e0e9324cSopenharmony_ci return bundleName_; 58e0e9324cSopenharmony_ci } 59e0e9324cSopenharmony_ci 60e0e9324cSopenharmony_ci std::string GetAbilityName() 61e0e9324cSopenharmony_ci { 62e0e9324cSopenharmony_ci return abilityName_; 63e0e9324cSopenharmony_ci } 64e0e9324cSopenharmony_ci 65e0e9324cSopenharmony_ci std::string GetDeviceId() 66e0e9324cSopenharmony_ci { 67e0e9324cSopenharmony_ci return deviceId_; 68e0e9324cSopenharmony_ci } 69e0e9324cSopenharmony_ci 70e0e9324cSopenharmony_ci std::string GetClassName() 71e0e9324cSopenharmony_ci { 72e0e9324cSopenharmony_ci return className_; 73e0e9324cSopenharmony_ci } 74e0e9324cSopenharmony_ci 75e0e9324cSopenharmony_ciprivate: 76e0e9324cSopenharmony_ci std::string deviceId_; 77e0e9324cSopenharmony_ci std::string className_; 78e0e9324cSopenharmony_ci std::string bundleName_; 79e0e9324cSopenharmony_ci std::string abilityName_; 80e0e9324cSopenharmony_ci}; 81e0e9324cSopenharmony_ci 82e0e9324cSopenharmony_ciunsigned long long GetThreadId(); 83e0e9324cSopenharmony_ciuint64_t GetCurrentMillisecond(); 84e0e9324cSopenharmony_ci 85e0e9324cSopenharmony_cistd::string ChangeCase(const std::string &value, bool lowerCase); 86e0e9324cSopenharmony_cistd::string Trim(std::string &&s, const std::string &chars = " \r\n\t"); 87e0e9324cSopenharmony_cistd::string &Trim(std::string &s, const std::string &chars = " \r\n\t"); 88e0e9324cSopenharmony_ci 89e0e9324cSopenharmony_cistd::vector<std::string> Split(const std::string &s, const char *delim); 90e0e9324cSopenharmony_cistd::vector<std::string> SplitOnce(const std::string &s, const char *delim); 91e0e9324cSopenharmony_ci 92e0e9324cSopenharmony_civoid SaveFile(const char *data, int32_t dataSize, const std::string &fileName); 93e0e9324cSopenharmony_ci 94e0e9324cSopenharmony_ci#if defined(__ARM_NEON__) 95e0e9324cSopenharmony_civoid NeonMemcpy(volatile unsigned char *dst, volatile unsigned char *src, int32_t size); 96e0e9324cSopenharmony_ci#endif 97e0e9324cSopenharmony_ci 98e0e9324cSopenharmony_ciuint16_t SwapEndian16(uint16_t value); 99e0e9324cSopenharmony_ciuint32_t SwapEndian32(uint32_t value); 100e0e9324cSopenharmony_ciuint64_t SwapEndian64(uint64_t value); 101e0e9324cSopenharmony_ci 102e0e9324cSopenharmony_ciuint16_t LoadBE16(const uint8_t *p); 103e0e9324cSopenharmony_ciuint32_t LoadBE24(const uint8_t *p); 104e0e9324cSopenharmony_ciuint32_t LoadBE32(const uint8_t *p); 105e0e9324cSopenharmony_ciuint64_t LoadBE64(const uint8_t *p); 106e0e9324cSopenharmony_ci 107e0e9324cSopenharmony_civoid SetBE24(void *p, uint32_t val); 108e0e9324cSopenharmony_civoid SetBE32(void *p, uint32_t val); 109e0e9324cSopenharmony_civoid SetLE32(void *p, uint32_t val); 110e0e9324cSopenharmony_ci 111e0e9324cSopenharmony_cistd::string GetAnonyString(const std::string &value); 112e0e9324cSopenharmony_ci} // namespace Sharing 113e0e9324cSopenharmony_ci} // namespace OHOS 114e0e9324cSopenharmony_ci#endif