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>
31 const char *STANDARD_FEATURES_LIST_FILE = "standard-features-list";
32 const char *TIZEN_ROOT_FEATURES = "http://tizen.org/privilege/tizen";
35 using namespace WrtDB;
37 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
39 PluginContainerSupport::PluginContainerSupport() : m_initialized(false)
41 // Reading standard features list from file
42 readStandardFeaturesList();
45 PluginContainerSupport::~PluginContainerSupport()
47 // Remove all plugin models
48 m_pluginModels.clear();
50 // Remove all feature models
51 m_featureModels.clear();
53 // Clear standard features list
54 m_standardFeatureList.clear();
57 void PluginContainerSupport::Initialize(int widgetHandle)
59 if (isInitialized() == false) {
60 readAllowedPlugins(widgetHandle);
61 readRootPlugins(widgetHandle);
65 std::list<std::string> PluginContainerSupport::getAllowedFeatures(
66 int widgetHandle) const
68 //TODO it has to return LIST NOT SET!!!
69 WidgetDAOReadOnly widgetDao(widgetHandle);
70 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
72 std::list<std::string> allowedFeatures;
73 FOREACH(it, features) {
74 LogInfo("Loading api-feature: " << it->name);
76 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
81 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
83 return allowedFeatures;
86 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
88 std::list<std::string> allowedFeatures(m_standardFeatureList);
89 auto requested = getAllowedFeatures(widgetHandle);
92 allowedFeatures.push_back(*f);
95 FeatureData* dt = NULL;
96 std::map<FeatureHandle,
97 FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(
99 DeviceCapList deviceCapabilities =
100 FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
101 FOREACH(data, featureDataList) {
102 dt = &(data->second);
103 registerPluginModel(dt->pluginHandle);
104 registerFeatureModel(data->first, dt, deviceCapabilities);
107 m_initialized = true;
110 void PluginContainerSupport::readRootPlugins(int widgetHandle)
112 WidgetDAOReadOnly dao(widgetHandle);
113 WidgetType appType = dao.getWidgetType();
114 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
115 WrtDB::FeatureDAOReadOnly dao(TIZEN_ROOT_FEATURES);
116 registerPluginModel(dao.GetPluginHandle());
118 LogDebug("Not defined app type");
120 m_initialized = true;
123 void PluginContainerSupport::registerFeatureModel(
124 FeatureHandle handle,
129 LogDebug("Analyzing feature: " << handle);
130 FeatureModelPtr model = getFeatureModel(handle);
132 LogDebug("Model for feature:" << handle << " already created");
136 LogDebug("Creating Model for feature:" << handle);
138 model.reset(new FeatureModel(handle));
140 std::set<std::string> devCapList;
141 auto ret = deviceCapabilities.equal_range(handle);
142 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
143 devCapList.insert((*devCapIt).second);
145 model->SetData(data->featureName, devCapList, data->pluginHandle);
146 m_featureModels.insert(model);
149 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
151 PluginModelPtr model = getPluginModelById(handle);
154 LogDebug("Model for plugin:" << handle << " already registered");
158 LogDebug("Creating Model for plugin: " << handle);
160 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
161 PluginDAOReadOnly::getInstallationStateForHandle(handle))
163 LogWarning("Failed To CreateModel for handle " << handle);
167 model.Reset(new PluginModel(handle));
169 LogInfo("Model Created. Handle: " <<
170 handle << ", name: " << model->LibraryName.Get());
172 m_pluginModels.insert(model);
175 void PluginContainerSupport::readStandardFeaturesList()
177 LogDebug("Reading standard features list from file...");
179 std::string path = GlobalConfig::GetDevicePluginPath();
181 path += STANDARD_FEATURES_LIST_FILE;
183 std::ifstream standardFeatureFile;
184 standardFeatureFile.open(path.c_str(), std::ifstream::in);
186 if (!standardFeatureFile.is_open()) {
187 LogError("Reading standard features list from file FAILED.");
193 while (!standardFeatureFile.eof()) {
194 standardFeatureFile.getline(buffer, sizeof(buffer));
196 if (buffer[0] == '\0') {
200 LogDebug("Standard Feature: <" << buffer << ">");
201 m_standardFeatureList.push_back(std::string(buffer));
204 standardFeatureFile.close();
208 PluginContainerSupport::getFeatureModel(const std::string &name) const
210 FOREACH(iter, m_featureModels)
212 if ((*iter)->Name.Get() == name) {
217 return FeatureModelPtr();
221 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
223 FOREACH(iter, m_featureModels)
225 if ((*iter)->FHandle.Get() == handle) {
230 return FeatureModelPtr();
234 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
236 FOREACH(pluginModel, m_pluginModels)
238 if ((*pluginModel)->Handle.Get() == handle) {
243 return PluginModelPtr();
247 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
250 Assert(feature && "Null Ptr for feature model");
251 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
253 return getPluginModelById(feature->PHandle.Get());
256 PluginContainerSupport::FeaturesList
257 PluginContainerSupport::getStandardFeatures() const
260 FeaturesList standardFeatures;
262 FOREACH(it, m_standardFeatureList)
264 FeatureModelPtr feature = getFeatureModel(*it);
266 LogWarning("Feature does not exist in DB " << *it);
270 //TODO maybe it should be sorted
271 standardFeatures.push_back(feature);
274 return standardFeatures;
277 PluginContainerSupport::PluginsList
278 PluginContainerSupport::getStandardPlugins() const
282 auto features = getStandardFeatures();
284 FOREACH(it, features)
286 auto plugin = getPluginModel(*it);
288 LogError("PluginModel not found");
292 plugins.push_back(plugin);
298 PluginContainerSupport::PluginsList
299 PluginContainerSupport::getPluginsList() const
305 FOREACH(it, m_pluginModels)
307 plugins.push_back(*it);
314 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
316 return getPluginModel(getFeatureModel(featureName));