From: Jan Olszak Date: Fri, 14 Dec 2012 08:54:42 +0000 (+0100) Subject: Dummy PkgmgrSignal for command line installation X-Git-Tag: accepted/tizen_2.1/20130425.023916~20^2~24^2~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0afdafc787c4f556757997cfbabb33015ecba12d;p=framework%2Fweb%2Fwrt-installer.git Dummy PkgmgrSignal for command line installation [Issue] During command line installation PkgMgr should only show log and check initialization. [Bug] N/A [Cause] N/A [Solution] Dummy PkgmgrSignal for command line installation [Verification] Build installer. Run command line installation. No logs that saying 'PkgmgrSingal not yet intialized' Change-Id: Ie354b35825db9ece9c43ff1321f029d5a5d4e071 --- diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index 2006f9c..5debb82 100644 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -328,9 +328,9 @@ bool JobWidgetInstall::setTizenId( if(!!configInfo.tizenId) { LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId); // send start signal of pkgmgr - PkgmgrSignalSingleton::Instance().setPkgname( + getInstallerStruct().pkgmgrInterface->setPkgname( DPL::ToUTF8String(*(configInfo.tizenId))); - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_START_KEY, PKGMGR_START_INSTALL); @@ -371,9 +371,9 @@ bool JobWidgetInstall::setTizenId( } LogInfo("tizen_id name was generated by WRT: " << tizenId); // send start signal of pkgmgr - PkgmgrSignalSingleton::Instance().setPkgname(DPL::ToUTF8String( + getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String( *m_installerContext.widgetConfig.pkgname)); - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_START_KEY, PKGMGR_START_INSTALL); } @@ -679,7 +679,7 @@ void JobWidgetInstall::SendProgress() // send progress signal of pkgmgr std::ostringstream percent; percent << static_cast(GetProgressPercent()); - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_PROGRESS_KEY, percent.str()); @@ -705,7 +705,7 @@ void JobWidgetInstall::SendFinishedSuccess() DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname; // send signal of pkgmgr - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_END_KEY, PKGMGR_END_SUCCESS); @@ -727,7 +727,7 @@ void JobWidgetInstall::SendFinishedFailure() LogDebug("Call widget install failure finishedCallback"); // send signal of pkgmgr - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_END_KEY, PKGMGR_END_FAILURE); diff --git a/src/jobs/widget_install/widget_installer_struct.h b/src/jobs/widget_install/widget_installer_struct.h index 716bb56..2a655c8 100755 --- a/src/jobs/widget_install/widget_installer_struct.h +++ b/src/jobs/widget_install/widget_installer_struct.h @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include //Widget Installer typedefs @@ -102,6 +104,7 @@ struct WidgetInstallationStruct : public WidgetInstallCallbackBase WidgetUpdateMode::Type updateMode; bool m_quiet; bool m_preload; + std::shared_ptr pkgmgrInterface; // It must be empty-constructible as a parameter of generic event WidgetInstallationStruct() : updateMode(WidgetUpdateMode::Zero), @@ -115,11 +118,14 @@ struct WidgetInstallationStruct : public WidgetInstallCallbackBase void *param, WidgetUpdateMode::Type mode, bool quiet, - bool preload) : + bool preload, + std::shared_ptr _pkgmgrInterface + ) : WidgetInstallCallbackBase(finished, progress, param), updateMode(mode), m_quiet(quiet), - m_preload(preload) + m_preload(preload), + pkgmgrInterface(_pkgmgrInterface) { } }; diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp index 392106f..1310d38 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp +++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp @@ -85,8 +85,8 @@ JobWidgetUninstall::JobWidgetUninstall(const std::string & widgetPkgName, AddTask(new TaskDeleteCertificates(m_context)); // send start signal of pkgmgr - if (PkgmgrSignalSingleton::Instance().setPkgname(m_context.pkgname)) { - PkgmgrSignalSingleton::Instance().sendSignal( + if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.pkgname)) { + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_START_KEY, PKGMGR_START_UNINSTALL); } @@ -121,7 +121,7 @@ void JobWidgetUninstall::SendProgress() // send progress signal of pkgmgr std::ostringstream percent; percent << static_cast(GetProgressPercent()); - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_PROGRESS_KEY, percent.str()); @@ -137,7 +137,7 @@ void JobWidgetUninstall::SendFinishedSuccess() { using namespace PackageManager; // send signal of pkgmgr - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_END_KEY, PKGMGR_END_SUCCESS); @@ -153,7 +153,7 @@ void JobWidgetUninstall::SendFinishedFailure() LogError("Message: " << m_exceptionMessage); // send signal of pkgmgr - PkgmgrSignalSingleton::Instance().sendSignal( + getInstallerStruct().pkgmgrInterface->sendSignal( PKGMGR_END_KEY, PKGMGR_END_FAILURE); diff --git a/src/jobs/widget_uninstall/widget_uninstaller_struct.h b/src/jobs/widget_uninstall/widget_uninstaller_struct.h index 4388164..ce2d4cc 100644 --- a/src/jobs/widget_uninstall/widget_uninstaller_struct.h +++ b/src/jobs/widget_uninstall/widget_uninstaller_struct.h @@ -29,6 +29,8 @@ #include #include #include +#include +#include //Widget Uninstaller typedefs typedef void (*UninstallerFinishedCallback)( @@ -44,6 +46,26 @@ typedef void (*UninstallerProgressCallback)( //UninstallationStruct typedef Jobs::JobCallbacksBase -WidgetUninstallationStruct; +WidgetUninstallCallbackBase; + +struct WidgetUninstallationStruct : public WidgetUninstallCallbackBase +{ + std::shared_ptr pkgmgrInterface; + + // It must be empty-constructible as a parameter of generic event + WidgetUninstallationStruct() + { + } + + WidgetUninstallationStruct(UninstallerFinishedCallback finished, + UninstallerProgressCallback progress, + void *param, + std::shared_ptr _pkgmgrInterface + ) : + WidgetUninstallCallbackBase(finished, progress, param), + pkgmgrInterface(_pkgmgrInterface) + { + } +}; #endif // WRT_SRC_INSTALLER_CORE_UNINSTALLER_TASKS_WIDGET_INSTALLER_STRUCT_H_ diff --git a/src/pkg-manager/pkgmgr_signal.cpp b/src/pkg-manager/pkgmgr_signal.cpp index 13b32b5..4b48b83 100644 --- a/src/pkg-manager/pkgmgr_signal.cpp +++ b/src/pkg-manager/pkgmgr_signal.cpp @@ -19,12 +19,10 @@ * @brief */ -#include #include #include #include -IMPLEMENT_SAFE_SINGLETON(PackageManager::PkgmgrSignal) namespace PackageManager { @@ -95,7 +93,7 @@ bool PkgmgrSignal::deinitialize() return true; } -bool PkgmgrSignal::setPkgname(std::string name) +bool PkgmgrSignal::setPkgname(const std::string& name) { if (!m_initialized) { @@ -115,7 +113,7 @@ bool PkgmgrSignal::setPkgname(std::string name) return true; } -bool PkgmgrSignal::sendSignal(std::string key, std::string value) const +bool PkgmgrSignal::sendSignal(const std::string& key, const std::string& value) const { if (!m_initialized) { diff --git a/src/pkg-manager/pkgmgr_signal.h b/src/pkg-manager/pkgmgr_signal.h index 6c4e043..a939c50 100644 --- a/src/pkg-manager/pkgmgr_signal.h +++ b/src/pkg-manager/pkgmgr_signal.h @@ -15,14 +15,15 @@ */ /* * @author Yunchan Cho (yunchan.cho@samsung.com) - * @version 0.1 + * @author Jan Olszak (j.olszak@samsung.com) + * @version 0.2 * @brief */ #ifndef WRT_PKGMGR_SIGNAL_H_ #define WRT_PKGMGR_SINGAL_H_ -#include +#include #include namespace PackageManager{ @@ -38,17 +39,20 @@ namespace PackageManager{ typedef pkgmgr_installer* PkgmgrHandle; -class PkgmgrSignal +class PkgmgrSignal: public IPkgmgrSignal { public: bool initialize(int argc, char* argv[]); bool deinitialize(); - bool setPkgname(std::string name); - bool sendSignal(std::string key, std::string value) const; + bool setPkgname(const std::string& name); + bool sendSignal(const std::string& key, const std::string& value) const; std::string getPkgname() const; int getRequestedType() const; bool isNoPopupRequired() const; + PkgmgrSignal(); + virtual ~PkgmgrSignal(); + private: bool m_initialized; PkgmgrHandle m_handle; @@ -56,15 +60,7 @@ class PkgmgrSignal std::string m_pkgname; bool m_noPopup; int m_reqType; - - PkgmgrSignal(); - ~PkgmgrSignal(); - - friend class DPL::Singleton; }; - -typedef DPL::Singleton PkgmgrSignalSingleton; - } // PackageManager #endif // WRT_PKGMGR_SIGNAL_H_ diff --git a/src/pkg-manager/pkgmgr_signal_dummy.h b/src/pkg-manager/pkgmgr_signal_dummy.h new file mode 100644 index 0000000..f8862ee --- /dev/null +++ b/src/pkg-manager/pkgmgr_signal_dummy.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011 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. + */ +/* + * @author Jan Olszak (j.olszak@samsung.com) + * @version 0.1 + * @brief Dummy version of PkgmgrSignal. + */ + +#ifndef WRT_PKGMGR_SIGNAL_DUMMY_H_ +#define WRT_PKGMGR_SIGNAL_DUMMY_H_ + +#include + +namespace PackageManager { + +class PkgmgrSignalDummy: public IPkgmgrSignal +{ +public: + PkgmgrSignalDummy() + { + } + + virtual ~PkgmgrSignalDummy() + { + } + bool setPkgname(const std::string& name) + { + return false; + } + + bool sendSignal(const std::string& key, const std::string& value) const + { + return false; + } + + std::string getPkgname() const + { + return ""; + } +}; + +} // PkgmgrSignalDummy + +#endif // WRT_PKGMGR_SIGNAL_DUMMY_H_ diff --git a/src/pkg-manager/pkgmgr_signal_interface.h b/src/pkg-manager/pkgmgr_signal_interface.h new file mode 100644 index 0000000..187efb5 --- /dev/null +++ b/src/pkg-manager/pkgmgr_signal_interface.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 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. + */ +/* + * @author Jan Olszak (j.olszak@samsung.com) + * @version 0.1 + * @brief Interface for PkgmgrSignal. + */ + +#ifndef WRT_PKGMGR_SIGNAL_INTERFACE_H_ +#define WRT_PKGMGR_SIGNAL_INTERFACE_H_ + +#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 ~IPkgmgrSignal(){}; +}; + +} // IPkgmgrSignal + +#endif // WRT_PKGMGR_SIGNAL_INTERFACE_H_ diff --git a/src/wrt-installer/wrt_installer.cpp b/src/wrt-installer/wrt_installer.cpp index 297ec7b..4f877a1 100644 --- a/src/wrt-installer/wrt_installer.cpp +++ b/src/wrt-installer/wrt_installer.cpp @@ -49,7 +49,8 @@ #include #include #include -#include + + #define NOFILE_CNT_FOR_INSTALLER 9999 @@ -114,6 +115,12 @@ void WrtInstaller::OnCreate() std::string arg = m_argv[0]; + pkgmgrSignalInterface = std::static_pointer_cast( + std::shared_ptr( + new PackageManager::PkgmgrSignalDummy() + ) + ); + if (arg.empty()) { return showHelpAndQuit(); } @@ -203,12 +210,18 @@ void WrtInstaller::OnCreate() using namespace PackageManager; m_installByPkgmgr = true; - PkgmgrSignalSingleton::Instance().initialize(m_argc, m_argv); - m_quiet = PkgmgrSignalSingleton::Instance().isNoPopupRequired(); + auto pkgmgrSignal = std::shared_ptr( + new PackageManager::PkgmgrSignal() + ); + + pkgmgrSignal->initialize(m_argc, m_argv); + m_quiet = pkgmgrSignal->isNoPopupRequired(); LogDebug("backend m_quiet"<getRequestedType(); + pkgmgrSignalInterface = + std::static_pointer_cast(pkgmgrSignal); switch (reqType) { case PKGMGR_REQ_INSTALL: m_packagePath = m_argv[4]; @@ -344,7 +357,8 @@ void WrtInstaller::installStep() ? &staticWrtInstallProgressCallback : NULL, m_installPolicy, m_quiet, - m_preloadWidget); + m_preloadWidget, + pkgmgrSignalInterface); } void WrtInstaller::installPluginsStep() @@ -425,7 +439,8 @@ void WrtInstaller::uninstallPkgNameStep() LogDebug("Package name : " << m_name); wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback, (!m_quiet || m_installByPkgmgr) - ? &staticWrtUninstallProgressCallback : NULL); + ? &staticWrtUninstallProgressCallback : NULL, + pkgmgrSignalInterface); } void WrtInstaller::uninstallGuidStep() @@ -436,7 +451,8 @@ void WrtInstaller::uninstallGuidStep() if (status == WRT_SUCCESS) { LogDebug("Guid : " << m_name); wrt_uninstall_widget(pkgname.c_str(), this, &staticWrtStatusCallback, - !m_quiet ? &staticWrtUninstallProgressCallback : NULL); + !m_quiet ? &staticWrtUninstallProgressCallback : NULL, + pkgmgrSignalInterface); } else { printf("failed: can not uninstall widget\n"); LogError("Fail to uninstalling widget... "); @@ -483,7 +499,8 @@ void WrtInstaller::unistallWgtFileStep() if (status == WRT_SUCCESS) { LogDebug("Pkgname from packagePath : " << pkgname); wrt_uninstall_widget(pkgname.c_str(), this, &staticWrtStatusCallback, - !m_quiet ? &staticWrtUninstallProgressCallback : NULL); + !m_quiet ? &staticWrtUninstallProgressCallback : NULL, + pkgmgrSignalInterface); } else { LogError("Fail to uninstalling widget... "); m_returnStatus = -1; diff --git a/src/wrt-installer/wrt_installer.h b/src/wrt-installer/wrt_installer.h index 3152f0e..723236f 100644 --- a/src/wrt-installer/wrt_installer.h +++ b/src/wrt-installer/wrt_installer.h @@ -31,7 +31,11 @@ #include #include #include -#include + +#include +#include +#include +#include namespace WRTInstallerNS { //anonymous DECLARE_GENERIC_EVENT_0(QuitEvent) @@ -134,6 +138,7 @@ class WrtInstaller : bool popupsEnabled() const; // Private data + std::shared_ptr pkgmgrSignalInterface; wrt_widget_install_mode_e m_installPolicy; std::string m_bundleValue; std::string m_packagePath; diff --git a/src/wrt-installer/wrt_installer_api.cpp b/src/wrt-installer/wrt_installer_api.cpp index 651a020..d643991 100755 --- a/src/wrt-installer/wrt_installer_api.cpp +++ b/src/wrt-installer/wrt_installer_api.cpp @@ -324,7 +324,9 @@ extern "C" WrtProgressCallback progress_cb, wrt_widget_update_mode_t update_mode, bool quiet, - bool preload) + bool preload, + std::shared_ptr pkgmgrInterface + ) { UNHANDLED_EXCEPTION_HANDLER_BEGIN { @@ -340,7 +342,8 @@ extern "C" userdata, status_cb, progress_cb), translateWidgetUpdateMode(update_mode), quiet, - preload))); + preload, + pkgmgrInterface))); } UNHANDLED_EXCEPTION_HANDLER_END } @@ -348,7 +351,8 @@ extern "C" EXPORT_API void wrt_uninstall_widget(const char * const pkg_name, void* userdata, WrtInstallerStatusCallback status_cb, - WrtProgressCallback progress_cb) + WrtProgressCallback progress_cb, + std::shared_ptr pkgmgrSignalInterface) { UNHANDLED_EXCEPTION_HANDLER_BEGIN { @@ -356,14 +360,18 @@ extern "C" LogInfo("[WRT-API] UNINSTALL WIDGET: " << widgetPkgName); // Post uninstallation event CONTROLLER_POST_EVENT( - Logic::InstallerController, - InstallerControllerEvents::UninstallWidgetEvent( - widgetPkgName, - WidgetUninstallationStruct( - InstallerCallbacksTranslate::uninstallFinishedCallback, - InstallerCallbacksTranslate::installProgressCallback, - new InstallerCallbacksTranslate::StatusCallbackStruct( - userdata, status_cb, progress_cb)))); + Logic::InstallerController, + InstallerControllerEvents::UninstallWidgetEvent( + widgetPkgName, + WidgetUninstallationStruct( + InstallerCallbacksTranslate::uninstallFinishedCallback, + InstallerCallbacksTranslate::installProgressCallback, + new InstallerCallbacksTranslate::StatusCallbackStruct( + userdata, status_cb, progress_cb), + pkgmgrSignalInterface + ) + ) + ); } UNHANDLED_EXCEPTION_HANDLER_END } diff --git a/src/wrt-installer/wrt_installer_api.h b/src/wrt-installer/wrt_installer_api.h index 6b091c9..6f2bea6 100755 --- a/src/wrt-installer/wrt_installer_api.h +++ b/src/wrt-installer/wrt_installer_api.h @@ -33,6 +33,8 @@ #include #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -241,7 +243,9 @@ void wrt_install_widget(const char *path, WrtProgressCallback progress_callback, wrt_widget_update_mode_t update_mode, bool quiet, - bool preload); + bool preload, + std::shared_ptr pkgmgrInterface + ); /** * @fn void wrt_installer_uninstall_widget (const char * const pkg_name, @@ -274,7 +278,8 @@ void wrt_install_widget(const char *path, void wrt_uninstall_widget (const char * const pkg_name, void* userdata, WrtInstallerStatusCallback status_cb, - WrtProgressCallback progress_cb); + WrtProgressCallback progress_cb, + std::shared_ptr pkgmgrSignalInterface); /** * @fn void wrt_install_plugin(const char *pluginDirectory,