1a1f62b723ed8d1a9adc2a2f0e40e0ebdb4b4f92
[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 <widget_uninstall/widget_uninstall_errors.h>
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
29 #include <app_manager.h>
30
31 namespace Jobs {
32 namespace WidgetUninstall {
33 TaskCheck::TaskCheck(UninstallerContext& context) :
34     DPL::TaskDecl<TaskCheck>(this),
35     m_context(context)
36 {
37     AddStep(&TaskCheck::StepUninstallPreCheck);
38 }
39
40 TaskCheck::~TaskCheck()
41 {}
42
43 void TaskCheck::StepUninstallPreCheck()
44 {
45     LogInfo("Uninstall check for appid: " << m_context.tzAppid);
46     //check if deferred
47     //TODO if widget to be updated, then remove it from Deferred list?
48
49     bool isRunning = false;
50     int ret = app_manager_is_running(m_context.tzAppid.c_str(), &isRunning);
51     if (APP_MANAGER_ERROR_NONE != ret) {
52         LogError("Fail to get running state");
53         ThrowMsg(Exceptions::PlatformAPIFailure,
54                  "Fail to get widget state");
55     }
56
57     if (true == isRunning) {
58         LogError("Widget is not stopped. Cannot uninstall!");
59         //TODO different error
60         ThrowMsg(Exceptions::AlreadyUninstalling,
61                  "Widget is not stopped. Cannot uninstall!");
62         //TODO or defer uninstall?
63     }
64
65     LogInfo("Widget Can be uninstalled. Pkgname : " << m_context.tzAppid);
66     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_PRECHECK,
67                                   "Uninstall pre-checking Finished");
68 }
69 } //namespace WidgetUninstall
70 } //namespace Jobs