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)
19 * @author Andrzej Surdej (a.surdej@samsung.com)
21 * @brief File contains definitions of wrt core module.
24 #include "core_module.h"
25 #include "runnable_widget_object.h"
27 #include <main_thread.h>
28 #include <global_context.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31 #include <dpl/exception.h>
32 #include <dpl/popup/popup_controller.h>
33 #include <dpl/singleton_impl.h>
34 #include "localization_setting.h"
35 #include <dpl/wrt-dao-ro/global_config.h>
36 #include <profiling_util.h>
37 #include <widget_deserialize_model.h>
38 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
42 IMPLEMENT_SINGLETON(WRT::CoreModule)
44 namespace { //Anonymous
46 const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
48 std::string cutOffFileName(const std::string& path)
50 size_t found = path.find_last_of("/");
51 if (found == std::string::npos) {
54 return path.substr(0, found);
58 bool isDir(const std::string& path)
61 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
64 LogError("Cannot access directory [ " << path << " ]");
70 using namespace WrtDB;
71 using namespace WrtDB::GlobalConfig;
74 if_ok &= (isDir(cutOffFileName(GetWrtDatabaseFilePath())));
76 LogError("Path <" << GetWrtDatabaseFilePath() << "> does not exist.");
79 if_ok &= (isDir(GetDevicePluginPath()));
81 LogError("Path <" << GetDevicePluginPath() << "> does not exist.");
84 if_ok &= (isDir(GetFactoryInstalledWidgetPath()));
86 LogError("Path <" << GetFactoryInstalledWidgetPath() <<
90 if_ok &= (isDir(GetUserInstalledWidgetPath()));
92 LogError("Path <" << GetUserInstalledWidgetPath() <<
97 }// namespace anonymous
105 CoreModuleImpl() : m_initialized(false), m_ewkContext(NULL)
112 LogDebug("Core module implementation destroyed");
117 if (!m_initialized) {
118 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
119 LogDebug("Initialize");
121 LogError("Required path does not exist");
127 // Needed settings for WKContext are located here
128 // create Ewk_Context
129 Ewk_Context* newEwkContext =
130 ewk_context_new_with_injected_bundle_path(bundlePath);
131 if (!newEwkContext) {
132 LogError("Failed to create Ewk_Context");
133 ThrowMsg(DPL::Exception, "Failed to create ewk context");
135 // cache model setting
136 ewk_context_cache_model_set(newEwkContext,
137 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
138 m_ewkContext = newEwkContext;
140 // To fork a Webprocess as soon as possible,
141 // the following ewk_api is called explicitly.
142 ewk_context_cookies_policy_set(m_ewkContext,
143 EWK_COOKIE_JAR_ACCEPT_ALWAYS);
145 GlobalContext::TouchArchitecture();
147 ADD_PROFILING_POINT("attach databases", "start");
148 MainThreadSingleton::Instance().AttachDatabases();
149 ADD_PROFILING_POINT("attach databases", "stop");
151 // Initialize popup manager
152 ADD_PROFILING_POINT("popup_manager_init", "start");
153 DPL::Popup::PopupManagerSingleton::Instance().Initialize(
154 DPL::Popup::PopupRendererPtr(new DPL::Popup::PopupRenderer));
155 ADD_PROFILING_POINT("popup_manager_init", "stop");
157 LogDebug("Initialize finished");
158 } catch (const DPL::Exception& ex) {
159 LogError("Internal Error during screen preparation:");
160 DPL::Exception::DisplayKnownException(ex);
162 * Do deinitialization: check on which step exception occured
163 * and deinitialize only initialized parts.
167 m_initialized = true;
175 LogInfo("finalizeEwkContext called");
176 ewk_context_delete(m_ewkContext);
179 MainThreadSingleton::Instance().DetachDatabases();
180 // Deinitialize popup manager
181 DPL::Popup::PopupManagerSingleton::Instance().Deinitialize();
183 m_initialized = false;
186 RunnableWidgetObjectPtr getRunnableWidgetObject(
187 const std::string& tizenId)
190 RunnableWidgetObjectPtr runnable;
191 WidgetModelPtr model = Domain::deserializeWidgetModel(tizenId);
193 runnable.reset(new RunnableWidgetObject(model, m_ewkContext));
196 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
197 LogDebug("Widget not found.");
198 return RunnableWidgetObjectPtr();
204 Ewk_Context* m_ewkContext;
207 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
211 CoreModule::~CoreModule()
215 bool CoreModule::Init()
217 return m_impl->Init();
220 void CoreModule::Terminate()
222 return m_impl->Terminate();
225 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
226 const std::string& tizenId)
228 return m_impl->getRunnableWidgetObject(tizenId);
231 } /* namespace WRT */