ba42bca5fa88c1d9a6c348a3f4b99e1dca86f77a
[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 #include <memory>
10
11 #include "hybrid/hybrid_installer.h"
12 #include "hybrid/hybrid_installer_factory.h"
13 #include "wgt/utils/wgt_app_query_interface.h"
14 #include "wgt/wgt_installer.h"
15 #include "wgt/wgt_installer_factory.h"
16
17 namespace ci = common_installer;
18
19 int main(int argc, char** argv) {
20   ci::PkgmgrInstaller pkgmgr_installer;
21   std::shared_ptr<wgt::WgtAppQueryInterface> query_interface(
22       new wgt::WgtAppQueryInterface());
23   try {
24     auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
25                                               query_interface);
26     std::unique_ptr<ci::InstallerFactory> installer_factory;
27     if (!pkgmgr) {
28       LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
29       return EINVAL;
30     }
31
32     // This is workaround for hybrid apps as they requires much different flow
33     // but installer does not branch at all in current design
34     if (query_interface->IsHybridApplication(
35         pkgmgr->GetRequestInfo(), pkgmgr->GetUid())) {
36       LOG(INFO) << "Hybrid package detected";
37       ci::InstallerRunner runner(
38           std::make_unique<hybrid::HybridInstallerFactory>(), pkgmgr);
39       return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
40     } else {
41       ci::InstallerRunner runner(
42           std::make_unique<wgt::WgtInstallerFactory>(), pkgmgr);
43       return (runner.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
44     }
45   } catch(...) {
46     LOG(ERROR) << "Exception occured";
47     return 1;
48   }
49 }