From cb5d43d210d31bcc0d912aebd95d819c1a54e75f Mon Sep 17 00:00:00 2001 From: quguiren Date: Wed, 25 Sep 2024 13:56:22 +0800 Subject: [PATCH] fix crossPlatformcompile Signed-off-by: quguiren --- adapter/BUILD.gn | 3 +- adapter/framework/common/udmf_utils.cpp | 65 +++++++++++++++++ adapter/framework/common/udmf_utils.h | 33 +++++++++ .../innerkitsimpl/client/udmf_client.h | 60 ++++++++++++++++ .../innerkitsimpl/client/utd_client.cpp | 27 +++++++ .../innerkitsimpl/client/utd_client.h | 71 +++++++++++++++++++ 6 files changed, 258 insertions(+), 1 deletion(-) mode change 100644 => 100755 adapter/BUILD.gn create mode 100755 adapter/framework/common/udmf_utils.cpp create mode 100755 adapter/framework/common/udmf_utils.h create mode 100755 adapter/framework/innerkitsimpl/client/udmf_client.h mode change 100644 => 100755 adapter/framework/innerkitsimpl/client/utd_client.cpp create mode 100755 adapter/framework/innerkitsimpl/client/utd_client.h diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn old mode 100644 new mode 100755 index 42963c5..32d4ff8 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -73,6 +73,7 @@ config("arkui_x_udmf_config") { } arkui_x_public_source = [ + "${udmf_framework_path}/innerkitsimpl/client/getter_system.cpp", "${udmf_framework_path}/innerkitsimpl/common/unified_key.cpp", "${udmf_framework_path}/innerkitsimpl/common/unified_meta.cpp", "${udmf_framework_path}/innerkitsimpl/data/application_defined_record.cpp", @@ -102,9 +103,9 @@ ohos_source_set("arkui_x_udmf_data") { "${udmf_framework_path}/common/custom_utd_json_parser.cpp", "${udmf_framework_path}/common/custom_utd_store.cpp", "${udmf_framework_path}/common/graph.cpp", - "${udmf_framework_path}/common/udmf_utils.cpp", "${udmf_framework_path}/common/utd_cfgs_checker.cpp", "${udmf_framework_path}/common/utd_graph.cpp", + "${udmf_root_path}/adapter/framework/common/udmf_utils.cpp", ] sources += arkui_x_public_source diff --git a/adapter/framework/common/udmf_utils.cpp b/adapter/framework/common/udmf_utils.cpp new file mode 100755 index 0000000..2c0c1b1 --- /dev/null +++ b/adapter/framework/common/udmf_utils.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "udmf_utils.h" +#include +#include + +namespace OHOS { +namespace UDMF { +namespace UTILS { +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; +constexpr char SPECIAL = '^'; + +std::vector StrSplit(const std::string &str, const std::string &delimiter) +{ + std::vector result; + size_t start = 0; + size_t end = str.find(delimiter); + while (end != std::string::npos) { + result.push_back(str.substr(start, end - start)); + start = end + delimiter.length(); + end = str.find(delimiter, start); + } + result.push_back(str.substr(start)); + return result; +} + +std::vector Random(int32_t len, int32_t minimum, int32_t maximum) +{ + std::random_device randomDevice; + std::uniform_int_distribution distribution(minimum, maximum); + std::vector key(len); + for (int32_t i = 0; i < len; i++) { + key[i] = static_cast(distribution(randomDevice)); + } + return key; +} + +std::string GenerateId() +{ + std::vector randomDevices = Random(ID_LEN, MINIMUM, MAXIMUM); + std::stringstream idStr; + for (auto &randomDevice : randomDevices) { + auto asc = randomDevice; + asc = asc >= SPECIAL ? asc + 1 : asc; + idStr << static_cast(asc); + } + return idStr.str(); +} +} // namespace UTILS +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/adapter/framework/common/udmf_utils.h b/adapter/framework/common/udmf_utils.h new file mode 100755 index 0000000..d64e4dd --- /dev/null +++ b/adapter/framework/common/udmf_utils.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UDMF_UTILS_H +#define UDMF_UTILS_H + +#include +#include +namespace OHOS { +namespace UDMF { +namespace UTILS { +std::vector StrSplit(const std::string &str, const std::string &delimiter); +std::vector Random(int32_t len, int32_t minimum = 0, + int32_t maximum = std::numeric_limits::max()); +std::string GenerateId(); + +} // namespace UTILS +} // namespace UDMF +} // namespace OHOS + +#endif /* UDMF_UTILS_H */ diff --git a/adapter/framework/innerkitsimpl/client/udmf_client.h b/adapter/framework/innerkitsimpl/client/udmf_client.h new file mode 100755 index 0000000..4398f83 --- /dev/null +++ b/adapter/framework/innerkitsimpl/client/udmf_client.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UDMF_CLIENT_H +#define UDMF_CLIENT_H + +#include +#include +#include +#include + +#include "concurrent_map.h" +#include "error_code.h" +#include "unified_data.h" +#include "unified_meta.h" +#include "unified_types.h" +#include "visibility.h" +namespace OHOS { +namespace UDMF { +class API_EXPORT UdmfClient { +public: + static UdmfClient &GetInstance(); + + Status SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key); + Status GetData(const QueryOption &query, UnifiedData &unifiedData); + Status GetBatchData(const QueryOption &query, std::vector &unifiedDataSet); + Status UpdateData(const QueryOption &query, UnifiedData &unifiedData); + Status DeleteData(const QueryOption &query, std::vector &unifiedDataSet); + Status GetSummary(const QueryOption &query, Summary& summary); + Status AddPrivilege(const QueryOption &query, Privilege &privilege); + Status Sync(const QueryOption &query, const std::vector &devices); + Status IsRemoteData(const QueryOption &query, bool &result); + Status SetAppShareOption(const std::string &intention, enum ShareOptions shareOption); + Status RemoveAppShareOption(const std::string &intention); + Status GetAppShareOption(const std::string &intention, enum ShareOptions &shareOption); + +private: + UdmfClient() = default; + ~UdmfClient() = default; + UdmfClient(const UdmfClient &obj) = delete; + UdmfClient &operator=(const UdmfClient &obj) = delete; + std::string GetSelfBundleName(); + + ConcurrentMap dataCache_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_CLIENT_H \ No newline at end of file diff --git a/adapter/framework/innerkitsimpl/client/utd_client.cpp b/adapter/framework/innerkitsimpl/client/utd_client.cpp old mode 100644 new mode 100755 index ec365ee..5f40226 --- a/adapter/framework/innerkitsimpl/client/utd_client.cpp +++ b/adapter/framework/innerkitsimpl/client/utd_client.cpp @@ -70,5 +70,32 @@ Status UtdClient::IsUtd(std::string typeId, bool &result) { return Status::E_OK; } + +Status UtdClient::GetUniformDataTypesByFilenameExtension(const std::string &fileExtension, + std::vector &typeIds, const std::string &belongsTo) +{ + return Status::E_OK; +} + +std::string UtdClient::GetTypeIdFromCfg(const std::string &mimeType) +{ + return ""; +} + +std::vector UtdClient::GetTypeIdsFromCfg(const std::string &mimeType) +{ + std::vector typeIdsInCfg; + return typeIdsInCfg; +} + +void UtdClient::SubscribeUtdChange() +{ +} + +Status UtdClient::GetUniformDataTypesByMIMEType(const std::string &mimeType, std::vector &typeIds, + const std::string &belongsTo) +{ + return Status::E_OK; +} } // namespace UDMF } // namespace OHOS diff --git a/adapter/framework/innerkitsimpl/client/utd_client.h b/adapter/framework/innerkitsimpl/client/utd_client.h new file mode 100755 index 0000000..6456385 --- /dev/null +++ b/adapter/framework/innerkitsimpl/client/utd_client.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTD_CLIENT_H +#define UTD_CLIENT_H + +#include +#include +#include +#include + +#include "error_code.h" +#include "flexible_type.h" +#include "preset_type_descriptors.h" +#include "preset_type_descriptors.h" +#include "type_descriptor.h" +#include "utd_common.h" +#include "visibility.h" +namespace OHOS { +namespace UDMF { +class TypeDescriptor; +class UtdChangeSubscriber; +class API_EXPORT UtdClient { +public: + static UtdClient &GetInstance(); + Status GetTypeDescriptor(const std::string &typeId, std::shared_ptr &descriptor); + Status GetUniformDataTypeByFilenameExtension(const std::string &fileExtension, std::string &typeId, + std::string belongsTo = DEFAULT_TYPE_ID); + Status GetUniformDataTypesByFilenameExtension(const std::string &fileExtension, + std::vector &typeIds, const std::string &belongsTo = DEFAULT_TYPE_ID); + Status GetUniformDataTypeByMIMEType(const std::string &mimeType, std::string &typeId, + std::string belongsTo = DEFAULT_TYPE_ID); + Status GetUniformDataTypesByMIMEType(const std::string &mimeType, std::vector &typeIds, + const std::string &belongsTo = DEFAULT_TYPE_ID); + Status IsUtd(std::string typeId, bool &result); + +private: + UtdClient(); + ~UtdClient(); + UtdClient(const UtdClient &obj) = delete; + UtdClient &operator=(const UtdClient &obj) = delete; + void Init(); + bool IsHapTokenType(); + std::string GetCustomUtdPath(); + Status GetCurrentActiveUserId(int32_t& userId); + bool IsValidFileExtension(const std::string &fileExtension); + bool IsValidMimeType(const std::string &mimeType); + Status GetFlexibleTypeDescriptor(const std::string &typeId, std::shared_ptr &descriptor); + std::string GetTypeIdFromCfg(const std::string &mimeType); + std::vector GetTypeIdsFromCfg(const std::string &mimeType); + void SubscribeUtdChange(); + + std::vector descriptorCfgs_; + std::shared_ptr subscriber_; + std::shared_mutex utdMutex_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UTD_CLIENT_H \ No newline at end of file