2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <installer_logic.h>
17 #include <installer_controller.h>
18 #include <dpl/string.h>
19 #include <dpl/foreach.h>
20 #include <dpl/wrt-dao-rw/feature_dao.h>
21 #include <dpl/wrt-dao-rw/plugin_dao.h>
22 #include <widget_install/job_widget_install.h>
23 #include <widget_uninstall/job_widget_uninstall.h>
24 #include <plugin_install/job_plugin_install.h>
25 #include <job_exception_base.h>
26 #include <plugin_install/plugin_objects.h>
28 using namespace WrtDB;
31 InstallerLogic::InstallerLogic() :
35 InstallerLogic::~InstallerLogic()
37 Assert(m_jobs.empty() && "There are still running jobs");
38 //FIXME what should be done here?
41 void InstallerLogic::Initialize()
46 void InstallerLogic::Terminate()
48 //TODO how to delete, if it is still running, paused and so on
51 it->second->SetPaused(true); //FIXME this is not enough!
57 Jobs::JobHandle InstallerLogic::AddAndStartJob(Jobs::Job *job)
59 Jobs::JobHandle handle = GetNewJobHandle();
60 job->SetJobHandle(handle);
62 m_jobs.insert(std::make_pair(handle, job));
65 CONTROLLER_POST_EVENT(InstallerController,
66 InstallerControllerEvents::NextStepEvent(job));
71 //InstallWidget, UninstallWidget InstallPlugin method are almost the same
72 // But each Job has different constructor, so creating new Job is specific
73 Jobs::JobHandle InstallerLogic::InstallWidget(
74 const std::string & widgetPath,
75 const WidgetInstallationStruct &
78 LogDebug("New Widget Installation:");
81 new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
83 return AddAndStartJob(job);
86 Jobs::JobHandle InstallerLogic::UninstallWidget(
87 const std::string & widgetPkgName,
89 WidgetUninstallationStruct &uninstallerStruct)
91 LogDebug("New Widget Uninstallation");
94 new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
97 return AddAndStartJob(job);
100 Jobs::JobHandle InstallerLogic::InstallPlugin(
101 std::string const & pluginPath,
102 const PluginInstallerStruct &
105 LogDebug("New Plugin Installation");
108 new Jobs::PluginInstall::JobPluginInstall(pluginPath, installerStruct);
109 // before start install plugin, reset plugin data which is stopped
110 // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
111 ResetProgressPlugins();
112 return AddAndStartJob(job);
115 #define TRANSLATE_JOB_EXCEPTION() \
116 _rethrown_exception.getParam()
117 #define TRANSLATE_JOB_MESSAGE() \
118 _rethrown_exception.GetMessage()
120 bool InstallerLogic::NextStep(Jobs::Job *job)
123 bool stepSucceded = job->NextStep();
128 return !job->IsPaused();
131 if (!job->GetUndoType()) {
132 //job successfully finished
134 //send finished callback
135 job->SendFinishedSuccess();
137 switch (job->GetInstallationType()) {
138 case Jobs::PluginInstallation:
139 //todo move it somewhere
140 InstallWaitingPlugins();
142 default: //because of warning
146 //job abort process completed
147 job->SendFinishedFailure();
151 m_jobs.erase(job->GetJobHandle());
155 } catch (Jobs::JobExceptionBase &exc) {
157 LogInfo("Exception occured: " << exc.getParam() <<
158 ". Reverting job...");
159 bool hasAbortSteps = job->Abort();
160 job->SetUndoType(true);
161 job->SaveExceptionData(exc);
163 if (!hasAbortSteps) {
165 job->SendFinishedFailure();
168 m_jobs.erase(job->GetJobHandle());
171 return hasAbortSteps;
175 void InstallerLogic::InstallWaitingPlugins()
177 PluginHandleSetPtr waitingPlugins;
180 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_WAITING);
182 FOREACH(it, *waitingPlugins)
184 resolvePluginDependencies(*it);
188 void InstallerLogic::ResetProgressPlugins()
190 PluginHandleSetPtr progressPlugins;
193 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_IN_PROGRESS);
195 FOREACH(it, *progressPlugins) {
196 FeatureHandleListPtr featureListPtr =
197 FeatureDAOReadOnly::GetFeatureHandleListForPlugin(*it);
198 FOREACH(ItFeature, *featureListPtr) {
199 FeatureDAO::UnregisterFeature(*ItFeature);
201 PluginDAO::unregisterPlugin(*it);
205 bool InstallerLogic::resolvePluginDependencies(PluginHandle handle)
207 PluginHandleSetPtr dependencies(new PluginHandleSet);
209 PluginObjects::ObjectsPtr requiredObjects =
210 PluginDAO::getRequiredObjectsForPluginHandle(handle);
212 PluginHandle depHandle =
213 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE;
215 FOREACH(requiredObject, *requiredObjects)
218 PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
221 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE)
223 LogError("Library implementing: " <<
224 *requiredObject << " NOT FOUND");
226 //PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING);
229 dependencies->insert(depHandle);
232 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
233 PluginDAO::setPluginInstallationStatus(handle,
234 PluginDAO::INSTALLATION_COMPLETED);