Introducing "Property" for ContextInstaller. 32/37632/3
authorPawel Sikorski <p.sikorski@samsung.com>
Wed, 1 Apr 2015 09:21:51 +0000 (11:21 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 3 Apr 2015 13:01:51 +0000 (15:01 +0200)
Currently, ContextInstaller contains attributes (declared as private).
And each attribute has its setter and getter defined.

Property hides declaration of these setters/getters.

TODO:
* Pi (PkgmgrSignal)

Change-Id: Iba6e8a796b54468798b35e708a8ecee03ec53988

20 files changed:
src/common/app_installer.cc
src/common/context_installer.cc
src/common/context_installer.h
src/common/step/step_check_signature.cc
src/common/step/step_copy.cc
src/common/step/step_generate_xml.cc
src/common/step/step_parse.cc
src/common/step/step_register_app.cc
src/common/step/step_register_security.cc
src/common/step/step_remove_files.cc
src/common/step/step_revoke_security.cc
src/common/step/step_signal.cc
src/common/step/step_signal.h
src/common/step/step_unregister_app.cc
src/common/step/step_unzip.cc
src/common/step/step_unzip.h
src/tpk/step/step_create_symbolic_link.cc
src/tpk/step/step_parse.cc
src/wgt/step/step_create_symbolic_link.cc
src/wgt/step/step_parse.cc

index 61e8e22..c902afd 100644 (file)
@@ -15,16 +15,16 @@ AppInstaller::AppInstaller(pkgmgr_installer *pi, const char* package_type)
   : context_(new ContextInstaller()) {
   int request_type = pkgmgr_installer_get_request_type(pi);
   context_->set_pi(std::unique_ptr<PkgmgrSignal>(new PkgmgrSignal(pi)));
-  context_->set_request_type(request_type);
-  context_->set_pkg_type(package_type);
+  context_->request_type.set(request_type);
+  context_->pkg_type.set(package_type);
   switch (request_type) {
     case PKGMGR_REQ_INSTALL:
-     context_->set_file_path(pkgmgr_installer_get_request_info(pi));
-     context_->set_pkgid(STR_EMPTY);
+     context_->file_path.set(pkgmgr_installer_get_request_info(pi));
+     context_->pkgid.set(STR_EMPTY);
     break;
     case PKGMGR_REQ_UNINSTALL:
-     context_->set_pkgid(pkgmgr_installer_get_request_info(pi));
-     context_->set_file_path(STR_EMPTY);
+     context_->pkgid.set(pkgmgr_installer_get_request_info(pi));
+     context_->file_path.set(STR_EMPTY);
     break;
   }
 }
index febb754..b33b568 100644 (file)
@@ -15,41 +15,23 @@ namespace common_installer {
 namespace fs = boost::filesystem;
 
 ContextInstaller::ContextInstaller()
-    : req_(PKGMGR_REQ_INVALID),
-      manifest_(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
-      uid_(getuid()),
-      config_data_(new ConfigData()) {
+    : request_type(PKGMGR_REQ_INVALID),
+      manifest_data(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
+      uid(getuid()) {
+
+    std::string root_app_path =
+        uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+          ? tzplatform_getenv(TZ_USER_APP)
+          : tzplatform_getenv(TZ_SYS_RW_APP);
+
+    root_application_path.set(root_app_path);
+    application_path.set(
+        (fs::path(root_app_path) / fs::path(pkgid.get())).native());
 }
 
 ContextInstaller::~ContextInstaller() {
-  if (manifest_)
-    pkgmgr_parser_free_manifest_xml(manifest_);
-}
-
-const char* ContextInstaller::GetRootApplicationPath() const {
-  return uid_ != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-      ? tzplatform_getenv(TZ_USER_APP) : tzplatform_getenv(TZ_SYS_RW_APP);
-}
-
-const char* ContextInstaller::GetApplicationPath() const {
-  return (fs::path(GetRootApplicationPath()) / fs::path(pkgid())).c_str();
-}
-
-
-void ContextInstaller::set_new_temporary_pkgid() {
-  static const char lookup[] =
-    "abcdefghijklmnopqrstuvwxyz"
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-    "0123456789";
-    static const int len = 12;
-    const size_t max_lookup = (sizeof(lookup)-1);
-
-    std::string pkgid(len, 0);
-
-    for (int i = 0; i < len-1; i++) {
-      pkgid.append(1, lookup[ rand() % max_lookup ]);
-    }
-    set_pkgid(pkgid);
+  if (manifest_data.get())
+    pkgmgr_parser_free_manifest_xml(manifest_data.get());
 }
 
 }  // namespace common_installer
index 6d1d802..eeab6fd 100644 (file)
 
 namespace common_installer {
 
-class ConfigData;
-using ConfigDataPtr = std::unique_ptr<ConfigData>;
+/** Template class for defining smart attributes.
+ *
+ *  Property should be used when, given attribute needs to have pure
+ *  setter and getter. This template class will generate getter and setter.
+ *  It uses operator() overloading.
+ */
+template<typename Type>
+class Property {
+ public:
+  Property() {}
+  Property(const Type &val): value_(val) { } // NOLINT
+  const Type& get() const { return value_; }
+  Type& get() { return value_; }
+  void set(const Type &val) { value_ = val; }
+ private:
+  Type value_;
+};
 
 class ConfigData {
  public:
   ConfigData() {}
-
-  std::string application_name() const { return application_name_; }
-  void set_application_name(const std::string& app_name) {
-    application_name_ = app_name;
-  }
-  std::string required_version() const { return required_version_; }
-  void set_required_version(const std::string& required_version) {
-    required_version_ = required_version;
-  }
-
- private:
-  std::string application_name_;
-  std::string required_version_;
+  Property<std::string> application_name;
+  Property<std::string> required_version;
 };
 
 // TODO(p.sikorski@samsung.com) this class should be divided into:
@@ -47,91 +51,50 @@ class ContextInstaller {
   ContextInstaller();
   ~ContextInstaller();
 
-  int request_type() const { return req_; }
-  void set_request_type(int req) {
-    req_ = req;
-  }
-
-  std::string pkg_type() const { return pkg_type_; }
-  void set_pkg_type(const std::string& pkg_type) {
-    pkg_type_ = pkg_type;
-  }
-
-  manifest_x* manifest_data() const { return manifest_; }
-  void set_manifest(manifest_x* manifest) {
-    manifest_ = manifest;
-  }
-
-  std::string xml_path() const { return xml_path_; }
-  void set_xml_path(const std::string& xml) {
-    xml_path_ = xml;
-  }
-
-  std::string pkgid() const { return pkgid_; }
-  void set_pkgid(const std::string& pkgid) {
-    pkgid_ = pkgid;
-  }
-  void set_new_temporary_pkgid(void);
-
-  std::string pkg_path() const { return pkg_path_; }
-  void set_pkg_path(const std::string& package_path) {
-    pkg_path_ = package_path;
-  }
-
-  std::string file_path() const { return file_path_; }
-  void set_file_path(const std::string& file_path) {
-    file_path_ = file_path;
-  }
-
-  void set_pi(std::unique_ptr<PkgmgrSignal> pi) {
-    pi_ = std::move(pi);
-  }
-
-  uid_t uid() const { return uid_; }
-
-  std::string unpacked_dir_path() const { return unpacked_dir_path_; }
-  void set_unpacked_dir_path(const std::string& dir_path) {
-    unpacked_dir_path_ = dir_path;
-  }
-
-  ConfigData* config_data() const { return config_data_.get(); }
-
-  PkgmgrSignal* pi() const { return pi_.get(); }
-
-  const char* GetApplicationPath() const;
-  const char* GetRootApplicationPath() const;
-
- private :
   // request type: Install, Reinstall, Uninstall, Update.
-  int req_;
+  Property<int> request_type;
+
+  // package_type
+  Property<std::string> pkg_type;
 
   //  manifest information used to generate xml file
-  manifest_x* manifest_;
+  Property<manifest_x*> manifest_data;
 
   // path to manifest xml file used to register data in databases
-  std::string xml_path_;
+  Property<std::string> xml_path;
 
   // pkgid used for update or uninstallation processing
-  std::string pkgid_;
-
-  // package_type
-  std::string pkg_type_;
-
-  // uid of the user that request the operation
-  uid_t uid_;
+  Property<std::string> pkgid;
 
   // package directory path containing app data
-  std::string pkg_path_;
+  Property<std::string> pkg_path;
 
   // file path used for installation or reinstallation process
-  std::string file_path_;
+  Property<std::string> file_path;
 
   // directory path where app data are temporarily extracted
-  std::string unpacked_dir_path_;
+  Property<std::string> unpacked_dir_path;
+
+  // uid of the user that request the operation
+  Property<uid_t> uid;
+
 
   // data from config.xml
-  ConfigDataPtr config_data_;
+  Property<ConfigData> config_data;
+
+  // TODO(p.sikorski@samsung.com) change "pi" to Property
+  PkgmgrSignal* pi() const { return pi_.get(); }
+  void set_pi(std::unique_ptr<PkgmgrSignal> pi) {
+    pi_ = std::move(pi);
+  }
 
+  // path for the applications directory
+  Property<std::string> application_path;
+
+  // path for the applications root directory
+  Property<std::string> root_application_path;
+
+ private :
   // data used to send signal
   std::unique_ptr<PkgmgrSignal> pi_;
 };
index f8e90bd..92edafd 100644 (file)
@@ -16,7 +16,7 @@ namespace common_installer {
 namespace signature {
 
 Step::Status StepCheckSignature::process() {
-  return (SignatureValidator::Check(bf::path(context_->unpacked_dir_path()))
+  return (SignatureValidator::Check(bf::path(context_->unpacked_dir_path.get()))
       == SignatureValidator::INVALID) ? Status::ERROR : Status::OK;
 }
 
index 5fffc07..03a4d2d 100644 (file)
@@ -15,19 +15,19 @@ namespace bf = boost::filesystem;
 namespace bs = boost::system;
 
 Step::Status StepCopy::process() {
-  assert(!context_->pkgid().empty());
+  assert(!context_->pkgid.get().empty());
 
-  bf::path install_path = bf::path(context_->GetApplicationPath());
+  bf::path install_path = bf::path(context_->application_path.get());
 
-  context_->set_pkg_path(install_path.string());
+  context_->pkg_path.set(install_path.string());
 
   // FIXME: correctly order app's data.
   // If there is 1 app in package, app's data are stored in <pkg_path>/<app_id>
   // If there are >1 apps in package, app's data are stored in <pkg_path>
   // considering that multiple apps data are already separated in folders.
-  if (context_->manifest_data()->uiapplication &&
-      !context_->manifest_data()->uiapplication->next)
-    install_path /= bf::path(context_->manifest_data()->mainapp_id);
+  if (context_->manifest_data.get()->uiapplication &&
+      !context_->manifest_data.get()->uiapplication->next)
+    install_path /= bf::path(context_->manifest_data.get()->mainapp_id);
 
   bs::error_code error;
   bf::create_directories(install_path.parent_path(), error);
@@ -36,23 +36,24 @@ Step::Status StepCopy::process() {
                << install_path.parent_path().string();
     return Step::Status::ERROR;
   }
-  bf::rename(context_->unpacked_dir_path(), install_path, error);
+  bf::rename(context_->unpacked_dir_path.get(), install_path, error);
   if (error) {
     LOG(DEBUG) << "Cannot move directory. Will try to copy...";
-    if (!utils::CopyDir(bf::path(context_->unpacked_dir_path()),
+    if (!utils::CopyDir(bf::path(context_->unpacked_dir_path.get()),
         install_path)) {
-      LOG(ERROR) << "Fail to copy tmp dir: " << context_->unpacked_dir_path()
-                 << " to dst dir: " << install_path.string();
+      LOG(ERROR) << "Fail to copy tmp dir: "
+          << context_->unpacked_dir_path.get()
+          << " to dst dir: " << install_path.string();
       return Step::Status::ERROR;
     }
     bs::error_code error;
-    bf::remove_all(context_->unpacked_dir_path(), error);
+    bf::remove_all(context_->unpacked_dir_path.get(), error);
     if (error) {
       LOG(WARNING) << "Cannot remove temporary directory: "
-                   << context_->unpacked_dir_path();
+                   << context_->unpacked_dir_path.get();
     }
   }
-  LOG(INFO) << "Successfully move/copy: " << context_->unpacked_dir_path()
+  LOG(INFO) << "Successfully move/copy: " << context_->unpacked_dir_path.get()
             << " to: " << install_path.string() << " directory";
   return Status::OK;
 }
@@ -62,8 +63,8 @@ Step::Status StepCopy::clean() {
 }
 
 Step::Status StepCopy::undo() {
-  if (bf::exists(context_->pkg_path()))
-    bf::remove_all(context_->pkg_path());
+  if (bf::exists(context_->pkg_path.get()))
+    bf::remove_all(context_->pkg_path.get());
   return Status::OK;
 }
 
index 351b95d..ad9788e 100644 (file)
@@ -26,16 +26,16 @@ namespace common_installer {
 namespace generate_xml {
 
 Step::Status StepGenerateXml::process() {
-  assert(context_->manifest_data());
+  assert(context_->manifest_data.get());
 
-  fs::path xml_path = fs::path(getUserManifestPath(context_->uid()))
-      / fs::path(context_->pkgid());
+  fs::path xml_path = fs::path(getUserManifestPath(context_->uid.get()))
+      / fs::path(context_->pkgid.get());
   xml_path += ".xml";
 
-  context_->set_xml_path(xml_path.string());
+  context_->xml_path.set(xml_path.string());
   boost::system::error_code error;
-  if ((!context_->manifest_data()->uiapplication) &&
-     (!context_->manifest_data()->serviceapplication)) {
+  if ((!context_->manifest_data.get()->uiapplication) &&
+     (!context_->manifest_data.get()->serviceapplication)) {
     LOG(ERROR) << "There is neither UI applications nor"
                << "Services applications described!";
     return Step::Status::ERROR;
@@ -51,7 +51,7 @@ Step::Status StepGenerateXml::process() {
 
   xmlTextWriterPtr writer;
 
-  writer = xmlNewTextWriterFilename(context_->xml_path().c_str(), 0);
+  writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0);
   if (!writer) {
     LOG(ERROR) << "Failed to create new file";
     return Step::Status::ERROR;
@@ -67,22 +67,22 @@ Step::Status StepGenerateXml::process() {
   xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
       BAD_CAST "http://tizen.org/ns/packages");
   xmlTextWriterWriteAttribute(writer, BAD_CAST "package",
-      BAD_CAST context_->manifest_data()->package);
+      BAD_CAST context_->manifest_data.get()->package);
   xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
-      BAD_CAST context_->manifest_data()->type);
+      BAD_CAST context_->manifest_data.get()->type);
   xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
-      BAD_CAST context_->manifest_data()->version);
+      BAD_CAST context_->manifest_data.get()->version);
 
-  if ( context_->manifest_data()->description &&
-      context_->manifest_data()->description->name )
+  if ( context_->manifest_data.get()->description &&
+      context_->manifest_data.get()->description->name )
     xmlTextWriterWriteFormatElement(writer, BAD_CAST "description",
-        "%s", BAD_CAST context_->manifest_data()->description->name);
+        "%s", BAD_CAST context_->manifest_data.get()->description->name);
   else
     xmlTextWriterWriteFormatElement(writer, BAD_CAST "description",
         "%s", BAD_CAST "");
 
   // add ui-application element per ui application
-  for (uiapplication_x* ui = context_->manifest_data()->uiapplication;
+  for (uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
       ui != nullptr; ui = ui->next) {
     xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
 
@@ -90,8 +90,9 @@ Step::Status StepGenerateXml::process() {
                                       BAD_CAST ui->appid);
 
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
-        / fs::path("bin") / fs::path(ui->appid);
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+            / fs::path("bin") / fs::path(ui->appid);
 
     xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
         BAD_CAST exec_path.string().c_str());
@@ -110,14 +111,14 @@ Step::Status StepGenerateXml::process() {
     // the icon is renamed to <appid.png>
     // and located in TZ_USER_ICON/TZ_SYS_ICON
     // if the icon isn't exist print the default icon app-installers.png
-    icon_path_ = fs::path(getIconPath(context_->uid()));
+    icon_path_ = fs::path(getIconPath(context_->uid.get()));
     utils::CreateDir(icon_path_);
 
     fs::path icon = fs::path(ui->appid) += fs::path(".png");
 
     if (ui->icon && ui->icon->name) {
-      fs::path app_icon = fs::path(context_->pkg_path()) / fs::path(ui->appid)
-        / fs::path(ui->icon->name);
+      fs::path app_icon = fs::path(context_->pkg_path.get())
+          / fs::path(ui->appid) / fs::path(ui->icon->name);
       if (fs::exists(app_icon))
         fs::rename(app_icon, icon_path_ /= icon);
     } else {
@@ -159,15 +160,16 @@ Step::Status StepGenerateXml::process() {
 
   // add service-application element per service application
   for (serviceapplication_x* svc =
-      context_->manifest_data()->serviceapplication;
+      context_->manifest_data.get()->serviceapplication;
       svc != nullptr; svc = svc->next) {
     xmlTextWriterStartElement(writer, BAD_CAST "service-application");
 
     xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST svc->appid);
 
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
-        / fs::path("bin") / fs::path(svc->appid);
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+            / fs::path("bin") / fs::path(svc->appid);
 
     xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
         BAD_CAST exec_path.string().c_str());
@@ -181,13 +183,14 @@ Step::Status StepGenerateXml::process() {
     // the icon is renamed to <appid.png>
     // and located in TZ_USER_ICON/TZ_SYS_ICON
     // if the icon isn't exist print the default icon app-installers.png
-    icon_path_ = fs::path(getIconPath(context_->uid()));
+    icon_path_ = fs::path(getIconPath(context_->uid.get()));
     utils::CreateDir(icon_path_);
     fs::path icon = fs::path(svc->appid) += fs::path(".png");
 
     if (svc->icon && svc->icon->name) {
-      fs::path app_icon = fs::path(context_->pkg_path()) / fs::path(svc->appid)
-          / fs::path(svc->icon->name);
+      fs::path app_icon =
+          fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+              / fs::path(svc->icon->name);
       if (fs::exists(app_icon))
         fs::rename(app_icon, icon_path_ /= icon);
     } else {
@@ -226,7 +229,9 @@ Step::Status StepGenerateXml::process() {
 
   // add privilege element
   privileges_x* pvlg = nullptr;
-  PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data()->privileges, pvlg);
+  PKGMGR_LIST_MOVE_NODE_TO_HEAD(
+      context_->manifest_data.get()->privileges,
+      pvlg);
   for (; pvlg != nullptr; pvlg = pvlg->next) {
     xmlTextWriterStartElement(writer, BAD_CAST "privileges");
     privilege_x* pv = nullptr;
@@ -244,12 +249,13 @@ Step::Status StepGenerateXml::process() {
   xmlFreeTextWriter(writer);
 
   if (pkgmgr_parser_check_manifest_validation(
-      context_->xml_path().c_str()) != 0) {
+      context_->xml_path.get().c_str()) != 0) {
     LOG(ERROR) << "Manifest is not valid";
     return Step::Status::ERROR;
   }
 
-  LOG(DEBUG) << "Successfully create manifest xml " << context_->xml_path();
+  LOG(DEBUG) << "Successfully create manifest xml "
+      << context_->xml_path.get();
   return Status::OK;
 }
 
index 56d8657..a724645 100644 (file)
@@ -19,21 +19,22 @@ namespace parse {
 namespace fs = boost::filesystem;
 
 Step::Status StepParse::process() {
-  fs::path xml_path = fs::path(getUserManifestPath(context_->uid()))
-      / fs::path(context_->pkgid());
+  fs::path xml_path = fs::path(getUserManifestPath(context_->uid.get()))
+      / fs::path(context_->pkgid.get());
   xml_path += ".xml";
 
-  context_->set_xml_path(xml_path.string());
+  context_->xml_path.set(xml_path.string());
   xmlInitParser();
   manifest_x* mfx = pkgmgr_parser_usr_process_manifest_xml(
-    context_->xml_path().c_str(), context_->uid());
+    context_->xml_path.get().c_str(), context_->uid.get());
   if (!mfx) {
-    LOG(ERROR) << "Failed to parse tizen manifest xml " << context_->xml_path();
+    LOG(ERROR) << "Failed to parse tizen manifest xml "
+        << context_->xml_path.get();
     return Step::Status::ERROR;
   }
 
-  context_->set_manifest(mfx);
-  context_->set_pkg_path(context_->GetApplicationPath());
+  context_->manifest_data.set(mfx);
+  context_->pkg_path.set(context_->application_path.get());
 
   LOG(DEBUG) << "Successfully parse tizen manifest xml";
 
index 0db57a9..2337c07 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <pkgmgr-info.h>
 #include <unistd.h>
-
 #include <boost/filesystem.hpp>
 #include <cassert>
 #include <cstring>
@@ -28,7 +27,7 @@ namespace register_app {
 namespace fs = boost::filesystem;
 
 Step::Status StepRegisterApplication::process() {
-  assert(!context_->xml_path().empty());
+  assert(!context_->xml_path.get().empty());
 
   const char* const appinst_tags[] = {"removable=true", nullptr, };
   // TODO(sdi2): Check if data->removable is correctly setting
@@ -38,12 +37,13 @@ Step::Status StepRegisterApplication::process() {
   // Having a specific step to implement a installer commandline tool
   // for image build could be usefull also.
 
-  int ret = context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
+  int ret = context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
       pkgmgr_parser_parse_usr_manifest_for_installation(
-          context_->xml_path().c_str(), context_->uid(),
+          context_->xml_path.get().c_str(), context_->uid.get(),
           const_cast<char* const*>(appinst_tags)) :
       pkgmgr_parser_parse_manifest_for_installation(
-          context_->xml_path().c_str(), const_cast<char* const*>(appinst_tags));
+          context_->xml_path.get().c_str(),
+          const_cast<char* const*>(appinst_tags));
 
   if (ret != 0) {
     LOG(ERROR) << "Failed to record package into database";
@@ -58,7 +58,7 @@ Step::Status StepRegisterApplication::clean() {
 }
 
 Step::Status StepRegisterApplication::undo() {
-  if (context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
+  if (context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
     const char* ail_cmd[] = {kAilInitUser, nullptr};
     const char* pkgmgr_cmd[] = {kPkgInitUser, nullptr};
 
index 1baf634..e8ec99f 100644 (file)
@@ -11,8 +11,8 @@ namespace security {
 
 Step::Status StepRegisterSecurity::process() {
   if (!RegisterSecurityContextForApps(
-      context_->pkgid(), context_->GetApplicationPath(),
-      context_->manifest_data())) {
+      context_->pkgid.get(), context_->application_path.get(),
+      context_->manifest_data.get())) {
     return Status::ERROR;
   }
   LOG(DEBUG) << "Security context installed";
@@ -21,7 +21,7 @@ Step::Status StepRegisterSecurity::process() {
 
 Step::Status StepRegisterSecurity::undo() {
   if (!UnregisterSecurityContextForApps(
-      context_->pkgid(), context_->manifest_data())) {
+      context_->pkgid.get(), context_->manifest_data.get())) {
     return Status::ERROR;
   }
   LOG(DEBUG) << "Security context uninstalled";
index 1a8799f..4c91597 100755 (executable)
@@ -17,22 +17,22 @@ namespace remove {
 namespace fs = boost::filesystem;
 
 Step::Status StepRemoveFiles::process() {
-  uiapplication_x* ui = context_->manifest_data()->uiapplication;
+  uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
 
-  if (!fs::exists(context_->pkg_path()))
-    LOG(DEBUG) << "dir: " << context_->pkg_path() << "not exist";
+  if (!fs::exists(context_->pkg_path.get()))
+    LOG(DEBUG) << "dir: " << context_->pkg_path.get() << "not exist";
 
-  fs::remove_all(context_->pkg_path());
+  fs::remove_all(context_->pkg_path.get());
   for (; ui != nullptr; ui = ui->next) {
-    fs::path app_icon = fs::path(getIconPath(context_->uid()))
+    fs::path app_icon = fs::path(getIconPath(context_->uid.get()))
       / fs::path(ui->appid);
     app_icon += fs::path(".png");
     if (fs::exists(app_icon))
       fs::remove_all(app_icon);
   }
-  fs::remove_all(context_->xml_path());
+  fs::remove_all(context_->xml_path.get());
 
-  LOG(DEBUG) << "Removing dir: " << context_->pkg_path();
+  LOG(DEBUG) << "Removing dir: " << context_->pkg_path.get();
 
   return Status::OK;
 }
index 3db369c..c870971 100644 (file)
@@ -11,9 +11,9 @@ namespace revoke_security {
 
 Step::Status StepRevokeSecurity::process() {
   if (!UnregisterSecurityContextForApps(
-      context_->pkgid(), context_->manifest_data())) {
+      context_->pkgid.get(), context_->manifest_data.get())) {
     LOG(ERROR) << "Failure on unregistering security context for app "
-               << context_->pkgid();
+               << context_->pkgid.get();
     return Status::ERROR;
   }
   LOG(DEBUG) << "Security context uninstalled";
@@ -22,10 +22,10 @@ Step::Status StepRevokeSecurity::process() {
 
 Step::Status StepRevokeSecurity::undo() {
   if (!RegisterSecurityContextForApps(
-      context_->pkgid(), context_->GetApplicationPath(),
-      context_->manifest_data())) {
+      context_->pkgid.get(), context_->application_path.get(),
+      context_->manifest_data.get())) {
     LOG(ERROR) << "Failure on re-installing security context for app "
-               << context_->pkgid();
+               << context_->pkgid.get();
     return Status::ERROR;
   }
   LOG(DEBUG) << "Security context installed";
index c595d87..a5e8575 100644 (file)
@@ -12,7 +12,7 @@ namespace signal {
 
 Step::Status StepSignal::process() {
   if (!context_->pi()->sendStarted(
-      context_->manifest_data()->type, context_->pkgid())) {
+      context_->manifest_data.get()->type, context_->pkgid.get())) {
     return Status::ERROR;
   }
   LOG(DEBUG) << "Send Start";
@@ -22,7 +22,7 @@ Step::Status StepSignal::process() {
 Step::Status StepSignal::clean() {
   if (!context_->pi()->sendFinished(
         PkgmgrSignal::Result::SUCCESS,
-        context_->manifest_data()->type, context_->pkgid())) {
+        context_->manifest_data.get()->type, context_->pkgid.get())) {
     return Status::ERROR;
   }
   LOG(DEBUG) << "Send Success";
@@ -32,7 +32,7 @@ Step::Status StepSignal::clean() {
 Step::Status StepSignal::undo() {
   if (!context_->pi()->sendFinished(
         PkgmgrSignal::Result::FAILED,
-        context_->manifest_data()->type, context_->pkgid())) {
+        context_->manifest_data.get()->type, context_->pkgid.get())) {
     return Status::ERROR;
   }
   LOG(ERROR) << "Send Error";
index e214d0b..5adf1de 100644 (file)
@@ -20,11 +20,7 @@ class StepSignal : public Step {
   Status process() override;
   Status clean() override;
   Status undo() override;
-
  private:
-  bool sendSignal(ContextInstaller* data, const std::string& key,
-      const std::string& value);
-
   SCOPE_LOG_TAG(Signal)
 };
 
index 642880b..1bc07f4 100755 (executable)
@@ -17,16 +17,17 @@ namespace unregister_app {
 namespace fs = boost::filesystem;
 
 Step::Status StepUnregisterApplication::process() {
-  assert(!context_->pkgid().empty());
+  assert(!context_->pkgid.get().empty());
 
   const char* const appinst_tags[] = {"removable=true", nullptr, };
 
-  int ret = context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
+  int ret = context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
       pkgmgr_parser_parse_usr_manifest_for_uninstallation(
-          context_->xml_path().c_str(), context_->uid(),
+          context_->xml_path.get().c_str(), context_->uid.get(),
           const_cast<char* const*>(appinst_tags)) :
       pkgmgr_parser_parse_manifest_for_uninstallation(
-          context_->xml_path().c_str(), const_cast<char* const*>(appinst_tags));
+          context_->xml_path.get().c_str(),
+          const_cast<char* const*>(appinst_tags));
 
   if (ret != 0) {
     LOG(ERROR) << "Failed to unregister package into database";
index b34e132..4f36052 100644 (file)
@@ -109,7 +109,7 @@ StepUnzip::StepUnzip(ContextInstaller* context)
     : Step(context),
       is_extracted_(false) {}
 
-boost::filesystem::path StepUnzip::GenerateTmpDir(const char* app_path) {
+boost::filesystem::path StepUnzip::GenerateTmpDir(const std::string &app_path) {
   boost::filesystem::path install_tmp_dir;
   boost::filesystem::path tmp_dir(app_path);
 
@@ -215,11 +215,11 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src,
 }
 
 Step::Status StepUnzip::process() {
-  assert(!context_->file_path().empty());
-  assert(!access(context_->file_path().c_str(), F_OK));
+  assert(!context_->file_path.get().empty());
+  assert(!access(context_->file_path.get().c_str(), F_OK));
 
   bf::path tmp_dir =
-      GenerateTmpDir(context_->GetRootApplicationPath());
+      GenerateTmpDir(context_->root_application_path.get());
 
   if (!utils::CreateDir(tmp_dir)) {
     LOG(ERROR) << "Failed to create temp directory: " << tmp_dir;
@@ -227,11 +227,11 @@ Step::Status StepUnzip::process() {
   }
 
   int64_t required_size =
-      GetUnpackedPackageSize(bf::path(context_->file_path()));
+      GetUnpackedPackageSize(bf::path(context_->file_path.get()));
 
   if (required_size == -1) {
     LOG(ERROR) << "Couldn't get uncompressed size for package: "
-               << context_->file_path();
+               << context_->file_path.get();
     return Step::Status::ERROR;
   }
 
@@ -243,27 +243,27 @@ Step::Status StepUnzip::process() {
   }
 
   if (!CheckFreeSpaceAtPath(required_size,
-      bf::path(context_->GetRootApplicationPath()))) {
+      bf::path(context_->root_application_path.get()))) {
     LOG(ERROR) << "There is not enough space to install application files";
     return Step::Status::OUT_OF_SPACE;
   }
 
-  if (ExtractToTmpDir(context_->file_path().c_str(), tmp_dir)
+  if (ExtractToTmpDir(context_->file_path.get().c_str(), tmp_dir)
       != Step::Status::OK) {
     LOG(ERROR) << "Failed to process unpack step";
     return Step::Status::ERROR;
   }
-  context_->set_unpacked_dir_path(tmp_dir.string());
+  context_->unpacked_dir_path.set(tmp_dir.string());
 
-  LOG(INFO) << context_->file_path() << " was successfully unzipped into "
-      << context_->unpacked_dir_path();
+  LOG(INFO) << context_->file_path.get() << " was successfully unzipped into "
+      << context_->unpacked_dir_path.get();
   return Status::OK;
 }
 
 Step::Status StepUnzip::undo() {
-  if (access(context_->unpacked_dir_path().c_str(), F_OK) == 0) {
-    bf::remove_all(context_->unpacked_dir_path());
-    LOG(DEBUG) << "remove temp dir: " << context_->unpacked_dir_path();
+  if (access(context_->unpacked_dir_path.get().c_str(), F_OK) == 0) {
+    bf::remove_all(context_->unpacked_dir_path.get());
+    LOG(DEBUG) << "remove temp dir: " << context_->unpacked_dir_path.get();
   }
   return Status::OK;
 }
index 868aeb7..40b9281 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <boost/filesystem/path.hpp>
 
+#include <string>
+
 #include "common/context_installer.h"
 #include "common/step/step.h"
 #include "utils/logging.h"
@@ -21,7 +23,7 @@ class StepUnzip : public Step {
   Status undo() override;
 
  private:
-  boost::filesystem::path GenerateTmpDir(const char* app_path);
+  boost::filesystem::path GenerateTmpDir(const std::string &app_path);
   Step::Status ExtractToTmpDir(const char* source_dir,
       const boost::filesystem::path& tmp_dir);
 
index da52bd8..fd057f2 100644 (file)
@@ -25,7 +25,7 @@ bool CreateSymLink(T *app, ContextInstaller* context) {
   boost::system::error_code error;
 
   for (; app != nullptr; app=app->next) {
-    fs::path bindir = fs::path(context->pkg_path()) / fs::path(app->appid) /
+    fs::path bindir = fs::path(context->pkg_path.get()) / fs::path(app->appid) /
         fs::path("bin");
     LOG(INFO) << "Creating dir: " << bindir;
     if (!common_installer::utils::CreateDir(bindir)) {
@@ -64,7 +64,7 @@ bool RemoveSymLink(T *app, ContextInstaller* context) {
    * So we don't remove the bin/ directory itself.
    */
   for (; app != nullptr; app=app->next) {
-    fs::path exec_path = fs::path(context->pkg_path()) /
+    fs::path exec_path = fs::path(context->pkg_path.get()) /
         fs::path(app->appid) / fs::path("bin");
     fs::remove_all(exec_path / fs::path(app->appid));
   }
@@ -77,7 +77,7 @@ bool RemoveSymLink(T *app, ContextInstaller* context) {
 
 Status StepCreateSymbolicLink::process() {
   // Get manifest_x
-  manifest_x *m = context_->manifest_data();
+  manifest_x *m = context_->manifest_data.get();
   if (!m) {
     LOG(ERROR) << "manifest_x is null";
     return Status::ERROR;
@@ -103,7 +103,7 @@ Status StepCreateSymbolicLink::clean() {
 
 
 Status StepCreateSymbolicLink::undo() {
-  manifest_x* m = context_->manifest_data();
+  manifest_x* m = context_->manifest_data.get();
   uiapplication_x *uiapp = m->uiapplication;
   serviceapplication_x *svcapp = m->serviceapplication;
   if (!RemoveSymLink(uiapp, context_)) return Status::ERROR;
index 7232f72..a64599c 100644 (file)
@@ -76,7 +76,7 @@ using boost::filesystem::path;
  */
 Status StepParse::process() {
   std::unique_ptr<boost::filesystem::path> mPath(
-      GetManifestFilePath(context_->unpacked_dir_path()));
+      GetManifestFilePath(context_->unpacked_dir_path.get()));
   if (!mPath) {
     return Status::ERROR;
   }
@@ -142,14 +142,15 @@ bool StepParse::SetContextByManifestParser(XmlTree* tree) {
   }
 
   // set context_
-  context_->config_data()->set_application_name(label->content());
-  context_->config_data()->set_required_version(manifest->attr("api_version"));
-  context_->set_pkgid(manifest->attr("package"));
-  context_->set_manifest(static_cast<manifest_x*>(
+  context_->config_data.get().application_name.set(label->content());
+  context_->config_data.get().required_version.set(
+      manifest->attr("api_version"));
+  context_->pkgid.set(manifest->attr("package"));
+  context_->manifest_data.set(static_cast<manifest_x*>(
       calloc(1, sizeof(manifest_x))));
 
   // set context_->manifest_data()
-  return SetPkgInfoManifest(context_->manifest_data(), tree, manifest);
+  return SetPkgInfoManifest(context_->manifest_data.get(), tree, manifest);
 }
 
 
index 0b82b09..be4087b 100644 (file)
@@ -19,10 +19,11 @@ namespace symbolic_link {
 namespace fs = boost::filesystem;
 
 common_installer::Step::Status StepCreateSymbolicLink::process() {
-  assert(context_->manifest_data());
+  assert(context_->manifest_data.get());
   boost::system::error_code error;
-  uiapplication_x* ui = context_->manifest_data()->uiapplication;
-  serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+  uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
+  serviceapplication_x* svc =
+      context_->manifest_data.get()->serviceapplication;
   if ((!ui) && (!svc)) {
      LOG(ERROR) << "There is neither UI applications nor"
         << "Services applications described!";
@@ -31,8 +32,9 @@ common_installer::Step::Status StepCreateSymbolicLink::process() {
   // add ui-application element per ui application
   for (; ui != nullptr; ui = ui->next) {
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
-        / fs::path("bin");
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+            / fs::path("bin");
     common_installer::utils::CreateDir(exec_path);
 
     exec_path /= fs::path(ui->appid);
@@ -46,8 +48,9 @@ common_installer::Step::Status StepCreateSymbolicLink::process() {
   }
   for (; svc != nullptr; svc = svc->next) {
     // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
-        / fs::path("bin");
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(svc->appid)/
+            fs::path("bin");
     common_installer::utils::CreateDir(exec_path);
 
     exec_path /= fs::path(svc->appid);
@@ -69,18 +72,20 @@ common_installer::Step::Status StepCreateSymbolicLink::clean() {
 }
 
 common_installer::Step::Status StepCreateSymbolicLink::undo() {
-  uiapplication_x* ui = context_->manifest_data()->uiapplication;
-  serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+  uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
+  serviceapplication_x* svc = context_->manifest_data.get()->serviceapplication;
 
   for (; ui != nullptr; ui = ui->next) {
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
-    / fs::path("bin");
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+            / fs::path("bin");
     if (fs::exists(exec_path))
       fs::remove_all(exec_path);
   }
   for (; svc != nullptr; svc = svc->next) {
-    fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
-    / fs::path("bin");
+    fs::path exec_path =
+        fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+            / fs::path("bin");
     if (fs::exists(exec_path))
       fs::remove_all(exec_path);
   }
index e5b11cd..8c3f93b 100644 (file)
@@ -167,7 +167,7 @@ bool StepParse::FillManifestX(manifest_x* manifest) {
 }
 
 common_installer::Step::Status StepParse::process() {
-  if (!StepParse::Check(context_->unpacked_dir_path())) {
+  if (!StepParse::Check(context_->unpacked_dir_path.get())) {
     LOG(ERROR) << "No config.xml";
     return common_installer::Step::Status::ERROR;
   }
@@ -196,7 +196,7 @@ common_installer::Step::Status StepParse::process() {
     return common_installer::Step::Status::ERROR;
   }
 
-  const manifest_x* manifest = context_->manifest_data();
+  const manifest_x* manifest = context_->manifest_data.get();
   if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
                <<  parser_->GetErrorMessage();
@@ -222,10 +222,10 @@ common_installer::Step::Status StepParse::process() {
       app_keys::kVersionKey, &version);
   required_api_version = info->required_version();
 
-  context_->config_data()->set_application_name(
+  context_->config_data.get().application_name.set(
       std::string(manifest->uiapplication->label->name));
-  context_->set_pkgid(std::string(manifest->package));
-  context_->config_data()->set_required_version(required_api_version);
+  context_->config_data.get().required_version.set(required_api_version);
+  context_->pkgid.set(std::string(manifest->package));
 
   std::shared_ptr<const PermissionsInfo> perm_info =
       std::static_pointer_cast<const PermissionsInfo>(