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.
17 * @file task_db_update.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
20 * @brief Implementation file for installer task database updating
23 #include <widget_install/task_db_update.h>
24 #include <widget_install/job_widget_install.h>
25 #include <widget_install/widget_install_errors.h>
26 #include <widget_install/widget_install_context.h>
27 #include <dpl/wrt-dao-ro/config_parser_data.h>
28 #include <dpl/utils/wrt_utility.h>
29 #include <dpl/wrt-dao-rw/widget_dao.h>
30 #include <dpl/foreach.h>
31 #include <dpl/log/log.h>
32 #include <dpl/assert.h>
33 #include <dpl/wrt-dao-ro/global_config.h>
35 #include <Ecore_File.h>
38 using namespace WrtDB;
41 namespace WidgetInstall {
42 TaskDbUpdate::TaskDbUpdate(InstallerContext& context) :
43 DPL::TaskDecl<TaskDbUpdate>(this),
46 AddStep(&TaskDbUpdate::StepDbUpdate);
48 AddAbortStep(&TaskDbUpdate::StepAbortDBUpdate);
51 void TaskDbUpdate::StepDbUpdate()
55 // If there is existing model, remove its database data
56 if (true == m_context.existingWidgetInfo.isExist) {
57 WidgetHandle old = m_context.existingWidgetInfo.existingHandle;
58 LogInfo("Unregistering widget...: " << old);
59 WidgetDAO::unregisterWidget(old);
60 LogInfo("Widget unregistered");
63 /* Set install Time */
64 time(&m_context.widgetConfig.installedTime);
66 LogInfo("Registering widget...");
68 WidgetDAO::registerWidget(
69 *(m_context.widgetHandle),
70 m_context.widgetConfig,
71 m_context.wacSecurity);
73 FOREACH (cap, m_context.staticPermittedDevCaps) {
74 LogInfo("staticPermittedDevCaps : " << cap->first
75 << " smack status: " << cap->second);
78 Assert(!!m_context.widgetConfig.pkgname
79 && "pkgName should be initialized");
81 WrtDB::WidgetDAO widgetDao(*m_context.widgetHandle);
82 widgetDao.setPkgName(m_context.widgetConfig.pkgname);
84 LogInfo("Widget registered");
86 Catch(WidgetDAO::Exception::DatabaseError)
88 LogWarning("Database failure!");
89 ReThrowMsg(Exceptions::DatabaseFailure, "Database failure!");
91 Catch(DPL::DB::SqlConnection::Exception::Base)
93 LogDebug("Database failure!");
94 ReThrowMsg(Exceptions::DatabaseFailure, "Database failure!");
97 m_context.job->UpdateProgress(
98 InstallerContext::INSTALL_DB_UPDATE,
99 "Widget DB UPDATE Finished");
102 void TaskDbUpdate::StepAbortDBUpdate()
104 LogWarning("[DB Update Task] Aborting... (DB Clean)");
105 Assert(!!m_context.widgetHandle);
108 WidgetDAO::unregisterWidget(*m_context.widgetHandle);
110 LogDebug("Cleaning DB successful!");
112 Catch(DPL::DB::SqlConnection::Exception::Base)
114 //TODO What should happen here?
115 LogError("Failed to handle StepAbortDBClean!");
116 // ReThrowMsg(Exceptions::DbStepFailed, "Failed to handle StepAbortDBClean!");
120 } //namespace WidgetInstall