WrtDAO clean up - unused function with widget handle usage
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 29 Oct 2012 12:20:51 +0000 (13:20 +0100)
committerJihoon Chung <jihoon.chung@samsung.com>
Mon, 12 Nov 2012 08:19:00 +0000 (17:19 +0900)
[Issue#]       N/A
[Bug]          Unused functions of wrtDAO
[Cause]        N/A
[Solution]     This removes unused methods and add registerWidget method version which generates free tizen id (this is for purpose of rewriting wrt-tests-dao without widget handle)
[Verification] build all repositories, wrt-installer should be still able to install, uninstall widgets. Run: wrt-tests-dao --output=text --regexp='widget_dao_'. Two tests fails. This will be fixed in wrt-extra commit.

Change-Id: Ib0155b240c1776d104fc0e48e5ffaa854468eb97

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

index cdb99da..deb55d2 100644 (file)
@@ -128,25 +128,22 @@ void WidgetDAO::registerWidget(
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
     {
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
-        DbWidgetHandle widgetHandle = registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
-        registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
-        //TODO: remove construction from handle and move that call to registerWidgetInternal
-        // in new version external fiels should be register together with other informations
+        registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
 }
 
 void WidgetDAO::registerWidget(
-            WrtDB::DbWidgetHandle handle,
-            const WidgetRegisterInfo & widgetRegInfo,
-            const IWacSecurity &wacSecurity)
+        WrtDB::DbWidgetHandle handle,
+        const WidgetRegisterInfo &widgetRegInfo,
+        const IWacSecurity &wacSecurity)
 {
     LogDebug("Registering widget");
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
     {
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
-        registerWidgetInternal(L"", widgetRegInfo, wacSecurity, handle);
+        registerWidgetInternal(generateTizenId(), widgetRegInfo, wacSecurity, handle);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
@@ -169,7 +166,16 @@ DbWidgetHandle WidgetDAO::registerWidget(
     return widgetHandle;
 }
 
-DbWidgetHandle WidgetDAO::registerWidgetInternal(
+WidgetPkgName WidgetDAO::registerWidgetGenerateTizenId(
+            const WidgetRegisterInfo &pWidgetRegisterInfo,
+            const IWacSecurity &wacSecurity)
+{
+    WidgetPkgName widgetPkgName = generateTizenId();
+    registerWidget(widgetPkgName, pWidgetRegisterInfo, wacSecurity);
+    return widgetPkgName;
+}
+
+void WidgetDAO::registerWidgetInternal(
         const WidgetPkgName & widgetName,
         const WidgetRegisterInfo &widgetRegInfo,
         const IWacSecurity &wacSecurity,
@@ -211,7 +217,7 @@ DbWidgetHandle WidgetDAO::registerWidgetInternal(
 
     registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
 
-    return widgetHandle;
+    registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
 }
 
 void WidgetDAO::registerOrUpdateWidget(
@@ -225,10 +231,7 @@ void WidgetDAO::registerOrUpdateWidget(
         DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
 
         unregisterWidgetInternal(widgetName);
-        DbWidgetHandle widgetHandle = registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
-        registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
-        //TODO: remove construction from handle and move that call to registerWidgetInternal
-        // in new version external fiels should be register together with other informations
+        registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
         transaction.Commit();
     }
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
@@ -310,7 +313,6 @@ DbWidgetHandle WidgetDAO::registerWidgetInfo(
     }
     row.Set_back_supported(widgetConfigurationInfo.backSupported);
     row.Set_access_network(widgetConfigurationInfo.accessNetwork);
-    row.Set_pkgname(regInfo.pkgname);
     row.Set_pkg_type(regInfo.packagingType.pkgType);
 
     Try
@@ -640,11 +642,6 @@ void WidgetDAO::registerEncryptedResouceInfo(DbWidgetHandle widgetHandle,
     }
 }
 
-void WidgetDAO::registerExternalLocations(const ExternalLocationList & externals)
-{
-    registerExternalLocations(m_widgetHandle, externals);
-}
-
 void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
                                           const ExternalLocationList & externals)
 {
index 9027d94..aa54c6b 100644 (file)
@@ -88,6 +88,8 @@ WidgetInfoRow getWidgetInfoRow(int widgetHandle)
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in GetWidgetInfoRow")
 }
 
+const int MAX_TIZENID_LENGTH = 10;
+
 } // namespace
 
 
@@ -408,7 +410,7 @@ bool WidgetDAOReadOnly::isWidgetInstalled(DbWidgetHandle handle)
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to check if widget exist")
 }
 
-bool WidgetDAOReadOnly::isWidgetInstalled(DPL::String pkgName)
+bool WidgetDAOReadOnly::isWidgetInstalled(const WidgetPkgName & pkgName)
 {
     LogDebug("Checking if widget exist. package name " << pkgName);
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
@@ -1129,6 +1131,20 @@ DPL::OptionalString WidgetDAOReadOnly::getBackgroundPage() const
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get background page")
 }
 
+WidgetPkgName WidgetDAOReadOnly::generateTizenId() {
+    std::string allowed("0123456789"
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+        "abcdefghijklmnopqrstuvwxyz");
+    WidgetPkgName tizenId;
+    tizenId.resize(MAX_TIZENID_LENGTH);
+    do {
+    for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
+        tizenId[i] = allowed[rand() % allowed.length()];
+    }
+    } while (isWidgetInstalled(tizenId));
+    return tizenId;
+}
+
 #undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
 #undef SQL_CONNECTION_EXCEPTION_HANDLER_END
 #undef CHECK_WIDGET_EXISTENCE
index 3be42ed..5b66498 100644 (file)
@@ -694,7 +694,7 @@ class WidgetDAOReadOnly
     bool getBackSupported() const;
 
     static bool isWidgetInstalled(DbWidgetHandle handle);
-    static bool isWidgetInstalled(DPL::String pkgName);
+    static bool isWidgetInstalled(const WidgetPkgName & pkgName);
 
     /* This method get path of the splash image.
      *
@@ -740,6 +740,16 @@ class WidgetDAOReadOnly
      * @return Name of file containing background page
      */
     DPL::OptionalString getBackgroundPage() const;
+
+    /**
+     * @brief generateTizenId generates new tizen id
+     *
+     * If widget do not supplies it's own tizen id, this method can be used,
+     * although it should be removed in future.
+     *
+     * @return new tizen id
+     */
+    static WidgetPkgName generateTizenId();
 };
 
 } // namespace WrtDB
index 30b355c..94aba6b 100644 (file)
@@ -67,16 +67,25 @@ class WidgetDAO : public WidgetDAOReadOnly
             const WidgetRegisterInfo &widgetRegInfo,
             const IWacSecurity &wacSecurity);
 
-    static void registerWidget(
-            WrtDB::DbWidgetHandle handle,
-            const WidgetRegisterInfo &widgetRegInfo,
-            const IWacSecurity &wacSecurity) __attribute__((deprecated));
-
     static DbWidgetHandle registerWidget(
                 const WidgetRegisterInfo &pWidgetRegisterInfo,
                 const IWacSecurity &wacSecurity) __attribute__((deprecated));
 
     /**
+     * @brief registerWidgetGenerateTizenId Registers widget with auto-generated tizen id
+     *
+     * This function is disadviced and should be used only in tests.
+     * Function is not thread-safe.
+     *
+     * @param pWidgetRegisterInfo registeration information
+     * @param wacSecurity Widget's security certificates.
+     * @return pkgname generated
+     */
+    static WidgetPkgName registerWidgetGenerateTizenId(
+                const WidgetRegisterInfo &pWidgetRegisterInfo,
+                const IWacSecurity &wacSecurity);
+
+    /**
      * This method re-registers the widget information to the DB when it is installed.
      *
      * It performs unregistration and new registration of widget in db in one transaction.
@@ -91,6 +100,11 @@ class WidgetDAO : public WidgetDAOReadOnly
             const WidgetRegisterInfo &widgetRegInfo,
             const IWacSecurity &wacSecurity);
 
+    static void registerWidget(
+            WrtDB::DbWidgetHandle handle,
+            const WidgetRegisterInfo &widgetRegInfo,
+            const IWacSecurity &wacSecurity) __attribute__((deprecated));
+
     /**
      * This method removes a widget's information from EmDB.
      *
@@ -126,8 +140,6 @@ class WidgetDAO : public WidgetDAOReadOnly
      */
     void updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature);
 
-    void registerExternalLocations(const ExternalLocationList & externals) __attribute__((deprecated));
-
   private:
     //Methods used during widget registering
     static DbWidgetHandle registerWidgetInfo(
@@ -182,7 +194,7 @@ class WidgetDAO : public WidgetDAOReadOnly
     static void registerExternalLocations(DbWidgetHandle widgetHandle,
                                 const ExternalLocationList & externals);
 
-    static DbWidgetHandle registerWidgetInternal(
+    static void registerWidgetInternal(
             const WidgetPkgName & widgetName,
             const WidgetRegisterInfo &widgetRegInfo,
             const IWacSecurity &wacSecurity,