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>
27 #include <installer_log.h>
29 using namespace WrtDB;
32 InstallerLogic::InstallerLogic() :
37 InstallerLogic::~InstallerLogic()
39 Assert(!m_job && "There are still running job");
40 //FIXME what should be done here?
43 void InstallerLogic::Initialize()
48 void InstallerLogic::Terminate()
50 //TODO how to delete, if it is still running, paused and so on
52 m_job->SetPaused(true);
57 Jobs::JobHandle InstallerLogic::AddAndStartJob()
59 Jobs::JobHandle handle = GetNewJobHandle();
60 m_job->SetJobHandle(handle);
62 CONTROLLER_POST_EVENT(InstallerController,
63 InstallerControllerEvents::NextStepEvent(m_job));
68 //InstallWidget, UninstallWidget InstallPlugin method are almost the same
69 // But each Job has different constructor, so creating new Job is specific
70 Jobs::JobHandle InstallerLogic::InstallWidget(
71 const std::string & widgetPath,
72 const std::string & pkgId,
73 const Jobs::WidgetInstall::WidgetInstallationStruct &
78 _E("Job is in progress. It is impossible to add new job");
82 _D("New Widget Installation:");
84 m_job = new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, pkgId, installerStruct);
86 return AddAndStartJob();
89 Jobs::JobHandle InstallerLogic::UninstallWidget(
90 const std::string & widgetPkgName,
92 WidgetUninstallationStruct &uninstallerStruct)
96 _E("Job is in progress. It is impossible to add new job");
100 _D("New Widget Uninstallation");
103 new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
106 return AddAndStartJob();
109 Jobs::JobHandle InstallerLogic::InstallPlugin(
110 std::string const & pluginPath, // TODO change type to PluginPath
111 const PluginInstallerStruct &
116 _E("Job is in progress. It is impossible to add new job");
120 _D("New Plugin Installation");
122 // TODO Conversion to PluginPath is temporary
124 new Jobs::PluginInstall::JobPluginInstall(PluginPath(pluginPath), installerStruct);
126 // before start install plugin, reset plugin data which is stopped
127 // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
128 ResetProgressPlugins();
130 return AddAndStartJob();
133 #define TRANSLATE_JOB_EXCEPTION() \
134 _rethrown_exception.getParam()
135 #define TRANSLATE_JOB_MESSAGE() \
136 _rethrown_exception.GetMessage()
138 bool InstallerLogic::NextStep(Jobs::Job *job)
141 bool stepSucceded = job->NextStep();
146 return !job->IsPaused();
149 if (!job->GetAbortStarted()) {
150 //job successfully finished
152 //send finished callback
153 job->SendFinishedSuccess();
155 switch (job->GetInstallationType()) {
156 case Jobs::PluginInstallation:
157 InstallWaitingPlugins();
159 default: //because of warning
163 //job abort process completed
164 job->SendFinishedFailure();
172 } catch (Jobs::JobExceptionBase &exc) {
174 _D("Exception occured: %d. Reverting job...", exc.getParam());
175 bool hasAbortSteps = job->Abort();
176 job->SetAbortStarted(true);
177 job->SaveExceptionData(exc);
179 if (!hasAbortSteps) {
181 job->SendFinishedFailure();
187 return hasAbortSteps;
191 void InstallerLogic::InstallWaitingPlugins()
193 PluginHandleSetPtr waitingPlugins;
196 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_WAITING);
198 FOREACH(it, *waitingPlugins)
200 resolvePluginDependencies(*it);
204 void InstallerLogic::ResetProgressPlugins()
206 PluginHandleSetPtr progressPlugins;
209 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_IN_PROGRESS);
211 FOREACH(it, *progressPlugins) {
212 FeatureHandleListPtr featureListPtr =
213 FeatureDAOReadOnly::GetFeatureHandleListForPlugin(*it);
214 FOREACH(ItFeature, *featureListPtr) {
215 FeatureDAO::UnregisterFeature(*ItFeature);
217 PluginDAO::unregisterPlugin(*it);
221 bool InstallerLogic::resolvePluginDependencies(PluginHandle handle)
223 PluginHandleSetPtr dependencies(new PluginHandleSet);
225 PluginObjects::ObjectsPtr requiredObjects =
226 PluginDAO::getRequiredObjectsForPluginHandle(handle);
228 PluginHandle depHandle =
229 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE;
231 FOREACH(requiredObject, *requiredObjects)
234 PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
237 Jobs::PluginInstall::JobPluginInstall::INVALID_HANDLE)
239 _E("Library implementing: %s NOT FOUND", (*requiredObject).c_str());
241 //PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING);
244 dependencies->insert(depHandle);
247 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
248 PluginDAO::setPluginInstallationStatus(handle,
249 PluginDAO::INSTALLATION_COMPLETED);