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 <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <dpl/exception.h>
31 #include <dpl/singleton_impl.h>
32 #include "localization_setting.h"
33 #include <dpl/wrt-dao-ro/global_config.h>
34 #include <profiling_util.h>
35 #include <widget_deserialize_model.h>
36 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
37 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
38 #include "webkit/bundles/plugin_module_support.h"
42 IMPLEMENT_SINGLETON(WRT::CoreModule)
44 namespace { //Anonymous
45 const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
47 std::string cutOffFileName(const std::string& path)
49 size_t found = path.find_last_of("/");
50 if (found == std::string::npos) {
53 return path.substr(0, found);
57 bool isDir(const std::string& path)
60 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
63 LogError("Cannot access directory [ " << path << " ]");
69 using namespace WrtDB;
70 using namespace WrtDB::GlobalConfig;
73 if_ok &= (isDir(cutOffFileName(GetWrtDatabaseFilePath())));
75 LogError("Path <" << GetWrtDatabaseFilePath() << "> does not exist.");
78 if_ok &= (isDir(GetDevicePluginPath()));
80 LogError("Path <" << GetDevicePluginPath() << "> does not exist.");
83 if_ok &= (isDir(GetUserInstalledWidgetPath()));
85 LogError("Path <" << GetUserInstalledWidgetPath() <<
90 } // namespace anonymous
97 CoreModuleImpl() : m_initialized(false), m_ewkContext(NULL)
104 LogDebug("Core module implementation destroyed");
109 if (!m_initialized) {
110 ADD_PROFILING_POINT("CoreModule::Init", "point");
111 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
112 LogDebug("Initialize");
114 LogError("Required path does not exist");
119 ADD_PROFILING_POINT("attach databases", "start");
120 MainThreadSingleton::Instance().AttachDatabases();
121 ADD_PROFILING_POINT("attach databases", "stop");
122 LogDebug("Initialize finished");
123 } catch (const DPL::Exception& ex) {
124 LogError("Internal Error during screen preparation:");
125 DPL::Exception::DisplayKnownException(ex);
127 * Do deinitialization: check on which step exception occured
128 * and deinitialize only initialized parts.
132 m_initialized = true;
139 MainThreadSingleton::Instance().DetachDatabases();
140 m_initialized = false;
143 RunnableWidgetObjectPtr getRunnableWidgetObject(
144 const std::string& tizenId)
147 RunnableWidgetObjectPtr runnable;
148 WidgetModelPtr model = Domain::deserializeWidgetModel(tizenId);
150 runnable.reset(new RunnableWidgetObject(model));
153 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
154 LogDebug("Widget not found.");
155 return RunnableWidgetObjectPtr();
159 CoreModule::NetworkAccessMode homeNetworkAccess()
161 switch (WrtDB::GlobalDAOReadOnly::GetHomeNetworkDataUsage()) {
162 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
163 return CoreModule::NEVER_CONNECT;
164 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
165 return CoreModule::ALWAYS_ASK;
166 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
167 return CoreModule::CONNECT_AUTOMATICALLY;
171 LogWarning("using default value");
172 return CoreModule::ALWAYS_ASK;
175 CoreModule::NetworkAccessMode roamingNetworkAccess()
177 switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
178 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
179 return CoreModule::NEVER_CONNECT;
180 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
181 return CoreModule::ALWAYS_ASK;
182 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
183 return CoreModule::CONNECT_AUTOMATICALLY;
187 LogWarning("using default value");
188 return CoreModule::ALWAYS_ASK;
193 return WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
198 Ewk_Context* m_ewkContext;
201 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
204 CoreModule::~CoreModule()
207 bool CoreModule::Init()
209 return m_impl->Init();
212 void CoreModule::Terminate()
214 return m_impl->Terminate();
217 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
218 const std::string& tizenId)
220 return m_impl->getRunnableWidgetObject(tizenId);
223 CoreModule::NetworkAccessMode CoreModule::homeNetworkAccess()
225 return m_impl->homeNetworkAccess();
228 CoreModule::NetworkAccessMode CoreModule::roamingNetworkAccess()
230 return m_impl->roamingNetworkAccess();
233 bool CoreModule::developerMode()
235 return m_impl->developerMode();
237 } /* namespace WRT */