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_new_db_insert.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
19 * @author Soyoung kim(sy037.kim@samsung.com)
21 * @brief Implementation file for installer task database updating for widget update
25 #include <widget_install/task_new_db_insert.h>
26 #include <widget_install/job_widget_install.h>
27 #include <widget_install/widget_install_errors.h>
28 #include <widget_install/widget_install_context.h>
29 //#include <dpl/wrt-dao-ro/config_parser_data.h>
30 #include <dpl/wrt-dao-rw/widget_dao.h>
31 #include <dpl/foreach.h>
32 #include <dpl/log/log.h>
33 #include <dpl/assert.h>
34 //#include <dpl/wrt-dao-ro/global_config.h>
38 using namespace WrtDB;
41 namespace WidgetInstall {
42 TaskNewDbInsert::TaskNewDbInsert(InstallerContext& context) :
43 DPL::TaskDecl<TaskNewDbInsert>(this),
46 AddStep(&TaskNewDbInsert::StepDBInsert);
48 AddAbortStep(&TaskNewDbInsert::StepAbortDBInsert);
51 void TaskNewDbInsert::StepDBInsert()
55 /* Set install Time */
56 time(&m_context.widgetConfig.installedTime);
58 LogInfo("Registering widget...");
60 WidgetDAO::registerWidget(
61 *(m_context.widgetHandle),
62 m_context.widgetConfig,
63 m_context.wacSecurity);
65 FOREACH (cap, m_context.staticPermittedDevCaps) {
66 LogInfo("staticPermittedDevCaps : " << cap->first
67 << " smack status: " << cap->second);
70 Assert(!!m_context.widgetConfig.pkgname
71 && "pkgName should be initialized");
73 WrtDB::WidgetDAO widgetDao(*m_context.widgetHandle);
74 widgetDao.setPkgName(m_context.widgetConfig.pkgname);
76 LogInfo("Widget registered");
78 Catch(WidgetDAO::Exception::DatabaseError)
80 LogWarning("Database failure!");
81 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
83 Catch(DPL::DB::SqlConnection::Exception::Base)
85 LogDebug("Database failure!");
86 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
89 m_context.job->UpdateProgress(
90 InstallerContext::INSTALL_NEW_DB_INSERT,
91 "New Widget DB UPDATE Finished");
94 void TaskNewDbInsert::StepAbortDBInsert()
96 LogWarning("[DB Update Task] Aborting... (DB Clean)");
97 Assert(!!m_context.widgetHandle);
100 WidgetDAO::unregisterWidget(*m_context.widgetHandle);
102 LogDebug("Cleaning DB successful!");
104 Catch(DPL::DB::SqlConnection::Exception::Base)
106 LogError("Failed to handle StepAbortDBClean!");
110 } //namespace WidgetInstall