Add WgtInstallerFactory and HybridInstallerFactory 07/231107/5
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 17 Apr 2020 08:06:10 +0000 (17:06 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 19 May 2020 06:54:13 +0000 (15:54 +0900)
Now wgt-backend uses installer-runner to run the installer

Change-Id: I801c452dcaababf77527de54876957689d48974f
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/hybrid/hybrid_installer_factory.cc [new file with mode: 0644]
src/hybrid/hybrid_installer_factory.h [new file with mode: 0644]
src/wgt/wgt_installer_factory.cc [new file with mode: 0644]
src/wgt/wgt_installer_factory.h [new file with mode: 0644]
src/wgt_backend/wgt_backend.cc

diff --git a/src/hybrid/hybrid_installer_factory.cc b/src/hybrid/hybrid_installer_factory.cc
new file mode 100644 (file)
index 0000000..52c5395
--- /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 "hybrid/hybrid_installer_factory.h"
+
+#include <unzip.h>
+
+#include <manifest_parser/utils/logging.h>
+#include <hybrid/hybrid_installer.h>
+#include <wgt/utils/wgt_app_query_interface.h>
+#include <wgt/wgt_installer.h>
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_query.h"
+
+namespace ci = common_installer;
+
+namespace hybrid {
+
+std::unique_ptr<ci::AppInstaller> HybridInstallerFactory::CreateInstaller(
+    ci::PkgMgrPtr pkgmgr, int idx) {
+  std::unique_ptr<ci::AppInstaller> installer;
+  wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+
+  pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+  installer.reset(new hybrid::HybridInstaller(pkgmgr));
+  installer->SetIndex(idx);
+
+  return installer;
+}
+
+}  // namespace hybrid
diff --git a/src/hybrid/hybrid_installer_factory.h b/src/hybrid/hybrid_installer_factory.h
new file mode 100644 (file)
index 0000000..f93bb76
--- /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 HYBRID_HYBRID_INSTALLER_FACTORY_H_
+#define HYBRID_HYBRID_INSTALLER_FACTORY_H_
+
+#include <common/installer_factory.h>
+#include <common/pkgmgr_interface.h>
+
+#include <memory>
+
+namespace ci = common_installer;
+
+namespace hybrid {
+
+class AppInstaller;
+
+class HybridInstallerFactory : public ci::InstallerFactory {
+ public:
+  std::unique_ptr<ci::AppInstaller> CreateInstaller(
+      ci::PkgMgrPtr pkgmgr, int idx);
+};
+
+}  // namespace hybrid
+
+#endif  // HYBRID_HYBRID_INSTALLER_FACTORY_H_
diff --git a/src/wgt/wgt_installer_factory.cc b/src/wgt/wgt_installer_factory.cc
new file mode 100644 (file)
index 0000000..e826ee2
--- /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 "wgt/wgt_installer_factory.h"
+
+#include <unzip.h>
+
+#include <manifest_parser/utils/logging.h>
+#include <hybrid/hybrid_installer.h>
+#include <wgt/utils/wgt_app_query_interface.h>
+#include <wgt/wgt_installer.h>
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_query.h"
+
+namespace ci = common_installer;
+
+namespace wgt {
+
+std::unique_ptr<ci::AppInstaller> WgtInstallerFactory::CreateInstaller(
+    ci::PkgMgrPtr pkgmgr, int idx) {
+  std::unique_ptr<ci::AppInstaller> installer;
+  WgtAppQueryInterface* wgt_aqi = new WgtAppQueryInterface();
+
+  pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+  installer.reset(new wgt::WgtInstaller(pkgmgr));
+  installer->SetIndex(idx);
+
+  return installer;
+}
+
+}  // namespace wgt
diff --git a/src/wgt/wgt_installer_factory.h b/src/wgt/wgt_installer_factory.h
new file mode 100644 (file)
index 0000000..dd1ff4f
--- /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 WGT_WGT_INSTALLER_FACTORY_H_
+#define WGT_WGT_INSTALLER_FACTORY_H_
+
+#include <common/installer_factory.h>
+#include <common/pkgmgr_interface.h>
+
+#include <memory>
+
+namespace ci = common_installer;
+
+namespace wgt {
+
+class AppInstaller;
+
+class WgtInstallerFactory : public ci::InstallerFactory {
+ public:
+  std::unique_ptr<ci::AppInstaller> CreateInstaller(
+      ci::PkgMgrPtr pkgmgr, int idx);
+};
+
+}  // namespace wgt
+
+#endif  // WGT_WGT_INSTALLER_FACTORY_H_
index 9f003e3..c72e135 100644 (file)
@@ -3,34 +3,53 @@
 // Use of this source code is governed by a apache 2.0 license that can be
 // found in the LICENSE file.
 
+#include <common/installer_runner.h>
 #include <common/pkgmgr_interface.h>
 #include <cerrno>
 
 #include "hybrid/hybrid_installer.h"
+#include "hybrid/hybrid_installer_factory.h"
 #include "wgt/utils/wgt_app_query_interface.h"
 #include "wgt/wgt_installer.h"
+#include "wgt/wgt_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(int argc, char** argv) {
   ci::PkgmgrInstaller pkgmgr_installer;
   wgt::WgtAppQueryInterface query_interface;
   auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
                                             &query_interface);
+  std::unique_ptr<ci::InstallerFactory> installer_factory;
   if (!pkgmgr) {
     LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
     return EINVAL;
   }
 
+#if __cplusplus >= 201300L
+  using std;
+#endif
   // This is workaround for hybrid apps as they requires much different flow
   // but installer does not branch at all in current design
   if (query_interface.IsHybridApplication(
       pkgmgr->GetRequestInfo(), pkgmgr->GetUid())) {
     LOG(INFO) << "Hybrid package detected";
-    hybrid::HybridInstaller installer(pkgmgr);
-    return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
+    ci::InstallerRunner runner(
+        make_unique<hybrid::HybridInstallerFactory>(), pkgmgr);
+    return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
   } else {
-    wgt::WgtInstaller installer(pkgmgr);
-    return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
+    ci::InstallerRunner runner(make_unique<wgt::WgtInstallerFactory>(), pkgmgr);
+    return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
   }
 }