Installer Jobs list clean up
authorRafal Bednarski <r.bednarski@samsung.com>
Wed, 29 May 2013 11:58:01 +0000 (13:58 +0200)
committerGerrit Code Review <gerrit2@kim11>
Thu, 6 Jun 2013 11:58:22 +0000 (20:58 +0900)
[Issue#] N/A
[Problem] wrt-installer cannot be used to install/uninstall
    multiple widgets at once. Because of that,
    InstallerLogic does not need to use the Jobs container
    for the jobs.
    InstallerLogic can run/use just one job at given time.
[Cause] N/A
[Solution] container is exchanged for a single pointer
    value that holds the job.
[Verification]  Verification should contain:
    running wrt-installer -p (plugins installation)
    installing, deinstalling, update widgets
    installing invalid widget (that should
    not be installed)

Change-Id: Ib738f61551c5fb39085b6c972b152c9515c9711f

src/logic/installer_logic.cpp
src/logic/installer_logic.h

index 10cda89..fe4f629 100644 (file)
@@ -29,12 +29,12 @@ using namespace WrtDB;
 
 namespace Logic {
 InstallerLogic::InstallerLogic() :
-    m_NextHandle(0)
+    m_NextHandle(0),m_job(0)
 {}
 
 InstallerLogic::~InstallerLogic()
 {
-    Assert(m_jobs.empty() && "There are still running jobs");
+        Assert(!m_job && "There are still running job");
     //FIXME what should be done here?
 }
 
@@ -46,24 +46,19 @@ void InstallerLogic::Initialize()
 void InstallerLogic::Terminate()
 {
     //TODO how to delete, if it is still running, paused and so on
-    FOREACH(it, m_jobs)
-    {
-        it->second->SetPaused(true); //FIXME this is not enough!
-    }
+    if(m_job)
+        m_job->SetPaused(true);
 
     LogDebug("Done");
 }
 
-Jobs::JobHandle InstallerLogic::AddAndStartJob(Jobs::Job *job)
+Jobs::JobHandle InstallerLogic::AddAndStartJob()
 {
     Jobs::JobHandle handle = GetNewJobHandle();
-    job->SetJobHandle(handle);
-
-    m_jobs.insert(std::make_pair(handle, job));
-
+    m_job->SetJobHandle(handle);
     //Start job
     CONTROLLER_POST_EVENT(InstallerController,
-                          InstallerControllerEvents::NextStepEvent(job));
+                          InstallerControllerEvents::NextStepEvent(m_job));
 
     return handle;
 }
@@ -75,12 +70,19 @@ Jobs::JobHandle InstallerLogic::InstallWidget(
     const WidgetInstallationStruct &
     installerStruct)
 {
+    if(m_job)
+    {
+        LogError("Job is in progress. It is impossible to add new job");
+        return -1;
+    }
+
     LogDebug("New Widget Installation:");
 
-    Jobs::Job *job =
+    m_job =
         new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
 
-    return AddAndStartJob(job);
+
+    return AddAndStartJob();
 }
 
 Jobs::JobHandle InstallerLogic::UninstallWidget(
@@ -88,13 +90,19 @@ Jobs::JobHandle InstallerLogic::UninstallWidget(
     const
     WidgetUninstallationStruct &uninstallerStruct)
 {
+    if(m_job)
+    {
+        LogError("Job is in progress. It is impossible to add new job");
+        return -1;
+    }
+
     LogDebug("New Widget Uninstallation");
 
-    Jobs::Job *job =
+    m_job  =
         new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
                                                       uninstallerStruct);
 
-    return AddAndStartJob(job);
+      return AddAndStartJob();
 }
 
 Jobs::JobHandle InstallerLogic::InstallPlugin(
@@ -102,14 +110,21 @@ Jobs::JobHandle InstallerLogic::InstallPlugin(
     const PluginInstallerStruct &
     installerStruct)
 {
+    if(m_job)
+    {
+        LogError("Job is in progress. It is impossible to add new job");
+        return -1;
+    }
+
     LogDebug("New Plugin Installation");
 
-    Jobs::Job *job =
+    m_job  =
         new Jobs::PluginInstall::JobPluginInstall(pluginPath, installerStruct);
     // before start install plugin, reset plugin data which is stopped
     // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
     ResetProgressPlugins();
-    return AddAndStartJob(job);
+
+    return AddAndStartJob();
 }
 
 #define TRANSLATE_JOB_EXCEPTION() \
@@ -148,8 +163,8 @@ bool InstallerLogic::NextStep(Jobs::Job *job)
         }
 
         //clean job
-        m_jobs.erase(job->GetJobHandle());
         delete job;
+        m_job=0;
 
         return false;
     } catch (Jobs::JobExceptionBase &exc) {
@@ -165,8 +180,8 @@ bool InstallerLogic::NextStep(Jobs::Job *job)
             job->SendFinishedFailure();
 
             //clean job
-            m_jobs.erase(job->GetJobHandle());
             delete job;
+            m_job=0;
         }
         return hasAbortSteps;
     }
index 496e967..0d3463e 100644 (file)
@@ -27,8 +27,7 @@
 namespace Logic {
 class InstallerLogic
 {
-    typedef std::map<Jobs::JobHandle, Jobs::Job*> JobsContainer;
-    JobsContainer m_jobs;
+    Jobs::Job* m_job;
 
     void ResetProgressPlugins();
     void InstallWaitingPlugins();
@@ -39,7 +38,7 @@ class InstallerLogic
     {
         return m_NextHandle++;
     }
-    Jobs::JobHandle AddAndStartJob(Jobs::Job *job);
+    Jobs::JobHandle AddAndStartJob();
 
   public:
     virtual ~InstallerLogic();