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 if ((*it)->Undo() != AppInstaller::Result::OK)
34 result = AppInstaller::Result::UNDO_ERROR;
35 } while (it-- != installers_.begin());
39 if ((*it)->Clean() != AppInstaller::Result::OK)
40 result = AppInstaller::Result::CLEANUP_ERROR;
41 } while (it-- != installers_.begin());
47 void InstallerRunner::Init() {
48 for (int i = 0; i < pkgmgr_->GetRequestInfoCount(); i++) {
49 std::unique_ptr<AppInstaller> installer =
50 factory_->CreateInstaller(pkgmgr_, i);
51 installers_.emplace_back(std::move(installer));
55 } // namespace common_installer