#include <plugin_install/job_plugin_install.h>
#include <job_exception_base.h>
#include <plugin_install/plugin_objects.h>
+#include <installer_log.h>
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;
}
//InstallWidget, UninstallWidget InstallPlugin method are almost the same
// But each Job has different constructor, so creating new Job is specific
-// i.e. widgetHandle, path etc...
-Jobs::JobHandle InstallerLogic::InstallWidget(std::string const & widgetPath,
- const WidgetInstallationStruct &installerStruct)
+Jobs::JobHandle InstallerLogic::InstallWidget(
+ const std::string & widgetPath,
+ 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;
+ }
+
+ _D("New Widget Installation:");
- Jobs::Job *job =
- new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
+ m_job = new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, pkgId, installerStruct);
- return AddAndStartJob(job);
+ return AddAndStartJob();
}
-Jobs::JobHandle InstallerLogic::UninstallWidget(WidgetHandle widgetHandle,
- const WidgetUninstallationStruct &uninstallerStruct)
+Jobs::JobHandle InstallerLogic::UninstallWidget(
+ const std::string & widgetPkgName,
+ 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 =
- new Jobs::WidgetUninstall::JobWidgetUninstall(widgetHandle,
+ m_job =
+ new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
uninstallerStruct);
- return AddAndStartJob(job);
+ return AddAndStartJob();
}
-Jobs::JobHandle InstallerLogic::InstallPlugin(std::string const & pluginPath,
- const PluginInstallerStruct &installerStruct)
+Jobs::JobHandle InstallerLogic::InstallPlugin(
+ 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() \
return !job->IsPaused();
}
- if (!job->GetUndoType()) {
+ if (!job->GetAbortStarted()) {
//job successfully finished
//send finished callback
switch (job->GetInstallationType()) {
case Jobs::PluginInstallation:
- //todo move it somewhere
InstallWaitingPlugins();
break;
default: //because of warning
}
//clean job
- m_jobs.erase(job->GetJobHandle());
delete job;
+ m_job=0;
return false;
- }
- catch (Jobs::JobExceptionBase &exc) {
+ } 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) {
job->SendFinishedFailure();
//clean job
- m_jobs.erase(job->GetJobHandle());
delete job;
+ m_job=0;
}
return hasAbortSteps;
}
}
-//TODO this should be moved somewhere...when it should take place? after widget
-//is closing?
-void InstallerLogic::InstallDeferredWidgetPackages()
-{
- LogWarning("Not implemented");
- // LogInfo("Installing deferred widget packages...");
- //
- // WidgetPackageList packages = GlobalDAO::GetDefferedWidgetPackageInstallationList();
- //
- // LogInfo(packages.size() << " widget package(s) to install");
- //
- // // Make a copy of widget packages to install, because some
- // // widget packages may still fail because they are running
- // m_packagesToInstall = packages;
- //
- // // Start processing
- // InstallSingleDeferredPackage();
-}
-
-void InstallerLogic::InstallSingleDeferredPackage()
-{
- LogWarning("Not implemented");
- // if (m_packagesToInstall.empty())
- // return;
- //
- // // Take single package
- // DPL::String widgetPackage = m_packagesToInstall.front();
- // m_packagesToInstall.pop_front();
- //
- // // Remove it from DB
- // GlobalDAO::RemoveDefferedWidgetPackageInstallation(widgetPackage);
- //
- // // Begin installation
- // LogInfo("Installing deferred widget package: " << widgetPackage);
- //
- // // Post installation
- // CONTROLLER_POST_EVENT(
- // InstallerController, InstallerControllerEvents::InstallWidgetEvent(
- // DPL::ToUTF8String(widgetPackage).c_str(), WidgetInstallationStruct(
- // &DummyInstallCallback, &DummyProgressCallback, NULL,
- // WidgetUpdateMode::PolicyWac)));
-}
-
void InstallerLogic::InstallWaitingPlugins()
{
PluginHandleSetPtr waitingPlugins;
PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
if (depHandle ==
- Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE) {
- LogError("Library implementing: " <<
- *requiredObject << " NOT FOUND");
+ Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE)
+ {
+ _E("Library implementing: %s NOT FOUND", (*requiredObject).c_str());
//PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING);
return false;
return true;
}
-
}