X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flogic%2Finstaller_logic.cpp;h=df67764dc5642a7ccce13b4b7a8c7fcd3c736d3d;hb=7a182e91c2ce7bbc7b325ddddee182f2b2909482;hp=10cda897380996eec53da0cc184d8633e7652690;hpb=a2d00194d64eb7080d19bacd6c6456e504d64409;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/logic/installer_logic.cpp b/src/logic/installer_logic.cpp index 10cda89..df67764 100644 --- a/src/logic/installer_logic.cpp +++ b/src/logic/installer_logic.cpp @@ -24,46 +24,43 @@ #include #include #include +#include using namespace WrtDB; namespace Logic { InstallerLogic::InstallerLogic() : + m_job(0), m_NextHandle(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? } void InstallerLogic::Initialize() { - LogDebug("Done"); + _D("Done"); } 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"); + _D("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; } @@ -72,15 +69,21 @@ Jobs::JobHandle InstallerLogic::AddAndStartJob(Jobs::Job *job) // But each Job has different constructor, so creating new Job is specific Jobs::JobHandle InstallerLogic::InstallWidget( const std::string & widgetPath, - const WidgetInstallationStruct & + const std::string & pkgId, + const Jobs::WidgetInstall::WidgetInstallationStruct & installerStruct) { - LogDebug("New Widget Installation:"); + if(m_job) + { + _E("Job is in progress. It is impossible to add new job"); + return -1; + } - Jobs::Job *job = - new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct); + _D("New Widget Installation:"); - return AddAndStartJob(job); + m_job = new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, pkgId, installerStruct); + + return AddAndStartJob(); } Jobs::JobHandle InstallerLogic::UninstallWidget( @@ -88,28 +91,43 @@ Jobs::JobHandle InstallerLogic::UninstallWidget( const WidgetUninstallationStruct &uninstallerStruct) { - LogDebug("New Widget Uninstallation"); + if(m_job) + { + _E("Job is in progress. It is impossible to add new job"); + return -1; + } + + _D("New Widget Uninstallation"); - Jobs::Job *job = + m_job = new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName, uninstallerStruct); - return AddAndStartJob(job); + return AddAndStartJob(); } Jobs::JobHandle InstallerLogic::InstallPlugin( - std::string const & pluginPath, + std::string const & pluginPath, // TODO change type to PluginPath const PluginInstallerStruct & installerStruct) { - LogDebug("New Plugin Installation"); + if(m_job) + { + _E("Job is in progress. It is impossible to add new job"); + return -1; + } + + _D("New Plugin Installation"); + + // TODO Conversion to PluginPath is temporary + m_job = + new Jobs::PluginInstall::JobPluginInstall(PluginPath(pluginPath), installerStruct); - Jobs::Job *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() \ @@ -128,7 +146,7 @@ bool InstallerLogic::NextStep(Jobs::Job *job) return !job->IsPaused(); } - if (!job->GetUndoType()) { + if (!job->GetAbortStarted()) { //job successfully finished //send finished callback @@ -136,7 +154,6 @@ bool InstallerLogic::NextStep(Jobs::Job *job) switch (job->GetInstallationType()) { case Jobs::PluginInstallation: - //todo move it somewhere InstallWaitingPlugins(); break; default: //because of warning @@ -148,16 +165,15 @@ bool InstallerLogic::NextStep(Jobs::Job *job) } //clean job - m_jobs.erase(job->GetJobHandle()); delete job; + m_job=0; return false; } catch (Jobs::JobExceptionBase &exc) { //start revert job - LogInfo("Exception occured: " << exc.getParam() << - ". Reverting job..."); + _D("Exception occured: %d. Reverting job...", exc.getParam()); bool hasAbortSteps = job->Abort(); - job->SetUndoType(true); + job->SetAbortStarted(true); job->SaveExceptionData(exc); if (!hasAbortSteps) { @@ -165,8 +181,8 @@ bool InstallerLogic::NextStep(Jobs::Job *job) job->SendFinishedFailure(); //clean job - m_jobs.erase(job->GetJobHandle()); delete job; + m_job=0; } return hasAbortSteps; } @@ -220,8 +236,7 @@ bool InstallerLogic::resolvePluginDependencies(PluginHandle handle) if (depHandle == Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE) { - LogError("Library implementing: " << - *requiredObject << " NOT FOUND"); + _E("Library implementing: %s NOT FOUND", (*requiredObject).c_str()); //PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING); return false;