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 Jobs::WidgetInstall::WidgetInstallationStruct &
77 _E("Job is in progress. It is impossible to add new job");
81 _D("New Widget Installation:");
84 new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
87 return AddAndStartJob();
90 Jobs::JobHandle InstallerLogic::UninstallWidget(
91 const std::string & widgetPkgName,
93 WidgetUninstallationStruct &uninstallerStruct)
97 _E("Job is in progress. It is impossible to add new job");
101 _D("New Widget Uninstallation");
104 new Jobs::WidgetUninstall::JobWidgetUninstall(widgetPkgName,
107 return AddAndStartJob();
110 Jobs::JobHandle InstallerLogic::InstallPlugin(
111 std::string const & pluginPath, // TODO change type to PluginPath
112 const PluginInstallerStruct &
117 _E("Job is in progress. It is impossible to add new job");
121 _D("New Plugin Installation");
123 // TODO Conversion to PluginPath is temporary
125 new Jobs::PluginInstall::JobPluginInstall(PluginPath(pluginPath), installerStruct);
127 // before start install plugin, reset plugin data which is stopped
128 // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS)
129 ResetProgressPlugins();
131 return AddAndStartJob();
134 #define TRANSLATE_JOB_EXCEPTION() \
135 _rethrown_exception.getParam()
136 #define TRANSLATE_JOB_MESSAGE() \
137 _rethrown_exception.GetMessage()
139 bool InstallerLogic::NextStep(Jobs::Job *job)
142 bool stepSucceded = job->NextStep();
147 return !job->IsPaused();
150 if (!job->GetAbortStarted()) {
151 //job successfully finished
153 //send finished callback
154 job->SendFinishedSuccess();
156 switch (job->GetInstallationType()) {
157 case Jobs::PluginInstallation:
158 InstallWaitingPlugins();
160 default: //because of warning
164 //job abort process completed
165 job->SendFinishedFailure();
173 } catch (Jobs::JobExceptionBase &exc) {
175 _D("Exception occured: %d. Reverting job...", exc.getParam());
176 bool hasAbortSteps = job->Abort();
177 job->SetAbortStarted(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 _E("Library implementing: %s NOT FOUND", (*requiredObject).c_str());
242 //PluginDAO::SetPluginInstallationStatus(INSTALLATION_WAITING);
245 dependencies->insert(depHandle);
248 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
249 PluginDAO::setPluginInstallationStatus(handle,
250 PluginDAO::INSTALLATION_COMPLETED);