From d932331f9f805478a17ccd7642513c21c92f78bd Mon Sep 17 00:00:00 2001 From: q30042978 Date: Tue, 23 May 2023 20:00:03 +0800 Subject: [PATCH] =?UTF-8?q?Description:=E8=A7=A3=E5=86=B3CustomOption?= =?UTF-8?q?=E7=9A=84Intention=E4=B8=8D=E4=BC=A0=E5=8F=82=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20Team:OTHERS=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source?= =?UTF-8?q?:No=20PrivateCode(Yes/No):No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30042978 --- framework/common/udmf_types_util.cpp | 2 +- .../innerkitsimpl/common/unified_meta.cpp | 22 ++++++++++++++++++- .../test/unittest/udmf_client_test.cpp | 3 +++ framework/manager/lifecycle/clean_after_get.h | 2 +- .../manager/lifecycle/lifecycle_manager.cpp | 2 +- .../manager/lifecycle/lifecycle_policy.cpp | 9 ++++---- framework/manager/store/runtime_store.cpp | 12 +++++----- framework/manager/store/runtime_store.h | 2 +- framework/manager/store/store.h | 2 +- interfaces/innerkits/common/unified_meta.h | 12 +++++++--- 10 files changed, 49 insertions(+), 19 deletions(-) diff --git a/framework/common/udmf_types_util.cpp b/framework/common/udmf_types_util.cpp index c3fb2e7..75a4b34 100755 --- a/framework/common/udmf_types_util.cpp +++ b/framework/common/udmf_types_util.cpp @@ -600,7 +600,7 @@ template<> bool Unmarshalling(Intention &output, MessageParcel &parcel) LOG_ERROR(UDMF_FRAMEWORK, "Unmarshal PlainText failed!"); return false; } - if (intention < UD_INTENTION_DRAG || intention >= UD_INTENTION_BUTT) { + if (!UnifiedDataUtils::IsValidIntention(intention)) { LOG_ERROR(UDMF_FRAMEWORK, "invalid UDIntention!"); return false; } diff --git a/framework/innerkitsimpl/common/unified_meta.cpp b/framework/innerkitsimpl/common/unified_meta.cpp index 8a03d01..3db4ced 100644 --- a/framework/innerkitsimpl/common/unified_meta.cpp +++ b/framework/innerkitsimpl/common/unified_meta.cpp @@ -24,7 +24,7 @@ bool UnifiedDataUtils::IsValidType(int32_t value) bool UnifiedDataUtils::IsValidIntention(int32_t value) { - return value >= UD_INTENTION_DRAG && value < UD_INTENTION_BUTT; + return value > UD_INTENTION_BASE && value < UD_INTENTION_BUTT; } size_t UnifiedDataUtils::GetVariantSize(UDVariant &variant) @@ -65,5 +65,25 @@ size_t UnifiedDataUtils::GetDetailsSize(UDDetails &details) } return total; } + +bool UnifiedDataUtils::IsPersist(const Intention &intention) +{ + return intention > UD_INTENTION_SYS && intention < UD_INTENTION_BUTT; +} + +bool UnifiedDataUtils::IsPersist(const std::string &intention) +{ + return IsPersist(GetIntentionByString(intention)); +} + +Intention UnifiedDataUtils::GetIntentionByString(const std::string &intention) +{ + for (const auto &it : UD_INTENTION_MAP) { + if (it.second == intention) { + return static_cast(it.first); + } + } + return UD_INTENTION_BUTT; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp index abab11d..56d67d2 100755 --- a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp +++ b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp @@ -218,6 +218,9 @@ HWTEST_F(UdmfClientTest, SetData001, TestSize.Level1) status = UdmfClient::GetInstance().SetData(option, data, key); EXPECT_EQ(status, E_INVALID_PARAMETERS); + option = {}; + status = UdmfClient::GetInstance().SetData(option, data, key); + EXPECT_EQ(status, E_INVALID_PARAMETERS); LOG_INFO(UDMF_TEST, "SetData001 end."); } diff --git a/framework/manager/lifecycle/clean_after_get.h b/framework/manager/lifecycle/clean_after_get.h index ef29196..94b7142 100644 --- a/framework/manager/lifecycle/clean_after_get.h +++ b/framework/manager/lifecycle/clean_after_get.h @@ -18,7 +18,7 @@ namespace OHOS { namespace UDMF { -class CleanAfterGetdata : public LifeCyclePolicy { +class CleanAfterGet : public LifeCyclePolicy { public: }; } // namespace UDMF diff --git a/framework/manager/lifecycle/lifecycle_manager.cpp b/framework/manager/lifecycle/lifecycle_manager.cpp index ddfd2f4..19f662c 100644 --- a/framework/manager/lifecycle/lifecycle_manager.cpp +++ b/framework/manager/lifecycle/lifecycle_manager.cpp @@ -23,7 +23,7 @@ namespace UDMF { std::shared_ptr LifeCycleManager::executorPool_ = std::make_shared(2, 1); std::unordered_map> LifeCycleManager::intentionPolicyMap_ = { - { UD_INTENTION_MAP.at(UD_INTENTION_DRAG), std::make_shared() }, + { UD_INTENTION_MAP.at(UD_INTENTION_DRAG), std::make_shared() }, }; LifeCycleManager &LifeCycleManager::GetInstance() diff --git a/framework/manager/lifecycle/lifecycle_policy.cpp b/framework/manager/lifecycle/lifecycle_policy.cpp index b689671..caaea62 100644 --- a/framework/manager/lifecycle/lifecycle_policy.cpp +++ b/framework/manager/lifecycle/lifecycle_policy.cpp @@ -19,7 +19,8 @@ namespace OHOS { namespace UDMF { -const LifeCyclePolicy::Duration LifeCyclePolicy::INTERVAL = std::chrono::milliseconds(60 * 60 * 1000); +using namespace std::chrono; +const LifeCyclePolicy::Duration LifeCyclePolicy::INTERVAL = milliseconds(60 * 60 * 1000); const std::string LifeCyclePolicy::DATA_PREFIX = "udmf://"; Status LifeCyclePolicy::DeleteOnGet(const UnifiedKey &key) @@ -70,13 +71,13 @@ std::vector LifeCyclePolicy::GetTimeoutKeys(const std::shared_ptr datas = store->GetDatas(DATA_PREFIX); std::vector timeoutKeys; if (datas.empty()) { - LOG_INFO(UDMF_FRAMEWORK, "entries is empty."); + LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); return timeoutKeys; } auto curTime = PreProcessUtils::GetInstance().GetTimeStamp(); for (const auto &data : datas) { - if (curTime > data.GetRuntime()->createTime - + std::chrono::duration_cast(interval).count()) { + if (curTime > data.GetRuntime()->createTime + duration_cast(interval).count() + || curTime < data.GetRuntime()->createTime) { timeoutKeys.push_back(data.GetRuntime()->key.key); } } diff --git a/framework/manager/store/runtime_store.cpp b/framework/manager/store/runtime_store.cpp index e8a2bca..ec4ba0a 100755 --- a/framework/manager/store/runtime_store.cpp +++ b/framework/manager/store/runtime_store.cpp @@ -82,7 +82,7 @@ Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) { std::vector entries = GetEntries(key); if (entries.empty()) { - LOG_ERROR(UDMF_FRAMEWORK, "KvStore getEntries failed, key: %{public}s.", key.c_str()); + LOG_DEBUG(UDMF_FRAMEWORK, "KvStore getEntries failed, key: %{public}s.", key.c_str()); return E_OK; } for (const auto &entry : entries) { @@ -148,7 +148,7 @@ Status RuntimeStore::Delete(const std::string &key) { std::vector entries = GetEntries(key); if (entries.empty()) { - LOG_INFO(UDMF_FRAMEWORK, "KvStore getEntries failed, key: %{public}s.", key.c_str()); + LOG_DEBUG(UDMF_FRAMEWORK, "KvStore getEntries failed, key: %{public}s.", key.c_str()); return E_OK; } std::vector keys; @@ -163,11 +163,11 @@ Status RuntimeStore::Delete(const std::string &key) return E_OK; } -Status RuntimeStore::DeleteBatch(std::vector timeoutKeys) +Status RuntimeStore::DeleteBatch(const std::vector &timeoutKeys) { Status status = E_OK; if (timeoutKeys.empty()) { - LOG_INFO(UDMF_SERVICE, "No need to delete!"); + LOG_DEBUG(UDMF_SERVICE, "No need to delete!"); return status; } for (const std::string &timeoutKey : timeoutKeys) { @@ -222,7 +222,7 @@ std::vector RuntimeStore::GetDatas(const std::string &dataPrefix) std::vector unifiedDatas; auto entries = GetEntries(dataPrefix); if (entries.empty()) { - LOG_INFO(UDMF_FRAMEWORK, "entries is empty."); + LOG_DEBUG(UDMF_FRAMEWORK, "entries is empty."); return unifiedDatas; } for (const auto &entry : entries) { @@ -244,7 +244,7 @@ std::vector RuntimeStore::GetEntries(const std::string &dataPrefix) query.OrderByWriteTime(true); auto status = kvStore_->GetEntries(query, entries); if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "KvStore getEntries failed, status: %{public}d.", static_cast(status)); + LOG_DEBUG(UDMF_SERVICE, "KvStore getEntries failed, status: %{public}d.", static_cast(status)); } return entries; } diff --git a/framework/manager/store/runtime_store.h b/framework/manager/store/runtime_store.h index dde13c3..48035b9 100755 --- a/framework/manager/store/runtime_store.h +++ b/framework/manager/store/runtime_store.h @@ -31,7 +31,7 @@ public: Status GetSummary(const std::string &key, Summary &summary) override; Status Update(const UnifiedData &unifiedData) override; Status Delete(const std::string &key) override; - Status DeleteBatch(std::vector timeoutKeys) override; + Status DeleteBatch(const std::vector &timeoutKeys) override; Status Sync(const std::vector &devices) override; Status Clear() override; void Close() override; diff --git a/framework/manager/store/store.h b/framework/manager/store/store.h index d9e288b..d7eb692 100755 --- a/framework/manager/store/store.h +++ b/framework/manager/store/store.h @@ -31,7 +31,7 @@ public: virtual Status GetSummary(const std::string &key, Summary &summary) = 0; virtual Status Update(const UnifiedData &unifiedData) = 0; virtual Status Delete(const std::string &key) = 0; - virtual Status DeleteBatch(std::vector timeoutKeys) = 0; + virtual Status DeleteBatch(const std::vector &timeoutKeys) = 0; virtual Status Sync(const std::vector &devices) = 0; virtual Status Clear() = 0; virtual bool Init() = 0; diff --git a/interfaces/innerkits/common/unified_meta.h b/interfaces/innerkits/common/unified_meta.h index d718e3f..0b090ee 100644 --- a/interfaces/innerkits/common/unified_meta.h +++ b/interfaces/innerkits/common/unified_meta.h @@ -103,14 +103,17 @@ using UDDetails = std::map; * UnifiedData Intention. */ enum Intention : int32_t { - UD_INTENTION_DRAG = 0, - UD_INTENTION_SYS, + UD_INTENTION_BASE = 0, + UD_INTENTION_DRAG, UD_INTENTION_SHARE, + UD_INTENTION_SYS, + UD_INTENTION_SUPERHUB, UD_INTENTION_BUTT, }; static const std::unordered_map UD_INTENTION_MAP { - {UD_INTENTION_DRAG, "drag"} + { UD_INTENTION_DRAG, "drag" }, + { UD_INTENTION_SUPERHUB, "SuperHub" }, }; class UnifiedDataUtils { @@ -119,6 +122,9 @@ public: static bool IsValidIntention(int32_t value); static size_t GetVariantSize(UDVariant &variant); static size_t GetDetailsSize(UDDetails &details); + static bool IsPersist(const Intention &intention); + static bool IsPersist(const std::string &intention); + static Intention GetIntentionByString(const std::string &intention); }; } // namespace UDMF } // namespace OHOS -- Gitee