2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <pkgmgr_installer_info.h>
20 #include "common/database.hh"
21 #include "common/exception.hh"
22 #include "common/log_private.hh"
23 #include "common/metadata_plugin.hh"
24 #include "common/metadata_type.hh"
28 void MetadataPlugin::AddAppEventArgs(const std::string& pkgid,
29 const std::string& appid, EventType event_type, GList* list) {
30 auto args = new (std::nothrow) AppEventArgs(appid, pkgid, event_type);
31 if (args == nullptr) {
38 metadata_t* md = static_cast<metadata_t*>(iter->data);
39 args->AddMetadata(std::unique_ptr<Metadata>(
40 new (std::nothrow) Metadata(md->key, md->value)));
41 iter = g_list_next(iter);
44 list_.emplace_back(args);
47 void MetadataPlugin::Clean() {
51 for (auto& args : list_) {
53 if (args->GetEventType() == EventType::Install) {
54 ret = StepInstall(args);
55 } else if (args->GetEventType() == EventType::Uninstall) {
56 ret = StepUninstall(args);
57 } else if (args->GetEventType() == EventType::Upgrade) {
58 ret = StepUpgrade(args);
69 Database* MetadataPlugin::GetDB() {
73 uid_t MetadataPlugin::GetUid() {
75 pkgmgr_installer_info_get_target_uid(&target_uid);
79 bool MetadataPlugin::Prepare() {
82 if (!db_->IntegrityCheck())
84 db_->BeginTransaction();
85 } catch (Exception& e) {
91 bool MetadataPlugin::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
95 bool MetadataPlugin::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
99 bool MetadataPlugin::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
103 void MetadataPlugin::Post() {
105 db_->EndTransaction();
107 } catch (Exception& e) {
108 _E("Exception(%d) occurs", e.GetErrorCode());
112 void MetadataPlugin::Rollback() {
115 } catch (Exception& e) {
116 _E("Exception(%d) occurs", e.GetErrorCode());
120 void MetadataPlugin::Undo() {
124 } // namespace plugin