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 <dpl/optional_typedefs.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>
38 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
39 #include "webkit/bundles/plugin_module_support.h"
43 IMPLEMENT_SINGLETON(WRT::CoreModule)
45 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())));
75 if_ok &= (isDir(GetDevicePluginPath()));
76 if_ok &= (isDir(GetUserInstalledWidgetPath()));
79 } // namespace anonymous
86 CoreModuleImpl() : m_initialized(false), m_ewkContext(NULL)
93 LogDebug("Core module implementation destroyed");
99 ADD_PROFILING_POINT("CoreModule::Init", "point");
100 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
101 LogDebug("Initialize");
103 LogError("Required path does not exist");
108 ADD_PROFILING_POINT("attach databases", "start");
109 MainThreadSingleton::Instance().AttachDatabases();
110 ADD_PROFILING_POINT("attach databases", "stop");
111 LogDebug("Initialize finished");
112 } catch (const DPL::Exception& ex) {
113 LogError("Internal Error during screen preparation:");
114 DPL::Exception::DisplayKnownException(ex);
116 * Do deinitialization: check on which step exception occured
117 * and deinitialize only initialized parts.
121 m_initialized = true;
128 MainThreadSingleton::Instance().DetachDatabases();
129 m_initialized = false;
132 RunnableWidgetObjectPtr getRunnableWidgetObject(
133 const std::string& tizenId,
134 DPL::OptionalUInt appControlIndex)
137 RunnableWidgetObjectPtr runnable;
138 WidgetModelPtr model =
139 Domain::deserializeWidgetModel(tizenId, appControlIndex);
141 runnable.reset(new RunnableWidgetObject(model));
144 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
145 LogDebug("Widget not found.");
146 return RunnableWidgetObjectPtr();
150 CoreModule::NetworkAccessMode homeNetworkAccess()
152 switch (WrtDB::GlobalDAOReadOnly::GetHomeNetworkDataUsage()) {
153 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
154 return CoreModule::NEVER_CONNECT;
155 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
156 return CoreModule::ALWAYS_ASK;
157 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
158 return CoreModule::CONNECT_AUTOMATICALLY;
162 LogWarning("using default value");
163 return CoreModule::ALWAYS_ASK;
166 CoreModule::NetworkAccessMode roamingNetworkAccess()
168 switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
169 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
170 return CoreModule::NEVER_CONNECT;
171 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
172 return CoreModule::ALWAYS_ASK;
173 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
174 return CoreModule::CONNECT_AUTOMATICALLY;
178 LogWarning("using default value");
179 return CoreModule::ALWAYS_ASK;
184 return WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
189 Ewk_Context* m_ewkContext;
192 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
195 CoreModule::~CoreModule()
198 bool CoreModule::Init()
200 return m_impl->Init();
203 void CoreModule::Terminate()
205 return m_impl->Terminate();
208 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
209 const std::string& tizenId,
210 DPL::OptionalUInt appControlIndex)
212 return m_impl->getRunnableWidgetObject(tizenId, appControlIndex);
215 CoreModule::NetworkAccessMode CoreModule::homeNetworkAccess()
217 return m_impl->homeNetworkAccess();
220 CoreModule::NetworkAccessMode CoreModule::roamingNetworkAccess()
222 return m_impl->roamingNetworkAccess();
225 bool CoreModule::developerMode()
227 return m_impl->developerMode();
229 } /* namespace WRT */