From: Ilho Kim Date: Tue, 20 Sep 2022 06:02:06 +0000 (+0900) Subject: Remove unused code X-Git-Tag: accepted/tizen/unified/20220923.052708~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e875d3995d1c17b30cec7cea574150e46d8d80e3;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Remove unused code Change-Id: I6e989171828fc4a555b98e4d696ba0d115384de1 Signed-off-by: Ilho Kim --- diff --git a/src/server/database/cache.cc b/src/server/database/cache.cc deleted file mode 100644 index f26ec0a..0000000 --- a/src/server/database/cache.cc +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 "cache.hh" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "filter_checker_provider.hh" -#include "utils/logging.hh" - -#include "pkgmgrinfo_private.h" -#include "pkgmgrinfo_internal.h" -#include "pkgmgrinfo_internal.hh" - -namespace pkgmgr_server { -namespace database { - -std::unordered_map> Cache::cache_map_; - -Cache::Cache(uid_t uid) : uid_(uid), status_(Status::UNPREPARED) {} - -Cache& Cache::GetInst(uid_t uid) { - static std::mutex singleton_lock_; - std::unique_lock u(singleton_lock_); - - auto& prov = cache_map_[uid]; - if (prov == nullptr) - prov.reset(new Cache(uid)); - - return *prov; -} - -void Cache::ReleaseAll() { - static std::mutex singleton_lock_; - std::unique_lock u(singleton_lock_); - - for (auto& i : cache_map_) - i.second->ReleaseCache(); -} - -bool Cache::IsCachePreparationNecessary() { - bool result = false; - std::unique_lock u(status_lock_); - if (status_ == Status::UNPREPARED) { - status_ = Status::PREPARING; - result = true; - } - - return result; -} - -void Cache::SetPrepared() { - std::unique_lock u(status_lock_); - status_ = Status::PREPARED; -} - -void Cache::SetUnprepared() { - std::unique_lock u(status_lock_); - status_ = Status::UNPREPARED; -} - -void Cache::SetPreparing() { - std::unique_lock u(status_lock_); - status_ = Status::PREPARING; -} - -bool Cache::IsPrepared() { - std::unique_lock u(status_lock_); - return (status_ == Status::PREPARED); -} - -void Cache::ReleaseCache() { - auto lock = GetWriterLock(); - SetStatus(Status::PREPARING); - - pkg_map_.clear(); - app_map_.clear(); - - SetStatus(Status::UNPREPARED); -} - -void Cache::SetStatus(Status status) { - std::unique_lock u(status_lock_); - status_ = status; -} - -std::unique_lock Cache::GetWriterLock() { - return std::unique_lock(lock_); -} - -void Cache::WriterUnLock() { - lock_.unlock(); -} - -std::shared_lock Cache::GetReaderLock() { - return std::shared_lock(lock_, std::defer_lock); -} - -void Cache::ReaderUnLock() { - lock_.unlock(); -} - -void Cache::AddPackage(std::string package, package_x* info) { - auto ptr = std::shared_ptr(info, pkgmgrinfo_basic_free_package); - pkg_map_[package].push_back(ptr); - pkg_map_[""].push_back(std::move(ptr)); -} - -void Cache::AddApplication( - std::string app, std::shared_ptr info) { - app_map_[app].push_back(info); - app_map_[""].push_back(std::move(info)); -} - -int Cache::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write, - const std::string& locale) { - // CacheProvider should lock first and try lock before executing this func - pkg_map_.clear(); - app_map_.clear(); - - GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal); - if (list == nullptr) { - LOG(ERROR) << "Out of memory"; - return PMINFO_R_ERROR; - } - - auto tmp_filter = reinterpret_cast( - calloc(1, sizeof(pkgmgrinfo_filter_x))); - if (tmp_filter == nullptr) { - LOG(ERROR) << "Out of memory"; - g_hash_table_destroy(list); - return PMINFO_R_ERROR; - } - - int ret = pkginfo_internal_filter_get_list(db, tmp_filter, uid_, - locale.c_str(), list); - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(tmp_filter); - return ret; - } - - GHashTableIter iter; - gpointer value; - g_hash_table_iter_init(&iter, list); - while (g_hash_table_iter_next(&iter, nullptr, &value)) { - auto* pkg = reinterpret_cast(value); - AddPackage(pkg->package, pkg); - } - g_hash_table_destroy(list); - - std::vector> app_list; - ret = pkgmgr_server::internal::appinfo_internal_filter_get_list(db, - tmp_filter, uid_, uid, locale.c_str(), app_list); - free(tmp_filter); - if (ret == PMINFO_R_OK) { - for (auto& app : app_list) { - app->privileges = pkg_map_[app->package].front()->privileges; - std::string appid = app->appid; - AddApplication(std::move(appid), std::move(app)); - } - } - - return 0; -} - -std::vector> Cache::GetPackages( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& package) { - std::vector> ret; - - for (auto& info : pkg_map_[package]) { - bool pass = true; - for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) { - auto node = reinterpret_cast(it->data); - auto* checker = FilterCheckerProvider::GetInst(). - GetPkgFilterChecker(node->prop); - if (!checker->CheckFilter(node, info.get())) { - pass = false; - break; - } - } - if (pass) - ret.push_back(info); - } - - return ret; -} - - -std::vector> Cache::GetApplications( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& app) { - /* make metadata filter map */ - std::unordered_map metadata_map; - for (auto* it = filter->list_metadata; it != nullptr; it = g_slist_next(it)) { - auto node = reinterpret_cast(it->data); - if (node->key == nullptr) - continue; - - metadata_map[node->key] = (node->value ? node->value : ""); - } - - std::vector> ret; - for (auto& info : app_map_[app]) { - bool pass = true; - for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) { - auto node = reinterpret_cast(it->data); - auto* checker = FilterCheckerProvider::GetInst(). - GetAppFilterChecker(node->prop); - if (!checker->CheckFilter(node, info.get())) { - pass = false; - break; - } - } - if (!pass) - continue; - - if (!metadata_map.empty()) { - pass = false; - for (auto* it = info->metadata; it != nullptr; it = g_list_next(it)) { - auto* node = reinterpret_cast(it->data); - if (node->key != nullptr) { - auto metadata = metadata_map.find(node->key); - if (metadata != metadata_map.end() && - strstr(node->value ? node->value : "", - metadata->second.c_str()) != nullptr) { - pass = true; - break; - } - } - } - } - - if (pass) - ret.push_back(info); - } - - return ret; -} - -} // namespace database -} // namespace pkgmgr_server diff --git a/src/server/database/cache.hh b/src/server/database/cache.hh deleted file mode 100644 index 4c9fee9..0000000 --- a/src/server/database/cache.hh +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 SERVER_CACHE_HH_ -#define SERVER_CACHE_HH_ - -#include - -#include -#include -#include -#include -#include - -#include - -#include "pkgmgrinfo_private.h" - -namespace pkgmgr_server { -namespace database { - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif - -class EXPORT_API Cache { - public: - ~Cache() = default; - static Cache& GetInst(uid_t uid); - - void ReleaseCache(); - bool IsCachePreparationNecessary(); - int UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write, - const std::string& locale); - std::vector> GetPackages( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& package); - std::vector> GetApplications( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& app); - void SetPrepared(); - void SetUnprepared(); - void SetPreparing(); - bool IsPrepared(); - - std::unique_lock GetWriterLock(); - void WriterUnLock(); - std::shared_lock GetReaderLock(); - void ReaderUnLock(); - - static void ReleaseAll(); - - private: - explicit Cache(uid_t uid); - enum class EXPORT_API Status { - UNPREPARED, - PREPARING, - PREPARED - }; - - void SetStatus(Status status); - - void AddPackage(std::string package, package_x* info); - void AddApplication(std::string app, std::shared_ptr info); - - std::mutex status_lock_; - std::shared_timed_mutex lock_; - uid_t uid_; - Status status_; - std::unordered_map>> - pkg_map_; - std::unordered_map>> - app_map_; - - static std::unordered_map> cache_map_; -}; - -} // namespace database -} // namespace pkgmgr_server - -#endif // SERVER_CACHE_HH_ diff --git a/src/server/database/cache_provider.cc b/src/server/database/cache_provider.cc deleted file mode 100644 index 25b82f7..0000000 --- a/src/server/database/cache_provider.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 "cache_provider.hh" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "cache.hh" -#include "filter_checker_provider.hh" -#include "utils/logging.hh" - -#include "pkgmgrinfo_private.h" -#include "pkgmgrinfo_internal.h" -#include "pkgmgrinfo_internal.hh" - -namespace { - -uid_t globaluser_uid = -1; - -uid_t GetGlobalUID() { - if (globaluser_uid == (uid_t)-1) - globaluser_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); - - return globaluser_uid; -} - -uid_t ConvertUID(uid_t uid) { - if (uid < REGULAR_USER) - return GetGlobalUID(); - else - return uid; -} - -} // namespace - -namespace pkgmgr_server { -namespace database { - -bool CacheProvider::IsCachePreparationNecessary() { - return Cache::GetInst(ConvertUID(uid_)).IsCachePreparationNecessary(); -} - -void CacheProvider::ReleaseCache() { - Cache::GetInst(ConvertUID(uid_)).ReleaseCache(); -} - -void CacheProvider::ReleaseAll() { - Cache::ReleaseAll(); -} - -bool CacheProvider::IsPrepared() { - return Cache::GetInst(ConvertUID(uid_)).IsPrepared(); -} - -bool CacheProvider::GetReadLock() { - reader_lock_ = Cache::GetInst(ConvertUID(uid_)).GetReaderLock(); - if (reader_lock_.try_lock() && Cache::GetInst(ConvertUID(uid_)).IsPrepared()) - return true; - - reader_lock_.unlock(); - return false; -} - -void CacheProvider::SetUnprepared() { - Cache::GetInst(ConvertUID(uid_)).SetUnprepared(); -} - -int CacheProvider::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write, - const std::string& locale) { - auto lock = Cache::GetInst(ConvertUID(uid_)).GetWriterLock(); - - int ret = Cache::GetInst(ConvertUID(uid_)).UpdateCache( - db, pid, uid, write, locale); - - if (ret == PMINFO_R_OK) - Cache::GetInst(ConvertUID(uid_)).SetPrepared(); - else - Cache::GetInst(ConvertUID(uid_)).SetUnprepared(); - - return ret; -} - -std::vector> CacheProvider::GetPackages( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& package) { - std::vector> ret; - - uid_t target_uid = ConvertUID(uid_); - ret = Cache::GetInst(target_uid).GetPackages(pid, write, filter, package); - - return ret; -} - -std::vector> CacheProvider::GetApplications( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& app) { - std::vector> ret; - uid_t target_uid = ConvertUID(uid_); - ret = Cache::GetInst(target_uid).GetApplications(pid, write, filter, app); - - return ret; -} - - -} // namespace database -} // namespace pkgmgr_server diff --git a/src/server/database/cache_provider.hh b/src/server/database/cache_provider.hh deleted file mode 100644 index d1b8db2..0000000 --- a/src/server/database/cache_provider.hh +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 SERVER_CACHE_PROVIDER_HH_ -#define SERVER_CACHE_PROVIDER_HH_ - -#include - -#include -#include -#include -#include -#include - -#include - -#include "pkgmgrinfo_private.h" - -namespace pkgmgr_server { -namespace database { - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif - -class EXPORT_API CacheProvider { - public: - enum class EXPORT_API CacheOpResult { - - PREPARED - }; - - CacheProvider(uid_t uid) : uid_(uid) {}; - bool IsCachePreparationNecessary(); - int UpdateCache(sqlite3* db, pid_t pid, uid_t uid, - bool write, const std::string& locale); - bool GetReadLock(); - bool IsPrepared(); - void ReleaseCache(); - static void ReleaseAll(); - void SetUnprepared(); - - std::vector> GetPackages( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& package); - std::vector> GetApplications( - pid_t pid, bool write, pkgmgrinfo_filter_x* filter, - const std::string& app); - - private: - uid_t uid_; - std::shared_lock reader_lock_; -}; - -} // namespace database -} // namespace pkgmgr_server - -#endif // SERVER_CACHE_PROVIDER_HH_