Update wrt-installer_0.0.54
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_install_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_install_ospsvc.cpp
18  * @author  Soyoung Kim (sy037.kim@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task  install osp service
21  */
22 #include "task_install_ospsvc.h"
23
24 #include <unistd.h>
25 #include <string>
26
27 #include <dpl/log/log.h>
28 #include <dpl/errno_string.h>
29 #include <dpl/foreach.h>
30 #include <dpl/wrt-dao-ro/global_config.h>
31
32 #include <widget_install/job_widget_install.h>
33 #include <widget_install/widget_install_context.h>
34 #include <widget_install/widget_install_errors.h>
35
36 using namespace WrtDB;
37
38 namespace {
39 const int MAX_BUF_SIZE = 128;
40 const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/oap -iv ";
41 }
42
43 namespace Jobs {
44 namespace WidgetInstall {
45 TaskInstallOspsvc::TaskInstallOspsvc(InstallerContext& context) :
46     DPL::TaskDecl<TaskInstallOspsvc>(this),
47     m_context(context)
48 {
49     AddStep(&TaskInstallOspsvc::StepInstallOspService);
50 }
51
52 void TaskInstallOspsvc::StepInstallOspService()
53 {
54     LogInfo("Step: installation for osp service");
55
56     std::ostringstream commStr;
57     commStr << OSP_INSTALL_STR << m_context.locations->getPackageInstallationDir();
58     //commStr << " 2>&1";
59     LogDebug("osp install command : " << commStr.str());
60
61     char readBuf[MAX_BUF_SIZE];
62     FILE *fd;
63     fd = popen(commStr.str().c_str(), "r");
64     if (NULL == fd) {
65         LogError("Failed to installtion osp service");
66         ThrowMsg(Exceptions::InstallOspsvcFailed, "Error occurs during\
67                 install osp service");
68     }
69     fgets(readBuf, MAX_BUF_SIZE, fd);
70     LogDebug("return value : " << readBuf);
71
72     int result = atoi(readBuf);
73     if (0 != result) {
74         ThrowMsg(Exceptions::InstallOspsvcFailed, "Error occurs during\
75                 install osp service");
76     }
77
78     pclose(fd);
79
80     m_context.job->UpdateProgress(
81         InstallerContext::INSTALL_INSTALL_OSPSVC,
82         "Installed Osp servcie");
83 }
84 } //namespace WidgetInstall
85 } //namespace Jobs