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)
ADD_SUBDIRECTORY(support)
ADD_SUBDIRECTORY(certificate_dao)
ADD_SUBDIRECTORY(i18n)
+ADD_SUBDIRECTORY(widget_interface_dao)
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(SYS_EFL_TEST_ENGINE
appcore-efl
+ libxml-2.0
REQUIRED)
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
--- /dev/null
+# 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)
+
--- /dev/null
+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
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)
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);
#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
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 {
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;
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");
args.erase(args.begin());
bool showHelp = false;
+ bool justList = false;
+ std::vector<std::string> xmlFiles;
TestResultsCollectorBasePtr currentCollector;
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)) {
} 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());
}
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();
}
}
+ 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
// 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())
{
struct WidgetAppControl
{
enum class Disposition {
- WINDOW = 0,
- INLINE
+ UNDEFINE = 0,
+ WINDOW = 1,
+ INLINE = 2
};
DPL::String src; /* start uri */
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;
}
/**
- * 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()
return ".cookie.db";
}
-/**
- * widget interface database file name
- */
-inline const char* GetWidgetInterfaceDatabaseFile()
-{
- return ".widget_interface.db";
-}
-
inline const char* GetTmpDirPath()
{
return "/tmp";
return "plugins/x86";
#endif
}
+
+inline const char* GetBackupDatabaseSuffix()
+{
+ return ".backup";
+}
} // namespace GlobalConfig
} // namespace WrtDB
--- /dev/null
+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
+)
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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
--- /dev/null
+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;
+)
--- /dev/null
+DATABASE_START(widget_interface)
+
+#include "widget_interface_db"
+
+DATABASE_END()
--- /dev/null
+/*
+ * 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"
#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