Add WgtInstallerFactory and HybridInstallerFactory
[platform/core/appfw/wgt-backend.git] / src / wgt_backend / wgt_backend.cc
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
5
6 #include <common/installer_runner.h>
7 #include <common/pkgmgr_interface.h>
8 #include <cerrno>
9
10 #include "hybrid/hybrid_installer.h"
11 #include "hybrid/hybrid_installer_factory.h"
12 #include "wgt/utils/wgt_app_query_interface.h"
13 #include "wgt/wgt_installer.h"
14 #include "wgt/wgt_installer_factory.h"
15
16 namespace ci = common_installer;
17
18 #if __cplusplus < 201300L
19 namespace {
20
21 template<typename T, typename... Args>
22 std::unique_ptr<T> make_unique(Args&&... args) {
23   return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
24 }
25
26 }  // namespace
27 #endif
28
29 int main(int argc, char** argv) {
30   ci::PkgmgrInstaller pkgmgr_installer;
31   wgt::WgtAppQueryInterface query_interface;
32   auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
33                                             &query_interface);
34   std::unique_ptr<ci::InstallerFactory> installer_factory;
35   if (!pkgmgr) {
36     LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
37     return EINVAL;
38   }
39
40 #if __cplusplus >= 201300L
41   using std;
42 #endif
43   // This is workaround for hybrid apps as they requires much different flow
44   // but installer does not branch at all in current design
45   if (query_interface.IsHybridApplication(
46       pkgmgr->GetRequestInfo(), pkgmgr->GetUid())) {
47     LOG(INFO) << "Hybrid package detected";
48     ci::InstallerRunner runner(
49         make_unique<hybrid::HybridInstallerFactory>(), pkgmgr);
50     return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
51   } else {
52     ci::InstallerRunner runner(make_unique<wgt::WgtInstallerFactory>(), pkgmgr);
53     return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
54   }
55 }