[Engine] patch for wrong pkgmgr signal and wrong db connection of backend library 1.0_post
authorYunchan Cho <yunchan.cho@samsung.com>
Thu, 7 Jun 2012 08:38:38 +0000 (17:38 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Wed, 20 Jun 2012 02:20:08 +0000 (11:20 +0900)
The following patch should be applied to wrt-commons
https://tizendev.org/gerrit/2277

Change-Id: I435fddadef17619fc64b7c1974a4f97f3c52021d

19 files changed:
src/CMakeLists.txt
src/jobs/plugin_install/plugin_metafile_reader.cpp
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/job_widget_install.h
src/jobs/widget_install/task_db_update.cpp
src/jobs/widget_install/task_db_update.h
src/jobs/widget_install/task_recovery.cpp [new file with mode: 0644]
src/jobs/widget_install/task_unzip.cpp
src/jobs/widget_install/task_widget_config.cpp
src/jobs/widget_install/widget_install_context.h
src/jobs/widget_uninstall/job_widget_uninstall.cpp
src/jobs/widget_uninstall/task_check.cpp
src/logic/installer_logic.cpp
src/pkg-manager/backendlib.cpp
src/pkg-manager/pkgmgr_signal.cpp [new file with mode: 0644]
src/pkg-manager/pkgmgr_signal.h [new file with mode: 0644]
src/wrt-installer/CMakeLists.txt
src/wrt-installer/wrt_installer.cpp
src/wrt-installer/wrt_installer.h

index 7b5c113..754a23f 100644 (file)
@@ -59,6 +59,7 @@ SET(INSTALLER_INCLUDES
     ${INSTALLER_SRC_DIR}/wrt-installer
     ${INSTALLER_SRC_DIR}/security
     ${INSTALLER_SRC_DIR}/commons
+    ${INSTALLER_SRC_DIR}/pkg-manager
 )
 
 SET(INSTALLER_SOURCES
@@ -96,6 +97,7 @@ SET(INSTALLER_SOURCES
     ${INSTALLER_SRC_DIR}/misc/wac_widget_id.cpp
     ${INSTALLER_SRC_DIR}/misc/feature_logic.cpp
     ${INSTALLER_CONFIG_GENERATOR}/config_generator.cpp
+    ${INSTALLER_SRC_DIR}/pkg-manager/pkgmgr_signal.cpp
     )
 
 MESSAGE(STATUS "add -DSEP_INSTALLER")
@@ -123,6 +125,7 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP
     libiri
     libpcrecpp
     REQUIRED
+    pkgmgr-installer
     )
 
 INCLUDE_DIRECTORIES(
index 7dd434a..a0c21ac 100644 (file)
@@ -91,23 +91,23 @@ void PluginMetafileReader::tokenEndLibraryName(PluginMetafileData &data)
 
 void PluginMetafileReader::tokenEndFeatureInstallURI(PluginMetafileData &data)
 {
-    data.m_featuresInstallURI = m_parserSchema.getText();
+    //data.m_featuresInstallURI = m_parserSchema.getText();
 }
 
 void PluginMetafileReader::tokenEndFeatureKeyCN(PluginMetafileData &data)
 {
-    data.m_featuresKeyCN = m_parserSchema.getText();
+    //data.m_featuresKeyCN = m_parserSchema.getText();
 }
 
 void PluginMetafileReader::tokenEndFeatureRootCN(PluginMetafileData &data)
 {
-    data.m_featuresRootCN = m_parserSchema.getText();
+    //data.m_featuresRootCN = m_parserSchema.getText();
 }
 
 void PluginMetafileReader::tokenEndFeatureRootFingerprint(
         PluginMetafileData &data)
 {
-    data.m_featuresRootFingerprint = m_parserSchema.getText();
+    //data.m_featuresRootFingerprint = m_parserSchema.getText();
 }
 
 void PluginMetafileReader::tokenEndApiFeature(PluginMetafileData &data)
index b4214c1..1f74710 100644 (file)
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
 #include <string>
-#include <dpl/wrt-dao-rw/widget_dao.h> //TODO remove
+#include <sys/time.h>
+#include <ctime>
+#include <cstdlib>
+#include <limits.h>
+#include <regex.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
 #include <aul.h>
 #include <dpl/localization/w3c_file_localization.h>
 #include <libiriwrapper.h>
+#include <pkg-manager/pkgmgr_signal.h>
 
 using namespace WrtDB;
 
@@ -58,6 +64,11 @@ namespace // anonymous
 {
 const char * const CONFIG_XML = "config.xml";
 
+//allowed: a-z, A-Z, 0-9, '.', '-', '_', ' '
+const char* REG_PKGNAME_PATTERN = "^[-. a-zA-Z0-9_@+=]*$";
+const int RESERVED_COUNT = 20;  //number of chars reserved in name (e.g. for '.desktop')
+const int MAX_PKGNAME_LENTH = 255 - RESERVED_COUNT;
+
 class InstallerTaskFail :
     public DPL::TaskDecl<InstallerTaskFail>
 {
@@ -83,85 +94,84 @@ class InstallerTaskFail :
         AddStep(&InstallerTaskFail::StepFail);
     }
 };
+
+const std::string XML_EXTENSION = ".xml";
+
+bool hasExtension(const std::string& filename, const std::string& extension) {
+    LogDebug("Looking for extension " << extension << " in: "  << filename);
+    size_t fileLen = filename.length();
+    size_t extLen = extension.length();
+    if (fileLen < extLen) {
+        LogError("Filename " << filename << " is shorter than extension "
+                    << extension);
+        return false;
+    }
+    return (0 == filename.compare(fileLen-extLen, extLen, extension));
+}
+
 } // namespace anonymous
 
 namespace Jobs {
 namespace WidgetInstall {
-JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
+JobWidgetInstall::JobWidgetInstall(std::string const & widgetPath,
         const WidgetInstallationStruct &installerStruct) :
     Job(Installation),
     JobContextBase<WidgetInstallationStruct>(installerStruct),
     m_exceptionCaught(Exceptions::Success)
 {
-    // Configure installation
-    ConfigureResult result = ConfigureInstallation(widgetPath, false);
-
-    if (result == ConfigureResult::Ok) {
-        LogInfo("Configure installation succeeded");
-
-        // Create installation tasks
-        AddTask(new TaskUnzip(m_installerContext));
-        AddTask(new TaskWidgetConfig(m_installerContext));
-        AddTask(new TaskCertify(m_installerContext));
-        AddTask(new TaskDbUpdate(m_installerContext));
-        // TODO: Update progress information for this task
+    //Check installation type (config.xml or widget.wgt)
+    bool fromBrowser = hasExtension(widgetPath, XML_EXTENSION);
+    LogInfo("Hosted app installation: " << fromBrowser);
 
-        AddTask(new TaskAceCheck(m_installerContext));
-        //This is sort of quick solution, because ACE verdicts are based upon
-        //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
-        //task.
-        AddTask(new TaskSmack(m_installerContext));
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    srand(time(NULL) + tv.tv_usec);
+    WrtDB::DbWidgetHandle handle;
+    do {
+        handle = rand() % INT_MAX + 1;
+        LogInfo("Random widget handle: " << handle);
+    } while (WidgetDAOReadOnly::isWidgetInstalled(handle));
 
-        AddTask(new TaskDesktopFile(m_installerContext));
-        AddTask(new TaskPrivateStorage(m_installerContext));
-    } else if (result == ConfigureResult::Deferred) {
-        // Installation is deferred
-        LogInfo("Configure installation deferred");
+    m_installerContext.widgetHandle = handle;
 
-        AddTask(new InstallerTaskFail(true));
-    } else if (result == ConfigureResult::Failed) {
-        // Installation is not allowed to proceed due to widget update policy
-        LogWarning("Configure installation failed!");
+    ConfigParserData configData = getWidgetDataFromXML(widgetPath, fromBrowser);
+    WidgetUpdateInfo update = detectWidgetUpdate(configData);
 
-        AddTask(new InstallerTaskFail(false));
+    // Configure installation
+    ConfigureResult result = ConfigureInstallation(widgetPath, fromBrowser, update);
+    if (!setWidgetPkgName(configData)) {
+        result = ConfigureResult::Failed;
     } else {
-        Assert(false && "Invalid configure result!");
+        using namespace PackageManager;
+        LogInfo("WidgetHandle: " << m_installerContext.widgetHandle);
+        LogInfo("Widget pkg name: " << m_installerContext.widgetConfig.pkgname);
+        // send start signal of pkgmgr
+        PkgmgrSignalSingleton::Instance().setPkgname(
+                    DPL::ToUTF8String(
+                        *m_installerContext.widgetConfig.pkgname));
+        PkgmgrSignalSingleton::Instance().sendSignal(
+                    PKGMGR_START_KEY,
+                    PKGMGR_START_INSTALL);
     }
-}
-
-JobWidgetInstall::JobWidgetInstall(
-        std::string const & widgetUrl,
-        std::string const & iconPath,
-        const WidgetInstallationStruct &installerStruct) :
-    Job(Installation),
-    JobContextBase<WidgetInstallationStruct>(installerStruct),
-    m_exceptionCaught(Exceptions::Success)
-{
-    // Configure installation
-    ConfigureResult result = ConfigureInstallation(widgetUrl, true);
 
     if (result == ConfigureResult::Ok) {
         LogInfo("Configure installation succeeded");
 
-        // Check web app url
-        LibIri::Wrapper iri(widgetUrl.c_str());
-        if (!iri.Validate()) {
-            ThrowMsg(Exceptions::InvalidWidgetUrl,
-                     "Web app url must be a valid iri/uri/url");
+        //Create installation tasks
+        if (!fromBrowser) {
+            AddTask(new TaskUnzip(m_installerContext));
+        }
+        AddTask(new TaskWidgetConfig(m_installerContext));
+        if (fromBrowser) {
+            AddTask(new TaskPrepareFiles(m_installerContext));
         }
-
-        m_installerContext.widgetConfig.configInfo.startFile =
-                DPL::FromUTF8String(widgetUrl);
-
-        m_installerContext.iconPath = iconPath;
 
         // Create installation tasks
-        AddTask(new TaskPrepareFiles(m_installerContext));
-        AddTask(new TaskWidgetConfig(m_installerContext));
         AddTask(new TaskCertify(m_installerContext));
         AddTask(new TaskDbUpdate(m_installerContext));
         // TODO: Update progress information for this task
 
+        AddTask(new TaskPrivateStorage(m_installerContext));
         AddTask(new TaskAceCheck(m_installerContext));
         //This is sort of quick solution, because ACE verdicts are based upon
         //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
@@ -169,7 +179,6 @@ JobWidgetInstall::JobWidgetInstall(
         AddTask(new TaskSmack(m_installerContext));
 
         AddTask(new TaskDesktopFile(m_installerContext));
-        AddTask(new TaskPrivateStorage(m_installerContext));
     } else if (result == ConfigureResult::Deferred) {
         // Installation is deferred
         LogInfo("Configure installation deferred");
@@ -185,17 +194,109 @@ JobWidgetInstall::JobWidgetInstall(
     }
 }
 
+bool JobWidgetInstall::setWidgetPkgName(
+        const WrtDB::ConfigParserData &configInfo)
+{
+    Assert(!!m_installerContext.widgetHandle
+           && "Widget Handle should be initialized");
+
+    if (!m_installerContext.widgetConfig.pkgname) {
+        regex_t reg;
+        regcomp(&reg, REG_PKGNAME_PATTERN, REG_NOSUB);
+        struct stat dirStat;
+        if(!!configInfo.pkgname) {
+            LogDebug("Setting pkgName provided in config.xml");
+            if ((regexec(&reg, DPL::ToUTF8String(*(configInfo.pkgname)).c_str(),
+                 static_cast<size_t>(0), NULL, 0) != 0) ||
+                (DPL::ToUTF8String(*(configInfo.pkgname)).size() > MAX_PKGNAME_LENTH) ||
+                (stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
+                       + DPL::ToUTF8String(*(configInfo.pkgname))).c_str(), &dirStat) == 0))
+            {
+                //it is true when pkgName does not fit REG_PKGNAME_PATTERN or
+                //pkgname is too long or there is widget with the same pkgname
+                LogError("pkgName provided but not proper.");
+                regfree(&reg);
+                return false;
+            }
+            m_installerContext.widgetConfig.pkgname = configInfo.pkgname;
+        } else {
+            LogInfo("package name is generated by WRT");
+            std::string pkgName = WrtDB::GlobalConfig::GetPkgnamePrefix();
+
+            bool named = false;
+            FOREACH(it, configInfo.localizedDataSet)
+            {
+                if (!!((it->second).name)) {
+                    //there is a name provided
+                    std::string name =  DPL::ToUTF8String(*(it->second).name);
+                    //cut very long widget's name
+                    name = name.substr(0, MAX_PKGNAME_LENTH - strlen(
+                        WrtDB::GlobalConfig::GetPkgnamePrefix()));
+                    //check name if all characters are supported by filesystem
+                    if (regexec(&reg, name.c_str(), static_cast<size_t>(0), NULL, 0)
+                        == 0)
+                    {
+                        //WidgetName is ok and can be used as package name
+                        //replace all spaces with '_'
+                        size_t pos = 0;
+                        while((pos = name.find(" ", pos)) != std::string::npos) {
+                            name.replace(pos, 1, "_");
+                            ++pos;
+                        }
+                        pkgName += name;
+                        named = true;
+                    }
+                    break;
+                }
+            }
+
+            if (!named) // there is no widget name provided, use widgetHandle
+            {
+                pkgName += std::to_string(*(m_installerContext.widgetHandle));
+            }
+
+            //check if there is package with same name and if generate different name
+            std::string path = GlobalConfig::GetUserInstalledWidgetPath();
+            path += "/";
+
+            std::ostringstream newPath;
+            newPath << path << pkgName;
+
+            std::string suffix;
+            for (int i = 0;; ++i) {
+                if (stat(newPath.str().c_str(), &dirStat) == 0) {
+                    //path exist, chose another one, eg. widgetName1
+                    suffix = std::to_string(i + 1);
+                    pkgName = pkgName.substr(
+                            0, MAX_PKGNAME_LENTH - suffix.size());
+                    newPath.str("");
+                    newPath << path << pkgName << suffix;
+                    continue;
+                }
+                pkgName += suffix;
+                break;
+            }
+
+            m_installerContext.widgetConfig.pkgname =
+                DPL::FromUTF8String(pkgName);
+        }
+        regfree(&reg);
+    }
+    LogInfo("package name : " << m_installerContext.widgetConfig.pkgname);
+    LogInfo("GUID : " << m_installerContext.widgetConfig.guid);
+    return true;
+}
+
 DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
 {
     return m_installerContext.widgetHandle;
 }
 
 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
-        const std::string &widgetSource, bool fromBrowser)
+        const std::string &widgetSource,
+        bool fromBrowser,
+        const WidgetUpdateInfo &update)
 {
-    // Detect widget update
-    WidgetUpdateInfo update = detectWidgetUpdate(widgetSource, fromBrowser);
-
     LogInfo(
         "Widget install/update: incoming guid = '" <<
         update.incomingGUID << "'");
@@ -243,6 +344,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
             }
         }
 
+        m_installerContext.widgetConfig.pkgname = pkgname;
         OptionalWidgetVersion existingVersion;
         existingVersion = update.existingWidgetInfo.existingVersion;
         OptionalWidgetVersion incomingVersion = update.incomingVersion;
@@ -259,7 +361,18 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
     // Init installer context
     m_installerContext.widgetSource = widgetSource;
     m_installerContext.tempWidgetPath = std::string();
-    m_installerContext.widgetConfig = WidgetRegisterInfo();
+
+    // setup config xml path
+    if (fromBrowser) {
+        LogInfo("widgetSource " << widgetSource);
+        size_t slash = widgetSource.find_last_of("\\/");
+        if (std::string::npos != slash) {
+            m_installerContext.tempWidgetPath = widgetSource.substr(0, slash+1);
+        } else {
+            m_installerContext.tempWidgetPath = ".";
+        }
+    }
+
     m_installerContext.installStep = InstallerContext::INSTALL_START;
     m_installerContext.job = this;
     m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
@@ -302,17 +415,24 @@ WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
     }
 }
 
-WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
-        const std::string &widgetSource, bool fromBrowser)
+ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
+        const std::string &widgetSource,
+        bool fromBrowser)
 {
-    LogInfo("Checking up widget package for config.xml...");
-
     Try
     {
+        // Parse config
+        ParserRunner parser;
+        ConfigParserData configInfo;
+
         DPL::OptionalString widgetGUID;
         OptionalWidgetVersion widgetVersion;
         if (fromBrowser) {
-            widgetGUID = DPL::FromUTF8String(widgetSource);
+            parser.Parse(widgetSource,
+                         ElementParserPtr(
+                             new RootParser<WidgetParser>(configInfo,
+                                                          DPL::FromUTF32String(
+                                                              L"widget"))));
         }
         else {
             // Open zip file
@@ -329,79 +449,94 @@ WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
             DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
             DPL::Copy(&inputAdapter, &outputAdapter);
 
-            // Parse config
-            ParserRunner parser;
-            ConfigParserData configInfo;
-
             parser.Parse(&buffer,
                          ElementParserPtr(
                              new RootParser<WidgetParser>(configInfo,
                                                           DPL::FromUTF32String(
                                                               L"widget"))));
-
-            // Check widget id
-            widgetGUID = configInfo.widget_id;
-
-            if (widgetGUID.IsNull()) {
-                LogDebug("Installed widget has no GUID");
-                return WidgetUpdateInfo();
-            }
-
-            LogDebug("Installed widget GUID: " << *widgetGUID);
-
-            // Locate widget ID with this GUID
-            // Incoming widget version
-            if (!configInfo.version.IsNull()) {
-                widgetVersion =
-                    DPL::Optional<WidgetVersion>(
-                        WidgetVersion(*configInfo.version));
-            }
         }
 
-        try
-        {
-            // Search widget handle by GUID
-            WidgetDAO dao(widgetGUID);
-            return WidgetUpdateInfo(
-                widgetGUID,
-                widgetVersion,
-                WidgetUpdateInfo::ExistingWidgetInfo(
-                    dao.getHandle(), dao.getVersion()));
-        }
-        Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){
-            // GUID isn't installed
-            return WidgetUpdateInfo(
-                widgetGUID,
-                widgetVersion,
-                WidgetUpdateInfo::ExistingWidgetInfo());
-        }
+        return configInfo;
     }
     Catch(DPL::ZipInput::Exception::OpenFailed)
     {
         LogDebug("Failed to open widget package");
-        return WidgetUpdateInfo();
+        return ConfigParserData();
     }
     Catch(DPL::ZipInput::Exception::OpenFileFailed)
     {
         LogDebug("Failed to open config.xml file");
-        return WidgetUpdateInfo();
+        return ConfigParserData();
     }
     Catch(DPL::CopyFailed)
     {
         LogDebug("Failed to extract config.xml file");
-        return WidgetUpdateInfo();
+        return ConfigParserData();
     }
     Catch(ElementParser::Exception::ParseError)
     {
         LogDebug("Failed to parse config.xml file");
+        return ConfigParserData();
+    }
+}
+
+WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
+        const ConfigParserData &configInfo)
+{
+    LogInfo("Checking up widget package for config.xml...");
+
+    DPL::OptionalString widgetGUID;
+    OptionalWidgetVersion widgetVersion;
+
+    // Check widget id
+    widgetGUID = configInfo.widget_id;
+
+    if (widgetGUID.IsNull()) {
+        LogDebug("Installed widget has no GUID");
         return WidgetUpdateInfo();
     }
+
+    LogDebug("Installed widget GUID: " << *widgetGUID);
+
+    // Locate widget ID with this GUID
+    // Incoming widget version
+    if (!configInfo.version.IsNull()) {
+        widgetVersion =
+            DPL::Optional<WidgetVersion>(
+                WidgetVersion(*configInfo.version));
+    }
+
+    Try
+    {
+        // Search widget handle by GUID
+        WidgetDAOReadOnly dao(widgetGUID);
+        return WidgetUpdateInfo(
+            widgetGUID,
+            widgetVersion,
+            WidgetUpdateInfo::ExistingWidgetInfo(
+                dao.getHandle(), dao.getVersion()));
+    }
+    Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
+    {
+        // GUID isn't installed
+        return WidgetUpdateInfo(
+            widgetGUID,
+            widgetVersion,
+            WidgetUpdateInfo::ExistingWidgetInfo());
+    }
 }
 
 void JobWidgetInstall::SendProgress()
 {
+    using namespace PackageManager;
     if (GetProgressFlag() != false) {
         if (getInstallerStruct().progressCallback != NULL) {
+            // send progress signal of pkgmgr
+            std::ostringstream percent;
+            percent << static_cast<int>(GetProgressPercent());
+            PkgmgrSignalSingleton::Instance().sendSignal(
+                        PKGMGR_PROGRESS_KEY,
+                        percent.str());
 
             LogDebug("Call widget install progressCallbak");
             getInstallerStruct().progressCallback(getInstallerStruct().userParam,
@@ -412,12 +547,21 @@ void JobWidgetInstall::SendProgress()
 
 void JobWidgetInstall::SendFinishedSuccess()
 {
+    using namespace PackageManager;
+    // TODO : sync should move to separate task.
+    sync();
+
     //inform widget info
     JobWidgetInstall::displayWidgetInfo();
 
     DPL::Optional<WidgetHandle> handle = getNewWidgetHandle();
     const WidgetHandle INVALID_WIDGET_HANDLE = 0;
 
+    // send signal of pkgmgr
+    PkgmgrSignalSingleton::Instance().sendSignal(
+                PKGMGR_END_KEY,
+                PKGMGR_END_SUCCESS);
+
     LogDebug("Call widget install successfinishedCallback");
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
             !!handle ? *handle : INVALID_WIDGET_HANDLE, Exceptions::Success);
@@ -425,12 +569,20 @@ void JobWidgetInstall::SendFinishedSuccess()
 
 void JobWidgetInstall::SendFinishedFailure()
 {
+    using namespace PackageManager;
+
     LogError("Error in installation step: " << m_exceptionCaught);
     LogError("Message: " << m_exceptionMessage);
     DPL::Optional<WidgetHandle> handle = getNewWidgetHandle();
     const WidgetHandle INVALID_WIDGET_HANDLE = 0;
 
     LogDebug("Call widget install failure finishedCallback");
+
+    // send signal of pkgmgr
+    PkgmgrSignalSingleton::Instance().sendSignal(
+                PKGMGR_END_KEY,
+                PKGMGR_END_FAILURE);
+
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
             !!handle ? *handle : INVALID_WIDGET_HANDLE, m_exceptionCaught);
 }
@@ -456,6 +608,7 @@ void JobWidgetInstall::displayWidgetInfo()
         "===================================== INSTALLED WIDGET INFO ========="\
         "============================";
     out << std::endl << "Name:                        " << localizedInfo.name;
+    out << std::endl << "PkgName:                     " << dao.getPkgname();
     WidgetSize size = dao.getPreferredSize();
     out << std::endl << "Width:                       " << size.width;
     out << std::endl << "Height:                      " << size.height;
index 0a4a08b..9d24a47 100644 (file)
@@ -30,6 +30,7 @@
 #include <dpl/utils/widget_version.h>
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_update_info.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
 #include "widget_installer_struct.h"
 
 namespace Jobs {
@@ -56,12 +57,17 @@ class JobWidgetInstall :
     };
 
     ConfigureResult ConfigureInstallation(const std::string &widgetSource,
-                                          bool fromBrowser);
-    WidgetUpdateInfo detectWidgetUpdate(const std::string &widgetSource,
-                                        bool fromBrowser);
+                                          bool fromBrowser,
+                                          const WidgetUpdateInfo &update);
+    static WrtDB::ConfigParserData getWidgetDataFromXML(
+            const std::string &widgetSource,
+            bool fromBrowser);
+    static WidgetUpdateInfo detectWidgetUpdate(
+            const WrtDB::ConfigParserData &configInfo);
     WidgetUpdateMode::Type CalcWidgetUpdatePolicy(
             const OptionalWidgetVersion &existingVersion,
             const OptionalWidgetVersion &incomingVersion) const;
+    bool setWidgetPkgName(const WrtDB::ConfigParserData &configInfo);
     void displayWidgetInfo();
 
   public:
index 8a8cf94..b97098c 100644 (file)
@@ -49,7 +49,6 @@ TaskDbUpdate::TaskDbUpdate(InstallerContext& context) :
     m_context(context)
 {
     AddStep(&TaskDbUpdate::StepDbUpdate);
-    AddStep(&TaskDbUpdate::StepSetPkgName);
     AddStep(&TaskDbUpdate::StepCreateDirs);
     AddStep(&TaskDbUpdate::StepRenamePath);
 
@@ -58,39 +57,6 @@ TaskDbUpdate::TaskDbUpdate(InstallerContext& context) :
     AddAbortStep(&TaskDbUpdate::StepAbortRenamePath);
 }
 
-void TaskDbUpdate::StepSetPkgName()
-{
-    // We shoud send to backend installer widget id and package name of
-    // installed widget so that backend installer can send two information
-    // to menuscreen. This work is needed for menuscreen to update installation
-    // of widget normally from samsung appstore client.
-    Assert(!!m_context.widgetHandle && "Widget Handle should be initialized");
-    std::string l_pkgname;
-
-    if (!!m_context.widgetConfig.pkgname) {
-        l_pkgname =
-                DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
-    } else {
-        LogInfo("package name is generated by WRT");
-        std::ostringstream pkgname_stream;
-
-        pkgname_stream << WrtDB::GlobalConfig::GetPkgnamePrefix() <<
-                *m_context.widgetHandle;
-
-        DPL::String pkgname = DPL::FromUTF8String(pkgname_stream.str());
-        m_context.widgetConfig.pkgname = pkgname;
-        l_pkgname = pkgname_stream.str();
-    }
-
-
-    LogInfo("package name : " << l_pkgname);
-    LogInfo("GUID : " << m_context.widgetConfig.guid);
-
-    WrtDB::WidgetDAO widgetDao(*m_context.widgetHandle);
-    widgetDao.setPkgName(m_context.widgetConfig.pkgname);
-}
-
-
 void TaskDbUpdate::StepCreateDirs()
 {
     std::ostringstream widgetPath;
@@ -139,10 +105,11 @@ void TaskDbUpdate::StepDbUpdate()
 
         LogInfo("Registering widget...");
 
-        m_context.widgetHandle = WidgetDAO::registerWidget(
+        WidgetDAO::registerWidget(
+                *(m_context.widgetHandle),
                 m_context.widgetConfig,
-                m_context.wacSecurity,
-                GetUserAgentLanguageTags());
+                m_context.wacSecurity);
+
 
         FOREACH (cap, m_context.staticPermittedDevCaps) {
             LogInfo("staticPermittedDevCaps : " << cap->first
@@ -153,6 +120,12 @@ void TaskDbUpdate::StepDbUpdate()
             *(m_context.widgetHandle),
             m_context.staticPermittedDevCaps);
 
+        Assert(!!m_context.widgetConfig.pkgname
+               && "pkgName should be initialized");
+
+        WrtDB::WidgetDAO widgetDao(*m_context.widgetHandle);
+        widgetDao.setPkgName(m_context.widgetConfig.pkgname);
+
         LogInfo("Widget registered");
     }
     Catch(WidgetDAO::Exception::DatabaseError)
index 6097e35..59e9c37 100644 (file)
@@ -41,8 +41,6 @@ class TaskDbUpdate :
     void StepAbortDBUpdate();
     void StepAbortRenamePath();
 
-    void StepSetPkgName();
-
   public:
     TaskDbUpdate(InstallerContext& context);
 };
diff --git a/src/jobs/widget_install/task_recovery.cpp b/src/jobs/widget_install/task_recovery.cpp
new file mode 100644 (file)
index 0000000..b7ae04d
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+/**
+ * @file    task_recovery.cpp
+ * @author  Soyoung Kim (sy037.kim@samsung.com)
+ * @version 1.0
+ * @brief   Implementation file for installer task recovery
+ */
+#include "task_recovery.h"
+
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string>
+#include <ail.h>
+
+#include <dpl/log/log.h>
+#include <dpl/errno_string.h>
+#include <dpl/foreach.h>
+
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include <dpl/utils/file_utils.h>
+#include <dpl/utils/wrt_utility.h>
+#include <widget_install/job_widget_install.h>
+#include <widget_install/widget_install_context.h>
+#include <widget_install/widget_install_errors.h>
+
+using namespace WrtDB;
+
+namespace Jobs {
+namespace WidgetInstall {
+TaskRecovery::TaskRecovery(InstallerContext& context) :
+    DPL::TaskDecl<TaskRecovery>(this),
+    m_context(context)
+{
+    AddStep(&TaskRecovery::StepCreateCheckFile);
+}
+
+void TaskRecovery::StepCreateCheckFile()
+{
+    LogInfo("Step: create information file for recovery");
+
+    std::string fileName;
+    size_t pos = m_context.widgetSource.rfind("/");
+    std::ostringstream infoPath;
+    infoPath << GlobalConfig::GetTempInstallInfoPath();
+    infoPath << "/";
+    infoPath << m_context.widgetSource.substr(pos+1);
+
+    FILE *temp = fopen(infoPath.str().c_str(), "w+");
+    if (temp != NULL) {
+        fputs(m_context.widgetSource.c_str(), temp);
+        fsync(temp->_fileno);
+        fclose(temp);
+
+        m_context.installInfo = infoPath.str();
+
+        LogDebug("Create file : " << m_context.installInfo);
+        m_context.job->UpdateProgress(
+                InstallerContext::INSTALL_LINK_DEPENDS_DIRECTORY,
+                "depends directory linked."
+                );
+    } else {
+        ThrowMsg(Exceptions::InternalError, "Fail to create file for recovery.");
+    }
+
+    m_context.job->UpdateProgress(
+        InstallerContext::INSTALL_CHECK_FILE,
+        "Create information file for recovery");
+}
+} //namespace WidgetInstall
+} //namespace Jobs
index 24d203a..0da5663 100644 (file)
@@ -22,6 +22,7 @@
 #include <widget_install/task_unzip.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
+#include <widget_install/job_widget_install.h>
 #include <dpl/log/log.h>
 #include <dpl/copy.h>
 #include <dpl/file_output.h>
@@ -99,6 +100,11 @@ void TaskUnzip::StepCreateTempPath()
 {
     // Step succedded, save temporary widget path
     m_installerContext.tempWidgetPath = createTempPath();
+
+    m_installerContext.job->SetProgressFlag(true);
+    m_installerContext.job->UpdateProgress(
+        InstallerContext::INSTALL_CREATE_TEMPDIR,
+        "Create temporary directory for unzip");
 }
 
 void TaskUnzip::StepUnzipPrepare()
@@ -184,6 +190,10 @@ void TaskUnzip::StepUnzipProgress()
     } else {
         SwitchToStep(&TaskUnzip::StepUnzipProgress);
     }
+
+    m_installerContext.job->UpdateProgress(
+        InstallerContext::INSTALL_UNZIP_FILES,
+        "Unzip widget files to temporary directory");
 }
 
 void TaskUnzip::StepUnzipFinished()
index 6addca6..f02fe30 100644 (file)
@@ -107,10 +107,9 @@ void TaskWidgetConfig::StepProcessConfigurationFile()
         ReThrow(Exceptions::WidgetConfigFileInvalid);
     }
 
-    m_installContext.job->SetProgressFlag(true);
     m_installContext.job->UpdateProgress(
         InstallerContext::INSTALL_WIDGET_CONFIG1,
-        "Parsing was suscessfull");
+        "Parse elements of configuration file and save them");
 }
 
 void TaskWidgetConfig::ReadLocaleFolders()
index 192bc5f..8c149bc 100644 (file)
@@ -44,6 +44,9 @@ struct InstallerContext
     typedef enum InstallStepEnum
     {
         INSTALL_START = 0,
+        INSTALL_CHECK_FILE,
+        INSTALL_CREATE_TEMPDIR,
+        INSTALL_UNZIP_FILES,
         INSTALL_WIDGET_CONFIG1,
         INSTALL_WIDGET_CONFIG2,
         INSTALL_WIDGET_CONFIG3,
index 8c1c5b8..eeaf53f 100644 (file)
@@ -18,6 +18,7 @@
 #include <widget_uninstall/task_db_update.h>
 #include <widget_uninstall/task_remove_files.h>
 #include <widget_uninstall/task_smack.h>
+#include <pkg-manager/pkgmgr_signal.h>
 
 using namespace WrtDB;
 
@@ -28,8 +29,7 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
     Job(Uninstallation),
     JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
 {
-    WidgetDAO dao(widgetHandle);
-
+    using namespace PackageManager;
     m_context.widgetHandle = widgetHandle;
     m_context.removeStarted = false;
     m_context.removeFinished = false;
@@ -40,6 +40,15 @@ JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
     AddTask(new TaskCheck(m_context));
     AddTask(new TaskRemoveFiles(m_context));
     AddTask(new TaskDbUpdate(m_context));
+
+    WrtDB::WidgetDAOReadOnly dao(widgetHandle);
+    std::string pkgname = DPL::ToUTF8String(*dao.getPkgname());
+    // send start signal of pkgmgr
+    if (PkgmgrSignalSingleton::Instance().setPkgname(pkgname)) {
+        PkgmgrSignalSingleton::Instance().sendSignal(
+                    PKGMGR_START_KEY,
+                    PKGMGR_START_UNINSTALL);
+    }
 }
 
 WidgetHandle JobWidgetUninstall::getRemovedWidgetHandle() const
@@ -59,9 +68,17 @@ bool JobWidgetUninstall::getRemoveFinishedFlag() const
 
 void JobWidgetUninstall::SendProgress()
 {
+    using namespace PackageManager;
     if (!getRemoveStartedFlag() ||
         (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
         if (NULL != getInstallerStruct().progressCallback) {
+            // send progress signal of pkgmgr
+            std::ostringstream percent;
+            percent << static_cast<int>(GetProgressPercent());
+            PkgmgrSignalSingleton::Instance().sendSignal(
+                        PKGMGR_PROGRESS_KEY,
+                        percent.str());
+
             LogDebug("Call widget uninstall progressCallback");
             getInstallerStruct().progressCallback(
                     getInstallerStruct().userParam,
@@ -72,6 +89,12 @@ void JobWidgetUninstall::SendProgress()
 
 void JobWidgetUninstall::SendFinishedSuccess()
 {
+    using namespace PackageManager;
+    // send signal of pkgmgr
+    PkgmgrSignalSingleton::Instance().sendSignal(
+                PKGMGR_END_KEY,
+                PKGMGR_END_SUCCESS);
+
     LogDebug("Call widget uninstall success finishedCallback");
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
             getRemovedWidgetHandle(),Exceptions::Success);
@@ -79,9 +102,15 @@ void JobWidgetUninstall::SendFinishedSuccess()
 
 void JobWidgetUninstall::SendFinishedFailure()
 {
+    using namespace PackageManager;
     LogError("Error in uninstallation step: " << m_exceptionCaught);
     LogError("Message: " << m_exceptionMessage);
 
+    // send signal of pkgmgr
+    PkgmgrSignalSingleton::Instance().sendSignal(
+                PKGMGR_END_KEY,
+                PKGMGR_END_FAILURE);
+
     LogDebug("Call widget uninstall failure finishedCallback");
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
         getRemovedWidgetHandle(), m_exceptionCaught); //TODO
index e1eb8d4..c6b187d 100644 (file)
@@ -58,6 +58,7 @@ void TaskCheck::StepUninstallPreCheck()
     }
 
     LogInfo("Widget Can be uninstalled. Handle : " << m_context.widgetHandle);
+    m_context.job->SetProgressFlag(true);
     m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_CHECK,
                                   "Uninstall pre-checking Finished");
 }
index 5caed4c..f7e5c0c 100644 (file)
@@ -115,7 +115,6 @@ Jobs::JobHandle InstallerLogic::InstallWidgetFromBrowser(
 
     Jobs::Job *job = new Jobs::WidgetInstall::JobWidgetInstall(
             url,
-            icon,
             installerStruct);
 
     return AddAndStartJob(job);
index 830ca84..e9a92d7 100644 (file)
@@ -51,22 +51,6 @@ extern "C"
 {
 #endif
 
-class DatabaseConnection
-{
-  public:
-    void AttachDatabase()
-    {
-        WrtDB::WrtDatabase::attachToThreadRO();
-    }
-
-    void DetachDatabase()
-    {
-        WrtDB::WrtDatabase::detachFromThread();
-    }
-};
-
-static DPL::ScopedPtr<DatabaseConnection> g_databaseConnection;
-
 static void pkg_native_plugin_on_unload();
 static int pkg_plugin_app_is_installed(const char *pkg_name);
 static int pkg_plugin_get_installed_apps_list(const char *category,
@@ -76,22 +60,6 @@ static int pkg_plugin_get_app_detail_info(const char *pkg_name,
 static int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
         package_manager_pkg_detail_info_t *pkg_detail_info);
 
-static int is_connected()
-{
-    if (NULL == g_databaseConnection) {
-        Try {
-            g_databaseConnection.Reset(new DatabaseConnection());
-            g_databaseConnection->AttachDatabase();
-        }
-        Catch (DPL::DB::SqlConnection::Exception::Base) {
-            LogDebug("Fail to connect DB");
-            return FALSE;
-        }
-    }
-
-    return TRUE;
-}
-
 static void pkg_native_plugin_on_unload()
 {
     LogDebug("pkg_native_plugin_unload() is called");
@@ -101,23 +69,17 @@ static int pkg_plugin_app_is_installed(const char *pkg_name)
 {
     LogDebug("pkg_plugin_app_is_installed() is called");
 
-    if (FALSE == is_connected()) {
-        LogError("Fail DB Connect");
-        return FALSE;
-    }
+    WrtDB::WrtDatabase::attachToThreadRO();
+    bool result = WidgetDAOReadOnly::isWidgetInstalled(
+                     DPL::FromUTF8String(pkg_name));
+    WrtDB::WrtDatabase::detachFromThread();
 
-    Try {
-        if (WidgetDAOReadOnly::isWidgetInstalled(
-                DPL::FromUTF8String(pkg_name))) {
-            return TRUE;
-        }
-    } Catch(DPL::DB::SqlConnection::Exception::Base) {
-        LogDebug("Databas Error");
+    if (result) {
+        return TRUE;
+    } else {
+        LogDebug("Widget Not Found");
         return FALSE;
     }
-
-    LogDebug("Widget Not Found");
-    return FALSE;
 }
 
 static int pkg_plugin_get_installed_apps_list(const char * /*category*/,
@@ -128,55 +90,48 @@ static int pkg_plugin_get_installed_apps_list(const char * /*category*/,
     package_manager_pkg_info_t *pkg_list = NULL;
     package_manager_pkg_info_t *pkg_last = NULL;
 
-    Try {
-        if (FALSE == is_connected()) {
-            LogError("Fail DB Connect");
+    WrtDB::WrtDatabase::attachToThreadRO();
+    WidgetHandleList hndlList = WidgetDAO::getHandleList();
+    *count = 0;
+
+    FOREACH(iterator, hndlList) {
+        package_manager_pkg_info_t *pkg_info =
+            static_cast<package_manager_pkg_info_t*>
+            (malloc(sizeof(package_manager_pkg_info_t)));
+        if (NULL == pkg_info) {
+            LogError("Error in malloc");
+            WrtDB::WrtDatabase::detachFromThread();
             return FALSE;
         }
 
-        WidgetHandleList hndlList = WidgetDAO::getHandleList();
-        *count = 0;
-
-        FOREACH(iterator, hndlList) {
-            package_manager_pkg_info_t *pkg_info =
-                static_cast<package_manager_pkg_info_t*>
-                (malloc(sizeof(package_manager_pkg_info_t)));
-            if (NULL == pkg_info) {
-                LogError("Error in malloc");
-                return FALSE;
-            }
-
-            if (NULL == pkg_list) {
-                pkg_list = pkg_info;
-                pkg_last = pkg_info;
-            } else {
-                pkg_last->next = pkg_info;
-            }
-
-            WidgetDAO widget(*iterator);
-            DPL::Optional<DPL::String> pkgname = widget.getPkgname();
-            strncpy(pkg_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
-            if(!pkgname.IsNull()) {
-                snprintf(pkg_info->pkg_name, PKG_NAME_STRING_LEN_MAX, "%s",
-                        DPL::ToUTF8String(*pkgname).c_str());
-            }
-
-            DPL::Optional<DPL::String> version = widget.getVersion();
-            if (!version.IsNull()) {
-                strncpy(pkg_info->version,
-                        DPL::ToUTF8String(*version).c_str(),
-                        PKG_VERSION_STRING_LEN_MAX);
-            }
-
-            (*count)++;
+        if (NULL == pkg_list) {
+            pkg_list = pkg_info;
             pkg_last = pkg_info;
+        } else {
+            pkg_last->next = pkg_info;
         }
-        *list = pkg_list;
-    }
-    Catch (WidgetDAO::Exception::DatabaseError) {
-        LogError("Database Error");
-        return FALSE;
+
+        WidgetDAO widget(*iterator);
+        DPL::Optional<DPL::String> pkgname = widget.getPkgname();
+        strncpy(pkg_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
+        if(!pkgname.IsNull()) {
+            snprintf(pkg_info->pkg_name, PKG_NAME_STRING_LEN_MAX, "%s",
+                    DPL::ToUTF8String(*pkgname).c_str());
+        }
+
+        DPL::Optional<DPL::String> version = widget.getVersion();
+        if (!version.IsNull()) {
+            strncpy(pkg_info->version,
+                    DPL::ToUTF8String(*version).c_str(),
+                    PKG_VERSION_STRING_LEN_MAX);
+        }
+
+        (*count)++;
+        pkg_last = pkg_info;
     }
+    *list = pkg_list;
+    WrtDB::WrtDatabase::detachFromThread();
+
     return TRUE;
 }
 
@@ -185,73 +140,65 @@ static int pkg_plugin_get_app_detail_info(const char *pkg_name,
 {
     LogDebug("pkg_plugin_get_app_detail_info() is called");
 
-    Try {
-        if (FALSE == is_connected()) {
-            LogError("Fail DB Connect");
-            return FALSE;
-        }
-
-        int handle = WidgetDAOReadOnly::getHandle(
-                        DPL::FromUTF8String(pkg_name));
-        WidgetDAO widget(handle);
+    WrtDB::WrtDatabase::attachToThreadRO();
+    int handle = WidgetDAOReadOnly::getHandle(
+                    DPL::FromUTF8String(pkg_name));
+    WidgetDAO widget(handle);
 
-        DPL::Optional<DPL::String> version = widget.getVersion();
-        DPL::Optional<DPL::String> id = widget.getGUID();
-        DPL::Optional<DPL::String> locale = widget.getDefaultlocale();
+    DPL::Optional<DPL::String> version = widget.getVersion();
+    DPL::Optional<DPL::String> id = widget.getGUID();
+    DPL::Optional<DPL::String> locale = widget.getDefaultlocale();
 
-        if (!version.IsNull()) {
-            strncpy(pkg_detail_info->version,
-                    DPL::ToUTF8String(*version).c_str(),
-                    PKG_VERSION_STRING_LEN_MAX);
-        }
-        snprintf(pkg_detail_info->optional_id, PKG_NAME_STRING_LEN_MAX, "%d",
-               handle);
-        WidgetLocalizedInfo localizedInfo;
-
-        if (locale.IsNull()) {
-            LogError("is NULL");
-            DPL::String languageTag(L"");
-            localizedInfo = widget.getLocalizedInfo(languageTag);
-        } else {
-            localizedInfo = widget.getLocalizedInfo(*locale);
-        }
-        DPL::Optional<DPL::String> desc(localizedInfo.description);
-
-        if (!desc.IsNull()) {
-            strncpy(pkg_detail_info->pkg_description,
-                    DPL::ToUTF8String(*desc).c_str(),
-                    PKG_VALUE_STRING_LEN_MAX);
-        }
-        strncpy(pkg_detail_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
-        strncpy(pkg_detail_info->pkg_name, pkg_name, PKG_NAME_STRING_LEN_MAX);
-
-        /* set installed time */
-        pkg_detail_info->installed_time = widget.getInstallTime();
-
-        /* set Widget size */
-        DPL::String pkgName = DPL::FromUTF8String(pkg_name);
-        std::string installPath = WidgetConfig::GetWidgetBasePath(pkgName);
-        std::string persistentPath =
-            WidgetConfig::GetWidgetPersistentStoragePath(pkgName);
-        std::string tempPath =
-            WidgetConfig::GetWidgetTemporaryStoragePath(pkgName);
-        installPath += "/";
-        tempPath += "/";
-        persistentPath += "/";
-
-        size_t installedSize = Utils::getFolderSize(installPath);
-        size_t persistentSize = Utils::getFolderSize(persistentPath);
-        size_t appSize = installedSize - persistentSize;
-        size_t dataSize = persistentSize + Utils::getFolderSize(tempPath);
-
-        pkg_detail_info->installed_size = GET_DIRECTORY_SIZE_KB(installedSize);
-        pkg_detail_info->app_size = GET_DIRECTORY_SIZE_KB(appSize);
-        pkg_detail_info->data_size = GET_DIRECTORY_SIZE_KB(dataSize);
+    if (!version.IsNull()) {
+        strncpy(pkg_detail_info->version,
+                DPL::ToUTF8String(*version).c_str(),
+                PKG_VERSION_STRING_LEN_MAX);
     }
-    Catch (WidgetDAO::Exception::DatabaseError) {
-        LogError("Database Error");
-        return FALSE;
+    snprintf(pkg_detail_info->optional_id, PKG_NAME_STRING_LEN_MAX, "%d",
+           handle);
+    WidgetLocalizedInfo localizedInfo;
+
+    if (locale.IsNull()) {
+        LogError("is NULL");
+        DPL::String languageTag(L"");
+        localizedInfo = widget.getLocalizedInfo(languageTag);
+    } else {
+        localizedInfo = widget.getLocalizedInfo(*locale);
+    }
+    DPL::Optional<DPL::String> desc(localizedInfo.description);
+
+    if (!desc.IsNull()) {
+        strncpy(pkg_detail_info->pkg_description,
+                DPL::ToUTF8String(*desc).c_str(),
+                PKG_VALUE_STRING_LEN_MAX);
     }
+    strncpy(pkg_detail_info->pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX);
+    strncpy(pkg_detail_info->pkg_name, pkg_name, PKG_NAME_STRING_LEN_MAX);
+
+    /* set installed time */
+    pkg_detail_info->installed_time = widget.getInstallTime();
+
+    /* set Widget size */
+    DPL::String pkgName = DPL::FromUTF8String(pkg_name);
+    std::string installPath = WidgetConfig::GetWidgetBasePath(pkgName);
+    std::string persistentPath =
+        WidgetConfig::GetWidgetPersistentStoragePath(pkgName);
+    std::string tempPath =
+        WidgetConfig::GetWidgetTemporaryStoragePath(pkgName);
+    installPath += "/";
+    tempPath += "/";
+    persistentPath += "/";
+
+    size_t installedSize = Utils::getFolderSize(installPath);
+    size_t persistentSize = Utils::getFolderSize(persistentPath);
+    size_t appSize = installedSize - persistentSize;
+    size_t dataSize = persistentSize + Utils::getFolderSize(tempPath);
+
+    pkg_detail_info->installed_size = GET_DIRECTORY_SIZE_KB(installedSize);
+    pkg_detail_info->app_size = GET_DIRECTORY_SIZE_KB(appSize);
+    pkg_detail_info->data_size = GET_DIRECTORY_SIZE_KB(dataSize);
+
+    WrtDB::WrtDatabase::detachFromThread();
     return TRUE;
 }
 
diff --git a/src/pkg-manager/pkgmgr_signal.cpp b/src/pkg-manager/pkgmgr_signal.cpp
new file mode 100644 (file)
index 0000000..700d670
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * 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      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/singleton_safe_impl.h>
+#include <dpl/log/log.h>
+#include <pkgmgr_installer.h>
+#include <pkg-manager/pkgmgr_signal.h>
+
+IMPLEMENT_SAFE_SINGLETON(PackageManager::PkgmgrSignal)
+
+namespace PackageManager {
+
+PkgmgrSignal::PkgmgrSignal() :
+    m_initialized(false),
+    m_handle(NULL),
+    m_noPopup(false),
+    m_reqType(PKGMGR_REQ_INVALID)
+{
+}
+
+PkgmgrSignal::~PkgmgrSignal()
+{
+}
+
+bool PkgmgrSignal::initialize(int argc, char* argv[])
+{
+    if(m_handle)
+    {
+        LogInfo("Release already allocated pkgmgr handle");
+        pkgmgr_installer_free(m_handle);
+        m_handle = NULL;
+    }
+
+    m_handle = pkgmgr_installer_new();
+    if(!m_handle) {
+        LogDebug("Fail to get pkgmgr installer handle");
+        return false;
+    }
+
+    // set information from pkgmgr
+    if (!pkgmgr_installer_receive_request(
+                m_handle, argc, argv))
+    {
+        m_noPopup = pkgmgr_installer_is_quiet(m_handle);
+        m_reqType = pkgmgr_installer_get_request_type(m_handle);
+        if (m_reqType != PKGMGR_REQ_INSTALL &&
+                m_reqType != PKGMGR_REQ_UNINSTALL)
+        {
+            LogDebug("Fail to get request type of pkgmgr");
+            pkgmgr_installer_free(m_handle);
+            m_handle = NULL;
+            return false;
+        }
+    } else {
+        LogDebug("Fail to get information of pkgmgr's request");
+        pkgmgr_installer_free(m_handle);
+        m_handle = NULL;
+        return false;
+    }
+
+    m_type = PKGMGR_WEBAPP_TYPE;
+    m_initialized = true;
+    return true;
+}
+
+bool PkgmgrSignal::deinitialize()
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+        return false;
+    }
+
+    pkgmgr_installer_free(m_handle);
+    m_handle = NULL;
+    m_initialized = false;
+    return true;
+}
+
+bool PkgmgrSignal::setPkgname(std::string name)
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+        return false;
+    }
+
+    if (name.empty())
+    {
+        LogDebug("name is empty");
+        return false;
+    }
+
+    m_pkgname = name;
+    LogInfo("Success to set tizen package name: " << m_pkgname);
+
+    return true;
+}
+
+bool PkgmgrSignal::sendSignal(std::string key, std::string value) const
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+        return false;
+    }
+
+    if (key.empty() || value.empty())
+    {
+        LogDebug("key or value is empty");
+        return false;
+    }
+
+    if (m_handle == NULL || m_type.empty() || m_pkgname.empty())
+    {
+        LogDebug("Some data of PkgmgrSignal is empty");
+        return false;
+    }
+
+    // send pkgmgr signal
+    if (pkgmgr_installer_send_signal(
+                m_handle, m_type.c_str(), m_pkgname.c_str(),
+                key.c_str(), value.c_str()))
+    {
+        LogDebug("Fail to send pkgmgr signal");
+        return false;
+    }
+
+    LogInfo("Success to send pkgmgr signal: " << key <<
+            " - " << value);
+    return true;
+}
+
+std::string PkgmgrSignal::getPkgname() const
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+    }
+
+    return m_pkgname;
+}
+
+int PkgmgrSignal::getRequestedType() const
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+    }
+
+    return m_reqType;
+}
+
+bool PkgmgrSignal::isNoPopupRequired() const
+{
+    if (!m_initialized)
+    {
+        LogDebug("PkgmgrSingal not yet intialized");
+    }
+
+    return m_noPopup;
+}
+} // PackageManager
diff --git a/src/pkg-manager/pkgmgr_signal.h b/src/pkg-manager/pkgmgr_signal.h
new file mode 100644 (file)
index 0000000..6c4e043
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef WRT_PKGMGR_SIGNAL_H_
+#define WRT_PKGMGR_SINGAL_H_
+
+#include <dpl/singleton.h>
+#include <pkgmgr_installer.h>
+
+namespace PackageManager{
+
+#define PKGMGR_WEBAPP_TYPE          "wgt"
+#define PKGMGR_START_KEY            "start"
+#define PKGMGR_START_INSTALL        "install"
+#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"
+
+typedef pkgmgr_installer* PkgmgrHandle;
+
+class PkgmgrSignal
+{
+    public:
+        bool initialize(int argc, char* argv[]);
+        bool deinitialize();
+        bool setPkgname(std::string name);
+        bool sendSignal(std::string key, std::string value) const;
+        std::string getPkgname() const;
+        int getRequestedType() const;
+        bool isNoPopupRequired() const;
+
+    private:
+        bool m_initialized;
+        PkgmgrHandle m_handle;
+        std::string m_type;
+        std::string m_pkgname;
+        bool m_noPopup;
+        int m_reqType;
+
+        PkgmgrSignal();
+        ~PkgmgrSignal();
+
+        friend class DPL::Singleton<PkgmgrSignal>;
+};
+
+typedef DPL::Singleton<PkgmgrSignal> PkgmgrSignalSingleton;
+
+} // PackageManager
+
+#endif // WRT_PKGMGR_SIGNAL_H_
+
index 9065231..f95f30b 100644 (file)
@@ -22,6 +22,10 @@ SET(WRT_INSTALLER_DIR
     ${INSTALLER_SRC_DIR}/wrt-installer
     )
 
+SET(PKG_MANAGER_DIR
+    ${INSTALLER_SRC_DIR}/pkg-manager
+    )
+
 SET(WRT_INSTALLER_SOURCES
     ${WRT_INSTALLER_DIR}/wrt_installer.cpp
     ${WRT_INSTALLER_DIR}/wrt_installer_api.cpp
@@ -30,6 +34,7 @@ SET(WRT_INSTALLER_SOURCES
     ${WRT_INSTALLER_DIR}/language_subtag_rst_tree.cpp
     ${WRT_INSTALLER_DIR}/installer_main_thread.cpp
     ${WRT_INSTALLER_DIR}/option_parser.cpp
+    ${PKG_MANAGER_DIR}/pkgmgr_signal.cpp
 )
 
 PKG_CHECK_MODULES(WRT_INSTALLER_DEPS
@@ -38,6 +43,7 @@ PKG_CHECK_MODULES(WRT_INSTALLER_DEPS
     REQUIRED)
 
 INCLUDE_DIRECTORIES(
+    ${PKG_MANAGER_DIR}
     ${WRT_INSTALLER_DEP_INCLUDES}
     ${WRT_INSTALLER_INCLUDES}
     ${WRT_INSTALLER_DEPS_INCLUDE_DIRS}
index b4cf831..76fa1c5 100644 (file)
 #include <dpl/optional_typedefs.h>
 #include <dpl/string.h>
 #include "option_parser.h"
+#include <parser_runner.h>
+#include <widget_parser.h>
+#include <root_parser.h>
+#include <pkg-manager/pkgmgr_signal.h>
 
-#define PKGMGR_SEND_SIG(installer, pkg_name, key, val) \
-    if(pkgmgr_installer_send_signal(installer, PKG_TYPE, pkg_name, key, val)) {\
-        LogDebug("Failed to send signal to pkgmgr");                           \
-    }
 #define NOFILE_CNT_FOR_INSTALLER 9999
 
 using namespace WrtDB;
+
 namespace { // anonymous
 const char AUL_ARG_KEY[] = "widget_arg";
-const char PKGMGR_START_KEY[] = "start";
-const char PKGMGR_END_KEY[] = "end";
-const char PKG_TYPE[] = "wgt";
-const char PKGMGR_PROGRESS_KEY[] = "install_percent";
-const char PKGMGR_OK_VAL[] = "ok";
-const char PKGMGR_FAIL_VAL[] = "fail";
-const char PKGMGR_INSTALL_MSG[] = "Install widget";
-const char PKGMGR_UNINSTALL_MSG[] = "Uninstall widget";
+const char * const PKGMGR_INSTALL_MSG = "Install widget";
+const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
 
 const double BASE_LAYOUT_W = 720.0f;
 const double BASE_LAYOUT_H = 1280.0f;
@@ -76,10 +71,8 @@ WrtInstaller::WrtInstaller(int argc, char **argv) :
     m_numPluginsToInstall(0),
     m_totalPlugins(0),
     m_returnStatus(-1),
-    m_installer(NULL),
     m_installByPkgmgr(false),
     m_quiet(true),
-    m_sendSig(false),
     m_popup(NULL),
     m_startupPluginInstallation(false)
 {
@@ -216,17 +209,15 @@ void WrtInstaller::OnCreate()
             AddStep(&WrtInstaller::installFromWebStep);
         }
     } else if (arg.find("backend") != std::string::npos) {
+        using namespace PackageManager;
         m_installByPkgmgr = true;
-        m_quiet = false;
-        m_sendSig = true;
 
-        m_installer = pkgmgr_installer_new();
-        if (!pkgmgr_installer_receive_request(m_installer, m_argc, m_argv)) {
-            //For package manager
-            int reqType = pkgmgr_installer_get_request_type(m_installer);
-            m_quiet = pkgmgr_installer_is_quiet(m_installer);
+        PkgmgrSignalSingleton::Instance().initialize(m_argc, m_argv);
+        m_quiet = PkgmgrSignalSingleton::Instance().isNoPopupRequired();
+
+        int reqType = PkgmgrSignalSingleton::Instance().getRequestedType();
 
-            switch (reqType) {
+        switch (reqType) {
             case PKGMGR_REQ_INSTALL:
                 m_packagePath = m_argv[4];
                 m_installPolicy = WRT_WIM_POLICY_NEVER_UPDATE;
@@ -239,7 +230,6 @@ void WrtInstaller::OnCreate()
             default:
                 LogDebug("Not available type");
                 break;
-            }
         }
     } else {
         // Launch widget based on application basename
@@ -586,13 +576,8 @@ void WrtInstaller::staticWrtStatusCallback(int handle,
         LogDebug("Step failed");
         This->m_returnStatus = -1;
 
-        if (This->m_installByPkgmgr) {
-            PKGMGR_SEND_SIG(This->m_installer, This->m_name.c_str(),
-                            PKGMGR_END_KEY, PKGMGR_FAIL_VAL);
-        }
-
         if (!This->m_quiet) {
-            resultMsg +=  L" : " + DPL::FromUTF8String(PKGMGR_FAIL_VAL);
+            resultMsg +=  L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
             This->m_popup->showPopup(This, resultMsg, failResultCallback);
         } else {
             This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
@@ -660,12 +645,7 @@ void WrtInstaller::staticWrtStatusCallback(int handle,
         LogDebug("Status succesfull");
         This->m_handle = handle;
         This->m_returnStatus = 0;
-        resultMsg +=  L" : " + DPL::FromUTF8String(PKGMGR_OK_VAL);
-
-        if (This->m_installByPkgmgr) {
-            PKGMGR_SEND_SIG(This->m_installer, This->m_name.c_str(),
-                            PKGMGR_END_KEY, PKGMGR_OK_VAL);
-        }
+        resultMsg +=  L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
 
         if (!This->m_quiet) {
             This->m_popup->showPopup(This, resultMsg, showResultCallback);
@@ -784,27 +764,6 @@ void WrtInstaller::staticWrtInstallProgressCallback(float percent,
     LogInfo(" progress: " << percent <<
             " description: " << description);
 
-    if (This->m_installByPkgmgr) {
-        if (This->m_sendSig) {
-            std::string desc = description;
-            size_t index = desc.find(" ");
-            std::string widgetId = desc.substr(0, index - 1);
-            This->m_name = desc.substr(index + 1, desc.length() - index);
-
-            PKGMGR_SEND_SIG(This->m_installer, widgetId.c_str(),
-                            PKGMGR_START_KEY, "install");
-            PKGMGR_SEND_SIG(This->m_installer, widgetId.c_str(),
-                            "change_pkg_name", This->m_name.c_str());
-
-            This->m_sendSig = false;
-        }
-        LogDebug("Broadcast Progress, pkgname " << This->m_name);
-
-        percentStr << static_cast<int>(percent);
-        PKGMGR_SEND_SIG(This->m_installer, This->m_name.c_str(),
-                        PKGMGR_PROGRESS_KEY, percentStr.str().c_str());
-    }
-
     if (!This->m_quiet) {
         This->m_popup->init();
         elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
@@ -819,19 +778,6 @@ void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
     LogInfo(" progress: " << percent <<
             " description: " << description);
 
-    if (This->m_installByPkgmgr) {
-        if (This->m_sendSig) {
-            PKGMGR_SEND_SIG(This->m_installer, This->m_name.c_str(),
-                            PKGMGR_START_KEY, "uninstall");
-            This->m_sendSig = false;
-        }
-        LogDebug("Broadcast Progress, pkgname " << This->m_name);
-
-        percentStr << static_cast<int>(percent);
-        PKGMGR_SEND_SIG(This->m_installer, This->m_name.c_str(),
-                        PKGMGR_PROGRESS_KEY, percentStr.str().c_str());
-    }
-
     if (!This->m_quiet) {
         This->m_popup->init();
         elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
index 04cc672..1fdc8c4 100644 (file)
@@ -142,11 +142,8 @@ class WrtInstaller :
     size_t m_numPluginsToInstall;
     size_t m_totalPlugins;
     int m_returnStatus;
-    //For package manager
-    pkgmgr_installer *m_installer;
     bool m_installByPkgmgr;
     bool m_quiet;
-    bool m_sendSig;
     InstallerPopup *m_popup;
     bool m_startupPluginInstallation;
     std::string m_webAppUrl;