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 std::list<std::string> PluginContainerSupport::getAllowedFeatures(int widgetHandle) const
59 //TODO it has to return LIST NOT SET!!!
60 WidgetDAOReadOnly widgetDao(widgetHandle);
61 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
63 std::list<std::string> allowedFeatures;
64 FOREACH(it, features) {
65 LogInfo("Loading api-feature: " << it->name);
67 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
72 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
74 return allowedFeatures;
77 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
79 std::list<std::string> allowedFeatures(m_standardFeatureList);
80 auto requested = getAllowedFeatures(widgetHandle);
83 allowedFeatures.push_back(*f);
86 FeatureData* dt = NULL;
87 std::map<FeatureHandle, FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(allowedFeatures);
88 DeviceCapList deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
89 FOREACH(data, featureDataList) {
91 registerPluginModel(dt->pluginHandle);
92 registerFeatureModel(data->first, dt, deviceCapabilities);
98 void PluginContainerSupport::readRootPlugins(int widgetHandle)
100 WidgetDAOReadOnly dao(widgetHandle);
101 WidgetType appType = dao.getWidgetType();
102 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
103 WrtDB::FeatureDAOReadOnly dao(TIZEN_ROOT_FEATURES);
104 registerPluginModel(dao.GetPluginHandle());
106 LogDebug("Not defined app type");
108 m_initialized = true;
111 void PluginContainerSupport::registerFeatureModel(FeatureHandle handle, FeatureData* data, DeviceCapList deviceCapabilities)
113 LogDebug("Analyzing feature: " << handle);
114 FeatureModelPtr model = getFeatureModel(handle);
116 LogDebug("Model for feature:" << handle << " already created");
120 LogDebug("Creating Model for feature:" << handle);
122 model.reset(new FeatureModel(handle));
124 std::set<std::string> devCapList;
125 auto ret = deviceCapabilities.equal_range(handle);
126 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
127 devCapList.insert((*devCapIt).second);
129 model->SetData(data->featureName, devCapList, data->pluginHandle);
130 m_featureModels.insert(model);
133 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
135 PluginModelPtr model = getPluginModelById(handle);
138 LogDebug("Model for plugin:" << handle << " already registered");
142 LogDebug("Creating Model for plugin: " << handle);
144 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
145 PluginDAOReadOnly::getInstallationStateForHandle(handle))
147 LogWarning("Failed To CreateModel for handle " << handle);
151 model.Reset(new PluginModel(handle));
153 LogInfo("Model Created. Handle: " <<
154 handle << ", name: " << model->LibraryName.Get());
156 m_pluginModels.insert(model);
159 void PluginContainerSupport::readStandardFeaturesList()
161 LogDebug("Reading standard features list from file...");
163 std::string path = GlobalConfig::GetDevicePluginPath();
165 path += STANDARD_FEATURES_LIST_FILE;
167 std::ifstream standardFeatureFile;
168 standardFeatureFile.open(path.c_str(), std::ifstream::in);
170 if (!standardFeatureFile.is_open()) {
171 LogError("Reading standard features list from file FAILED.");
177 while (!standardFeatureFile.eof()) {
178 standardFeatureFile.getline(buffer, sizeof(buffer));
180 if (buffer[0] == '\0') {
184 LogDebug("Standard Feature: <" << buffer << ">");
185 m_standardFeatureList.push_back(std::string(buffer));
188 standardFeatureFile.close();
192 PluginContainerSupport::getFeatureModel(const std::string &name) const
194 FOREACH(iter, m_featureModels)
196 if ((*iter)->Name.Get() == name) {
201 return FeatureModelPtr();
205 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
207 FOREACH(iter, m_featureModels)
209 if ((*iter)->FHandle.Get() == handle) {
214 return FeatureModelPtr();
218 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
220 FOREACH(pluginModel, m_pluginModels)
222 if ((*pluginModel)->Handle.Get() == handle) {
227 return PluginModelPtr();
231 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
234 Assert(feature && "Null Ptr for feature model");
235 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
237 return getPluginModelById(feature->PHandle.Get());
240 PluginContainerSupport::FeaturesList
241 PluginContainerSupport::getStandardFeatures() const
244 FeaturesList standardFeatures;
246 FOREACH(it, m_standardFeatureList)
248 FeatureModelPtr feature = getFeatureModel(*it);
250 LogWarning("Feature does not exist in DB " << *it);
254 //TODO maybe it should be sorted
255 standardFeatures.push_back(feature);
258 return standardFeatures;
261 PluginContainerSupport::PluginsList
262 PluginContainerSupport::getStandardPlugins() const
266 auto features = getStandardFeatures();
268 FOREACH(it, features)
270 auto plugin = getPluginModel(*it);
273 LogError("PluginModel not found");
277 plugins.push_back(plugin);
284 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
286 return getPluginModel(getFeatureModel(featureName));