1 // Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/installer_runner.h"
7 #include <manifest_parser/utils/logging.h>
11 #include "common/app_installer.h"
12 #include "common/installer_factory.h"
13 #include "common/pkgmgr_interface.h"
15 namespace common_installer {
17 InstallerRunner::InstallerRunner(
18 std::unique_ptr<InstallerFactory> factory, PkgMgrPtr pkgmgr)
19 : factory_(std::move(factory)), pkgmgr_(pkgmgr) {
23 AppInstaller::Result InstallerRunner::Run() {
24 AppInstaller::Result result = AppInstaller::Result::OK;
25 std::list<std::unique_ptr<AppInstaller>>::iterator it(installers_.begin());
26 for (; it != installers_.end(); ++it) {
27 result = (*it)->Process();
28 if (result != AppInstaller::Result::OK)
31 if (it != installers_.end() && result == AppInstaller::Result::ERROR) {
33 AppInstaller::Result ret = (*it)->Undo();
34 if (ret != AppInstaller::Result::OK && ret != AppInstaller::Result::ERROR)
35 result = AppInstaller::Result::UNDO_ERROR;
36 } while (it-- != installers_.begin());
40 // Clean operation always succeeds
42 } while (it-- != installers_.begin());
48 void InstallerRunner::Init() {
49 for (int i = 0; i < pkgmgr_->GetRequestInfoCount(); i++) {
50 std::unique_ptr<AppInstaller> installer =
51 factory_->CreateInstaller(pkgmgr_, i);
52 installers_.emplace_back(std::move(installer));
56 } // namespace common_installer