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/foreach.h>
27 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
28 #include <dpl/wrt-dao-ro/global_config.h>
30 using namespace WrtDB;
32 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34 PluginContainerSupport::PluginContainerSupport() : m_initialized(false)
36 // Reading root plugins list from so files
37 readRootPluginsList();
40 PluginContainerSupport::~PluginContainerSupport()
42 // Remove all plugin models
43 m_pluginModels.clear();
45 // Remove all feature models
46 m_featureModels.clear();
49 void PluginContainerSupport::Initialize(int widgetHandle)
51 if (isInitialized() == false) {
52 readAllowedPlugins(widgetHandle);
53 readRootPlugins(widgetHandle);
57 std::list<std::string> PluginContainerSupport::getAllowedFeatures(
58 int widgetHandle) const
60 //TODO it has to return LIST NOT SET!!!
61 WidgetDAOReadOnly widgetDao(widgetHandle);
62 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
64 std::list<std::string> allowedFeatures;
65 FOREACH(it, features) {
66 LogInfo("Loading api-feature: " << it->name);
68 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
73 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
75 return allowedFeatures;
78 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
80 std::list<std::string> allowedFeatures;
81 auto requested = getAllowedFeatures(widgetHandle);
84 allowedFeatures.push_back(*f);
87 FeatureData* dt = NULL;
88 std::map<FeatureHandle,
89 FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(
91 DeviceCapList deviceCapabilities =
92 FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
93 FOREACH(data, featureDataList) {
95 registerPluginModel(dt->pluginHandle);
96 registerFeatureModel(data->first, dt, deviceCapabilities);
102 void PluginContainerSupport::readRootPlugins(int widgetHandle)
104 WidgetDAOReadOnly dao(widgetHandle);
105 WidgetType appType = dao.getWidgetType();
106 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
107 FOREACH(it_rootPluginHandle, m_rootPluginsList)
109 LogDebug("*it_rootPluginHandle: " << *it_rootPluginHandle);
110 registerPluginModel(*it_rootPluginHandle);
113 LogDebug("Not defined app type");
115 m_initialized = true;
118 void PluginContainerSupport::registerFeatureModel(
119 FeatureHandle handle,
124 LogDebug("Analyzing feature: " << handle);
125 FeatureModelPtr model = getFeatureModel(handle);
127 LogDebug("Model for feature:" << handle << " already created");
131 LogDebug("Creating Model for feature:" << handle);
133 model.reset(new FeatureModel(handle));
135 std::set<std::string> devCapList;
136 auto ret = deviceCapabilities.equal_range(handle);
137 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
138 devCapList.insert((*devCapIt).second);
140 model->SetData(data->featureName, devCapList, data->pluginHandle);
141 m_featureModels.insert(model);
144 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
146 PluginModelPtr model = getPluginModelById(handle);
149 LogDebug("Model for plugin:" << handle << " already registered");
153 LogDebug("Creating Model for plugin: " << handle);
155 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
156 PluginDAOReadOnly::getInstallationStateForHandle(handle))
158 LogWarning("Failed To CreateModel for handle " << handle);
162 model.Reset(new PluginModel(handle));
164 LogInfo("Model Created. Handle: " <<
165 handle << ", name: " << model->LibraryName.Get());
167 m_pluginModels.insert(model);
170 void PluginContainerSupport::readRootPluginsList()
172 LogDebug("Reading root plugins list from so files...");
174 PluginHandleList pluginHandleList =
175 PluginDAOReadOnly::getPluginHandleList();
177 FOREACH(it_pluginHandle, pluginHandleList)
179 PluginDAOReadOnly pluginDao(*it_pluginHandle);
180 PluginHandleSetPtr retDependencies;
181 retDependencies = pluginDao.getLibraryDependencies();
182 if (retDependencies->empty()) {
183 LogDebug("Root plugin Handle: " << *it_pluginHandle);
184 m_rootPluginsList.push_back(*it_pluginHandle);
190 PluginContainerSupport::getFeatureModel(const std::string &name) const
192 FOREACH(iter, m_featureModels)
194 if ((*iter)->Name.Get() == name) {
199 return FeatureModelPtr();
203 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
205 FOREACH(iter, m_featureModels)
207 if ((*iter)->FHandle.Get() == handle) {
212 return FeatureModelPtr();
216 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
218 FOREACH(pluginModel, m_pluginModels)
220 if ((*pluginModel)->Handle.Get() == handle) {
225 return PluginModelPtr();
229 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
232 Assert(feature && "Null Ptr for feature model");
233 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
235 return getPluginModelById(feature->PHandle.Get());
238 PluginContainerSupport::PluginsList
239 PluginContainerSupport::getRootPlugins() const
243 FOREACH(it, m_rootPluginsList)
245 PluginModelPtr plugin = getPluginModelById(*it);
247 LogError("PluginModel not found");
251 plugins.push_back(plugin);
257 PluginContainerSupport::PluginsList
258 PluginContainerSupport::getPluginsList() const
264 FOREACH(it, m_pluginModels)
266 plugins.push_back(*it);
273 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
275 return getPluginModel(getFeatureModel(featureName));