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>
42 IMPLEMENT_SINGLETON(WRT::CoreModule)
45 const char* const TEXT_DOMAIN = "wrt";
46 const char* const TEXT_LOCALE_PATH = "/usr/share/wrt-engine/locale";
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 bindtextdomain(TEXT_DOMAIN, TEXT_LOCALE_PATH);
122 m_initialized = true;
129 MainThreadSingleton::Instance().DetachDatabases();
130 m_initialized = false;
133 RunnableWidgetObjectPtr getRunnableWidgetObject(
134 const std::string& tizenId,
135 DPL::OptionalUInt appControlIndex)
138 RunnableWidgetObjectPtr runnable;
139 WidgetModelPtr model =
140 Domain::deserializeWidgetModel(tizenId, appControlIndex);
142 runnable.reset(new RunnableWidgetObject(model));
145 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
146 LogDebug("Widget not found.");
147 return RunnableWidgetObjectPtr();
151 CoreModule::NetworkAccessMode homeNetworkAccess()
153 switch (WrtDB::GlobalDAOReadOnly::GetHomeNetworkDataUsage()) {
154 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
155 return CoreModule::NEVER_CONNECT;
156 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
157 return CoreModule::ALWAYS_ASK;
158 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
159 return CoreModule::CONNECT_AUTOMATICALLY;
163 LogWarning("using default value");
164 return CoreModule::ALWAYS_ASK;
167 CoreModule::NetworkAccessMode roamingNetworkAccess()
169 switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
170 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
171 return CoreModule::NEVER_CONNECT;
172 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
173 return CoreModule::ALWAYS_ASK;
174 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
175 return CoreModule::CONNECT_AUTOMATICALLY;
179 LogWarning("using default value");
180 return CoreModule::ALWAYS_ASK;
185 Ewk_Context* m_ewkContext;
188 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
191 CoreModule::~CoreModule()
194 bool CoreModule::Init()
196 return m_impl->Init();
199 void CoreModule::Terminate()
201 return m_impl->Terminate();
204 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
205 const std::string& tizenId,
206 DPL::OptionalUInt appControlIndex)
208 return m_impl->getRunnableWidgetObject(tizenId, appControlIndex);
211 CoreModule::NetworkAccessMode CoreModule::homeNetworkAccess()
213 return m_impl->homeNetworkAccess();
216 CoreModule::NetworkAccessMode CoreModule::roamingNetworkAccess()
218 return m_impl->roamingNetworkAccess();
221 } /* namespace WRT */