Update wrt-installer_0.0.51
[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 <widget_uninstall/task_uninstall_ospsvc.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
30 using namespace WrtDB;
31
32 namespace {
33 const int MAX_BUF_SIZE = 128;
34 const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/oap -uv ";
35 }
36
37 namespace Jobs {
38 namespace WidgetUninstall {
39 TaskUninstallOspsvc::TaskUninstallOspsvc(UninstallerContext& context) :
40     DPL::TaskDecl<TaskUninstallOspsvc>(this),
41     m_context(context)
42 {
43     AddStep(&TaskUninstallOspsvc::StepUninstallOspsvc);
44 }
45
46 TaskUninstallOspsvc::~TaskUninstallOspsvc()
47 {
48 }
49
50 void TaskUninstallOspsvc::StepUninstallOspsvc()
51 {
52     LogInfo("Step : Uninstall Osp service ");
53
54     std::ostringstream commStr;
55     commStr << OSP_INSTALL_STR << m_context.pkgname;;
56     LogDebug("@@osp uninstall command : " << commStr.str());
57
58     char readBuf[MAX_BUF_SIZE];
59     FILE *fd;
60     fd = popen(commStr.str().c_str(), "r");
61     if (NULL == fd) {
62         LogError("Failed to uninstalltion osp service");
63         ThrowMsg(Exceptions::UninstallOspSvcFailed, "Error occurs during\
64                 uninstall osp service");
65     }
66     fgets( readBuf, MAX_BUF_SIZE, fd);
67     LogDebug("return value : " << readBuf);
68
69     int result = atoi(readBuf);
70     if (0 != result) {
71         ThrowMsg(Exceptions::UninstallOspSvcFailed, "Error occurs during\
72                 install osp service");
73     }
74
75     pclose(fd);
76     
77     LogInfo("Widget Can be uninstalled. Handle : " << m_context.widgetHandle);
78     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_REMOVE_OSPSVC,
79                                   "Uninstall OSP service finished");
80 }
81
82 } //namespace WidgetUninstall
83 } //namespace Jobs