Add static tpk backend library 38/46138/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 11 Aug 2015 08:28:21 +0000 (10:28 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 18 Aug 2015 15:43:01 +0000 (08:43 -0700)
For linking with testsuites.
Task was renamed to TpkInstaller class.

HOSTTEST was removed due to missing files for this configuration
in project files.

Change-Id: I97de47bb1b4a622cfea89c8f7a692253056a1535

CMakeLists.txt
src/tpk/CMakeLists.txt
src/tpk/main.cc [deleted file]
src/tpk/task.cc [deleted file]
src/tpk/task.h [deleted file]
src/tpk/tpk_backend.cc [new file with mode: 0644]
src/tpk/tpk_installer.cc [new file with mode: 0644]
src/tpk/tpk_installer.h [new file with mode: 0644]

index 94bb3e0..6f1f24c 100644 (file)
@@ -24,6 +24,7 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++11 -g --coverage")
 # Targets
 SET(TARGET_LIBNAME_COMMON "common-installer")
 SET(TARGET_LIBNAME_WGT "wgt-installer")
+SET(TARGET_LIBNAME_TPK "tpk-installer")
 SET(TARGET_WGT_BACKEND "wgt-backend")
 SET(TARGET_TPK_BACKEND "tpk-backend")
 
index 00188ad..6b3a2e5 100644 (file)
@@ -1,36 +1,22 @@
-IF(NOT DEFINED TARGET_TPK_BACKEND)
-  SET(TARGET_TPK_BACKEND "tpk-backend")
-ENDIF(NOT DEFINED TARGET_TPK_BACKEND)
-
-SET(TARGET_TPK ${TARGET_TPK_BACKEND})
-OPTION(HOSTTEST "Option for the test on the host PC" OFF)
 SET(SRCS
-    main.cc
-    task.cc
     step/step_parse.cc
     step/step_create_symbolic_link.cc
     step/step_copy_manifest_xml.cc
     tpk_app_query_interface.cc
+    tpk_installer.cc
     xml_parser/xml_parser.cc
 )
-ADD_EXECUTABLE(${TARGET_TPK} ${SRCS})
-
-SET(TPK_LDFLAGS -rdynamic)
-IF(${HOSTTEST})
-  MESSAGE("Host Test mode.")
-SET(TPK_CFLAGS ${TPK_CFLAGS} -DHOSTTEST)
-  SET(MOCK_MODULES test/mock_pkgmgr_installer.c)
-SET(SRCS ${SRCS} ${MOCK_MODULES})
+ADD_LIBRARY(${TARGET_LIBNAME_TPK} STATIC ${SRCS})
+ADD_EXECUTABLE(${TARGET_TPK_BACKEND} "tpk_backend.cc")
 
-ELSE(${HOSTTEST})
-  SET(TPK_CFLAGS ${TPK_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/../)
-  ADD_DEFINITIONS(${TPK_CFLAGS})
-ENDIF(${HOSTTEST})
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_TPK} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TPK_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
 
-APPLY_PKG_CONFIG(${TARGET_TPK}
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_TPK}
   PUBLIC PKGMGR_DEPS
   Boost
 )
-TARGET_LINK_LIBRARIES(${TARGET_TPK} PUBLIC ${TARGET_LIBNAME_COMMON})
+TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_TPK} PUBLIC ${TARGET_LIBNAME_COMMON})
+TARGET_LINK_LIBRARIES(${TARGET_TPK_BACKEND} PRIVATE ${TARGET_LIBNAME_TPK})
 
-INSTALL(TARGETS ${TARGET_TPK} DESTINATION ${BINDIR})
+INSTALL(TARGETS ${TARGET_TPK_BACKEND} DESTINATION ${BINDIR})
diff --git a/src/tpk/main.cc b/src/tpk/main.cc
deleted file mode 100644 (file)
index e960ed0..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-#include <iostream>
-#include "tpk/task.h"
-#include "common/utils/logging.h"
-
-
-int main(const int argc, char* argv[]) {
-  tpk::Task t;
-  if (!t.Init(argc, argv)) {
-    std::cerr << "Task init failure" << std::endl;
-    return -1;
-  }
-  if (!t.Run()) {
-    std::cerr << "Task run failure" << std::endl;
-    return -1;
-  }
-  return 0;
-}
diff --git a/src/tpk/task.cc b/src/tpk/task.cc
deleted file mode 100644 (file)
index 3fb50f3..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-#include "tpk/task.h"
-#ifdef HOSTTEST
-#include "test/mock_pkgmgr_installer.h"
-#else
-#include "common/app_installer.h"
-#include "common/step/step_configure.h"
-#include "common/step/step_backup_icons.h"
-#include "common/step/step_backup_manifest.h"
-#include "common/step/step_create_icons.h"
-#include "common/step/step_create_storage_directories.h"
-#include "common/step/step_copy.h"
-#include "common/step/step_copy_backup.h"
-#include "common/step/step_check_old_certificate.h"
-#include "common/step/step_generate_xml.h"
-#include "common/step/step_old_manifest.h"
-#include "common/step/step_parse.h"
-#include "common/step/step_register_app.h"
-#include "common/step/step_remove_icons.h"
-#include "common/step/step_remove_files.h"
-#include "common/step/step_revoke_security.h"
-#include "common/step/step_register_security.h"
-#include "common/step/step_check_signature.h"
-#include "common/step/step_unregister_app.h"
-#include "common/step/step_unzip.h"
-#include "common/step/step_update_app.h"
-#include "common/step/step_update_security.h"
-#include "common/utils/logging.h"
-#include "tpk/step/step_copy_manifest_xml.h"
-#include "tpk/step/step_create_symbolic_link.h"
-#include "tpk/step/step_parse.h"
-#endif
-
-namespace ci = common_installer;
-
-namespace {
-
-const char kPkgType[] = "tpk";
-
-}  // namespace
-
-namespace tpk {
-
-Task::Task() {
-}
-
-Task::~Task() {
-}
-
-bool Task::Init(int argc, char** argv) {
-  query_interface_.reset(new TpkAppQueryInterface());
-  pkgmgr_ = ci::PkgMgrInterface::Create(argc, argv, query_interface_.get());
-  if (!pkgmgr_) {
-    LOG(ERROR) << "Cannot connect to PkgMgrInstaller";
-    return false;
-  }
-  return true;
-}
-
-bool Task::Run() {
-  switch (pkgmgr_->GetRequestType()) {
-    case ci::RequestType::Install:
-      return Install();
-    case ci::RequestType::Update:
-      return Update();
-    case ci::RequestType::Uninstall:
-      return Uninstall();
-    case ci::RequestType::Reinstall:
-      return Reinstall();
-    case ci::RequestType::Recovery:
-      // TODO(t.iwanek): recovery mode invocation...
-      return false;
-    default:
-      break;
-  }
-  return false;
-}
-
-bool Task::Install() {
-  ci::AppInstaller ai(kPkgType, pkgmgr_);
-
-  ai.AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  ai.AddStep<ci::filesystem::StepUnzip>();
-  ai.AddStep<tpk::parse::StepParse>();
-  ai.AddStep<ci::security::StepCheckSignature>();
-  ai.AddStep<ci::filesystem::StepCopy>();
-  ai.AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  ai.AddStep<tpk::filesystem::StepCreateSymbolicLink>();
-  ai.AddStep<ci::filesystem::StepCreateIcons>();
-  ai.AddStep<ci::security::StepRegisterSecurity>();
-  ai.AddStep<tpk::filesystem::StepCopyManifestXml>();
-  ai.AddStep<ci::pkgmgr::StepRegisterApplication>();
-
-  return ai.Run() == ci::AppInstaller::Result::OK;
-}
-
-bool Task::Update() {
-  ci::AppInstaller ai(kPkgType, pkgmgr_);
-
-  ai.AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  ai.AddStep<ci::filesystem::StepUnzip>();
-  ai.AddStep<tpk::parse::StepParse>();
-  ai.AddStep<ci::security::StepCheckSignature>();
-  ai.AddStep<ci::security::StepCheckOldCertificate>();
-  ai.AddStep<ci::backup::StepOldManifest>();
-  ai.AddStep<ci::backup::StepBackupManifest>();
-  ai.AddStep<ci::backup::StepBackupIcons>();
-  ai.AddStep<ci::backup::StepCopyBackup>();
-  ai.AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  // TODO(t.iwanek): handle coping storage directories
-  ai.AddStep<tpk::filesystem::StepCreateSymbolicLink>();
-  ai.AddStep<ci::filesystem::StepCreateIcons>();
-  ai.AddStep<ci::security::StepUpdateSecurity>();
-  ai.AddStep<tpk::filesystem::StepCopyManifestXml>();
-  ai.AddStep<ci::pkgmgr::StepUpdateApplication>();
-
-  return ai.Run() == ci::AppInstaller::Result::OK;
-}
-
-bool Task::Uninstall() {
-  ci::AppInstaller ai(kPkgType, pkgmgr_);
-
-  ai.AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  ai.AddStep<ci::parse::StepParse>();
-  ai.AddStep<ci::backup::StepBackupManifest>();
-  ai.AddStep<ci::pkgmgr::StepUnregisterApplication>();
-  ai.AddStep<ci::security::StepRevokeSecurity>();
-  ai.AddStep<ci::filesystem::StepRemoveFiles>();
-  ai.AddStep<ci::filesystem::StepRemoveIcons>();
-
-  return ai.Run() == ci::AppInstaller::Result::OK;
-}
-
-bool Task::Reinstall() {
-  return false;
-}
-
-}  // namespace tpk
-
diff --git a/src/tpk/task.h b/src/tpk/task.h
deleted file mode 100644 (file)
index e913190..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-#ifndef TPK_TASK_H_
-#define TPK_TASK_H_
-
-#include <memory>
-
-#ifdef HOSTTEST
-#include "test/mock_pkgmgr_installer.h"
-#endif
-#include "common/utils/logging.h"
-
-#include "common/pkgmgr_interface.h"
-#include "tpk/tpk_app_query_interface.h"
-
-namespace tpk {
-
-class Task {
- public:
-  Task();
-  ~Task();
-  bool Init(int argc, char** argv);
-  bool Run();
-
- private:
-  bool Install();
-  bool Update();
-  bool Uninstall();
-  bool Reinstall();
-
-  common_installer::PkgMgrPtr pkgmgr_;
-  std::unique_ptr<TpkAppQueryInterface> query_interface_;
-
-  SCOPE_LOG_TAG(TpkTask)
-};  //  class Task
-
-}  //  namespace tpk
-
-#endif  // TPK_TASK_H_
diff --git a/src/tpk/tpk_backend.cc b/src/tpk/tpk_backend.cc
new file mode 100644 (file)
index 0000000..09c1270
--- /dev/null
@@ -0,0 +1,25 @@
+/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
+
+#include <iostream>
+
+#include "common/pkgmgr_interface.h"
+#include "common/utils/logging.h"
+#include "tpk/tpk_app_query_interface.h"
+#include "tpk/tpk_installer.h"
+
+namespace ci = common_installer;
+
+int main(const int argc, char* argv[]) {
+  tpk::TpkAppQueryInterface interface;
+  ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &interface);
+  if (!pkgmgr) {
+    LOG(ERROR) << "Failed to create pkgmgr interface";
+    return -1;
+  }
+  tpk::TpkInstaller t(pkgmgr);
+  if (t.Run() != ci::AppInstaller::Result::OK) {
+    LOG(ERROR) << "TpkInstaller run failure";
+    return -1;
+  }
+  return 0;
+}
diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc
new file mode 100644 (file)
index 0000000..d33b7f8
--- /dev/null
@@ -0,0 +1,121 @@
+/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
+#include "tpk/tpk_installer.h"
+#include "common/app_installer.h"
+#include "common/step/step_configure.h"
+#include "common/step/step_backup_icons.h"
+#include "common/step/step_backup_manifest.h"
+#include "common/step/step_create_icons.h"
+#include "common/step/step_create_storage_directories.h"
+#include "common/step/step_copy.h"
+#include "common/step/step_copy_backup.h"
+#include "common/step/step_check_old_certificate.h"
+#include "common/step/step_fail.h"
+#include "common/step/step_generate_xml.h"
+#include "common/step/step_old_manifest.h"
+#include "common/step/step_parse.h"
+#include "common/step/step_register_app.h"
+#include "common/step/step_remove_icons.h"
+#include "common/step/step_remove_files.h"
+#include "common/step/step_revoke_security.h"
+#include "common/step/step_register_security.h"
+#include "common/step/step_check_signature.h"
+#include "common/step/step_unregister_app.h"
+#include "common/step/step_unzip.h"
+#include "common/step/step_update_app.h"
+#include "common/step/step_update_security.h"
+#include "common/utils/logging.h"
+#include "tpk/step/step_copy_manifest_xml.h"
+#include "tpk/step/step_create_symbolic_link.h"
+#include "tpk/step/step_parse.h"
+
+namespace ci = common_installer;
+
+namespace {
+
+const char kPkgType[] = "tpk";
+
+}  // namespace
+
+namespace tpk {
+
+TpkInstaller::TpkInstaller(common_installer::PkgMgrPtr pkgmgr)
+    : AppInstaller(kPkgType, pkgmgr) {
+  Prepare();
+}
+
+TpkInstaller::~TpkInstaller() {
+}
+
+void TpkInstaller::Prepare() {
+  switch (pkgmgr_->GetRequestType()) {
+    case ci::RequestType::Install:
+      InstallSteps();
+      break;
+    case ci::RequestType::Update:
+      UpdateSteps();
+      break;
+    case ci::RequestType::Uninstall:
+      UninstallSteps();
+      break;
+    case ci::RequestType::Reinstall:
+      ReinstallSteps();
+      break;
+    case ci::RequestType::Recovery:
+      AddStep<ci::configuration::StepFail>();
+      // TODO(t.iwanek): recovery mode invocation...
+      break;
+    default:
+      AddStep<ci::configuration::StepFail>();
+      break;
+  }
+}
+
+void TpkInstaller::InstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<tpk::parse::StepParse>();
+  AddStep<ci::security::StepCheckSignature>();
+  AddStep<ci::filesystem::StepCopy>();
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  AddStep<tpk::filesystem::StepCreateSymbolicLink>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<tpk::filesystem::StepCopyManifestXml>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+}
+
+void TpkInstaller::UpdateSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<tpk::parse::StepParse>();
+  AddStep<ci::security::StepCheckSignature>();
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::backup::StepOldManifest>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::backup::StepBackupIcons>();
+  AddStep<ci::backup::StepCopyBackup>();
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  // TODO(t.iwanek): handle coping storage directories
+  AddStep<tpk::filesystem::StepCreateSymbolicLink>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<tpk::filesystem::StepCopyManifestXml>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+}
+
+void TpkInstaller::UninstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::parse::StepParse>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::pkgmgr::StepUnregisterApplication>();
+  AddStep<ci::filesystem::StepRemoveFiles>();
+  AddStep<ci::filesystem::StepRemoveIcons>();
+  AddStep<ci::security::StepRevokeSecurity>();
+}
+
+void TpkInstaller::ReinstallSteps() {
+  AddStep<ci::configuration::StepFail>();
+}
+
+}  // namespace tpk
+
diff --git a/src/tpk/tpk_installer.h b/src/tpk/tpk_installer.h
new file mode 100644 (file)
index 0000000..f7d723c
--- /dev/null
@@ -0,0 +1,37 @@
+/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
+
+#ifndef TPK_TPK_INSTALLER_H_
+#define TPK_TPK_INSTALLER_H_
+
+#include "common/app_installer.h"
+#include "common/pkgmgr_interface.h"
+#include "common/utils/logging.h"
+
+namespace tpk {
+
+/**
+ * @brief The TpkInstaller class
+ *        Handles request of tpk packages.
+ *
+ * This class is main class for installation/update/deinstallation of tpk
+ * packages. Pkgmgr request is parsed within and sequence of steps is built to
+ * be run.
+ */
+class TpkInstaller : public common_installer::AppInstaller {
+ public:
+  explicit TpkInstaller(common_installer::PkgMgrPtr pkgmgr);
+  ~TpkInstaller();
+  void Prepare();
+
+ private:
+  void InstallSteps();
+  void UpdateSteps();
+  void UninstallSteps();
+  void ReinstallSteps();
+
+  SCOPE_LOG_TAG(TpkInstaller)
+};
+
+}  // namespace tpk
+
+#endif  // TPK_TPK_INSTALLER_H_