1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/pkgmgr/step_run_parser_plugins.h"
10 #include "common/pkgmgr_registration.h"
11 #include "common/plugins/plugin_manager.h"
13 namespace common_installer {
16 bool StepRunParserPlugin::InitPluginManager(
17 const boost::filesystem::path& xml_path, manifest_x* manifest, uid_t uid) {
18 // PLUGINS_LIST_INSTALL_PATH path generated from cmake
19 const std::string listPath(PLUGINS_LIST_INSTALL_PATH);
20 plugin_manager_.reset(
21 new PluginManager(xml_path.string(), listPath, context_->pkgid.get(),
23 if (!plugin_manager_.get()) {
24 LOG(ERROR) << "plugin_manager_ reset fail, plugin_manager_ is NULL";
28 if (!plugin_manager_.get()->LoadPlugins(action_type_)) {
29 LOG(ERROR) << "Loading plugins failed in progress";
36 StepRunParserPlugin::StepRunParserPlugin(
37 InstallerContext* context, Plugin::ActionType action_type)
38 : Step(context), action_type_(action_type) {}
40 bool StepRunParserPlugin::ProcessPlugins(
41 const boost::filesystem::path& xml_path, manifest_x* manifest,
42 Plugin::ActionType action_type) {
43 if (!plugin_manager_.get()) {
44 if (!InitPluginManager(xml_path, manifest, context_->uid.get()))
47 if (!plugin_manager_.get()->RunPlugins(action_type))
50 LOG(INFO) << "Processing plugins done";
54 Step::Status StepRunParserPlugin::process() {
55 if (context_->force_clean_from_db.get())
57 if (!ProcessPlugins(context_->xml_path.get(), context_->manifest_data.get(),
61 switch (action_type_) {
62 case Plugin::ActionType::Install:
63 if (!RegisterPluginInfo(context_->manifest_data.get(),
65 context_->request_mode.get())) {
66 LOG(ERROR) << "Failed to register plugin execution info";
67 return Step::Status::REGISTER_ERROR;
70 case Plugin::ActionType::Upgrade:
71 if (!UpdatePluginInfo(context_->manifest_data.get(),
73 context_->request_mode.get())) {
74 LOG(ERROR) << "Failed to update plugin execution info";
75 return Step::Status::REGISTER_ERROR;
78 case Plugin::ActionType::Uninstall:
79 if (!UnregisterPluginInfo(context_->pkgid.get(),
81 context_->request_mode.get())) {
82 LOG(ERROR) << "Failed to remove plugin execution info";
83 return Step::Status::REGISTER_ERROR;
89 return Step::Status::OK;
92 Step::Status StepRunParserPlugin::undo() {
93 Step::Status ret = Status::OK;
94 switch (action_type_) {
95 case Plugin::ActionType::Install:
96 if (!UnregisterPluginInfo(context_->pkgid.get(),
98 context_->request_mode.get())) {
99 LOG(ERROR) << "Failed to undo registering plugin execution info";
100 ret = Step::Status::REGISTER_ERROR;
103 case Plugin::ActionType::Upgrade:
104 if (!UnregisterPluginInfo(context_->pkgid.get(),
106 context_->request_mode.get())) {
107 LOG(ERROR) << "Failed to revert plugin execution info";
108 ret = Step::Status::REGISTER_ERROR;
111 if (!RegisterPluginInfo(context_->old_manifest_data.get(),
113 context_->request_mode.get())) {
114 LOG(ERROR) << "Failed to revert plugin execution info";
115 ret = Step::Status::REGISTER_ERROR;
118 case Plugin::ActionType::Uninstall:
119 if (!RegisterPluginInfo(context_->manifest_data.get(),
121 context_->request_mode.get())) {
122 LOG(ERROR) << "Failed to remove plugin execution info";
123 ret = Step::Status::REGISTER_ERROR;
130 // For update, we need to reread configuration of old version of widget
131 // so running whole process from beginning
132 if (action_type_ == Plugin::ActionType::Install) {
133 if (!ProcessPlugins(context_->xml_path.get(),
134 context_->manifest_data.get(),
135 Plugin::ActionType::Undo))
137 } else if (action_type_ == Plugin::ActionType::Upgrade) {
138 plugin_manager_.reset();
139 if (!ProcessPlugins(context_->backup_xml_path.get(),
140 context_->old_manifest_data.get(),
141 Plugin::ActionType::Undo))
147 Step::Status StepRunParserPlugin::clean() {
148 ProcessPlugins(context_->xml_path.get(),
149 context_->manifest_data.get(),
150 Plugin::ActionType::Clean);
155 } // namespace pkgmgr
156 } // namespace common_installer