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/global_config.h>
30 const char *STANDARD_FEATURES_LIST_FILE = "standard-features-list";
33 using namespace WrtDB;
35 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
37 PluginContainerSupport::PluginContainerSupport(): m_initialized(false)
39 // Reading standard features list from file
40 readStandardFeaturesList();
43 PluginContainerSupport::~PluginContainerSupport()
45 // Remove all plugin models
46 m_pluginModels.clear();
48 // Remove all feature models
49 m_featureModels.clear();
51 // Clear standard features list
52 m_standardFeatureList.clear();
55 std::list<std::string> PluginContainerSupport::getAllowedFeatures(int widgetHandle) const
57 //TODO it has to return LIST NOT SET!!!
58 WidgetDAOReadOnly widgetDao(widgetHandle);
59 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
61 std::list<std::string> allowedFeatures;
62 FOREACH(it, features) {
63 LogInfo("Loading api-feature: " << it->name);
65 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
70 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
72 return allowedFeatures;
75 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
77 std::list<std::string> allowedFeatures(m_standardFeatureList);
78 auto requested = getAllowedFeatures(widgetHandle);
81 allowedFeatures.push_back(*f);
84 FeatureData* dt = NULL;
85 std::map<FeatureHandle, FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(allowedFeatures);
86 DeviceCapList deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
87 FOREACH(data, featureDataList) {
89 registerPluginModel(dt->pluginHandle);
90 registerFeatureModel(data->first, dt, deviceCapabilities);
96 void PluginContainerSupport::registerFeatureModel(FeatureHandle handle, FeatureData* data, DeviceCapList deviceCapabilities)
98 LogDebug("Analyzing feature: " << handle);
99 FeatureModelPtr model = getFeatureModel(handle);
101 LogDebug("Model for feature:" << handle << " already created");
105 LogDebug("Creating Model for feature:" << handle);
107 model.reset(new FeatureModel(handle));
109 std::set<std::string> devCapList;
110 auto ret = deviceCapabilities.equal_range(handle);
111 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
112 devCapList.insert((*devCapIt).second);
114 model->SetData(data->featureName, devCapList, data->pluginHandle);
115 m_featureModels.insert(model);
118 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
120 PluginModelPtr model = getPluginModelById(handle);
123 LogDebug("Model for plugin:" << handle << " already registered");
127 LogDebug("Creating Model for plugin: " << handle);
129 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
130 PluginDAOReadOnly::getInstallationStateForHandle(handle))
132 LogWarning("Failed To CreateModel for handle " << handle);
136 model.Reset(new PluginModel(handle));
138 LogInfo("Model Created. Handle: " <<
139 handle << ", name: " << model->LibraryName.Get());
141 m_pluginModels.insert(model);
144 void PluginContainerSupport::readStandardFeaturesList()
146 LogDebug("Reading standard features list from file...");
148 std::string path = GlobalConfig::GetDevicePluginPath();
150 path += STANDARD_FEATURES_LIST_FILE;
152 std::ifstream standardFeatureFile;
153 standardFeatureFile.open(path.c_str(), std::ifstream::in);
155 if (!standardFeatureFile.is_open()) {
156 LogError("Reading standard features list from file FAILED.");
162 while (!standardFeatureFile.eof()) {
163 standardFeatureFile.getline(buffer, sizeof(buffer));
165 if (buffer[0] == '\0') {
169 LogDebug("Standard Feature: <" << buffer << ">");
170 m_standardFeatureList.push_back(std::string(buffer));
173 standardFeatureFile.close();
177 PluginContainerSupport::getFeatureModel(const std::string &name) const
179 FOREACH(iter, m_featureModels)
181 if ((*iter)->Name.Get() == name) {
186 return FeatureModelPtr();
190 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
192 FOREACH(iter, m_featureModels)
194 if ((*iter)->FHandle.Get() == handle) {
199 return FeatureModelPtr();
203 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
205 FOREACH(pluginModel, m_pluginModels)
207 if ((*pluginModel)->Handle.Get() == handle) {
212 return PluginModelPtr();
216 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
219 Assert(feature && "Null Ptr for feature model");
220 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
222 return getPluginModelById(feature->PHandle.Get());
225 PluginContainerSupport::FeaturesList
226 PluginContainerSupport::getStandardFeatures() const
229 FeaturesList standardFeatures;
231 FOREACH(it, m_standardFeatureList)
233 FeatureModelPtr feature = getFeatureModel(*it);
235 LogWarning("Feature does not exist in DB " << *it);
239 //TODO maybe it should be sorted
240 standardFeatures.push_back(feature);
243 return standardFeatures;
246 PluginContainerSupport::PluginsList
247 PluginContainerSupport::getStandardPlugins() const
251 auto features = getStandardFeatures();
253 FOREACH(it, features)
255 auto plugin = getPluginModel(*it);
258 LogError("PluginModel not found");
262 plugins.push_back(plugin);
269 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
271 return getPluginModel(getFeatureModel(featureName));