2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file core_module.cpp
18 * @author Przemyslaw Ciezkowski (p.ciezkowski@samsung.com)
20 * @brief File contains definitions of wrt core module.
23 #include "core_module.h"
24 #include "runnable_widget_object.h"
26 #include <main_thread.h>
27 #include <global_context.h>
28 #include <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <dpl/exception.h>
31 #include <dpl/popup/popup_controller.h>
32 #include <libxml/parser.h>
33 #include "localization_setting.h"
34 #include <dpl/wrt-dao-ro/global_config.h>
35 #include <profiling_util.h>
36 #include <widget_deserialize_model.h>
37 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
39 namespace { //Anonymous
41 std::string cutOffFileName(const std::string& path)
43 size_t found = path.find_last_of("/");
44 if (found == std::string::npos) {
47 return path.substr(0, found);
51 bool isDir(const std::string& path)
54 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
57 LogError("Cannot access directory [ " << path << " ]");
63 using namespace WrtDB;
64 using namespace WrtDB::GlobalConfig;
67 if_ok &= (isDir(cutOffFileName(GetWrtDatabaseFilePath())));
69 LogError("Path <" << GetWrtDatabaseFilePath() << "> does not exist.");
72 if_ok &= (isDir(GetDevicePluginPath()));
74 LogError("Path <" << GetDevicePluginPath() << "> does not exist.");
77 if_ok &= (isDir(GetFactoryInstalledWidgetPath()));
79 LogError("Path <" << GetFactoryInstalledWidgetPath() <<
83 if_ok &= (isDir(GetUserInstalledWidgetPath()));
85 LogError("Path <" << GetUserInstalledWidgetPath() <<
90 }// namespace anonymous
94 namespace CoreModule {
98 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
99 LogDebug("Initialize");
101 LogError("Required path does not exist");
106 GlobalContext::TouchArchitecture();
108 ADD_PROFILING_POINT("attach databases", "start");
109 MainThreadSingleton::Instance().AttachDatabases();
110 ADD_PROFILING_POINT("attach databases", "stop");
112 ADD_PROFILING_POINT("xml_parser_init", "start");
114 ADD_PROFILING_POINT("xml_parser_init", "stop");
116 // Initialize popup manager
117 ADD_PROFILING_POINT("popup_manager_init", "start");
118 DPL::Popup::PopupManagerSingleton::Instance().Initialize(
119 DPL::Popup::PopupRendererPtr(new DPL::Popup::PopupRenderer));
120 ADD_PROFILING_POINT("popup_manager_init", "stop");
122 // Initialize Language Subtag registry
123 ADD_PROFILING_POINT("language_rst_init", "start");
124 LocalizationSetting::Initialize();
125 ADD_PROFILING_POINT("language_rst_init", "stop");
127 LogDebug("Initialize finished");
128 } catch (const DPL::Exception& ex) {
129 LogError("Internal Error during screen preparation:");
130 DPL::Exception::DisplayKnownException(ex);
132 * Do deinitialization: check on which step exception occured
133 * and deinitialize only initialized parts.
142 MainThreadSingleton::Instance().DetachDatabases();
143 // Deinitialize popup manager
144 DPL::Popup::PopupManagerSingleton::Instance().Deinitialize();
146 LogInfo("Cleanup libxml2 global values.");
150 RunnableWidgetObjectPtr getRunnableWidgetObject(
151 const WidgetHandle& handle)
153 RunnableWidgetObjectPtr runnable;
154 WidgetModelPtr model = Domain::deserializeWidgetModel(handle);
156 runnable.reset(new RunnableWidgetObject(model));
161 RunnableWidgetObjectPtr getRunnableWidgetObject(const std::string& packageName)
163 DPL::OptionalString pkgName(DPL::FromUTF8String(packageName));
165 return CoreModule::getRunnableWidgetObject(
166 WrtDB::WidgetDAOReadOnly::getHandle(pkgName));
167 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
168 LogDebug("Widget not found.");
169 return RunnableWidgetObjectPtr();
173 } //namespace CoreModule
175 } /* namespace WRT */