Create interface defining strategy of initialization of pkgmgr_installer object 42/59442/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 15 Feb 2016 09:34:51 +0000 (10:34 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 16 Feb 2016 09:07:27 +0000 (10:07 +0100)
Smoke tests are randomly crashing since some changes with dbus
connection closing in slp-pkgmgr. It seems to be some time hazard (?)
on closing connection.

Anyway, tests are setting up and closing connection repeatingly.
Introduced interface will allow to customize creation of pkgmgr_installer
object in smoke tests.

Following changes need to be submitted together:
     - https://review.tizen.org/gerrit/59442
     - https://review.tizen.org/gerrit/59443
     - https://review.tizen.org/gerrit/59444

Change-Id: I69f5972c09a593cfe9a282f2120845f85aa65b52

src/common/app_installer.cc
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h

index 9c585fe..e5197a5 100644 (file)
@@ -24,11 +24,13 @@ AppInstaller::AppInstaller(const char* package_type, PkgMgrPtr pkgmgr)
   context_->pkg_type.set(package_type);
   context_->installation_mode.set(pkgmgr->GetInstallationMode());
 
-  if (context_->installation_mode.get() == InstallationMode::ONLINE) {
-    // pkgmgr signal should work only for online mode
-    // there is no one to receive it in offline mode
-    pi_.reset(new PkgmgrSignal(pkgmgr.get()->GetRawPi(),
-                               pkgmgr->GetRequestType()));
+  if (pkgmgr->ShouldCreateSignal()) {
+    if (context_->installation_mode.get() == InstallationMode::ONLINE) {
+      // pkgmgr signal should work only for online mode
+      // there is no one to receive it in offline mode
+      pi_.reset(new PkgmgrSignal(pkgmgr.get()->GetRawPi(),
+                                 pkgmgr->GetRequestType()));
+    }
   }
 }
 
index 942acbb..60b3a82 100644 (file)
@@ -24,9 +24,33 @@ const char kDeltaFileExtension[] = ".delta";
 
 namespace common_installer {
 
+bool PkgmgrInstaller::CreatePkgMgrInstaller(pkgmgr_installer** installer,
+                             InstallationMode* mode) {
+  *installer = pkgmgr_installer_new();
+  if (!*installer) {
+    LOG(WARNING) << "Cannot create pkgmgr_installer object. Will try offline";
+    // TODO(t.iwanek): app-installer should recognize offline installation and
+    // this information should be accesible in installation context
+    *installer = pkgmgr_installer_offline_new();
+    if (!*installer) {
+      return false;
+    }
+    *mode = InstallationMode::OFFLINE;
+  } else {
+    *mode = InstallationMode::ONLINE;
+  }
+  return true;
+}
+
+bool PkgmgrInstaller::ShouldCreateSignal() const {
+  return true;
+}
+
 PkgMgrPtr PkgMgrInterface::Create(int argc, char** argv,
-                                  AppQueryInterface* interface) {
-  PkgMgrPtr instance(new PkgMgrInterface(interface));
+    PkgmgrInstallerInterface* pkgmgr_installer_interface,
+    AppQueryInterface* interface) {
+  PkgMgrPtr instance(new PkgMgrInterface(pkgmgr_installer_interface,
+                                         interface));
   int result = instance->InitInternal(argc, argv);
   if (result != 0)
     return nullptr;
@@ -35,20 +59,10 @@ PkgMgrPtr PkgMgrInterface::Create(int argc, char** argv,
 }
 
 int PkgMgrInterface::InitInternal(int argc, char** argv) {
-  pi_ = pkgmgr_installer_new();
-
-  if (!pi_) {
-    LOG(WARNING) << "Cannot create pkgmgr_installer object. Will try offline";
-    // TODO(t.iwanek): app-installer should recognize offline installation and
-    // this information should be accesible in installation context
-    pi_ = pkgmgr_installer_offline_new();
-    if (!pi_) {
-      LOG(ERROR) << "Cannot create pkgmgr_installer object. Aborting.";
-      return ENOMEM;
-    }
-    install_mode_ = InstallationMode::OFFLINE;
-  } else {
-    install_mode_ = InstallationMode::ONLINE;
+  if (!pkgmgr_installer_interface_->CreatePkgMgrInstaller(&pi_,
+                                                          &install_mode_)) {
+    LOG(ERROR) << "Cannot create pkgmgr_installer object. Aborting.";
+    return false;
   }
 
   int result = pkgmgr_installer_receive_request(pi_, argc, argv);
index 90d3891..a5690fb 100644 (file)
@@ -25,6 +25,35 @@ class PkgMgrInterface;
 typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
 
 /**
+ * \brief The PkgmgrInstallerInterface class
+ *        Interface defining strategy for creation of pkgmgr_installer object
+ *        and PkgmgrSignal object.
+ *
+ * This interface is injected to PkgMgrInterface class to decide:
+ *  - how to create pkgmgr_installer,
+ *  - if to create PkgmgrSignal object,
+ *  - what installation mode should be set in installer context.
+ */
+class PkgmgrInstallerInterface {
+ public:
+  virtual bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+                             InstallationMode* mode) = 0;
+  virtual bool ShouldCreateSignal() const = 0;
+};
+
+/**
+ * \brief The PkgmgrInstaller class
+ *        Implementation of PkgmgrInstallerInterface that handles creation of
+ *        pkgmgr_installer class in online and offline mode.
+ */
+class PkgmgrInstaller : public PkgmgrInstallerInterface {
+ public:
+  bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+                             InstallationMode* mode);
+  bool ShouldCreateSignal() const;
+};
+
+/**
  * \brief Encapsulates pkgmgr API which handles parsing backend options
  *        and returns values/modes for installation process.
  */
@@ -49,11 +78,14 @@ class PkgMgrInterface {
    *
    * \param argc main() argc argument passed to the backend
    * \param argv main() argv argument passed to the backend
+   * \param pkgmgr_installer_interface interface defining strategy of creation
+   *                                   of pkgmgr_installer
    * \param interface pointer to AppQueryInterface
    *
    * \return Smart pointer to the PkgMgrInterface
    */
   static PkgMgrPtr Create(int argc, char** argv,
+        PkgmgrInstallerInterface* pkgmgr_installer_interface,
         AppQueryInterface* interface = nullptr);
 
   /**
@@ -92,21 +124,33 @@ class PkgMgrInterface {
   */
   InstallationMode GetInstallationMode() const { return install_mode_; }
 
+  /**
+   * @brief ShouldCreateSignal
+   *
+   *
+   * @return true if pkgmgr signal should be created
+   */
+  bool ShouldCreateSignal() const {
+    return pkgmgr_installer_interface_->ShouldCreateSignal();
+  }
 
   /** PkgMgrInstance destructor. */
   ~PkgMgrInterface();
 
  private:
-  explicit PkgMgrInterface(AppQueryInterface* interface)
+  explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
+                           AppQueryInterface* interface)
       : pi_(nullptr),
         install_mode_(InstallationMode::ONLINE),
         is_app_installed_(false),
+        pkgmgr_installer_interface_(pkgmgr_installer_interface),
         query_interface_(interface) {}
   int InitInternal(int argc, char** argv);
 
   pkgmgr_installer* pi_;
   InstallationMode install_mode_;
   bool is_app_installed_;
+  PkgmgrInstallerInterface* pkgmgr_installer_interface_;
 
   AppQueryInterface* query_interface_;