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)
61 readAllowedPlugins(widgetHandle);
62 readRootPlugins(widgetHandle);
66 std::list<std::string> PluginContainerSupport::getAllowedFeatures(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, FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(allowedFeatures);
97 DeviceCapList deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
98 FOREACH(data, featureDataList) {
100 registerPluginModel(dt->pluginHandle);
101 registerFeatureModel(data->first, dt, deviceCapabilities);
104 m_initialized = true;
107 void PluginContainerSupport::readRootPlugins(int widgetHandle)
109 WidgetDAOReadOnly dao(widgetHandle);
110 WidgetType appType = dao.getWidgetType();
111 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
112 WrtDB::FeatureDAOReadOnly dao(TIZEN_ROOT_FEATURES);
113 registerPluginModel(dao.GetPluginHandle());
115 LogDebug("Not defined app type");
117 m_initialized = true;
120 void PluginContainerSupport::registerFeatureModel(FeatureHandle handle, FeatureData* data, DeviceCapList deviceCapabilities)
122 LogDebug("Analyzing feature: " << handle);
123 FeatureModelPtr model = getFeatureModel(handle);
125 LogDebug("Model for feature:" << handle << " already created");
129 LogDebug("Creating Model for feature:" << handle);
131 model.reset(new FeatureModel(handle));
133 std::set<std::string> devCapList;
134 auto ret = deviceCapabilities.equal_range(handle);
135 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
136 devCapList.insert((*devCapIt).second);
138 model->SetData(data->featureName, devCapList, data->pluginHandle);
139 m_featureModels.insert(model);
142 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
144 PluginModelPtr model = getPluginModelById(handle);
147 LogDebug("Model for plugin:" << handle << " already registered");
151 LogDebug("Creating Model for plugin: " << handle);
153 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
154 PluginDAOReadOnly::getInstallationStateForHandle(handle))
156 LogWarning("Failed To CreateModel for handle " << handle);
160 model.Reset(new PluginModel(handle));
162 LogInfo("Model Created. Handle: " <<
163 handle << ", name: " << model->LibraryName.Get());
165 m_pluginModels.insert(model);
168 void PluginContainerSupport::readStandardFeaturesList()
170 LogDebug("Reading standard features list from file...");
172 std::string path = GlobalConfig::GetDevicePluginPath();
174 path += STANDARD_FEATURES_LIST_FILE;
176 std::ifstream standardFeatureFile;
177 standardFeatureFile.open(path.c_str(), std::ifstream::in);
179 if (!standardFeatureFile.is_open()) {
180 LogError("Reading standard features list from file FAILED.");
186 while (!standardFeatureFile.eof()) {
187 standardFeatureFile.getline(buffer, sizeof(buffer));
189 if (buffer[0] == '\0') {
193 LogDebug("Standard Feature: <" << buffer << ">");
194 m_standardFeatureList.push_back(std::string(buffer));
197 standardFeatureFile.close();
201 PluginContainerSupport::getFeatureModel(const std::string &name) const
203 FOREACH(iter, m_featureModels)
205 if ((*iter)->Name.Get() == name) {
210 return FeatureModelPtr();
214 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
216 FOREACH(iter, m_featureModels)
218 if ((*iter)->FHandle.Get() == handle) {
223 return FeatureModelPtr();
227 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
229 FOREACH(pluginModel, m_pluginModels)
231 if ((*pluginModel)->Handle.Get() == handle) {
236 return PluginModelPtr();
240 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
243 Assert(feature && "Null Ptr for feature model");
244 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
246 return getPluginModelById(feature->PHandle.Get());
249 PluginContainerSupport::FeaturesList
250 PluginContainerSupport::getStandardFeatures() const
253 FeaturesList standardFeatures;
255 FOREACH(it, m_standardFeatureList)
257 FeatureModelPtr feature = getFeatureModel(*it);
259 LogWarning("Feature does not exist in DB " << *it);
263 //TODO maybe it should be sorted
264 standardFeatures.push_back(feature);
267 return standardFeatures;
270 PluginContainerSupport::PluginsList
271 PluginContainerSupport::getStandardPlugins() const
275 auto features = getStandardFeatures();
277 FOREACH(it, features)
279 auto plugin = getPluginModel(*it);
282 LogError("PluginModel not found");
286 plugins.push_back(plugin);
292 PluginContainerSupport::PluginsList
293 PluginContainerSupport::getPluginsList() const
299 FOREACH(it, m_pluginModels)
301 plugins.push_back(*it);
308 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
310 return getPluginModel(getFeatureModel(featureName));