tizen beta release
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / job_widget_uninstall.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 #include <widget_uninstall/job_widget_uninstall.h>
17 #include <widget_uninstall/task_check.h>
18 #include <widget_uninstall/task_db_update.h>
19 #include <widget_uninstall/task_remove_files.h>
20 #include <widget_uninstall/task_smack.h>
21
22 using namespace WrtDB;
23
24 namespace Jobs {
25 namespace WidgetUninstall {
26 JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
27         const WidgetUninstallationStruct &uninstallerStruct) :
28     Job(Uninstallation),
29     JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
30 {
31     WidgetDAO dao(widgetHandle);
32
33     m_context.widgetHandle = widgetHandle;
34     m_context.removeStarted = false;
35     m_context.removeFinished = false;
36     m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
37     m_context.job = this;
38
39     AddTask(new TaskSmack(m_context));
40     AddTask(new TaskCheck(m_context));
41     AddTask(new TaskRemoveFiles(m_context));
42     AddTask(new TaskDbUpdate(m_context));
43 }
44
45 WidgetHandle JobWidgetUninstall::getRemovedWidgetHandle() const
46 {
47     return m_context.widgetHandle;
48 }
49
50 bool JobWidgetUninstall::getRemoveStartedFlag() const
51 {
52     return m_context.removeStarted;
53 }
54
55 bool JobWidgetUninstall::getRemoveFinishedFlag() const
56 {
57     return m_context.removeFinished;
58 }
59
60 void JobWidgetUninstall::SendProgress()
61 {
62     if (!getRemoveStartedFlag() ||
63         (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
64         if (NULL != getInstallerStruct().progressCallback) {
65             LogDebug("Call widget uninstall progressCallback");
66             getInstallerStruct().progressCallback(
67                     getInstallerStruct().userParam,
68                     GetProgressPercent(), GetProgressDescription());
69         }
70     }
71 }
72
73 void JobWidgetUninstall::SendFinishedSuccess()
74 {
75     LogDebug("Call widget uninstall success finishedCallback");
76     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
77             getRemovedWidgetHandle(),Exceptions::Success);
78 }
79
80 void JobWidgetUninstall::SendFinishedFailure()
81 {
82     LogError("Error in uninstallation step: " << m_exceptionCaught);
83     LogError("Message: " << m_exceptionMessage);
84
85     LogDebug("Call widget uninstall failure finishedCallback");
86     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
87         getRemovedWidgetHandle(), m_exceptionCaught); //TODO
88     LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
89 }
90
91 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
92 {
93     m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
94     m_exceptionMessage = e.GetMessage();
95 }
96 } //namespace WidgetUninstall
97 } //namespace Jobs