tizen beta release
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / task_check.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_check.cpp
18  * @author  Pawel Sikorski(p.sikorski@samsung.com)
19  * @version 1.0
20  * @brief   Header file for widget uninstall task check
21  */
22 #include <dpl/sstream.h>
23 #include <widget_uninstall/task_check.h>
24 #include <widget_uninstall/job_widget_uninstall.h>
25 #include <widget_uninstall/uninstaller_context.h>
26 #include <dpl/wrt-dao-ro/global_config.h>
27 #include <aul.h>
28
29 namespace Jobs {
30 namespace WidgetUninstall {
31 TaskCheck::TaskCheck(UninstallerContext& context) :
32     DPL::TaskDecl<TaskCheck>(this),
33     m_context(context)
34 {
35     AddStep(&TaskCheck::StepUninstallPreCheck);
36 }
37
38 TaskCheck::~TaskCheck()
39 {
40 }
41
42 void TaskCheck::StepUninstallPreCheck()
43 {
44     LogInfo("Uninstall check for widget Handle: " << m_context.widgetHandle);
45     //check if deferred
46     //TODO if widget to be updated, then remove it from Deferred list?
47
48     DPL::OptionalString pkgName =
49             WrtDB::WidgetDAO(m_context.widgetHandle).getPkgname();
50
51     LogInfo("Widget model exists. Pkg name: " << pkgName);
52     if (aul_app_is_running(DPL::ToUTF8String(*pkgName).c_str())) {
53         LogError("Widget is not stopped. Cannot uninstall!");
54         //TODO different error
55         ThrowMsg(Exceptions::AlreadyUninstalling,
56                  "Widget is not stopped. Cannot uninstall!");
57         //TODO or defer uninstall?
58     }
59
60     LogInfo("Widget Can be uninstalled. Handle : " << m_context.widgetHandle);
61     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_CHECK,
62                                   "Uninstall pre-checking Finished");
63 }
64
65 } //namespace WidgetUninstall
66 } //namespace Jobs