[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_install_ospsvc.cpp
index 0a26435..0a3e2f6 100644 (file)
 #include <unistd.h>
 #include <string>
 
+#include <pkgmgr/pkgmgr_parser.h>
+#include <pkgmgr-info.h>
+#include <fstream>
 #include <dpl/log/log.h>
 #include <dpl/errno_string.h>
 #include <dpl/foreach.h>
 #include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/utils/bash_utils.h>
 
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_context.h>
@@ -37,7 +41,7 @@ using namespace WrtDB;
 
 namespace {
 const int MAX_BUF_SIZE = 128;
-const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/oap -iv ";
+const char* OSP_INSTALL_STR = "/usr/etc/package-manager/backend/tpk -iv ";
 }
 
 namespace Jobs {
@@ -46,16 +50,18 @@ TaskInstallOspsvc::TaskInstallOspsvc(InstallerContext& context) :
     DPL::TaskDecl<TaskInstallOspsvc>(this),
     m_context(context)
 {
+    AddStep(&TaskInstallOspsvc::StartStep);
     AddStep(&TaskInstallOspsvc::StepInstallOspService);
+    AddStep(&TaskInstallOspsvc::EndStep);
 }
 
 void TaskInstallOspsvc::StepInstallOspService()
 {
-    LogInfo("Step: installation for osp service");
+    LogDebug("Step: installation for osp service");
 
     std::ostringstream commStr;
-    commStr << OSP_INSTALL_STR << GlobalConfig::GetUserInstalledWidgetPath();
-    commStr << "/" << m_context.widgetConfig.pkgname;
+    commStr << OSP_INSTALL_STR << BashUtils::escape_arg(
+        m_context.locations->getPackageInstallationDir());
     //commStr << " 2>&1";
     LogDebug("osp install command : " << commStr.str());
 
@@ -64,23 +70,43 @@ void TaskInstallOspsvc::StepInstallOspService()
     fd = popen(commStr.str().c_str(), "r");
     if (NULL == fd) {
         LogError("Failed to installtion osp service");
-        ThrowMsg(Exceptions::InstallOspsvcFailed, "Error occurs during\
+        ThrowMsg(Exceptions::InstallOspsvcFailed,
+                 "Error occurs during\
+                install osp service");
+    }
+
+    if (fgets(readBuf, MAX_BUF_SIZE, fd) == NULL)
+    {
+        LogError("Failed to installtion osp service.\
+                Inability of reading file.");
+        ThrowMsg(Exceptions::InstallOspsvcFailed,
+                "Error occurs during\
                 install osp service");
     }
-    fgets(readBuf, MAX_BUF_SIZE, fd);
     LogDebug("return value : " << readBuf);
 
     int result = atoi(readBuf);
     if (0 != result) {
-        ThrowMsg(Exceptions::InstallOspsvcFailed, "Error occurs during\
+        ThrowMsg(Exceptions::InstallOspsvcFailed,
+                 "Error occurs during\
                 install osp service");
     }
 
     pclose(fd);
+}
 
+void TaskInstallOspsvc::StartStep()
+{
+    LogDebug("--------- <TaskInstallOspsvc> : START ----------");
+}
+
+void TaskInstallOspsvc::EndStep()
+{
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_INSTALL_OSPSVC,
         "Installed Osp servcie");
+
+    LogDebug("--------- <TaskInstallOspsvc> : END ----------");
 }
 } //namespace WidgetInstall
 } //namespace Jobs