Add TpkInstallerFactory 05/231105/4
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 17 Apr 2020 07:40:26 +0000 (16:40 +0900)
committerilho kim <ilho159.kim@samsung.com>
Tue, 19 May 2020 06:17:00 +0000 (06:17 +0000)
Now tpk-backend uses installer-runner to run the installer

Change-Id: I8cbc1b19f4f6fb9887ffab001453e4badef08f96
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/tpk/tpk_backend.cc
src/tpk/tpk_installer_factory.cc [new file with mode: 0644]
src/tpk/tpk_installer_factory.h [new file with mode: 0644]

index e23da22ce57749153130219ce053de13cb32e8e0..4e0cc0319f7cc7174f65f7da3fd3188096d349ec 100644 (file)
@@ -1,5 +1,6 @@
 /* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
 
+#include <common/installer_runner.h>
 #include <common/pkgmgr_interface.h>
 
 #include <manifest_parser/utils/logging.h>
@@ -8,10 +9,21 @@
 #include <TTraceWrapper.h>
 
 #include "tpk/tpk_app_query_interface.h"
-#include "tpk/tpk_installer.h"
+#include "tpk/tpk_installer_factory.h"
 
 namespace ci = common_installer;
 
+#if __cplusplus < 201300L
+namespace {
+
+template<typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args&&... args) {
+  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+}  // namespace
+#endif
+
 int main(const int argc, char* argv[]) {
   TTRACE(TTRACE_TAG_APP, "TPK_BACKEND");
 
@@ -25,10 +37,12 @@ int main(const int argc, char* argv[]) {
     return -1;
   }
 
-  tpk::TpkInstaller t(pkgmgr);
-  if (t.Run() != ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "TpkInstaller run failure";
-    return -1;
-  }
-  return 0;
+#if __cplusplus >= 201300L
+  using std;
+#endif
+  ci::InstallerRunner runner(
+      make_unique<tpk::TpkInstallerFactory>(), pkgmgr);
+  ci::AppInstaller::Result result = runner.Run();
+
+  return (result == ci::AppInstaller::Result::OK) ? 0 : 1;
 }
diff --git a/src/tpk/tpk_installer_factory.cc b/src/tpk/tpk_installer_factory.cc
new file mode 100644 (file)
index 0000000..f8f7a5f
--- /dev/null
@@ -0,0 +1,37 @@
+// 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 "tpk/tpk_installer_factory.h"
+
+#include <unzip.h>
+
+#include <manifest_parser/utils/logging.h>
+#include <tpk/tpk_app_query_interface.h>
+#include <tpk/tpk_installer.h>
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_query.h"
+
+namespace ci = common_installer;
+
+namespace tpk {
+
+std::unique_ptr<ci::AppInstaller> TpkInstallerFactory::CreateInstaller(
+    ci::PkgMgrPtr pkgmgr, int idx) {
+  std::unique_ptr<ci::AppInstaller> installer;
+  TpkAppQueryInterface* tpk_aqi = new TpkAppQueryInterface();
+
+  pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+  installer.reset(new TpkInstaller(pkgmgr));
+
+  installer->SetIndex(idx);
+
+  return installer;
+}
+
+}  // namespace tpk
diff --git a/src/tpk/tpk_installer_factory.h b/src/tpk/tpk_installer_factory.h
new file mode 100644 (file)
index 0000000..214fdb9
--- /dev/null
@@ -0,0 +1,27 @@
+// 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 TPK_TPK_INSTALLER_FACTORY_H_
+#define TPK_TPK_INSTALLER_FACTORY_H_
+
+#include <common/installer_factory.h>
+#include <common/pkgmgr_interface.h>
+
+#include <memory>
+
+namespace ci = common_installer;
+
+namespace tpk {
+
+class AppInstaller;
+
+class TpkInstallerFactory : public ci::InstallerFactory {
+ public:
+  std::unique_ptr<ci::AppInstaller> CreateInstaller(
+      ci::PkgMgrPtr pkgmgr, int idx);
+};
+
+}  // namespace tpk
+
+#endif  // TPK_TPK_INSTALLER_FACTORY_H_