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 m_rootPluginsList = PluginDAOReadOnly::getRootPluginHandleList();
178 PluginContainerSupport::getFeatureModel(const std::string &name) const
180 FOREACH(iter, m_featureModels)
182 if ((*iter)->Name.Get() == name) {
187 return FeatureModelPtr();
191 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
193 FOREACH(iter, m_featureModels)
195 if ((*iter)->FHandle.Get() == handle) {
200 return FeatureModelPtr();
204 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
206 FOREACH(pluginModel, m_pluginModels)
208 if ((*pluginModel)->Handle.Get() == handle) {
213 return PluginModelPtr();
217 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
221 LogDebug("Null Ptr for feature model");
222 return PluginModelPtr();
226 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
227 return getPluginModelById(feature->PHandle.Get());
231 PluginContainerSupport::PluginsList
232 PluginContainerSupport::getRootPlugins() const
236 FOREACH(it, m_rootPluginsList)
238 PluginModelPtr plugin = getPluginModelById(*it);
240 LogError("PluginModel not found");
244 plugins.push_back(plugin);
250 PluginContainerSupport::PluginsList
251 PluginContainerSupport::getPluginsList() const
257 FOREACH(it, m_pluginModels)
259 plugins.push_back(*it);
266 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
268 return getPluginModel(getFeatureModel(featureName));