[Engine] patch for normal support of pkgmgr signal and thread problem 1.0_post
authorYunchan Cho <yunchan.cho@samsung.com>
Thu, 7 Jun 2012 08:39:48 +0000 (17:39 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Wed, 20 Jun 2012 01:54:56 +0000 (10:54 +0900)
Change-Id: I9b19a9f2a4a1d10138f3299a673048afa78b84ab

modules/core/include/dpl/thread.h
modules/core/src/thread.cpp
modules/localization/include/dpl/localization/w3c_file_localization.h
modules/localization/src/localization_utils.cpp
modules/localization/src/w3c_file_localization.cpp
modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/dao/widget_dao_read_only.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/widget_dao_read_only.h
modules/widget_dao/include/dpl/wrt-dao-rw/widget_dao.h
modules/widget_dao/orm/wrt_db

index b49ee09..422239d 100644 (file)
@@ -172,6 +172,12 @@ public:
     void Quit();
 
     /**
+     * Checks if current thread is main one
+     * Returns true if it is main program thread, false otherwise
+     */
+    static bool IsMainThread();
+
+    /**
      * Current thread retrieval
      * Returns DPL thread handle or NULL if it is main program thread
      */
@@ -281,7 +287,7 @@ private:
             // If yes, pthread_exit(NULL) is required
             if (!g_TLSforMainCreated)
             {
-                if (Thread::GetCurrentThread() == NULL)
+                if (Thread::IsMainThread())
                 {
                     g_TLSforMainCreated = true;
                     atexit(&MainThreadExitClean);
index ec7166a..0a06b0a 100644 (file)
@@ -89,6 +89,11 @@ Thread::~Thread()
     m_eventList.clear();
 }
 
+bool Thread::IsMainThread()
+{
+    return (pthread_equal(pthread_self(), g_mainThread));
+}
+
 Thread *Thread::GetCurrentThread()
 {
     if (pthread_equal(pthread_self(), g_mainThread))
index d52bd6c..156923c 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef W3C_FILE_LOCALIZATION_H
 #define W3C_FILE_LOCALIZATION_H
 
-#include <dpl/wrt-dao-rw/widget_dao.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
 #include <dpl/optional.h>
 #include <dpl/string.h>
 #include <list>
index 9a63800..8dc7e3b 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <dpl/foreach.h>
 #include <dpl/mutex.h>
-#include <dpl/wrt-dao-rw/widget_dao.h>
 
 namespace {
 
index bb41c5d..3860ffb 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <dpl/localization/w3c_file_localization.h>
 
-#include <dpl/wrt-dao-rw/widget_dao.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
 #include <dpl/localization/localization_utils.h>
 
 #include <dpl/log/log.h>
@@ -107,7 +107,7 @@ DPL::Optional<DPL::String> getFilePathInWidgetPackageFromUrl(
         const DPL::String &url)
 {
     DPL::String req = url;
-    WidgetDAO dao(widgetHandle);
+    WidgetDAOReadOnly dao(widgetHandle);
 
     if (req.find(WIDGET_URI_BEGIN) == 0) {
         req.erase(0, WIDGET_URI_BEGIN.length());
@@ -141,7 +141,7 @@ DPL::Optional<DPL::String> getFilePathInWidgetPackage(
         const LanguageTagsList &languageTags,
         const DPL::String& file)
 {
-    WidgetDAO dao(widgetHandle);
+    WidgetDAOReadOnly dao(widgetHandle);
     return GetFilePathInWidgetPackageInternal(languageTags, dao.getPath(), file);
 }
 
@@ -149,10 +149,10 @@ DPL::OptionalString getStartFile(const WrtDB::DbWidgetHandle widgetHandle)
 {
     using namespace LocalizationUtils;
 
-    WidgetDAO dao(widgetHandle);
+    WidgetDAOReadOnly dao(widgetHandle);
 
-    WidgetDAO::LocalizedStartFileList locList = dao.getLocalizedStartFileList();
-    WidgetDAO::WidgetStartFileList list = dao.getStartFileList();
+    WidgetDAOReadOnly::LocalizedStartFileList locList = dao.getLocalizedStartFileList();
+    WidgetDAOReadOnly::WidgetStartFileList list = dao.getStartFileList();
     LanguageTagsList tagsList = LocalizationUtils::GetUserAgentLanguageTags();
 
     DPL::OptionalString defaultLoc = dao.getDefaultlocale();
@@ -181,10 +181,10 @@ DPL::OptionalString getStartFile(const WrtDB::DbWidgetHandle widgetHandle)
 OptionalWidgetIcon getIcon(const WrtDB::DbWidgetHandle widgetHandle)
 {
     using namespace LocalizationUtils;
-    WidgetDAO dao(widgetHandle);
+    WidgetDAOReadOnly dao(widgetHandle);
 
-    WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
-    WidgetDAO::WidgetIconList list = dao.getIconList();
+    WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
+    WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
     LanguageTagsList tagsList = LocalizationUtils::GetUserAgentLanguageTags();
 
     DPL::OptionalString defaultLoc = dao.getDefaultlocale();
@@ -219,8 +219,8 @@ WidgetIconList getValidIconsList(
         const LanguageTagsList &languageTags)
 {
     using namespace LocalizationUtils;
-    WidgetDAO dao(widgetHandle);
-    WidgetDAO::WidgetIconList list = dao.getIconList();
+    WidgetDAOReadOnly dao(widgetHandle);
+    WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
 
     WidgetIconList outlist;
 
@@ -249,10 +249,10 @@ OptionalWidgetStartFileInfo getStartFileInfo(
 
     WidgetStartFileInfo info;
 
-    WidgetDAO dao(widgetHandle);
-    WidgetDAO::LocalizedStartFileList locList =
+    WidgetDAOReadOnly dao(widgetHandle);
+    WidgetDAOReadOnly::LocalizedStartFileList locList =
         dao.getLocalizedStartFileList();
-    WidgetDAO::WidgetStartFileList list = dao.getStartFileList();
+    WidgetDAOReadOnly::WidgetStartFileList list = dao.getStartFileList();
 
     FOREACH(tag, tagsList)
     {
@@ -286,7 +286,7 @@ WidgetLocalizedInfo getLocalizedInfo(const WrtDB::DbWidgetHandle handle)
 {
     LanguageTagList languages =
         LocalizationUtils::GetUserAgentLanguageTags();
-    WidgetDAO dao(handle);
+    WidgetDAOReadOnly dao(handle);
     DPL::OptionalString dl = dao.getDefaultlocale();
     if (!!dl) {
         languages.push_back(*dl);
index bc7fcc6..5a7d801 100644 (file)
@@ -124,9 +124,10 @@ void WidgetDAO::setPkgName(const DPL::OptionalString& pkgName)
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
 }
 
-DbWidgetHandle WidgetDAO::registerWidget(const WidgetRegisterInfo &widgetRegInfo,
-                                       const IWacSecurity &wacSecurity,
-                                       const LanguageTagsList& languageTags)
+void WidgetDAO::registerWidget(
+        const DbWidgetHandle& widgetHandle,
+        const WidgetRegisterInfo &widgetRegInfo,
+        const IWacSecurity &wacSecurity)
 {
     LogDebug("Registering widget");
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
@@ -135,16 +136,12 @@ DbWidgetHandle WidgetDAO::registerWidget(const WidgetRegisterInfo &widgetRegInfo
 
         //Register into WidgetInfo has to be first
         //as all other tables depend upon that
-        DbWidgetHandle widgetHandle =
-                registerWidgetInfo(widgetRegInfo, wacSecurity);
+        registerWidgetInfo(widgetHandle, widgetRegInfo, wacSecurity);
 
         registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
 
         registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
 
-        registerWidgetUserAgentLocales(
-                widgetHandle, widgetRegInfo, languageTags);
-
         registerWidgetIcons(widgetHandle, widgetRegInfo);
 
         registerWidgetStartFile(widgetHandle, widgetRegInfo);
@@ -168,8 +165,6 @@ DbWidgetHandle WidgetDAO::registerWidget(const WidgetRegisterInfo &widgetRegInfo
         registerAppService(widgetHandle, widgetRegInfo);
 
         transaction.Commit();
-
-        return widgetHandle;
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
 }
@@ -197,11 +192,14 @@ void WidgetDAO::registerWidgetExtendedInfo(DbWidgetHandle widgetHandle,
     row.Set_test_widget(regInfo.isTestWidget);
     row.Set_install_time(regInfo.installedTime);
 
+
     DO_INSERT(row, WidgetExtendedInfo)
 }
 
-DbWidgetHandle WidgetDAO::registerWidgetInfo(const WidgetRegisterInfo &regInfo,
-                                   const IWacSecurity &wacSecurity)
+void WidgetDAO::registerWidgetInfo(
+        const DbWidgetHandle& widgetHandle,
+        const WidgetRegisterInfo &regInfo,
+        const IWacSecurity &wacSecurity)
 {
     using namespace DPL::DB::ORM;
     using namespace DPL::DB::ORM::wrt;
@@ -211,6 +209,7 @@ DbWidgetHandle WidgetDAO::registerWidgetInfo(const WidgetRegisterInfo &regInfo,
     // Because of that, "Optional" is not used there
 
     WidgetInfo::Row row;
+    row.Set_app_id(widgetHandle);
     row.Set_widget_type(regInfo.type.appType);
     row.Set_widget_id(widgetConfigurationInfo.widget_id);
     row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
@@ -234,13 +233,15 @@ DbWidgetHandle WidgetDAO::registerWidgetInfo(const WidgetRegisterInfo &regInfo,
     row.Set_access_network(widgetConfigurationInfo.accessNetwork);
     row.Set_pkgname(regInfo.pkgname);
 
-    wrt::WidgetInfo::app_id::ColumnType appID;
+    Try
+    {
+        DO_INSERT(row, WidgetInfo);
+    }
+    Catch(DPL::DB::SqlConnection::Exception::Base)
     {
-        WRT_DB_INSERT(insert, WidgetInfo, &WrtDatabase::interface())
-        insert->Values(row);
-        appID = insert->Execute();
+        ReThrowMsg(WidgetDAO::Exception::DatabaseError,
+                   "Failed to register widget info.");
     }
-    return appID;
 }
 
 void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
index 02ebd28..dd4a063 100644 (file)
@@ -99,6 +99,11 @@ WidgetDAOReadOnly::WidgetDAOReadOnly(DbWidgetHandle widgetHandle) :
 {
 }
 
+WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
+    m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
+{
+}
+
 WidgetDAOReadOnly::~WidgetDAOReadOnly()
 {
 }
index 7b220c1..79fd084 100644 (file)
@@ -284,6 +284,7 @@ class WidgetDAOReadOnly
      * @param[in] widgetHandle application id of widget.
      */
     WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
+    WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
 
     /**
      * Destructor
index 356facf..5cce077 100644 (file)
@@ -29,6 +29,9 @@
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
 #include <list>
 #include <string>
+#include <sys/time.h>
+#include <ctime>
+#include <cstdlib>
 #include <dpl/exception.h>
 #include <dpl/db/orm.h>
 #include <dpl/wrt-dao-ro/config_parser_data.h>
@@ -60,13 +63,31 @@ class WidgetDAO : public WidgetDAOReadOnly
      *
      * @see WidgetRegisterInfo
      * @see UnRegisterWidget()
+     * @param[in] widgetHandle  Widget ID that will be registered.
      * @param[in] pWidgetRegisterInfo    Specified the widget's information needed to be registered.
-     * @return widget's app id issued by app manager; 0 represents a failure during register.
+     * @param[in] wacSecurity   Widget's security certificates.
      */
+    static void registerWidget(
+            const DbWidgetHandle& widgetHandle,
+            const WidgetRegisterInfo &pWidgetRegisterInfo,
+            const IWacSecurity &wacSecurity);
+
     static DbWidgetHandle registerWidget(
             const WidgetRegisterInfo &pWidgetRegisterInfo,
-            const IWacSecurity &wacSecurity,
-            const LanguageTagsList& languageTags);
+            const IWacSecurity &wacSecurity) __attribute__((deprecated))
+    {
+        //make it more precise due to very fast tests
+        struct timeval tv;
+        gettimeofday(&tv, NULL);
+        srand(time(NULL) + tv.tv_usec);
+        DbWidgetHandle widgetHandle;
+        do {
+            widgetHandle = rand();
+        } while (isWidgetInstalled(widgetHandle));
+
+        registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
+        return widgetHandle;
+    }
 
     /**
      * This method removes a widget's information from EmDB.
@@ -99,7 +120,8 @@ class WidgetDAO : public WidgetDAOReadOnly
 
   private:
     //Methods used during widget registering
-    static DbWidgetHandle registerWidgetInfo(
+    static void registerWidgetInfo(
+            const DbWidgetHandle& widgetHandle,
             const WidgetRegisterInfo &regInfo,
             const IWacSecurity &wacSecurity);
     static void registerWidgetExtendedInfo(
index 00b50cc..f1326c0 100644 (file)
@@ -18,7 +18,7 @@ SQL(
 )
 
 CREATE_TABLE(WidgetInfo)
-    COLUMN_NOT_NULL(app_id,         INTEGER,         PRIMARY KEY AUTOINCREMENT)
+    COLUMN_NOT_NULL(app_id,         INTEGER,         PRIMARY KEY)
     COLUMN(widget_type,               INT,  DEFAULT 1)
     COLUMN(widget_id,               VARCHAR(256),  DEFAULT '')
     COLUMN(widget_version,          VARCHAR(256),  DEFAULT '')