[Release] wrt-commons_0.2.148
authorsung-su.kim <sung-su.kim@samsung.com>
Wed, 14 Aug 2013 02:02:10 +0000 (11:02 +0900)
committersung-su.kim <sung-su.kim@samsung.com>
Wed, 14 Aug 2013 02:02:10 +0000 (11:02 +0900)
Change-Id: If6fa67044a807e8f5fdca217d5f0d8d4490481e7

21 files changed:
CMakeLists.txt
build/CMakeLists.txt
build/test/CMakeLists.txt
build/test/dpl-test-efl.pc.in
build/widget_interface_dao/CMakeLists.txt [new file with mode: 0644]
build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in [new file with mode: 0644]
modules/CMakeLists.txt
modules/test/include/dpl/test/test_runner.h
modules/test/src/test_runner.cpp
modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/common_dao_types.h
modules/widget_dao/include/dpl/wrt-dao-ro/config_parser_data.h
modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h
modules/widget_interface_dao/CMakeLists.txt [new file with mode: 0644]
modules/widget_interface_dao/dao/widget_interface_dao.cpp [new file with mode: 0644]
modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h [new file with mode: 0644]
modules/widget_interface_dao/orm/orm_generator_widget_interface.h [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db_definitions [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h [new file with mode: 0644]
packaging/wrt-commons.spec

index 92f1d49..6b92bd0 100644 (file)
@@ -192,6 +192,7 @@ SET(TARGET_SECURITY_ORIGIN_DAO_LIB "wrt-commons-security-origin-dao")
 SET(TARGET_CERTIFICATE_DAO_LIB "wrt-commons-certificate-dao")
 SET(TARGET_DPL_UTILS_EFL "lib${PROJECT_NAME}-utils-efl")
 SET(TARGET_I18N_DAO_RO_LIB "wrt-commons-i18n-dao-ro")
+SET(TARGET_WIDGET_INTERFACE_DAO_LIB "wrt-commons-widget-interface-dao")
 
 macro(configure_and_install_pkg PKG_FILE)
     CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
index b9598d6..b94d51f 100644 (file)
@@ -33,3 +33,4 @@ ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(support)
 ADD_SUBDIRECTORY(certificate_dao)
 ADD_SUBDIRECTORY(i18n)
+ADD_SUBDIRECTORY(widget_interface_dao)
index 710fc4e..d992952 100644 (file)
@@ -21,6 +21,7 @@
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(SYS_EFL_TEST_ENGINE
   appcore-efl
+  libxml-2.0
   REQUIRED)
 
 
index 9d6f871..056ae09 100644 (file)
@@ -6,6 +6,6 @@ includedir=${prefix}/include
 Name: dpl-test-efl
 Description: DPL Test Engine - EFL based
 Version: @VERSION@
-Requires: dpl-efl
+Requires: dpl-efl libxml-2.0
 Libs: -L${libdir} -ldpl-test-efl
 Cflags: -I${includedir}/dpl-efl
diff --git a/build/widget_interface_dao/CMakeLists.txt b/build/widget_interface_dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e726271
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+# @file        CMakeLists.txt
+# @author      Jihoon Chung (jihoon.chung@samsung.com)
+# @brief
+#
+
+configure_and_install_pkg(wrt-commons-widget-interface-dao.pc)
+
diff --git a/build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in b/build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in
new file mode 100644 (file)
index 0000000..348b178
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+exec_prefix=${prefix}
+
+libdir=${prefix}/lib
+includedir=${prefix}/include
+Name: wrt-commons-widget-interface-dao
+Description: wrt-commons-widget-interface-dao
+
+Version: @VERSION@
+Requires: dpl-efl
+Libs: -lwrt-commons-widget-interface-dao -L${libdir}
+Cflags: -I${includedir}/dpl-efl
index a80bb78..07c4c05 100644 (file)
@@ -28,6 +28,7 @@ include(rpc/config.cmake)
 include(test/config.cmake)
 include(log/config.cmake)
 ADD_SUBDIRECTORY(widget_dao)
+ADD_SUBDIRECTORY(widget_interface_dao)
 ADD_SUBDIRECTORY(security_origin_dao)
 ADD_SUBDIRECTORY(custom_handler_dao)
 ADD_SUBDIRECTORY(certificate_dao)
index 99a2cb5..ae5c712 100644 (file)
@@ -97,6 +97,10 @@ class TestRunner
     void InvalidArgs(const std::string& message = "Invalid arguments!");
     void Usage();
 
+    bool filterGroupsByXmls(const std::vector<std::string> & files);
+    bool filterByXML(std::map<std::string, bool> & casesMap);
+    void normalizeXMLTag(std::string& str, const std::string& testcase);
+
     enum Status { FAILED, IGNORED, PASS };
 
     Status RunTestCase(const TestCaseStruct& testCase);
index 126f1b0..594ba0c 100644 (file)
 #include <cstdlib>
 #include <dpl/utils/wrt_global_settings.h>
 
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
 #include <dpl/singleton_impl.h>
 IMPLEMENT_SINGLETON(DPL::Test::TestRunner)
 
+namespace {
+
+std::string getXMLNode(xmlNodePtr node)
+{
+    std::string ret;
+    xmlChar * value = xmlNodeGetContent(node);
+    ret = std::string(reinterpret_cast<char*>(value));
+    xmlFree(value);
+    return ret;
+}
+
+}
+
+
 namespace DPL {
 namespace Test {
 namespace // anonymous
@@ -89,6 +108,143 @@ void TestRunner::InitGroup(const char* name)
     m_currentGroup = name;
 }
 
+void TestRunner::normalizeXMLTag(std::string& str, const std::string& testcase)
+{
+    //Add testcase if missing
+    std::string::size_type pos = str.find(testcase);
+    if(pos != 0)
+    {
+        str = testcase + "_" + str;
+    }
+
+    //dpl test runner cannot have '-' character in name so it have to be replaced
+    // for TCT case to make comparision works
+    std::replace(str.begin(), str.end(), '-', '_');
+}
+
+bool TestRunner::filterGroupsByXmls(const std::vector<std::string> & files)
+{
+    DECLARE_EXCEPTION_TYPE(DPL::Exception, XMLError)
+
+    const std::string idPath = "/test_definition/suite/set/testcase/@id";
+
+    bool success = true;
+    std::map<std::string, bool> casesMap;
+
+    std::string testsuite;
+    if(!m_testGroups.empty())
+    {
+        for(TestCaseGroupMap::const_iterator cit = m_testGroups.begin(); cit != m_testGroups.end(); ++cit)
+        {
+            if(!cit->second.empty())
+            {
+                for(TestCaseStructList::const_iterator cj = cit->second.begin(); cj != cit->second.end(); ++cj)
+                {
+                    std::string name = cj->name;
+                    std::string::size_type st = name.find('_');
+                    if(st != std::string::npos)
+                    {
+                        name = name.substr(0, st);
+                        testsuite = name;
+                        break;
+                    }
+                }
+                if(!testsuite.empty()) break;
+            }
+        }
+    }
+
+    xmlInitParser();
+    LIBXML_TEST_VERSION
+    xmlXPathInit();
+
+    Try
+    {
+        FOREACH(file, files)
+        {
+            xmlDocPtr doc;
+            xmlXPathContextPtr xpathCtx;
+
+            doc = xmlReadFile(file->c_str(), NULL, 0);
+            if (doc == NULL) {
+                ThrowMsg(XMLError, "File Problem");
+            } else {
+                //context
+                xpathCtx = xmlXPathNewContext(doc);
+                if (xpathCtx == NULL) {
+                    ThrowMsg(XMLError,
+                             "Error: unable to create new XPath context\n");
+                }
+                xpathCtx->node = xmlDocGetRootElement(doc);
+            }
+
+            std::string result;
+            xmlXPathObjectPtr xpathObject;
+            //get requested node's values
+            xpathObject = xmlXPathEvalExpression(BAD_CAST idPath.c_str(), xpathCtx);
+            if (xpathObject == NULL)
+            {
+                ThrowMsg(XMLError, "XPath evaluation failure: " << idPath);
+            }
+            xmlNodeSetPtr nodes = xpathObject->nodesetval;
+            unsigned size = (nodes) ? nodes->nodeNr : 0;
+            LogDebug("Found " << size << " nodes matching xpath");
+            for(unsigned i = 0; i < size; ++i)
+            {
+                LogPedantic("Type: " << nodes->nodeTab[i]->type);
+                if (nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE) {
+                    xmlNodePtr curNode = nodes->nodeTab[i];
+                    result = getXMLNode(curNode);
+                    LogPedantic("Result: " << result);
+                    normalizeXMLTag(result, testsuite);
+                    casesMap.insert(make_pair(result, false));
+                }
+            }
+            //Cleanup of XPath data
+            xmlXPathFreeObject(xpathObject);
+            xmlXPathFreeContext(xpathCtx);
+            xmlFreeDoc(doc);
+        }
+    }
+    Catch(XMLError)
+    {
+        LogError("Libxml error: " << _rethrown_exception.DumpToString());
+        success = false;
+    }
+    xmlCleanupParser();
+
+    if(!filterByXML(casesMap))
+    {
+        success = false;
+    }
+
+    return success;
+}
+
+bool TestRunner::filterByXML(std::map<std::string, bool> & casesMap)
+{
+    FOREACH(group, m_testGroups) {
+        TestCaseStructList newList;
+        FOREACH(iterator, group->second)
+        {
+            if (casesMap.find(iterator->name) != casesMap.end()) {
+                casesMap[iterator->name] = true;
+                newList.push_back(*iterator);
+            }
+        }
+        group->second = newList;
+    }
+    FOREACH(cs, casesMap)
+    {
+        if(cs->second == false)
+        {
+            LogError("Cannot find testcase from XML file: " << cs->first);
+            return false;
+        }
+    }
+    return true;
+}
+
 TestRunner::Status TestRunner::RunTestCase(const TestCaseStruct& testCase)
 {
     try {
@@ -156,6 +312,11 @@ void TestRunner::RunTests()
                       collector.second->Start();
                   });
 
+    unsigned count = 0;
+    FOREACH(group, m_testGroups) {
+        count += group->second.size();
+    }
+    fprintf(stderr, "%sFound %d testcases...%s\n", GREEN_BEGIN, count, GREEN_END);
     fprintf(stderr, "%s%s%s\n", GREEN_BEGIN, "Running tests...", GREEN_END);
     FOREACH(group, m_testGroups) {
         TestCaseStructList list = group->second;
@@ -265,6 +426,10 @@ void TestRunner::Usage()
     fprintf(stderr, "  --runignored\t Run also ignored tests\n");
     fprintf(stderr, "  --list\t Show a list of Test IDs\n");
     fprintf(stderr, "  --listgroups\t Show a list of Test Group names \n");
+    fprintf(stderr, "  --only-from-xml=<xml file>\t Run only testcases specified in XML file \n"
+                    "       XML name is taken from attribute id=\"part1_part2\" as whole.\n"
+                    "       If part1 is not found (no _) then it is implicitily "
+                           "set according to suite part1 from binary tests\n");
     fprintf(
         stderr,
         "  --listingroup=<group name>\t Show a list of Test IDS in one group\n");
@@ -316,6 +481,8 @@ int TestRunner::ExecTestRunner(const ArgsList& value)
     args.erase(args.begin());
 
     bool showHelp = false;
+    bool justList = false;
+    std::vector<std::string> xmlFiles;
 
     TestResultsCollectorBasePtr currentCollector;
 
@@ -332,6 +499,7 @@ int TestRunner::ExecTestRunner(const ArgsList& value)
         const std::string listGroupsCmd = "--listgroups";
         const std::string listInGroup = "--listingroup=";
         const std::string allowChildLogs = "--allowchildlogs";
+        const std::string onlyFromXML = "--only-from-xml=";
 
         if (currentCollector) {
             if (currentCollector->ParseCollectorSpecificArg(arg)) {
@@ -376,12 +544,7 @@ int TestRunner::ExecTestRunner(const ArgsList& value)
         } else if (arg == runIgnored) {
             m_runIgnored = true;
         } else if (arg == listCmd) {
-            FOREACH(group, m_testGroups) {
-                FOREACH(test, group->second) {
-                    printf("ID:%s:%s\n", group->first.c_str(), test->name.c_str());
-                }
-            }
-            return 0;
+            justList = true;
         } else if (arg == listGroupsCmd) {
             FOREACH(group, m_testGroups) {
                 printf("GR:%s\n", group->first.c_str());
@@ -443,6 +606,26 @@ int TestRunner::ExecTestRunner(const ArgsList& value)
                 }
                 group->second = newList;
             }
+        } else if(arg.find(onlyFromXML) == 0) {
+            arg.erase(0, onlyFromXML.length());
+            if (arg.length() == 0) {
+                InvalidArgs();
+                Usage();
+                return -1;
+            }
+
+            if (arg[0] == '\'' && arg[arg.length() - 1] == '\'') {
+                arg.erase(0);
+                arg.erase(arg.length() - 1);
+            }
+
+            if (arg.length() == 0) {
+                InvalidArgs();
+                Usage();
+                return -1;
+            }
+
+            xmlFiles.push_back(arg);
         } else {
             InvalidArgs();
             Usage();
@@ -450,6 +633,25 @@ int TestRunner::ExecTestRunner(const ArgsList& value)
         }
     }
 
+    if(!xmlFiles.empty())
+    {
+        if(!filterGroupsByXmls(xmlFiles))
+        {
+            fprintf(stderr, "XML file is not correct\n");
+            return 0;
+        }
+    }
+
+    if(justList)
+    {
+        FOREACH(group, m_testGroups) {
+            FOREACH(test, group->second) {
+                printf("ID:%s:%s\n", group->first.c_str(), test->name.c_str());
+            }
+        }
+        return 0;
+    }
+
     currentCollector.reset();
 
     // Show help
index ed66aa2..f50016e 100644 (file)
@@ -717,11 +717,11 @@ void WidgetDAO::registerAppControl(DbWidgetHandle widgetHandle,
     // appControlList
     FOREACH(appControl_it, widgetConfigurationInfo.appControlList)
     {
-        DPL::String src       = appControl_it->m_src;
+        DPL::String src = appControl_it->m_src;
         DPL::String operation = appControl_it->m_operation;
-        unsigned index        = appControl_it->m_index;
-        unsigned disposition  = appControl_it->m_disposition ==
-            ConfigParserData::AppControlInfo::Disposition::INLINE ? 1 : 0;
+        unsigned index = appControl_it->m_index;
+        unsigned disposition =
+            static_cast<unsigned>(appControl_it->m_disposition);
 
         if (!appControl_it->m_uriList.empty())
         {
index 9537ce1..13ff04a 100644 (file)
@@ -359,8 +359,9 @@ namespace AppControlPrefix {
 struct WidgetAppControl
 {
     enum class Disposition {
-        WINDOW = 0,
-        INLINE
+        UNDEFINE = 0,
+        WINDOW   = 1,
+        INLINE   = 2
     };
 
     DPL::String src;       /* start uri */
index 399cbde..3069fa0 100644 (file)
@@ -160,11 +160,13 @@ class ConfigParserData
     struct AppControlInfo
     {
         enum class Disposition {
-            WINDOW = 0,
-            INLINE
+            UNDEFINE = 0,
+            WINDOW   = 1,
+            INLINE   = 2
         };
         AppControlInfo(const DPL::String& operation) :
             m_operation(operation),
+            m_disposition(Disposition::UNDEFINE),
             m_index(0)
         {}
         DPL::String m_src;
index 6d193e4..0eba4e4 100644 (file)
@@ -37,14 +37,6 @@ inline const char* GetWrtDatabaseFilePath()
 }
 
 /**
- * WRT origin widget interface database path
- */
-inline const char* GetWrtWidgetInterfaceDatabaseFilePath()
-{
-    return "/usr/share/wrt-plugins-common/widget_interface_db.sql";
-}
-
-/**
  * WRT device plugin path
  */
 inline const char* GetDevicePluginPath()
@@ -247,14 +239,6 @@ inline const char* GetCookieDatabaseFile()
     return ".cookie.db";
 }
 
-/**
- * widget interface database file name
- */
-inline const char* GetWidgetInterfaceDatabaseFile()
-{
-    return ".widget_interface.db";
-}
-
 inline const char* GetTmpDirPath()
 {
     return "/tmp";
@@ -303,6 +287,11 @@ inline const char* GetNPRuntimePluginsPath()
     return "plugins/x86";
 #endif
 }
+
+inline const char* GetBackupDatabaseSuffix()
+{
+    return ".backup";
+}
 } // namespace GlobalConfig
 } // namespace WrtDB
 
diff --git a/modules/widget_interface_dao/CMakeLists.txt b/modules/widget_interface_dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8acad9b
--- /dev/null
@@ -0,0 +1,45 @@
+SET(TARGET_WIDGET_INTERFACE_DAO_DB "Sqlite3DbWidgetInterface")
+
+ADD_CUSTOM_COMMAND( OUTPUT .widget_interface.db
+   COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db
+   COMMAND gcc -Wall -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm -E ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql
+   COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db ".read ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db
+   DEPENDS ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db
+   )
+
+ADD_CUSTOM_TARGET(${TARGET_WIDGET_INTERFACE_DAO_DB} ALL DEPENDS .widget_interface.db)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql DESTINATION share/wrt-engine/)
+
+INCLUDE(FindPkgConfig)
+
+PKG_CHECK_MODULES(WIDGET_INTERFACE_DAO_DEPS
+    glib-2.0
+    REQUIRED)
+
+SET(WIDGET_INTERFACE_DAO_INCLUDE_DIRS
+    ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/include
+    ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm
+    ${PROJECT_SOURCE_DIR}/modules/core/include
+    ${PROJECT_SOURCE_DIR}/modules/db/include
+    ${PROJECT_SOURCE_DIR}/modules/log/include
+    ${PROJECT_SOURCE_DIR}/modules/widget_dao/include
+)
+
+SET(WIDGET_INTERFACE_DAO_SOURCES
+    dao/widget_interface_dao.cpp
+)
+
+INCLUDE_DIRECTORIES(SYSTEM ${WIDGET_INTERFACE_DAO_DEPS_INCLUDE_DIRS} )
+INCLUDE_DIRECTORIES(${WIDGET_INTERFACE_DAO_INCLUDE_DIRS})
+
+ADD_LIBRARY(${TARGET_WIDGET_INTERFACE_DAO_LIB} SHARED ${WIDGET_INTERFACE_DAO_SOURCES})
+SET_TARGET_PROPERTIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} PROPERTIES SOVERSION ${API_VERSION} VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} ${TARGET_DPL_EFL} ${TARGET_DPL_DB_EFL} ${TARGET_WRT_DAO_RO_LIB} ${WIDGET_INTERFACE_DAO_DEPS_LIBRARIES})
+ADD_DEPENDENCIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} ${TARGET_WIDGET_INTERFACE_DAO_DB})
+
+INSTALL(TARGETS ${TARGET_WIDGET_INTERFACE_DAO_LIB} DESTINATION lib)
+
+INSTALL(FILES
+    include/wrt-commons/widget-interface-dao/widget_interface_dao.h
+    DESTINATION include/dpl-efl/wrt-commons/widget-interface-dao
+)
diff --git a/modules/widget_interface_dao/dao/widget_interface_dao.cpp b/modules/widget_interface_dao/dao/widget_interface_dao.cpp
new file mode 100644 (file)
index 0000000..88e13ac
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * 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      Lukasz Marek (l.marek@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <wrt-commons/widget-interface-dao/widget_interface_dao.h>
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <sys/stat.h>
+#include <dpl/db/sql_connection.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/string.h>
+#include <dpl/wrt-dao-ro/property_dao_read_only.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include "orm_generator_widget_interface.h"
+
+namespace WidgetInterfaceDB {
+using namespace DPL::DB::ORM;
+using namespace DPL::DB::ORM::widget_interface;
+
+#define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN          Try
+#define SQL_CONNECTION_EXCEPTION_HANDLER_END(message)            \
+    Catch(DPL::DB::SqlConnection::Exception::Base) {             \
+        LogError(message);                                       \
+        ReThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError, \
+                   message);                                     \
+    }
+
+namespace {
+DPL::DB::SqlConnection::Flag::Type DATABASE_FLAG =
+    DPL::DB::SqlConnection::Flag::UseLucene;
+DPL::DB::SqlConnection::Flag::Option DATABASE_OPTION =
+    DPL::DB::SqlConnection::Flag::RW;
+const char *KEY_WIDGET_ARG = "widget_arg";
+
+const char* const DATABASE_NAME = ".widget_interface.db";
+const char* const DATABASE_FILE_PATH =
+    "/usr/share/wrt-engine/widget_interface_db.sql";
+const char* const DATABASE_JOURNAL_FILENAME = "-journal";
+
+const int APP_UID = 5000;
+const int APP_GUID = 5000;
+} // anonymous namespace
+
+WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) :
+    m_widgetHandle(widgetHandle),
+    m_databaseInterface(databaseFileName(widgetHandle), DATABASE_FLAG)
+{
+    checkDatabase();
+    m_databaseInterface.AttachToThread(DATABASE_OPTION);
+}
+
+WidgetInterfaceDAO::~WidgetInterfaceDAO()
+{
+    m_databaseInterface.DetachFromThread();
+}
+
+void WidgetInterfaceDAO::checkDatabase()
+{
+    std::string databaseFile = databaseFileName(m_widgetHandle);
+    struct stat buffer;
+    if (stat(databaseFile.c_str(), &buffer) != 0) {
+        //Create fresh database
+        LogDebug("Creating database " << databaseFile);
+
+        std::fstream file;
+        file.open(DATABASE_FILE_PATH, std::ios_base::in);
+        if (!file) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Cannot create database. SQL file is missing.");
+        }
+
+        std::stringstream stream;
+        stream << file.rdbuf();
+
+        file.close();
+
+        SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+        {
+            DPL::DB::SqlConnection con(databaseFile,
+                                       DATABASE_FLAG,
+                                       DATABASE_OPTION);
+            con.ExecCommand(stream.str().c_str());
+            copyPropertiesFromWrtDatabase();
+        }
+        SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot create database")
+
+        if(chown(databaseFile.c_str(), APP_UID, APP_GUID) != 0) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Fail to change uid/guid");
+        }
+        std::string databaseJournal =
+            databaseFile + DATABASE_JOURNAL_FILENAME;
+        if(chown(databaseJournal.c_str(), APP_UID, APP_GUID) != 0) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Fail to change uid/guid");
+        }
+    }
+}
+
+void WidgetInterfaceDAO::copyPropertiesFromWrtDatabase()
+{
+    WrtDB::WrtDatabase::attachToThreadRO();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
+
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        WrtDB::PropertyDAOReadOnly::WidgetPreferenceList existing =
+            WrtDB::PropertyDAOReadOnly::GetPropertyList(m_widgetHandle);
+
+        //save all properties read from config.xml
+        FOREACH(prop, existing) {
+            std::string key = DPL::ToUTF8String(prop->key_name);
+            if (key != KEY_WIDGET_ARG) {
+                std::string value;
+                if (!prop->key_value.IsNull()) {
+                    value = DPL::ToUTF8String(*(prop->key_value));
+                }
+                bool readonly = !prop->readonly.IsNull() && (*prop->readonly);
+                setItem(key, value, readonly, true);
+            }
+        }
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END(
+        "Cannot copy properties read from config.xml");
+
+    WrtDB::WrtDatabase::detachFromThread();
+    m_databaseInterface.DetachFromThread();
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+                                 const std::string& value,
+                                 bool readOnly)
+{
+    setItem(key, value, readOnly, false);
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+                                 const std::string& value,
+                                 bool readOnly,
+                                 bool fromConfigXml)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        ScopedTransaction tran(&m_databaseInterface);
+        //check if key exists
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        std::list<Properties::Row> rows = select.GetRowList();
+
+        if (rows.empty()) {
+            Properties::Insert insert(&m_databaseInterface);
+            Properties::Row row;
+            row.Set_key(DPL::FromUTF8String(key));
+            row.Set_value(DPL::FromUTF8String(value));
+            row.Set_readonly(readOnly ? 1 : 0);
+            row.Set_configxml(fromConfigXml ? 1 : 0);
+            insert.Values(row);
+            insert.Execute();
+        } else {
+            Assert(rows.size() == 1);
+            Properties::Row row = rows.front();
+            if (row.Get_readonly() != 0) {
+                Throw(Exception::LocalStorageValueNoModifableException);
+            }
+            row.Set_value(DPL::FromUTF8String(value));
+            row.Set_readonly(readOnly ? 1 : 0);
+            Properties::Update update(&m_databaseInterface);
+            update.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+            update.Values(row);
+            update.Execute();
+        }
+        tran.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot set item");
+}
+
+void WidgetInterfaceDAO::removeItem(const std::string& key)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        bool readonly = select.GetSingleValue<Properties::readonly>();
+        if (readonly) {
+            ThrowMsg(Exception::LocalStorageValueNoModifableException,
+                     "Cannot delete item. Item is readonly");
+        }
+        Properties::Delete deleteItem(&m_databaseInterface);
+        deleteItem.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        deleteItem.Execute();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot delete item");
+}
+
+DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
+    const std::string& key) const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        std::list<DPL::String> value =
+            select.GetValueList<Properties::value>();
+        if (value.empty()) {
+            return DPL::Optional<std::string>();
+        }
+        return DPL::Optional<std::string>(DPL::ToUTF8String(value.front()));
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Not found item");
+}
+
+void WidgetInterfaceDAO::clear(bool removeReadOnly)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Delete deleteItem(&m_databaseInterface);
+        if (!removeReadOnly) {
+            deleteItem.Where(Equals<Properties::readonly>(0));
+        }
+        deleteItem.Execute();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot delete all items");
+}
+
+size_t WidgetInterfaceDAO::getStorageSize() const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        std::list<DPL::String> list =
+            select.GetValueList<Properties::key>();
+        return list.size();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+}
+
+std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.OrderBy("key");
+        std::list<DPL::String> list = select.GetValueList<Properties::key>();
+        if (index >= list.size()) {
+            Throw(Exception::InvalidArgumentException);
+        }
+        for (size_t i = 0; i < index; ++i) {
+            list.pop_front();
+        }
+        return DPL::ToUTF8String(list.front());
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+}
+
+std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
+{
+    using namespace DPL::DB::ORM;
+    using namespace WrtDB::WidgetConfig;
+
+    WrtDB::WrtDatabase::attachToThreadRO();
+    std::stringstream filename;
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
+        WrtDB::TizenPkgId pkgid = widgetDAO.getTizenPkgId();
+
+        filename << GetWidgetPersistentStoragePath(pkgid)
+                 << "/"
+                 << DATABASE_NAME;
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+    WrtDB::WrtDatabase::detachFromThread();
+    return filename.str();
+}
+} // namespace WidgetInterfaceDB
diff --git a/modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h b/modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h
new file mode 100644 (file)
index 0000000..8b35344
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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      Lukasz Marek (l.marek@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WIDGET_INTERFACE_DAO_H_
+#define _WIDGET_INTERFACE_DAO_H_
+
+#include <string>
+#include <dpl/db/thread_database_support.h>
+#include <dpl/db/orm_interface.h>
+
+namespace WidgetInterfaceDB {
+class WidgetInterfaceDAO
+{
+  public:
+
+    /**
+     * WidgetInterfaceDAO Exception classes
+     */
+    class Exception
+    {
+      public:
+        DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+        DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
+        DECLARE_EXCEPTION_TYPE(Base, LocalStorageValueNoModifableException)
+        DECLARE_EXCEPTION_TYPE(Base, InvalidArgumentException)
+    };
+    WidgetInterfaceDAO(int widgetHandle);
+    virtual ~WidgetInterfaceDAO();
+
+    static std::string databaseFileName(int widgetHandle);
+    void setItem(const std::string& key,
+                 const std::string& value,
+                 bool readOnly,
+                 bool fromConfigXml);
+    void setItem(const std::string& key,
+                 const std::string& value,
+                 bool readOnly);
+    void removeItem(const std::string& key);
+    DPL::Optional<std::string> getValue(const std::string& key) const;
+    void clear(bool removeReadOnly);
+    size_t getStorageSize() const;
+    std::string getKeyByIndex(size_t index) const;
+
+  protected:
+    int m_widgetHandle;
+    mutable DPL::DB::ThreadDatabaseSupport m_databaseInterface;
+
+  private:
+    void checkDatabase();
+    void copyPropertiesFromWrtDatabase();
+};
+typedef std::unique_ptr<WidgetInterfaceDAO> WidgetInterfaceDAOPtr;
+}
+#endif //_WIDGET_INTERFACE_DAO_H_
diff --git a/modules/widget_interface_dao/orm/orm_generator_widget_interface.h b/modules/widget_interface_dao/orm/orm_generator_widget_interface.h
new file mode 100644 (file)
index 0000000..87a3e05
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+#ifndef ORM_GENERATOR_WIDGET_INTERFACE_H_
+#define ORM_GENERATOR_WIDGET_INTERFACE_H_
+
+#define ORM_GENERATOR_DATABASE_NAME widget_interface_db_definitions
+#include <dpl/db/orm_generator.h>
+#undef ORM_GENERATOR_DATABASE_NAME
+
+#endif
diff --git a/modules/widget_interface_dao/orm/widget_interface_db b/modules/widget_interface_dao/orm/widget_interface_db
new file mode 100644 (file)
index 0000000..d33ec48
--- /dev/null
@@ -0,0 +1,17 @@
+SQL(
+    PRAGMA foreign_keys = ON;
+    BEGIN TRANSACTION;
+)
+
+CREATE_TABLE(Properties)
+    COLUMN_NOT_NULL(key,      TEXT,)
+    COLUMN_NOT_NULL(value,    TEXT,)
+    COLUMN_NOT_NULL(readonly, INTEGER, check(readonly between 0 and 1))
+    COLUMN_NOT_NULL(configxml, INTEGER, check(readonly between 0 and 1) DEFAULT 0)
+
+    TABLE_CONSTRAINTS(unique(key))
+CREATE_TABLE_END()
+
+SQL(
+    COMMIT;
+)
diff --git a/modules/widget_interface_dao/orm/widget_interface_db_definitions b/modules/widget_interface_dao/orm/widget_interface_db_definitions
new file mode 100644 (file)
index 0000000..85f627d
--- /dev/null
@@ -0,0 +1,5 @@
+DATABASE_START(widget_interface)
+
+#include "widget_interface_db"
+
+DATABASE_END()
diff --git a/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h b/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h
new file mode 100644 (file)
index 0000000..b4ce0b6
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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        wrt_db_sql_generator.h
+ * @author      Bartosz Janiak (b.janiak@samsung.com)
+ * @version     1.0
+ * @brief       Macro definitions for generating the SQL input file from
+ * database definition.
+ */
+
+//Do not include this file directly! It is used only for SQL code generation.
+
+#include <dpl/db/orm_macros.h>
+
+#include "widget_interface_db_definitions"
index 47dade7..a6e840d 100644 (file)
@@ -1,7 +1,7 @@
 #git:framework/web/wrt-commons
 Name:       wrt-commons
 Summary:    Wrt common library
-Version:    0.2.145
+Version:    0.2.148
 Release:    1
 Group:      Development/Libraries
 License:    Apache License, Version 2.0