StepConfigure - new step responsible for the InstallerContext 11/38311/2
authorPawel Sikorski <p.sikorski@samsung.com>
Tue, 14 Apr 2015 09:37:30 +0000 (11:37 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 17 Apr 2015 13:04:39 +0000 (06:04 -0700)
configuration.

Previously, AppInstaller included the general logic and some setup of
InstallerContext. However, InstallerContext should be only used within steps
(AppInstaller) should not mix the data and the logic.

Hence, Almost all context setup was moved to separate, new step - Configure

Change-Id: I508d2383bd6fca66326aa18df1bedb6f52fae3a6

src/common/CMakeLists.txt
src/common/app_installer.cc
src/common/step/step_configure.cc [new file with mode: 0644]
src/common/step/step_configure.h [new file with mode: 0644]
src/tpk/task.cc
src/wgt/wgt_backend.cc

index 6915b3b..30ac543 100644 (file)
@@ -7,6 +7,7 @@ SET(SRCS
   security_registration.cc
   step/step_unzip.cc
   step/step_check_signature.cc
+  step/step_configure.cc
   step/step_copy.cc
   step/step_generate_xml.cc
   step/step_register_app.cc
index dc6a84a..3fc382a 100644 (file)
@@ -11,8 +11,6 @@
 #include "common/pkgmgr_signal.h"
 #include "utils/logging.h"
 
-#define STR_EMPTY ""
-
 namespace {
 
 const unsigned kProgressRange = 100;
@@ -25,21 +23,10 @@ AppInstaller::AppInstaller(const char* package_type)
     : context_(new ContextInstaller()) {
   PkgMgrPtr pkgmgr = PkgMgrInterface::Instance();
   pi_.reset(new PkgmgrSignal(pkgmgr.get()->GetRawPi()));
+
+  // TODO(p.sikorski) below property is only used in AppInstaller.
+  // maybe it should then be kept in AppInstaller
   context_->pkg_type.set(package_type);
-  switch (pkgmgr->GetRequestType()) {
-    case PkgMgrInterface::Type::Install:
-      context_->file_path.set(pkgmgr->GetRequestInfo());
-      context_->pkgid.set(STR_EMPTY);
-      break;
-    case PkgMgrInterface::Type::Uninstall:
-      context_->pkgid.set(pkgmgr->GetRequestInfo());
-      context_->file_path.set(STR_EMPTY);
-      break;
-    default:
-      // currently, only installation and uninstallation handled
-      // TODO(p.sikorski): should return unsupported, and display error
-      break;
-  }
 }
 
 AppInstaller::~AppInstaller() {
diff --git a/src/common/step/step_configure.cc b/src/common/step/step_configure.cc
new file mode 100644 (file)
index 0000000..7ccebf3
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_configure.h"
+
+#include "common/pkgmgr_interface.h"
+
+namespace common_installer {
+namespace configure {
+
+const char *kStrEmpty = "";
+
+Step::Status StepConfigure::process() {
+  PkgMgrPtr pkgmgr = PkgMgrInterface::Instance();
+
+  switch (pkgmgr->GetRequestType()) {
+    case PkgMgrInterface::Type::Install:
+      context_->file_path.set(pkgmgr->GetRequestInfo());
+      context_->pkgid.set(kStrEmpty);
+      break;
+    case PkgMgrInterface::Type::Uninstall:
+      context_->pkgid.set(pkgmgr->GetRequestInfo());
+      context_->file_path.set(kStrEmpty);
+      break;
+    default:
+      // currently, only installation and uninstallation handled
+      // TODO(p.sikorski): should return unsupported, and display error
+      LOG(ERROR) << "Only installation and uninstallation is now supported";
+      return Status::ERROR;
+      break;
+  }
+
+  return Status::OK;
+}
+
+}  // namespace configure
+}  // namespace common_installer
diff --git a/src/common/step/step_configure.h b/src/common/step/step_configure.h
new file mode 100644 (file)
index 0000000..9a003c9
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_CONFIGURE_H_
+#define COMMON_STEP_STEP_CONFIGURE_H_
+
+#include "common/context_installer.h"
+
+#include "common/step/step.h"
+#include "utils/logging.h"
+
+namespace common_installer {
+namespace configure {
+
+class StepConfigure : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+
+  SCOPE_LOG_TAG(Configure)
+};
+
+}  // namespace configure
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_CONFIGURE_H_
index 50098e5..c3787d9 100644 (file)
@@ -5,6 +5,7 @@
 #else
 #include "common/pkgmgr_interface.h"
 #include "common/app_installer.h"
+#include "common/step/step_configure.h"
 #include "common/step/step_copy.h"
 #include "common/step/step_generate_xml.h"
 #include "common/step/step_parse.h"
@@ -78,6 +79,7 @@ bool Task::Run() {
 int Task::Install() {
   ci::AppInstaller ai(kPkgType);
 
+  ai.AddStep<ci::configure::StepConfigure>();
   ai.AddStep<ci::unzip::StepUnzip>();
   ai.AddStep<ci::signature::StepCheckSignature>();
   ai.AddStep<tpk::step::StepParse>();
@@ -93,6 +95,7 @@ int Task::Install() {
 int Task::Uninstall() {
   ci::AppInstaller ai(kPkgType);
 
+  ai.AddStep<ci::configure::StepConfigure>();
   ai.AddStep<ci::parse::StepParse>();
   ai.AddStep<ci::unregister_app::StepUnregisterApplication>();
   ai.AddStep<ci::remove::StepRemoveFiles>();
index cc8d193..39ff124 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "common/app_installer.h"
 #include "common/pkgmgr_interface.h"
+#include "common/step/step_configure.h"
 #include "common/step/step_copy.h"
 #include "common/step/step_generate_xml.h"
 #include "common/step/step_parse.h"
@@ -36,6 +37,7 @@ int main(int argc, char** argv) {
   /* treat the request */
   switch (pkgmgr->GetRequestType()) {
     case ci::PkgMgrInterface::Type::Install : {
+      installer.AddStep<ci::configure::StepConfigure>();
       installer.AddStep<ci::unzip::StepUnzip>();
       installer.AddStep<ci::signature::StepCheckSignature>();
       installer.AddStep<wgt::parse::StepParse>();
@@ -47,6 +49,7 @@ int main(int argc, char** argv) {
       break;
     }
     case ci::PkgMgrInterface::Type::Uninstall: {
+      installer.AddStep<ci::configure::StepConfigure>();
       installer.AddStep<ci::parse::StepParse>();
       installer.AddStep<ci::unregister_app::StepUnregisterApplication>();
       installer.AddStep<ci::remove::StepRemoveFiles>();