15e81a82fSopenharmony_ci/* 25e81a82fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35e81a82fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45e81a82fSopenharmony_ci * you may not use this file except in compliance with the License. 55e81a82fSopenharmony_ci * You may obtain a copy of the License at 65e81a82fSopenharmony_ci * 75e81a82fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85e81a82fSopenharmony_ci * 95e81a82fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105e81a82fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115e81a82fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125e81a82fSopenharmony_ci * See the License for the specific language governing permissions and 135e81a82fSopenharmony_ci * limitations under the License. 145e81a82fSopenharmony_ci * Description: common method for cast session 155e81a82fSopenharmony_ci * Author: lijianzhao 165e81a82fSopenharmony_ci * Create: 2022-01-19 175e81a82fSopenharmony_ci */ 185e81a82fSopenharmony_ci 195e81a82fSopenharmony_ci#ifndef UTILS_H 205e81a82fSopenharmony_ci#define UTILS_H 215e81a82fSopenharmony_ci 225e81a82fSopenharmony_ci#include <locale> 235e81a82fSopenharmony_ci#include <string> 245e81a82fSopenharmony_ci#include <vector> 255e81a82fSopenharmony_ci 265e81a82fSopenharmony_cinamespace OHOS { 275e81a82fSopenharmony_cinamespace CastEngine { 285e81a82fSopenharmony_cinamespace CastEngineService { 295e81a82fSopenharmony_ci#if !defined(DISALLOW_COPY_AND_ASSIGN) 305e81a82fSopenharmony_ci#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 315e81a82fSopenharmony_ci TypeName(const TypeName &); \ 325e81a82fSopenharmony_ci void operator = (const TypeName &) 335e81a82fSopenharmony_ci#endif 345e81a82fSopenharmony_ci 355e81a82fSopenharmony_ci#if !defined(DISALLOW_EVIL_CONSTRUCTORS) 365e81a82fSopenharmony_ci#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) 375e81a82fSopenharmony_ci#endif 385e81a82fSopenharmony_ci 395e81a82fSopenharmony_ci#if !defined(DISALLOW_IMPLICIT_CONSTRUCTORS) 405e81a82fSopenharmony_ci#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 415e81a82fSopenharmony_ci TypeName(); \ 425e81a82fSopenharmony_ci DISALLOW_COPY_AND_ASSIGN(TypeName) 435e81a82fSopenharmony_ci#endif 445e81a82fSopenharmony_ci 455e81a82fSopenharmony_cistruct PacketData { 465e81a82fSopenharmony_ci uint8_t *data; 475e81a82fSopenharmony_ci int length; 485e81a82fSopenharmony_ci}; 495e81a82fSopenharmony_ci 505e81a82fSopenharmony_cistruct ConstPacketData { 515e81a82fSopenharmony_ci const uint8_t *data; 525e81a82fSopenharmony_ci int length; 535e81a82fSopenharmony_ci}; 545e81a82fSopenharmony_ci 555e81a82fSopenharmony_ciclass Utils { 565e81a82fSopenharmony_cipublic: 575e81a82fSopenharmony_ci Utils() {} 585e81a82fSopenharmony_ci ~Utils() {} 595e81a82fSopenharmony_ci static void SplitString(const std::string &src, std::vector<std::string> &dest, const std::string &seperator); 605e81a82fSopenharmony_ci static std::string &Trim(std::string &str); 615e81a82fSopenharmony_ci static std::string &ToLower(std::string &str); 625e81a82fSopenharmony_ci static bool StartWith(const std::string &mainStr, const std::string &subStr); 635e81a82fSopenharmony_ci static int IntToByteArray(int num, int length, uint8_t *output); 645e81a82fSopenharmony_ci static uint32_t ByteArrayToInt(const uint8_t *input, unsigned int length); 655e81a82fSopenharmony_ci static int32_t StringToInt(const std::string &str); 665e81a82fSopenharmony_ci static std::string GetWifiIp(); 675e81a82fSopenharmony_ci static bool IsArrayAllZero(const uint8_t *input, int length); 685e81a82fSopenharmony_ci 695e81a82fSopenharmony_ci static bool Base64Encode(const std::string &source, std::string &encoded); 705e81a82fSopenharmony_ci static bool Base64Decode(const std::string &encoded, std::string &decoded); 715e81a82fSopenharmony_ci 725e81a82fSopenharmony_ciprivate: 735e81a82fSopenharmony_ci static const int BYTE_TO_BIT_OFFSET = 8; 745e81a82fSopenharmony_ci static const uint8_t INT_TO_BYTE = 0xff; 755e81a82fSopenharmony_ci static const std::string BASE64_CHARS; 765e81a82fSopenharmony_ci static inline bool IsBase64(unsigned char c); 775e81a82fSopenharmony_ci static const int DECIMALISM = 10; 785e81a82fSopenharmony_ci static std::string ConvertIpv4Address(unsigned int addressIpv4); 795e81a82fSopenharmony_ci}; 805e81a82fSopenharmony_ci 815e81a82fSopenharmony_ciinline constexpr char SANDBOX_PATH[] = "/data/service/el1/public/cast_engine_service"; 825e81a82fSopenharmony_ciinline constexpr char PARAM_MEDIA_DUMP[] = "debug.cast.media.dump"; 835e81a82fSopenharmony_ciinline constexpr char PARAM_VIDEO_CACHE[] = "debug.cast.video.cache"; 845e81a82fSopenharmony_ciinline constexpr char UNIQUE_SCREEN[] = "debug.cast.unique.screen"; 855e81a82fSopenharmony_ciinline constexpr char NOTIFY_DEVICE_FOUND[] = "debug.cast.device.found"; 865e81a82fSopenharmony_ci} // namespace CastEngineService 875e81a82fSopenharmony_ci} // namespace CastEngine 885e81a82fSopenharmony_ci} // namespace OHOS 895e81a82fSopenharmony_ci 905e81a82fSopenharmony_ci#endif 91