Add InstallerFactory, InstallerRunner classes for multi pkg install 55/225055/11
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 7 Feb 2020 06:14:44 +0000 (15:14 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 24 Mar 2020 05:15:01 +0000 (14:15 +0900)
These new classes are for multi pkg install feature.
The backend which wants to handle multiple install request at once
should implement its own factory class. The main function of backend
should create instance of InstallerRunner class with its own factory
class and invoke Run() method of InstallerRunner class.

Change-Id: I57da804ede61e793e64cb1b8fc4765a8b75b90c3
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/installer_factory.h [new file with mode: 0644]
src/common/installer_runner.cc [new file with mode: 0644]
src/common/installer_runner.h [new file with mode: 0644]

diff --git a/src/common/installer_factory.h b/src/common/installer_factory.h
new file mode 100644 (file)
index 0000000..8e7cc4e
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_INSTALLER_FACTORY_H_
+#define COMMON_INSTALLER_FACTORY_H_
+
+#include <memory>
+
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+class AppInstaller;
+
+class InstallerFactory {
+ public:
+  virtual std::unique_ptr<AppInstaller> CreateInstaller(PkgMgrPtr pkgmgr,
+      int idx) = 0;
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_INSTALLER_FACTORY_H_
diff --git a/src/common/installer_runner.cc b/src/common/installer_runner.cc
new file mode 100644 (file)
index 0000000..c9e45ca
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/installer_runner.h"
+
+#include <manifest_parser/utils/logging.h>
+
+#include <list>
+
+#include "common/app_installer.h"
+#include "common/installer_factory.h"
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+InstallerRunner::InstallerRunner(
+    std::unique_ptr<InstallerFactory> factory, PkgMgrPtr pkgmgr)
+    : factory_(std::move(factory)), pkgmgr_(pkgmgr) {
+  Init();
+}
+
+AppInstaller::Result InstallerRunner::Run() {
+  AppInstaller::Result result = AppInstaller::Result::OK;
+  std::list<std::unique_ptr<AppInstaller>>::iterator it(installers_.begin());
+  for (; it != installers_.end(); ++it) {
+    result = (*it)->Process();
+    if (result != AppInstaller::Result::OK)
+      break;
+  }
+  if (it != installers_.end() && result == AppInstaller::Result::ERROR) {
+    do {
+      if ((*it)->Undo() != AppInstaller::Result::OK)
+        result = AppInstaller::Result::UNDO_ERROR;
+    } while (it-- != installers_.begin());
+  } else {
+    --it;
+    do {
+      if ((*it)->Clean() != AppInstaller::Result::OK)
+        result = AppInstaller::Result::CLEANUP_ERROR;
+    } while (it-- != installers_.begin());
+  }
+
+  return result;
+}
+
+void InstallerRunner::Init() {
+  for (int i = 0; i < pkgmgr_->GetRequestInfoCount(); i++) {
+    std::unique_ptr<AppInstaller> installer =
+        factory_->CreateInstaller(pkgmgr_, i);
+    installers_.emplace_back(std::move(installer));
+  }
+}
+
+}  // namespace common_installer
diff --git a/src/common/installer_runner.h b/src/common/installer_runner.h
new file mode 100644 (file)
index 0000000..83a76df
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_INSTALLER_RUNNER_H_
+#define COMMON_INSTALLER_RUNNER_H_
+
+#include <list>
+#include <memory>
+
+#include "common/app_installer.h"
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+
+class InstallerFactory;
+
+class InstallerRunner {
+ public:
+  explicit InstallerRunner(
+      std::unique_ptr<InstallerFactory> factory, PkgMgrPtr pkgmgr);
+
+  AppInstaller::Result Run();
+
+ private:
+  void Init();
+
+  std::unique_ptr<InstallerFactory> factory_;
+  PkgMgrPtr pkgmgr_;
+  std::list<std::unique_ptr<AppInstaller>> installers_;
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_INSTALLER_RUNNER_H_