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 PluginManager.h
25 #ifndef __PLUGINMANAGER_H
26 #define __PLUGINMANAGER_H
33 #include <sys/types.h>
34 #include <sys/inotify.h>
36 #include <boost/thread.hpp>
37 #include <boost/bind.hpp>
41 #include "OCPlatform.h"
44 #define EVENT_SIZE ( sizeof (struct inotify_event) )
45 #define BUF_LEN (int)( 1024 * ( EVENT_SIZE + 16 ) )
51 struct PluginManagerConfig
53 std::string rootPluinPath;
57 * @brief After installing a plug-in in a directory, each plug-ins can be managed by this class.
65 * A function to register pluins in the path.
66 * This function will load plugins in plugin manager table.
68 * @param path plugin file path to be registered.
69 * @return int, 1 is success, 0 is fail.
74 int registerPlugin(const std::string path);
78 * A function to register pluins in the path.
79 * This function will load plugins in plugin manager table.
81 * @param path plugin file path to be registered.
82 * recursive load plugins sub folders recursively.
83 * @return int, 1 is success, 0 is fail.
88 int registerAllPlugin(const std::string path);
94 * @param plugin plugin object to be unregistered.
95 * @return int, 1 is success, 0 is fail.
97 int unregisterPlugin(Plugin *const plugin);
101 * Unregister All plugin.
103 * @return int, 1 is success, 0 is fail.
105 int unregisterAllPlugin(void);
109 * get all plugins which currently registered.
111 * @return vector of currently registered plugins
114 std::vector<Plugin> &getAllPlugins(void);
118 * find plugins which have the key and value
120 * @return vector of currently registered plugins
122 std::vector<Plugin> *findPlugins(const std::string key, const std::string value);
126 * Get plugin which has the id
128 * @param pluginID plugin id to find
129 * @return Plugin instance
131 Plugin *getPlugin(const std::string pluginID);
135 * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
138 * @param Platform pointer.
139 * @return int, 1 is success, 0 is fail.
141 int start(Plugin *const plugin, void *const arg);
146 * This function will call stop function of plugin and unload dynamic plugin library from memory.
149 * @return int, 1 is success, 0 is fail.
151 int stop(Plugin *const plugin);
155 * Check whether the plugin started or not
157 * @param Plugin to identify the Starting.
158 * @return true if started, false is stop.
161 bool isStarted(Plugin *plugin);
167 * @return Plugin state.
169 const std::string getState(const std::string plugID);
174 * new Singleton pattern instance.
176 * @return PluginManager pointer Address.
178 static PluginManager *Getinstance()
180 if (NULL == s_pinstance)
182 s_pinstance = new PluginManager();
192 typedef std::map<std::string, bool> File_list;
193 std::vector<Plugin> m_plugins;
194 cp_context_t *m_context;
195 cp_status_t m_status;
196 cp_plugin_info_t **m_cp_plugins;
197 cp_plugin_info_t *m_plugin;
198 boost::thread m_file_detect_thread;
199 boost::thread_group m_thread_g;
201 static PluginManager *s_pinstance;
204 * Constructor for PluginManager.
205 * During construction time, all plugins under the root plugin path will be loaded.
213 virtual ~PluginManager(void);
216 * delete Singleton pattern instance.
218 static void deleteinstance()
220 if (NULL != s_pinstance)
228 * detect plugins(add, delete, move)
230 * @param plugin file path.
233 void observePluginPath(void *);
237 * change Number to String.
240 * @return State String.
242 const char *state_to_string(int state);
245 * Get whole "SO" file list.
247 * @param OUT, SO file list.
249 * @return true or false.
251 bool getFileList(File_list &list, const std::string strDir);
254 * print whole plugin info.
256 * @param cpluff plugins
258 void printPluginList(cp_plugin_info_t **plugins);
261 * install plugin using c-pluff.
264 * @return int, 1 is success, 0 is fail.
266 int installPlugin(const std::string path);
270 * find Plugin and install plugin.(Recursive)
273 * @return int, 1 is success, 0 is fail.
275 int findPluginRecursive(const std::string path);
278 * load Plugin information to PluginManager table.
280 * @param path to observe
281 * @return int, 1 is success, 0 is fail.
283 int loadPluginInfoToManager(const std::string path);
287 #endif //__PLUGINMANAGER_H