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() :
32 m_NextHandle(0),m_job(0)
35 InstallerLogic::~InstallerLogic()
37 Assert(!m_job && "There are still running job");
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
50 m_job->SetPaused(true);
55 Jobs::JobHandle InstallerLogic::AddAndStartJob()
57 Jobs::JobHandle handle = GetNewJobHandle();
58 m_job->SetJobHandle(handle);
60 CONTROLLER_POST_EVENT(InstallerController,
61 InstallerControllerEvents::NextStepEvent(m_job));
66 //InstallWidget, UninstallWidget InstallPlugin method are almost the same
67 // But each Job has different constructor, so creating new Job is specific
68 Jobs::JobHandle InstallerLogic::InstallWidget(
69 const std::string & widgetPath,
70 const WidgetInstallationStruct &
75 LogError("Job is in progress. It is impossible to add new job");
79 LogDebug("New Widget Installation:");
82 new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
85 return AddAndStartJob();
88 Jobs::JobHandle InstallerLogic::UninstallWidget(
89 const std::string & widgetPkgName,
91 WidgetUninstallationStruct &uninstallerStruct)
95 LogError("Job is in progress. It is impossible to add new job");
99 LogDebug("New Widget Uninstallation");
102 new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
105 return AddAndStartJob();
108 Jobs::JobHandle InstallerLogic::InstallPlugin(
109 std::string const & pluginPath, // TODO change type to PluginPath
110 const PluginInstallerStruct &
115 LogError("Job is in progress. It is impossible to add new job");
119 LogDebug("New Plugin Installation");
121 // TODO Conversion to PluginPath is temporary
123 new Jobs::PluginInstall::JobPluginInstall(PluginPath(pluginPath), installerStruct);
125 // before start install plugin, reset plugin data which is stopped
126 // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
127 ResetProgressPlugins();
129 return AddAndStartJob();
132 #define TRANSLATE_JOB_EXCEPTION() \
133 _rethrown_exception.getParam()
134 #define TRANSLATE_JOB_MESSAGE() \
135 _rethrown_exception.GetMessage()
137 bool InstallerLogic::NextStep(Jobs::Job *job)
140 bool stepSucceded = job->NextStep();
145 return !job->IsPaused();
148 if (!job->GetUndoType()) {
149 //job successfully finished
151 //send finished callback
152 job->SendFinishedSuccess();
154 switch (job->GetInstallationType()) {
155 case Jobs::PluginInstallation:
156 //todo move it somewhere
157 InstallWaitingPlugins();
159 default: //because of warning
163 //job abort process completed
164 job->SendFinishedFailure();
172 } catch (Jobs::JobExceptionBase &exc) {
174 LogDebug("Exception occured: " << exc.getParam() <<
175 ". Reverting job...");
176 bool hasAbortSteps = job->Abort();
177 job->SetUndoType(true);
178 job->SaveExceptionData(exc);
180 if (!hasAbortSteps) {
182 job->SendFinishedFailure();
188 return hasAbortSteps;
192 void InstallerLogic::InstallWaitingPlugins()
194 PluginHandleSetPtr waitingPlugins;
197 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_WAITING);
199 FOREACH(it, *waitingPlugins)
201 resolvePluginDependencies(*it);
205 void InstallerLogic::ResetProgressPlugins()
207 PluginHandleSetPtr progressPlugins;
210 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_IN_PROGRESS);
212 FOREACH(it, *progressPlugins) {
213 FeatureHandleListPtr featureListPtr =
214 FeatureDAOReadOnly::GetFeatureHandleListForPlugin(*it);
215 FOREACH(ItFeature, *featureListPtr) {
216 FeatureDAO::UnregisterFeature(*ItFeature);
218 PluginDAO::unregisterPlugin(*it);
222 bool InstallerLogic::resolvePluginDependencies(PluginHandle handle)
224 PluginHandleSetPtr dependencies(new PluginHandleSet);
226 PluginObjects::ObjectsPtr requiredObjects =
227 PluginDAO::getRequiredObjectsForPluginHandle(handle);
229 PluginHandle depHandle =
230 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE;
232 FOREACH(requiredObject, *requiredObjects)
235 PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
238 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE)
240 LogError("Library implementing: " <<
241 *requiredObject << " NOT FOUND");
243 //PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING);
246 dependencies->insert(depHandle);
249 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
250 PluginDAO::setPluginInstallationStatus(handle,
251 PluginDAO::INSTALLATION_COMPLETED);