Add WgtInstallerFactory and HybridInstallerFactory
[platform/core/appfw/wgt-backend.git] / src / wgt_backend / wgt_backend.cc
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;
   }
 }