[Release] wrt-installer_0.1.85
[platform/framework/web/wrt-installer.git] / src / logic / installer_logic.cpp
index 10cda89..6b3f06c 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,23 @@ 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 =
-        new Jobs::PluginInstall::JobPluginInstall(pluginPath, installerStruct);
+    //Conversion to DPL::Utils::Path is temporary
+    m_job =
+        new Jobs::PluginInstall::JobPluginInstall(DPL::Utils::Path(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 +165,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 +182,8 @@ bool InstallerLogic::NextStep(Jobs::Job *job)
             job->SendFinishedFailure();
 
             //clean job
-            m_jobs.erase(job->GetJobHandle());
             delete job;
+            m_job=0;
         }
         return hasAbortSteps;
     }