123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <string> 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_ci#include "base/log/log.h" 2223b3eb3cSopenharmony_ci#include "base/geometry/rect.h" 2323b3eb3cSopenharmony_ci#include "core/common/asset_manager_impl.h" 2423b3eb3cSopenharmony_ci#include "core/components_ng/property/safe_area_insets.h" 2523b3eb3cSopenharmony_ci 2623b3eb3cSopenharmony_cinamespace OHOS::Rosen { 2723b3eb3cSopenharmony_ci class AvoidArea; 2823b3eb3cSopenharmony_ci struct DMRect; 2923b3eb3cSopenharmony_ci} 3023b3eb3cSopenharmony_cinamespace OHOS::Ace { 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_cistd::string GetStringFromFile(const std::string& packagePathStr, const std::string& fileName); 3323b3eb3cSopenharmony_cistd::string GetStringFromHap(const std::string& hapPath, const std::string& fileName); 3423b3eb3cSopenharmony_cibool CheckUrlValid(const std::string& url, const std::string& hapPath); 3523b3eb3cSopenharmony_ci 3623b3eb3cSopenharmony_ciRefPtr<AssetProviderImpl> CreateAssetProviderImpl( 3723b3eb3cSopenharmony_ci const std::string& packagePath, const std::vector<std::string>& assetBasePaths, bool useCache = true); 3823b3eb3cSopenharmony_ci 3923b3eb3cSopenharmony_ciinline const std::string GenerateFullPath(const std::string& prePath, const std::string& postPath) 4023b3eb3cSopenharmony_ci{ 4123b3eb3cSopenharmony_ci if (prePath.empty() && postPath.empty()) { 4223b3eb3cSopenharmony_ci return ""; 4323b3eb3cSopenharmony_ci } 4423b3eb3cSopenharmony_ci std::string tmpPostPath = postPath; 4523b3eb3cSopenharmony_ci if (tmpPostPath.back() == '/') { 4623b3eb3cSopenharmony_ci tmpPostPath.pop_back(); 4723b3eb3cSopenharmony_ci } 4823b3eb3cSopenharmony_ci std::string fullPath = prePath; 4923b3eb3cSopenharmony_ci if (fullPath.empty() || fullPath.back() == '/') { 5023b3eb3cSopenharmony_ci fullPath += tmpPostPath; 5123b3eb3cSopenharmony_ci } else { 5223b3eb3cSopenharmony_ci fullPath += "/" + tmpPostPath; 5323b3eb3cSopenharmony_ci } 5423b3eb3cSopenharmony_ci return fullPath; 5523b3eb3cSopenharmony_ci} 5623b3eb3cSopenharmony_ci 5723b3eb3cSopenharmony_cienum class ResultSetDataType { 5823b3eb3cSopenharmony_ci TYPE_NULL = 0, 5923b3eb3cSopenharmony_ci TYPE_STRING, 6023b3eb3cSopenharmony_ci TYPE_INT32, 6123b3eb3cSopenharmony_ci TYPE_INT64, 6223b3eb3cSopenharmony_ci TYPE_DOUBLE 6323b3eb3cSopenharmony_ci}; 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ciclass ResultSetUtils { 6623b3eb3cSopenharmony_cipublic: 6723b3eb3cSopenharmony_ci template<typename T> 6823b3eb3cSopenharmony_ci static std::variant<int32_t, std::string, int64_t, double> GetValFromColumn(const std::string &columnName, 6923b3eb3cSopenharmony_ci T &resultSet, ResultSetDataType type) 7023b3eb3cSopenharmony_ci { 7123b3eb3cSopenharmony_ci if (resultSet == nullptr) { 7223b3eb3cSopenharmony_ci return DefaultVariantVal(type); 7323b3eb3cSopenharmony_ci } 7423b3eb3cSopenharmony_ci 7523b3eb3cSopenharmony_ci int32_t err = 0; 7623b3eb3cSopenharmony_ci int32_t index = 0; 7723b3eb3cSopenharmony_ci err = resultSet->GetColumnIndex(columnName, index); 7823b3eb3cSopenharmony_ci if (err) { 7923b3eb3cSopenharmony_ci return DefaultVariantVal(type); 8023b3eb3cSopenharmony_ci } 8123b3eb3cSopenharmony_ci 8223b3eb3cSopenharmony_ci std::variant<int32_t, std::string, int64_t, double> data; 8323b3eb3cSopenharmony_ci switch (type) { 8423b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_STRING: { 8523b3eb3cSopenharmony_ci data = GetStringValFromColumn(index, resultSet); 8623b3eb3cSopenharmony_ci break; 8723b3eb3cSopenharmony_ci } 8823b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_INT32: { 8923b3eb3cSopenharmony_ci data = GetIntValFromColumn(index, resultSet); 9023b3eb3cSopenharmony_ci break; 9123b3eb3cSopenharmony_ci } 9223b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_INT64: { 9323b3eb3cSopenharmony_ci data = GetLongValFromColumn(index, resultSet); 9423b3eb3cSopenharmony_ci break; 9523b3eb3cSopenharmony_ci } 9623b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_DOUBLE: { 9723b3eb3cSopenharmony_ci data = GetDoubleValFromColumn(index, resultSet); 9823b3eb3cSopenharmony_ci break; 9923b3eb3cSopenharmony_ci } 10023b3eb3cSopenharmony_ci default: { 10123b3eb3cSopenharmony_ci return DefaultVariantVal(type); 10223b3eb3cSopenharmony_ci break; 10323b3eb3cSopenharmony_ci } 10423b3eb3cSopenharmony_ci } 10523b3eb3cSopenharmony_ci 10623b3eb3cSopenharmony_ci return data; 10723b3eb3cSopenharmony_ci } 10823b3eb3cSopenharmony_ci 10923b3eb3cSopenharmony_ci template<typename T> 11023b3eb3cSopenharmony_ci static inline std::string GetStringValFromColumn(int index, T &resultSet) 11123b3eb3cSopenharmony_ci { 11223b3eb3cSopenharmony_ci std::string stringVal; 11323b3eb3cSopenharmony_ci if (resultSet->GetString(index, stringVal)) { 11423b3eb3cSopenharmony_ci return ""; 11523b3eb3cSopenharmony_ci } 11623b3eb3cSopenharmony_ci return stringVal; 11723b3eb3cSopenharmony_ci } 11823b3eb3cSopenharmony_ci 11923b3eb3cSopenharmony_ci template<typename T> 12023b3eb3cSopenharmony_ci static inline int32_t GetIntValFromColumn(int index, T &resultSet) 12123b3eb3cSopenharmony_ci { 12223b3eb3cSopenharmony_ci int32_t integerVal; 12323b3eb3cSopenharmony_ci if (resultSet->GetInt(index, integerVal)) { 12423b3eb3cSopenharmony_ci return 0; 12523b3eb3cSopenharmony_ci } 12623b3eb3cSopenharmony_ci return integerVal; 12723b3eb3cSopenharmony_ci } 12823b3eb3cSopenharmony_ci 12923b3eb3cSopenharmony_ci template<typename T> 13023b3eb3cSopenharmony_ci static inline int64_t GetLongValFromColumn(int index, T &resultSet) 13123b3eb3cSopenharmony_ci { 13223b3eb3cSopenharmony_ci int64_t integer64Val; 13323b3eb3cSopenharmony_ci if (resultSet->GetLong(index, integer64Val)) { 13423b3eb3cSopenharmony_ci return 0; 13523b3eb3cSopenharmony_ci } 13623b3eb3cSopenharmony_ci return integer64Val; 13723b3eb3cSopenharmony_ci } 13823b3eb3cSopenharmony_ci 13923b3eb3cSopenharmony_ci template<typename T> 14023b3eb3cSopenharmony_ci static inline double GetDoubleValFromColumn(int index, T &resultSet) 14123b3eb3cSopenharmony_ci { 14223b3eb3cSopenharmony_ci double doubleVal; 14323b3eb3cSopenharmony_ci if (resultSet->GetDouble(index, doubleVal)) { 14423b3eb3cSopenharmony_ci return 0; 14523b3eb3cSopenharmony_ci } 14623b3eb3cSopenharmony_ci return doubleVal; 14723b3eb3cSopenharmony_ci } 14823b3eb3cSopenharmony_ci 14923b3eb3cSopenharmony_ciprivate: 15023b3eb3cSopenharmony_ci static std::variant<int32_t, std::string, int64_t, double> DefaultVariantVal(ResultSetDataType type) 15123b3eb3cSopenharmony_ci { 15223b3eb3cSopenharmony_ci switch (type) { 15323b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_STRING: 15423b3eb3cSopenharmony_ci return std::string(); 15523b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_INT32: 15623b3eb3cSopenharmony_ci return 0; 15723b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_INT64: 15823b3eb3cSopenharmony_ci return static_cast<int64_t>(0); 15923b3eb3cSopenharmony_ci case ResultSetDataType::TYPE_DOUBLE: 16023b3eb3cSopenharmony_ci return static_cast<double>(0.0); 16123b3eb3cSopenharmony_ci default: 16223b3eb3cSopenharmony_ci return 0; 16323b3eb3cSopenharmony_ci } 16423b3eb3cSopenharmony_ci 16523b3eb3cSopenharmony_ci return 0; 16623b3eb3cSopenharmony_ci } 16723b3eb3cSopenharmony_ci}; 16823b3eb3cSopenharmony_ci 16923b3eb3cSopenharmony_ciNG::SafeAreaInsets ConvertAvoidArea(const OHOS::Rosen::AvoidArea& avoidArea); 17023b3eb3cSopenharmony_ciRect ConvertDMRect2Rect(const OHOS::Rosen::DMRect& displayAvailableRect); 17123b3eb3cSopenharmony_ci} // namespace OHOS::Ace 17223b3eb3cSopenharmony_ci 17323b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H 174