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";
31 const char* FEATURE_WAC20_DEVICAPIS_NAME = "http://wacapps.net/api/deviceapis";
34 using namespace WrtDB;
36 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
38 PluginContainerSupport::PluginContainerSupport(): m_initialized(false)
40 // Reading standard features list from file
41 readStandardFeaturesList();
44 PluginContainerSupport::~PluginContainerSupport()
46 // Remove all plugin models
47 m_pluginModels.clear();
49 // Remove all feature models
50 m_featureModels.clear();
52 // Clear standard features list
53 m_standardFeatureList.clear();
56 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
58 //TODO it has to return LIST NOT SET!!!
59 WidgetDAOReadOnly widgetDao(widgetHandle);
60 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
62 std::list<std::string> allowedFeatures(m_standardFeatureList);
63 FOREACH(it, features) {
64 LogInfo("Loading api-feature: " << it->name);
66 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
71 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
74 auto widgetType = widgetDao.getWidgetType();
77 if (widgetType == APP_TYPE_WAC20) {
78 auto it = find(allowedFeatures.begin(),
79 allowedFeatures.end(),
80 FEATURE_WAC20_DEVICAPIS_NAME);
82 if (allowedFeatures.end() == it) {
83 LogInfo("WAC2.0 Deviceapis not declared but added");
84 allowedFeatures.push_front(FEATURE_WAC20_DEVICAPIS_NAME);
88 FeatureData* dt = NULL;
89 std::map<FeatureHandle, FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(allowedFeatures);
90 DeviceCapList deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
91 FOREACH(data, featureDataList) {
93 registerPluginModel(dt->pluginHandle);
94 registerFeatureModel(data->first, dt, deviceCapabilities);
100 void PluginContainerSupport::registerFeatureModel(FeatureHandle handle, FeatureData* data, DeviceCapList deviceCapabilities)
102 LogDebug("Analyzing feature: " << handle);
103 FeatureModelPtr model = getFeatureModel(handle);
105 LogDebug("Model for feature:" << handle << " already created");
109 LogDebug("Creating Model for feature:" << handle);
111 model.Reset(new FeatureModel(handle));
113 std::set<std::string> devCapList;
114 auto ret = deviceCapabilities.equal_range(handle);
115 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
116 devCapList.insert((*devCapIt).second);
118 model->SetData(data->featureName, devCapList, data->pluginHandle);
119 m_featureModels.insert(model);
122 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
124 PluginModelPtr model = getPluginModelById(handle);
127 LogDebug("Model for plugin:" << handle << " already registered");
131 LogDebug("Creating Model for plugin: " << handle);
133 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
134 PluginDAOReadOnly::getInstallationStateForHandle(handle))
136 LogWarning("Failed To CreateModel for handle " << handle);
140 model.Reset(new PluginModel(handle));
142 LogInfo("Model Created. Handle: " <<
143 handle << ", name: " << model->LibraryName.Get());
145 m_pluginModels.insert(model);
148 void PluginContainerSupport::readStandardFeaturesList()
150 LogDebug("Reading standard features list from file...");
152 std::string path = GlobalConfig::GetDevicePluginPath();
154 path += STANDARD_FEATURES_LIST_FILE;
156 std::ifstream standardFeatureFile;
157 standardFeatureFile.open(path.c_str(), std::ifstream::in);
159 if (!standardFeatureFile.is_open()) {
160 LogError("Reading standard features list from file FAILED.");
166 while (!standardFeatureFile.eof()) {
167 standardFeatureFile.getline(buffer, sizeof(buffer));
169 if (buffer[0] == '\0') {
173 LogDebug("Standard Feature: <" << buffer << ">");
174 m_standardFeatureList.push_back(std::string(buffer));
177 standardFeatureFile.close();
181 PluginContainerSupport::getFeatureModel(const std::string &name) const
183 FOREACH(iter, m_featureModels)
185 if ((*iter)->Name.Get() == name) {
190 return FeatureModelPtr();
194 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
196 FOREACH(iter, m_featureModels)
198 if ((*iter)->FHandle.Get() == handle) {
203 return FeatureModelPtr();
207 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
209 FOREACH(pluginModel, m_pluginModels)
211 if ((*pluginModel)->Handle.Get() == handle) {
216 return PluginModelPtr();
220 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
223 Assert(feature && "Null Ptr for feature model");
224 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
226 return getPluginModelById(feature->PHandle.Get());
229 PluginContainerSupport::FeaturesList
230 PluginContainerSupport::getStandardFeatures() const
233 FeaturesList standardFeatures;
235 FOREACH(it, m_standardFeatureList)
237 FeatureModelPtr feature = getFeatureModel(*it);
239 LogWarning("Feature does not exist in DB " << *it);
243 //TODO maybe it should be sorted
244 standardFeatures.push_back(feature);
247 return standardFeatures;
250 PluginContainerSupport::PluginsList
251 PluginContainerSupport::getStandardPlugins() const
255 auto features = getStandardFeatures();
257 FOREACH(it, features)
259 auto plugin = getPluginModel(*it);
262 LogError("PluginModel not found");
266 plugins.push_back(plugin);
273 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
275 return getPluginModel(getFeatureModel(featureName));