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
*/
// If yes, pthread_exit(NULL) is required
if (!g_TLSforMainCreated)
{
- if (Thread::GetCurrentThread() == NULL)
+ if (Thread::IsMainThread())
{
g_TLSforMainCreated = true;
atexit(&MainThreadExitClean);
m_eventList.clear();
}
+bool Thread::IsMainThread()
+{
+ return (pthread_equal(pthread_self(), g_mainThread));
+}
+
Thread *Thread::GetCurrentThread()
{
if (pthread_equal(pthread_self(), g_mainThread))
#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>
#include <dpl/foreach.h>
#include <dpl/mutex.h>
-#include <dpl/wrt-dao-rw/widget_dao.h>
namespace {
#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>
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());
const LanguageTagsList &languageTags,
const DPL::String& file)
{
- WidgetDAO dao(widgetHandle);
+ WidgetDAOReadOnly dao(widgetHandle);
return GetFilePathInWidgetPackageInternal(languageTags, dao.getPath(), file);
}
{
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();
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();
const LanguageTagsList &languageTags)
{
using namespace LocalizationUtils;
- WidgetDAO dao(widgetHandle);
- WidgetDAO::WidgetIconList list = dao.getIconList();
+ WidgetDAOReadOnly dao(widgetHandle);
+ WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
WidgetIconList outlist;
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)
{
{
LanguageTagList languages =
LocalizationUtils::GetUserAgentLanguageTags();
- WidgetDAO dao(handle);
+ WidgetDAOReadOnly dao(handle);
DPL::OptionalString dl = dao.getDefaultlocale();
if (!!dl) {
languages.push_back(*dl);
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
//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);
registerAppService(widgetHandle, widgetRegInfo);
transaction.Commit();
-
- return widgetHandle;
}
SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
}
row.Set_test_widget(regInfo.isTestWidget);
row.Set_install_time(regInfo.installedTime);
+
DO_INSERT(row, WidgetExtendedInfo)
}
-DbWidgetHandle WidgetDAO::registerWidgetInfo(const WidgetRegisterInfo ®Info,
- const IWacSecurity &wacSecurity)
+void WidgetDAO::registerWidgetInfo(
+ const DbWidgetHandle& widgetHandle,
+ const WidgetRegisterInfo ®Info,
+ const IWacSecurity &wacSecurity)
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
// 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);
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,
{
}
+WidgetDAOReadOnly::WidgetDAOReadOnly(DPL::OptionalString widgetGUID) :
+ m_widgetHandle(WidgetDAOReadOnly::getHandle(widgetGUID))
+{
+}
+
WidgetDAOReadOnly::~WidgetDAOReadOnly()
{
}
* @param[in] widgetHandle application id of widget.
*/
WidgetDAOReadOnly(DbWidgetHandle widgetHandle);
+ WidgetDAOReadOnly(DPL::OptionalString widgetGUID);
/**
* Destructor
#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>
*
* @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.
private:
//Methods used during widget registering
- static DbWidgetHandle registerWidgetInfo(
+ static void registerWidgetInfo(
+ const DbWidgetHandle& widgetHandle,
const WidgetRegisterInfo ®Info,
const IWacSecurity &wacSecurity);
static void registerWidgetExtendedInfo(
)
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 '')