From: Tomasz Iwanek Date: Thu, 3 Oct 2013 15:54:36 +0000 (+0200) Subject: Clean up pkgmgr_installer API usage X-Git-Tag: 2.2.1_release~8^2~2 X-Git-Url: http://review.tizen.org/git/?p=framework%2Fweb%2Fwrt-installer.git;a=commitdiff_plain;h=8d794299b9d43f783957a24d9ec8f1d5a23267fd Clean up pkgmgr_installer API usage [Issue#] LINUXWRT-894 [Problem] Pkgmgr refactoring [Cause] N/A [Solution] Refactoring - minor fixes: - hiding sending signals -> adding extra methods - hiding pkgmgr_installer types in pkgmgr_signal.h header [Verification] Build repository. Review that logic is the same. Change-Id: Iac7a229628af072974500724f38fc7efd95eb6e1 --- diff --git a/src/jobs/job.h b/src/jobs/job.h index 982b961..3963fc6 100644 --- a/src/jobs/job.h +++ b/src/jobs/job.h @@ -18,17 +18,10 @@ #include +#include + namespace Jobs { class JobExceptionBase; -/** - * @brief Defines installation and uninstallation type. - */ -enum InstallationType -{ - Installation, ///< defines install process - Uninstallation, ///< defines uninstall process - PluginInstallation ///< defines plugin installation process -}; typedef int JobHandle; diff --git a/src/jobs/job_types.h b/src/jobs/job_types.h new file mode 100644 index 0000000..5f845bf --- /dev/null +++ b/src/jobs/job_types.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file job_types.h + * @author Tomasz Iwanek () + */ +#ifndef JOB_TYPES_H +#define JOB_TYPES_H + +namespace Jobs { +/** + * @brief Defines installation and uninstallation type. + */ +enum InstallationType +{ + UnknownInstallation, ///< defines installation of yet unknown type + NewInstallation, ///< defines install process + UpdateInstallation, ///< defines update installation + Uninstallation, ///< defines uninstall process + PluginInstallation ///< defines plugin installation process +}; + +} + +#endif // JOB_TYPES_H diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index 7241597..bd43f8d 100644 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -72,7 +72,7 @@ JobWidgetInstall::JobWidgetInstall( std::string const &widgetPath, const Jobs::WidgetInstall::WidgetInstallationStruct & installerStruct) : - Job(Installation), + Job(UnknownInstallation), JobContextBase(installerStruct), m_exceptionCaught(Jobs::Exceptions::Success) { @@ -177,11 +177,7 @@ void JobWidgetInstall::SendProgress() if (GetProgressFlag() != false) { if (GetInstallerStruct().progressCallback != NULL) { // send progress signal of pkgmgr - std::ostringstream percent; - percent << static_cast(GetProgressPercent()); - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_PROGRESS_KEY, - percent.str()); + GetInstallerStruct().pkgmgrInterface->sendProgress(GetProgressPercent()); _D("Call widget install progressCallback"); GetInstallerStruct().progressCallback( @@ -198,9 +194,7 @@ void JobWidgetInstall::SendProgressIconPath(const std::string &path) if (GetProgressFlag() != false) { if (GetInstallerStruct().progressCallback != NULL) { // send progress signal of pkgmgr - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_ICON_PATH, - path); + GetInstallerStruct().pkgmgrInterface->sendIconPath(path); } } } @@ -229,9 +223,7 @@ void JobWidgetInstall::SendFinishedSuccess() TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid; // send signal of pkgmgr - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_END_KEY, - PKGMGR_END_SUCCESS); + GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught); _D("Call widget install successfinishedCallback"); GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam, @@ -250,17 +242,9 @@ void JobWidgetInstall::SendFinishedFailure() TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid; _D("Call widget install failure finishedCallback"); - std::stringstream errorNum; - errorNum << m_exceptionCaught; // send signal of pkgmgr - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_ERROR, - errorNum.str()); - - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_END_KEY, - PKGMGR_END_FAILURE); + GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught); GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam, DPL::ToUTF8String( diff --git a/src/jobs/widget_install/task_configuration.cpp b/src/jobs/widget_install/task_configuration.cpp index 7c9efef..978a9af 100644 --- a/src/jobs/widget_install/task_configuration.cpp +++ b/src/jobs/widget_install/task_configuration.cpp @@ -131,9 +131,7 @@ void TaskConfiguration::EndStep() void TaskConfiguration::PkgmgrStartStep() { - pkgMgrInterface()->sendSignal( - PKGMGR_PROGRESS_KEY, - PKGMGR_START_VALUE); + pkgMgrInterface()->sendProgress(0); } void TaskConfiguration::AppendTasklistStep() @@ -383,10 +381,10 @@ void TaskConfiguration::DetectUpdateInstallationStep() m_context.isUpdateMode = true; //if update, notify pkgmgr that this is update - pkgMgrInterface()->sendSignal( PKGMGR_START_KEY, PKGMGR_START_UPDATE); + pkgMgrInterface()->startJob(InstallationType::UpdateInstallation); } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) { - pkgMgrInterface()->sendSignal(PKGMGR_START_KEY, PKGMGR_START_INSTALL); + pkgMgrInterface()->startJob(InstallationType::NewInstallation); m_context.isUpdateMode = false; diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp index 31d5b53..6be8dcc 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp +++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp @@ -109,9 +109,7 @@ JobWidgetUninstall::JobWidgetUninstall( // send start signal of pkgmgr if (GetInstallerStruct().pkgmgrInterface->setPkgname(m_context.tzPkgid)) { - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_START_KEY, - PKGMGR_START_UNINSTALL); + GetInstallerStruct().pkgmgrInterface->startJob(InstallationType::Uninstallation); } AddTask(new TaskCheck(m_context)); @@ -221,9 +219,7 @@ void JobWidgetUninstall::SendFinishedSuccess() { using namespace PackageManager; // send signal of pkgmgr - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_END_KEY, - PKGMGR_END_SUCCESS); + GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught); _D("Call widget uninstall success finishedCallback"); GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam, @@ -238,9 +234,7 @@ void JobWidgetUninstall::SendFinishedFailure() _E("Message: %s", m_exceptionMessage.c_str()); // send signal of pkgmgr - GetInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_END_KEY, - PKGMGR_END_FAILURE); + GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught); _D("Call widget uninstall failure finishedCallback"); GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam, diff --git a/src/pkg-manager/pkgmgr_signal.cpp b/src/pkg-manager/pkgmgr_signal.cpp index fb933e3..140e224 100644 --- a/src/pkg-manager/pkgmgr_signal.cpp +++ b/src/pkg-manager/pkgmgr_signal.cpp @@ -19,15 +19,53 @@ * @brief */ +#include + #include #include #include +namespace { +// package type sent in every signal +const char PKGMGR_WEBAPP_TYPE[] = "wgt"; + +// notification about opoeration start +const char PKGMGR_START_KEY[] = "start"; + +// value for new installation +const char PKGMGR_START_INSTALL[] = "install"; + +// value for update installation +const char PKGMGR_START_UPDATE[] = "update"; + +// value for uninstallation +const char PKGMGR_START_UNINSTALL[] = "uninstall"; + +// notification about progress of installation with percentage number +const char PKGMGR_PROGRESS_KEY[] = "install_percent"; + +// notification about icon path for installation frontend +const char PKGMGR_ICON_PATH[] = "icon_path"; + +// notification about error before end with given error code +// (currently, same as backend exit status) +const char PKGMGR_ERROR[] = "error"; + +// notification about end of installation with status +const char PKGMGR_END_KEY[] = "end"; + +// success value of end of installation +const char PKGMGR_END_SUCCESS[] = "ok"; + +// failure value of end of installation +const char PKGMGR_END_FAILURE[] = "fail"; +} + namespace PackageManager { PkgmgrSignal::PkgmgrSignal() : m_initialized(false), m_handle(NULL), - m_reqType(PKGMGR_REQ_INVALID) + m_reqType(RequestType::UNSUPPORTED) {} PkgmgrSignal::~PkgmgrSignal() @@ -51,10 +89,24 @@ bool PkgmgrSignal::initialize(int argc, char* argv[]) if (!pkgmgr_installer_receive_request( m_handle, argc, argv)) { - m_reqType = pkgmgr_installer_get_request_type(m_handle); - if (m_reqType != PKGMGR_REQ_INSTALL && - m_reqType != PKGMGR_REQ_UNINSTALL && - m_reqType != PKGMGR_REQ_REINSTALL) + auto pkgmgrtype = pkgmgr_installer_get_request_type(m_handle); + switch(pkgmgrtype) + { + case PKGMGR_REQ_INSTALL: + m_reqType = RequestType::INSTALL; + break; + case PKGMGR_REQ_UNINSTALL: + m_reqType = RequestType::UNINSTALL; + break; + case PKGMGR_REQ_REINSTALL: + m_reqType = RequestType::REINSTALL; + break; + default: + m_reqType = RequestType::UNSUPPORTED; + break; + } + + if (m_reqType == RequestType::UNSUPPORTED) { _E("Fail to get request type of pkgmgr"); pkgmgr_installer_free(m_handle); @@ -108,6 +160,49 @@ bool PkgmgrSignal::setPkgname(const std::string& name) return true; } +bool PkgmgrSignal::startJob(Jobs::InstallationType type) +{ + switch(type) + { + case Jobs::InstallationType::NewInstallation: + sendSignal(PKGMGR_START_KEY, PKGMGR_START_INSTALL); + break; + case Jobs::InstallationType::UpdateInstallation: + sendSignal(PKGMGR_START_KEY, PKGMGR_START_UPDATE); + break; + case Jobs::InstallationType::Uninstallation: + sendSignal(PKGMGR_START_KEY, PKGMGR_START_UNINSTALL); + break; + default: + _E("Trying to send unknown installation type to pkgmgr"); + return false; + } + return true; +} + +bool PkgmgrSignal::endJob(Jobs::Exceptions::Type ecode) +{ + if(ecode == Jobs::Exceptions::Type::Success) + { + return sendSignal(PKGMGR_END_KEY, PKGMGR_END_SUCCESS); + } + else + { + sendSignal(PKGMGR_ERROR, DPL::lexical_cast(ecode)); + return sendSignal(PKGMGR_END_KEY, PKGMGR_END_FAILURE); + } +} + +bool PkgmgrSignal::sendProgress(int percent) +{ + return sendSignal(PKGMGR_PROGRESS_KEY, DPL::lexical_cast(percent)); +} + +bool PkgmgrSignal::sendIconPath(const std::string & iconpath) +{ + return sendSignal(PKGMGR_ICON_PATH, iconpath); +} + bool PkgmgrSignal::sendSignal(const std::string& key, const std::string& value) const { @@ -148,7 +243,7 @@ std::string PkgmgrSignal::getPkgname() const return m_pkgname; } -int PkgmgrSignal::getRequestedType() const +PkgmgrSignal::RequestType PkgmgrSignal::getRequestedType() const { if (!m_initialized) { _E("PkgmgrSingal not yet intialized"); diff --git a/src/pkg-manager/pkgmgr_signal.h b/src/pkg-manager/pkgmgr_signal.h index e44ae82..abd756b 100644 --- a/src/pkg-manager/pkgmgr_signal.h +++ b/src/pkg-manager/pkgmgr_signal.h @@ -24,44 +24,46 @@ #define WRT_PKGMGR_SIGNAL_H_ #include -#include -namespace PackageManager { -#define PKGMGR_WEBAPP_TYPE "wgt" -#define PKGMGR_START_KEY "start" -#define PKGMGR_START_INSTALL "install" -#define PKGMGR_START_UPDATE "update" -#define PKGMGR_START_UNINSTALL "uninstall" -#define PKGMGR_END_KEY "end" -#define PKGMGR_END_SUCCESS "ok" -#define PKGMGR_END_FAILURE "fail" -#define PKGMGR_PROGRESS_KEY "install_percent" -#define PKGMGR_ICON_PATH "icon_path" -#define PKGMGR_ERROR "error" -#define PKGMGR_START_VALUE "0" +struct pkgmgr_installer; -typedef pkgmgr_installer* PkgmgrHandle; +namespace PackageManager { class PkgmgrSignal : public IPkgmgrSignal { - public: +public: + enum class RequestType + { + UNSUPPORTED, + INSTALL, + UNINSTALL, + REINSTALL + }; + bool initialize(int argc, char* argv[]); bool deinitialize(); bool setPkgname(const std::string& name); - bool sendSignal(const std::string& key, const std::string& value) const; std::string getPkgname() const; - int getRequestedType() const; + RequestType getRequestedType() const; std::string getCallerId() const; + bool startJob(Jobs::InstallationType type); + bool endJob(Jobs::Exceptions::Type ecode); + bool sendProgress(int percent); + bool sendIconPath(const std::string & iconpath); + PkgmgrSignal(); virtual ~PkgmgrSignal(); - private: +protected: + bool sendSignal(const std::string& key, const std::string& value) const; + +private: bool m_initialized; - PkgmgrHandle m_handle; + pkgmgr_installer* m_handle; std::string m_type; std::string m_pkgname; - int m_reqType; + RequestType m_reqType; std::string m_callerId; }; } // PackageManager diff --git a/src/pkg-manager/pkgmgr_signal_dummy.h b/src/pkg-manager/pkgmgr_signal_dummy.h index 26668d1..52ce346 100644 --- a/src/pkg-manager/pkgmgr_signal_dummy.h +++ b/src/pkg-manager/pkgmgr_signal_dummy.h @@ -24,6 +24,8 @@ #include +#include + namespace PackageManager { class PkgmgrSignalDummy : public IPkgmgrSignal { @@ -33,12 +35,8 @@ class PkgmgrSignalDummy : public IPkgmgrSignal virtual ~PkgmgrSignalDummy() {} - bool setPkgname(const std::string& /*name*/) - { - return false; - } - bool sendSignal(const std::string& /*key*/, const std::string& /*value*/) const + bool setPkgname(const std::string& /*name*/) { return false; } @@ -52,6 +50,26 @@ class PkgmgrSignalDummy : public IPkgmgrSignal { return ""; } + + bool startJob(Jobs::InstallationType type DPL_UNUSED) + { + return false; + } + + bool endJob(Jobs::Exceptions::Type ecode DPL_UNUSED) + { + return false; + } + + bool sendProgress(int percent DPL_UNUSED) + { + return false; + } + + bool sendIconPath(const std::string & iconpath DPL_UNUSED) + { + return false; + } }; } // PkgmgrSignalDummy diff --git a/src/pkg-manager/pkgmgr_signal_interface.h b/src/pkg-manager/pkgmgr_signal_interface.h index b94917d..1e38a17 100644 --- a/src/pkg-manager/pkgmgr_signal_interface.h +++ b/src/pkg-manager/pkgmgr_signal_interface.h @@ -23,15 +23,22 @@ #define WRT_PKGMGR_SIGNAL_INTERFACE_H_ #include + +#include +#include + namespace PackageManager { class IPkgmgrSignal { public: virtual bool setPkgname(const std::string& name) = 0; - virtual bool sendSignal(const std::string& key, - const std::string& value) const = 0; virtual std::string getPkgname() const = 0; virtual std::string getCallerId() const = 0; + + virtual bool startJob(Jobs::InstallationType type) = 0; + virtual bool endJob(Jobs::Exceptions::Type ecode) = 0; + virtual bool sendProgress(int percent) = 0; + virtual bool sendIconPath(const std::string & iconpath) = 0; virtual ~IPkgmgrSignal(){} }; } // IPkgmgrSignal diff --git a/src/wrt-installer/wrt-installer.cpp b/src/wrt-installer/wrt-installer.cpp index c7fb784..8c41ef1 100644 --- a/src/wrt-installer/wrt-installer.cpp +++ b/src/wrt-installer/wrt-installer.cpp @@ -271,13 +271,13 @@ void WrtInstaller::OnCreate() pkgmgrSignal->initialize(m_argc, m_argv); - int reqType = pkgmgrSignal->getRequestedType(); + PackageManager::PkgmgrSignal::RequestType reqType = pkgmgrSignal->getRequestedType(); pkgmgrSignalInterface = std::static_pointer_cast( pkgmgrSignal); switch (reqType) { - case PKGMGR_REQ_INSTALL: + case PackageManager::PkgmgrSignal::RequestType::INSTALL: m_packagePath = m_argv[4]; struct stat info; if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) { @@ -289,7 +289,7 @@ void WrtInstaller::OnCreate() } AddStep(&WrtInstaller::installStep); break; - case PKGMGR_REQ_UNINSTALL: + case PackageManager::PkgmgrSignal::RequestType::UNINSTALL: { m_name = m_argv[4]; pkgmgrinfo_pkginfo_h handle = NULL; @@ -315,7 +315,7 @@ void WrtInstaller::OnCreate() } break; } - case PKGMGR_REQ_REINSTALL: + case PackageManager::PkgmgrSignal::RequestType::REINSTALL: m_packagePath = m_argv[4]; m_installMode.command = InstallMode::Command::REINSTALL; m_installMode.extension = InstallMode::ExtensionType::DIR; @@ -719,7 +719,6 @@ void WrtInstaller::staticWrtInitPreloadStatusCallback(std::string tizenId, WrtInstaller *This = static_cast(userdata); Assert(This); - DPL::String resultMsg; std::string printMsg = "initialization"; if (WRT_SUCCESS != status) { @@ -738,7 +737,6 @@ void WrtInstaller::staticWrtInitPreloadStatusCallback(std::string tizenId, printMsg.c_str()); _D("Status succesfull"); This->m_returnStatus = 0; - resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS); This->DPL::Event::ControllerEventHandler @@ -754,16 +752,13 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId, Assert(This); Step current = This->GetCurrentStep(); - DPL::String resultMsg; std::string printMsg; if (current == &WrtInstaller::installStep) { - resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG); printMsg = "installation"; } else if (current == &WrtInstaller::uninstallPkgNameStep || current == &WrtInstaller::unistallWgtFileStep) { - resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG); printMsg = "uninstallation"; } @@ -783,7 +778,6 @@ void WrtInstaller::staticWrtStatusCallback(std::string tizenId, printMsg.c_str()); _D("Status succesfull"); This->m_returnStatus = 0; - resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS); if (This->m_installMode.installTime == InstallMode::InstallTime::PRELOAD && !This->m_packagePath.empty())