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 plugin_container_support.h
18 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
22 #include "plugin_container_support.h"
26 #include <dpl/log/secure_log.h>
27 #include <dpl/foreach.h>
28 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
29 #include <dpl/wrt-dao-ro/global_config.h>
31 using namespace WrtDB;
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
35 PluginContainerSupport::PluginContainerSupport() :
39 // Reading root plugins list from so files
40 readRootPluginsList();
43 PluginContainerSupport::~PluginContainerSupport()
45 // Remove all plugin models
46 m_pluginModels.clear();
48 // Remove all feature models
49 m_featureModels.clear();
52 void PluginContainerSupport::Initialize(WidgetHandle widgetHandle)
54 if (isInitialized() == true && m_widgetHandle != widgetHandle) {
55 // re-initialize required
56 m_initialized = false;
58 m_pluginModels.clear();
59 m_featureModels.clear();
62 if (isInitialized() == false) {
64 m_widgetHandle = widgetHandle;
66 readAllowedPlugins(widgetHandle);
67 readRootPlugins(widgetHandle);
71 std::list<std::string> PluginContainerSupport::getAllowedFeatures(
72 WidgetHandle widgetHandle) const
74 //TODO it has to return LIST NOT SET!!!
75 WidgetDAOReadOnly widgetDao(widgetHandle);
76 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
78 std::list<std::string> allowedFeatures;
79 FOREACH(it, features) {
80 _D("Loading api-feature: %ls", it->name.c_str());
82 _W("Api-feature was rejected by ace. (Api-feature name: %ls)",
87 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
89 return allowedFeatures;
92 void PluginContainerSupport::readAllowedPlugins(WidgetHandle widgetHandle)
94 std::list<std::string> allowedFeatures;
95 auto requested = getAllowedFeatures(widgetHandle);
98 allowedFeatures.push_back(*f);
101 FeatureData* dt = NULL;
102 std::map<FeatureHandle,
103 FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(
105 DeviceCapList deviceCapabilities =
106 FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
107 FOREACH(data, featureDataList) {
108 dt = &(data->second);
109 registerPluginModel(dt->pluginHandle);
110 registerFeatureModel(data->first, dt, deviceCapabilities);
114 void PluginContainerSupport::readRootPlugins(WidgetHandle widgetHandle)
116 WidgetDAOReadOnly dao(widgetHandle);
117 WidgetType appType = dao.getWidgetType();
118 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
119 FOREACH(it_rootPluginHandle, m_rootPluginsList)
121 _D("*it_rootPluginHandle: %d", *it_rootPluginHandle);
122 registerPluginModel(*it_rootPluginHandle);
125 _D("Not defined app type");
129 void PluginContainerSupport::registerFeatureModel(
130 FeatureHandle handle,
135 FeatureModelPtr model = getFeatureModel(handle);
137 _D("Model for feature: %d already created", handle);
141 _D("Creating Model for feature: %d", handle);
143 model.reset(new FeatureModel(handle));
145 std::set<std::string> devCapList;
146 auto ret = deviceCapabilities.equal_range(handle);
147 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
148 devCapList.insert((*devCapIt).second);
150 model->SetData(data->featureName, devCapList, data->pluginHandle);
151 m_featureModels.insert(model);
154 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
156 PluginModelPtr model = getPluginModelById(handle);
159 _D("Model for plugin: %d already registered", handle);
163 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
164 PluginDAOReadOnly::getInstallationStateForHandle(handle))
166 _W("Failed To CreateModel for handle %d", handle);
171 model.reset(new PluginModel(handle));
172 } Catch(WrtDB::PluginDAOReadOnly::Exception::PluginNotExist) {
173 // database changed between receiving plugin handle and creating PluginModel
174 _E("Failed to create PluginModel - database may be changed");
177 \r_D("Model Created. Handle: %d, name: %s",
179 model->LibraryName.Get().c_str());
181 m_pluginModels.insert(model);
184 void PluginContainerSupport::readRootPluginsList()
186 _D("Reading root plugins list from so files...");
187 m_rootPluginsList = PluginDAOReadOnly::getRootPluginHandleList();
191 PluginContainerSupport::getFeatureModel(const std::string &name) const
193 FOREACH(iter, m_featureModels)
195 if ((*iter)->Name.Get() == name) {
200 return FeatureModelPtr();
204 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
206 FOREACH(iter, m_featureModels)
208 if ((*iter)->FHandle.Get() == handle) {
213 return FeatureModelPtr();
217 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
219 FOREACH(pluginModel, m_pluginModels)
221 if ((*pluginModel)->Handle.Get() == handle) {
226 return PluginModelPtr();
230 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
233 _D("Null Ptr for feature model");
234 return PluginModelPtr();
236 _D("Feature located in plugin: %d", feature->PHandle.Get());
237 return getPluginModelById(feature->PHandle.Get());
241 PluginContainerSupport::PluginsList
242 PluginContainerSupport::getRootPlugins() const
246 FOREACH(it, m_rootPluginsList) {
247 PluginModelPtr plugin = getPluginModelById(*it);
249 _W("PluginModel not found");
253 plugins.push_back(plugin);
259 PluginContainerSupport::PluginsList
260 PluginContainerSupport::getPluginsList() const
264 FOREACH(it, m_pluginModels) {
265 plugins.push_back(*it);
272 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
274 return getPluginModel(getFeatureModel(featureName));