[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_uninstall / task_uninstall_ospsvc.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_uninstall_ospsvc.cpp
18  * @author  Soyoung Kim(sy037.kim@samsung.com)
19  * @version 1.0
20  * @brief   Header file for widget uninstall task to uninstall ospsvc
21  */
22 #include <dpl/sstream.h>
23 #include <dpl/utils/bash_utils.h>
24 #include <widget_uninstall/task_uninstall_ospsvc.h>
25 #include <widget_uninstall/job_widget_uninstall.h>
26 #include <widget_uninstall/uninstaller_context.h>
27 #include <widget_uninstall/widget_uninstall_errors.h>
28 #include <dpl/wrt-dao-ro/global_config.h>
29 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30
31 using namespace WrtDB;
32
33 namespace {
34 const int MAX_BUF_SIZE = 128;
35 const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/tpk -uv ";
36 }
37
38 namespace Jobs {
39 namespace WidgetUninstall {
40 TaskUninstallOspsvc::TaskUninstallOspsvc(UninstallerContext& context) :
41     DPL::TaskDecl<TaskUninstallOspsvc>(this),
42     m_context(context)
43 {
44     AddStep(&TaskUninstallOspsvc::StartStep);
45     AddStep(&TaskUninstallOspsvc::StepUninstallOspsvc);
46     AddStep(&TaskUninstallOspsvc::EndStep);
47 }
48
49 TaskUninstallOspsvc::~TaskUninstallOspsvc()
50 {}
51
52 void TaskUninstallOspsvc::StepUninstallOspsvc()
53 {
54     LogDebug("Step : Uninstall Osp service ");
55
56     std::ostringstream commStr;
57     commStr << OSP_INSTALL_STR << BashUtils::escape_arg(m_context.tzPkgid);
58     LogDebug("osp uninstall command : " << commStr.str());
59
60     char readBuf[MAX_BUF_SIZE];
61     FILE *fd;
62     fd = popen(commStr.str().c_str(), "r");
63     if (NULL == fd) {
64         LogError("Failed to uninstalltion osp service");
65         ThrowMsg(Exceptions::UninstallOspSvcFailed,
66                  "Error occurs during\
67                 uninstall osp service");
68     }
69
70     if(fgets(readBuf, MAX_BUF_SIZE, fd) == NULL)
71     {
72         LogError("Failed to uninstalltion osp service\
73                         Inability of reading file.");
74         ThrowMsg(Exceptions::UninstallOspSvcFailed,
75                 "Error occurs during\
76                 uninstall osp service");
77     }
78     LogDebug("return value : " << readBuf);
79
80     int result = atoi(readBuf);
81     if (0 != result) {
82         ThrowMsg(Exceptions::UninstallOspSvcFailed,
83                  "Error occurs during\
84                 install osp service");
85     }
86
87     pclose(fd);
88
89     LogDebug("Widget Can be uninstalled. Pkgname : " << m_context.tzPkgid);
90     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_REMOVE_OSPSVC,
91                                   "Uninstall OSP service finished");
92 }
93
94 void TaskUninstallOspsvc::StartStep()
95 {
96     LogDebug("--------- <TaskUninstallOspsvc> : START ----------");
97 }
98
99 void TaskUninstallOspsvc::EndStep()
100 {
101     LogDebug("--------- <TaskUninstallOspsvc> : END ----------");
102 }
103 } //namespace WidgetUninstall
104 } //namespace Jobs