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(int 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 int 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: %s", DPL::ToUTF8String(it->name).c_str());
82 _W("Api-feature was rejected by ace. (Api-feature name: %s)",
87 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
89 return allowedFeatures;
92 void PluginContainerSupport::readAllowedPlugins(int 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(int 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);
170 model.Reset(new PluginModel(handle));
172 \r_D("Model Created. Handle: %d, name: %s",
174 model->LibraryName.Get().c_str());
176 m_pluginModels.insert(model);
179 void PluginContainerSupport::readRootPluginsList()
181 _D("Reading root plugins list from so files...");
182 m_rootPluginsList = PluginDAOReadOnly::getRootPluginHandleList();
186 PluginContainerSupport::getFeatureModel(const std::string &name) const
188 FOREACH(iter, m_featureModels)
190 if ((*iter)->Name.Get() == name) {
195 return FeatureModelPtr();
199 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
201 FOREACH(iter, m_featureModels)
203 if ((*iter)->FHandle.Get() == handle) {
208 return FeatureModelPtr();
212 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
214 FOREACH(pluginModel, m_pluginModels)
216 if ((*pluginModel)->Handle.Get() == handle) {
221 return PluginModelPtr();
225 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
228 _D("Null Ptr for feature model");
229 return PluginModelPtr();
231 _D("Feature located in plugin: %d", feature->PHandle.Get());
232 return getPluginModelById(feature->PHandle.Get());
236 PluginContainerSupport::PluginsList
237 PluginContainerSupport::getRootPlugins() const
241 FOREACH(it, m_rootPluginsList) {
242 PluginModelPtr plugin = getPluginModelById(*it);
244 _W("PluginModel not found");
248 plugins.push_back(plugin);
254 PluginContainerSupport::PluginsList
255 PluginContainerSupport::getPluginsList() const
259 FOREACH(it, m_pluginModels) {
260 plugins.push_back(*it);
267 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
269 return getPluginModel(getFeatureModel(featureName));