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";
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();
43 // Reading root plugins list from so files
44 readRootPluginsList();
47 PluginContainerSupport::~PluginContainerSupport()
49 // Remove all plugin models
50 m_pluginModels.clear();
52 // Remove all feature models
53 m_featureModels.clear();
55 // Clear standard features list
56 m_standardFeatureList.clear();
59 void PluginContainerSupport::Initialize(int widgetHandle)
61 if (isInitialized() == false) {
62 readAllowedPlugins(widgetHandle);
63 readRootPlugins(widgetHandle);
67 std::list<std::string> PluginContainerSupport::getAllowedFeatures(
68 int widgetHandle) const
70 //TODO it has to return LIST NOT SET!!!
71 WidgetDAOReadOnly widgetDao(widgetHandle);
72 DbWidgetFeatureSet features = widgetDao.getFeaturesList();
74 std::list<std::string> allowedFeatures;
75 FOREACH(it, features) {
76 LogInfo("Loading api-feature: " << it->name);
78 LogWarning("Api-feature was rejected by ace. (Api-feature name: "
83 allowedFeatures.push_back(DPL::ToUTF8String(it->name));
85 return allowedFeatures;
88 void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
90 std::list<std::string> allowedFeatures(m_standardFeatureList);
91 auto requested = getAllowedFeatures(widgetHandle);
94 allowedFeatures.push_back(*f);
97 FeatureData* dt = NULL;
98 std::map<FeatureHandle,
99 FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(
101 DeviceCapList deviceCapabilities =
102 FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
103 FOREACH(data, featureDataList) {
104 dt = &(data->second);
105 registerPluginModel(dt->pluginHandle);
106 registerFeatureModel(data->first, dt, deviceCapabilities);
109 m_initialized = true;
112 void PluginContainerSupport::readRootPlugins(int widgetHandle)
114 WidgetDAOReadOnly dao(widgetHandle);
115 WidgetType appType = dao.getWidgetType();
116 if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
117 FOREACH(it_rootPluginHandle, m_rootPluginsList)
119 LogDebug("*it_rootPluginHandle: " << *it_rootPluginHandle);
120 registerPluginModel(*it_rootPluginHandle);
123 LogDebug("Not defined app type");
125 m_initialized = true;
128 void PluginContainerSupport::registerFeatureModel(
129 FeatureHandle handle,
134 LogDebug("Analyzing feature: " << handle);
135 FeatureModelPtr model = getFeatureModel(handle);
137 LogDebug("Model for feature:" << handle << " already created");
141 LogDebug("Creating Model for feature:" << handle);
143 model.reset(new FeatureModel(handle));
145 std::set<std::string> devCapList;
146 auto ret = deviceCapabilities.equal_range(handle);
147 for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
148 devCapList.insert((*devCapIt).second);
150 model->SetData(data->featureName, devCapList, data->pluginHandle);
151 m_featureModels.insert(model);
154 void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
156 PluginModelPtr model = getPluginModelById(handle);
159 LogDebug("Model for plugin:" << handle << " already registered");
163 LogDebug("Creating Model for plugin: " << handle);
165 if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
166 PluginDAOReadOnly::getInstallationStateForHandle(handle))
168 LogWarning("Failed To CreateModel for handle " << handle);
172 model.Reset(new PluginModel(handle));
174 LogInfo("Model Created. Handle: " <<
175 handle << ", name: " << model->LibraryName.Get());
177 m_pluginModels.insert(model);
180 void PluginContainerSupport::readStandardFeaturesList()
182 LogDebug("Reading standard features list from file...");
184 std::string path = GlobalConfig::GetDevicePluginPath();
186 path += STANDARD_FEATURES_LIST_FILE;
188 std::ifstream standardFeatureFile;
189 standardFeatureFile.open(path.c_str(), std::ifstream::in);
191 if (!standardFeatureFile.is_open()) {
192 LogError("Reading standard features list from file FAILED.");
198 while (!standardFeatureFile.eof()) {
199 standardFeatureFile.getline(buffer, sizeof(buffer));
201 if (buffer[0] == '\0') {
205 LogDebug("Standard Feature: <" << buffer << ">");
206 m_standardFeatureList.push_back(std::string(buffer));
209 standardFeatureFile.close();
212 void PluginContainerSupport::readRootPluginsList()
214 LogDebug("Reading root plugins list from so files...");
216 PluginHandleList pluginHandleList =
217 PluginDAOReadOnly::getPluginHandleList();
219 FOREACH(it_pluginHandle, pluginHandleList)
221 PluginDAOReadOnly pluginDao(*it_pluginHandle);
222 PluginHandleSetPtr retDependencies;
223 retDependencies = pluginDao.getLibraryDependencies();
224 if (retDependencies->empty()) {
225 LogDebug("Root plugin Handle: " << *it_pluginHandle);
226 m_rootPluginsList.push_back(*it_pluginHandle);
232 PluginContainerSupport::getFeatureModel(const std::string &name) const
234 FOREACH(iter, m_featureModels)
236 if ((*iter)->Name.Get() == name) {
241 return FeatureModelPtr();
245 PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
247 FOREACH(iter, m_featureModels)
249 if ((*iter)->FHandle.Get() == handle) {
254 return FeatureModelPtr();
258 PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
260 FOREACH(pluginModel, m_pluginModels)
262 if ((*pluginModel)->Handle.Get() == handle) {
267 return PluginModelPtr();
271 PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
274 Assert(feature && "Null Ptr for feature model");
275 LogDebug("Feature located in plugin: " << feature->PHandle.Get());
277 return getPluginModelById(feature->PHandle.Get());
280 PluginContainerSupport::FeaturesList
281 PluginContainerSupport::getStandardFeatures() const
284 FeaturesList standardFeatures;
286 FOREACH(it, m_standardFeatureList)
288 FeatureModelPtr feature = getFeatureModel(*it);
290 LogWarning("Feature does not exist in DB " << *it);
294 //TODO maybe it should be sorted
295 standardFeatures.push_back(feature);
298 return standardFeatures;
301 PluginContainerSupport::PluginsList
302 PluginContainerSupport::getStandardPlugins() const
306 auto features = getStandardFeatures();
308 FOREACH(it, features)
310 auto plugin = getPluginModel(*it);
312 LogError("PluginModel not found");
316 plugins.push_back(plugin);
322 PluginContainerSupport::PluginsList
323 PluginContainerSupport::getRootPlugins() const
327 FOREACH(it, m_rootPluginsList)
329 PluginModelPtr plugin = getPluginModelById(*it);
331 LogError("PluginModel not found");
335 plugins.push_back(plugin);
341 PluginContainerSupport::PluginsList
342 PluginContainerSupport::getPluginsList() const
348 FOREACH(it, m_pluginModels)
350 plugins.push_back(*it);
357 PluginContainerSupport::getPluginForFeature(const std::string& featureName)
359 return getPluginModel(getFeatureModel(featureName));