1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file PluginManagerImpl.cpp
25 #include "PluginManagerImpl.h"
29 PluginManagerImpl *PluginManagerImpl::s_pinstance = nullptr;
31 extern "C" PluginManagerImpl *create_object()
33 PluginManagerImpl *newobj;
34 newobj = new PluginManagerImpl;
38 extern "C" void destroy_object( PluginManagerImpl *object )
43 PluginManagerImpl::PluginManagerImpl()
45 cppm = CpluffAdapter::Getinstance();
46 javappm = FelixAdapter::Getinstance();
50 PluginManagerImpl::~PluginManagerImpl()
55 int PluginManagerImpl::registerPlugin(std::string path)
58 flag = cppm->registerPlugin(path);
59 flag = javappm->registerPlugin(path);
64 int PluginManagerImpl::registerAllPlugin(std::string path)
67 flag = cppm->registerAllPlugin(path);
68 flag = javappm->registerAllPlugin(path);
73 int PluginManagerImpl::unregisterPlugin(std::string id)
77 Plugin *plugin = new Plugin;
78 plugin->setValue("Id", id);
80 for (unsigned int i = 0 ; i < m_plugins.size(); i++)
82 if (!m_plugins[i].getID().compare(id))
84 if (!m_plugins[i].getValueByAttribute("Language").compare("CPP"))
86 if ((flag = cppm->unregisterPlugin(&m_plugins[i])))
88 m_plugins.erase(m_plugins.begin() + i);
91 else if (!m_plugins[i].getValueByAttribute("Language").compare("JAVA"))
93 if ((flag = javappm->unregisterPlugin(&m_plugins[i])))
95 m_plugins.erase(m_plugins.begin() + i);
104 int PluginManagerImpl::unregisterAllPlugin()
107 flag = cppm->unregisterAllPlugin();
108 flag = javappm->unregisterAllPlugin();
114 std::vector<Plugin> &PluginManagerImpl::getAllPlugins(void)
119 std::vector<Plugin> *PluginManagerImpl::findPlugins(const std::string key,
120 const std::string value)
122 std::vector<Plugin> *re_plugins;
123 re_plugins = new std::vector<Plugin>;
124 for (unsigned int i = 0; i < m_plugins.size(); i++)
126 if (!m_plugins[i].getValueByAttribute(key).compare(value))
128 re_plugins->push_back(m_plugins[i]);
135 Plugin *PluginManagerImpl::getPlugin(const std::string pluginID)
137 for (unsigned int i = 0; i < m_plugins.size(); i++)
139 if (!(m_plugins[i].getID().compare(pluginID)))
141 return &(m_plugins[i]);
147 int PluginManagerImpl::startPlugins(const std::string key, const std::string value)
150 std::string resourcetype = "";
151 int size = value.size();
153 //Parsing Resource_Type
154 for (int i = size - 1; i > -1 ; i--)
156 if (value.at(i) == '.' && value.at(i) == '/')
160 resourcetype += value.at(i);
163 //Reverse string(Resource value)
164 reverse(resourcetype.begin(), resourcetype.end());
167 std::vector<Plugin> *resource_plugin = findPlugins(key, resourcetype);
170 std::vector<Plugin>::iterator it;
171 for (it = resource_plugin->begin(); it != resource_plugin->end(); it++)
173 if (!isStarted(&(*it))) // started : 1, stop : 0
175 flag = startPlugins(&(*it));//TODO PASS the OCPlatform
178 delete(resource_plugin);
179 resource_plugin = nullptr;
183 int PluginManagerImpl::startPlugins(Plugin *const plugin)
188 flag = startbyPlatform(plugin, arg);
193 int PluginManagerImpl::stopPlugins(const std::string key, const std::string value)
196 std::string resourcetype = "";
197 int size = value.size();
199 //Parsing Resource_Type
200 for (int i = size - 1; i > -1 ; i--)
202 if (value.at(i) == '.' && value.at(i) == '/')
206 resourcetype += value.at(i);
209 //Reverse string(Resource value)
211 reverse(resourcetype.begin(), resourcetype.end());
213 // printf("resource value = %s\n", resourcetype.c_str());
216 std::vector<Plugin> *resource_plugin = findPlugins(key, resourcetype);
219 std::vector<Plugin>::iterator it;
220 for (it = resource_plugin->begin(); it != resource_plugin->end(); it++)
222 if (isStarted(&(*it))) // started : 1, stop : 0
224 flag = stopPlugins(&(*it));//TODO PASS the OCPlatform
227 delete(resource_plugin);
228 resource_plugin = nullptr;
232 int PluginManagerImpl::stopPlugins(Plugin *const plugin)
236 flag = stopbyPlatform(plugin);
241 int PluginManagerImpl::startbyPlatform(Plugin *const plugin, void *const arg)
245 for (unsigned int i = 0 ; i < m_plugins.size(); i++)
247 if (!m_plugins[i].getID().compare(plugin->getID()))
249 if (!m_plugins[i].getValueByAttribute("Language").compare("CPP"))
251 flag = cppm->start(plugin, arg);
253 else if (!m_plugins[i].getValueByAttribute("Language").compare("JAVA"))
255 flag = javappm->start(plugin, arg);
267 int PluginManagerImpl::stopbyPlatform(Plugin *const plugin)
271 for (unsigned int i = 0 ; i < m_plugins.size(); i++)
273 if (!m_plugins[i].getID().compare(plugin->getID()))
275 if (!m_plugins[i].getValueByAttribute("Language").compare("CPP"))
277 flag = cppm->stop(plugin);
279 else if (!m_plugins[i].getValueByAttribute("Language").compare("JAVA"))
281 flag = javappm->stop(plugin);
293 bool PluginManagerImpl::isStarted(Plugin *plugin)
296 if (cppm->isStarted(plugin))
302 if (javappm->isStarted(plugin))
310 std::string PluginManagerImpl::getState(std::string plugID)
312 std::string str = "";
314 for (unsigned int i = 0 ; i < m_plugins.size(); i++)
316 if (!m_plugins[i].getID().compare(plugID))
318 if (!m_plugins[i].getValueByAttribute("Language").compare("CPP"))
320 str = cppm->getState(plugID);
322 else if (!m_plugins[i].getValueByAttribute("Language").compare("JAVA"))
324 str = javappm->getState(plugID);
332 std::vector<Plugin> PluginManagerImpl::refreshPluginInfo()
335 m_plugins = cppm->getAllPlugins();
337 std::vector<Plugin> java_plugins = javappm->getAllPlugins();
338 int size = java_plugins.size();
340 for (int i = 0 ; i < size ; i++)
342 m_plugins.push_back(java_plugins[i]);