tizen 2.4 release
[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 #include <dpl/log/secure_log.h>
31
32 #if USE(CORE_HYBRID_PKG)
33 #include <dpl/utils/wrt_utility.h>
34 #endif
35
36 using namespace WrtDB;
37
38 namespace {
39 const int MAX_BUF_SIZE = 128;
40
41 #if USE(CORE_HYBRID_PKG)
42 const char* CORE_UNINSTALL_STR = "/usr/etc/package-manager/backend/rpm -uv ";
43 const char* const CORE_MANIFEST_XML = "tizen-manifest.xml";
44 #else
45 const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/tpk -uv ";
46 #endif
47 }
48
49 namespace Jobs {
50 namespace WidgetUninstall {
51 TaskUninstallOspsvc::TaskUninstallOspsvc(UninstallerContext& context) :
52     DPL::TaskDecl<TaskUninstallOspsvc>(this),
53     m_context(context)
54 {
55     AddStep(&TaskUninstallOspsvc::StartStep);
56     AddStep(&TaskUninstallOspsvc::StepUninstallOspsvc);
57     AddStep(&TaskUninstallOspsvc::EndStep);
58 }
59
60 TaskUninstallOspsvc::~TaskUninstallOspsvc()
61 {}
62
63 void TaskUninstallOspsvc::StepUninstallOspsvc()
64 {
65     _D("Step : Uninstall Osp service");
66
67     std::ostringstream commStr;
68 #if USE(CORE_HYBRID_PKG)
69     WidgetDAOReadOnly dao(WidgetDAOReadOnly::getTizenAppId(DPL::FromUTF8String(m_context.tzPkgid)));
70     std::string pkgPath = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
71     if (bf::exists(bf::path(pkgPath + "/" + CORE_MANIFEST_XML)))
72         commStr << CORE_UNINSTALL_STR << BashUtils::escape_arg(m_context.tzPkgid);
73 #else
74         commStr << OSP_INSTALL_STR << BashUtils::escape_arg(m_context.tzPkgid);
75 #endif
76     _D("Hybrid uninstall command : %s", commStr.str().c_str());
77
78     char readBuf[MAX_BUF_SIZE];
79     FILE *fd;
80     fd = popen(commStr.str().c_str(), "r");
81     if (NULL == fd) {
82         _E("Failed to uninstalltion osp service");
83         ThrowMsg(Exceptions::UninstallOspSvcFailed,
84                  "Error occurs during\
85                 uninstall osp service");
86     }
87
88     if(fgets(readBuf, MAX_BUF_SIZE, fd) == NULL)
89     {
90         _E("Failed to uninstalltion osp service\
91                         Inability of reading file.");
92         ThrowMsg(Exceptions::UninstallOspSvcFailed,
93                 "Error occurs during\
94                 uninstall osp service");
95     }
96     _D("return value : %s", readBuf);
97
98     int result = atoi(readBuf);
99     if (0 != result) {
100         ThrowMsg(Exceptions::UninstallOspSvcFailed,
101                  "Error occurs during\
102                 install osp service");
103     }
104
105     pclose(fd);
106
107     _D("Widget Can be uninstalled. Pkgname : %s", m_context.tzPkgid.c_str());
108     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_REMOVE_OSPSVC,
109                                   "Uninstall OSP service finished");
110 }
111
112 void TaskUninstallOspsvc::StartStep()
113 {
114     LOGI("--------- <TaskUninstallOspsvc> : START ----------");
115 }
116
117 void TaskUninstallOspsvc::EndStep()
118 {
119     LOGI("--------- <TaskUninstallOspsvc> : END ----------");
120 }
121 } //namespace WidgetUninstall
122 } //namespace Jobs