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 FelixAdapter.h
25 #ifndef __FELIXADAPTER_H__
26 #define __FELIXADAPTER_H__
33 #include <sys/types.h>
34 #include <sys/inotify.h>
36 #include <boost/thread.hpp>
37 #include <boost/bind.hpp>
43 #define EVENT_SIZE ( sizeof (struct inotify_event) )
44 #define BUF_LEN (int)( 1024 * ( EVENT_SIZE + 16 ) )
49 * @brief After installing a plug-in in a directory, each plug-ins can be managed by this class.
57 * A function to register pluins in the path.
58 * This function will load plugins in plugin manager table.
60 * @param path plugin file path to be registered.
61 * @return int, 1 is success, 0 is fail.
66 int registerPlugin(const std::string path);
70 * A function to register pluins in the path.
71 * This function will load plugins in plugin manager table.
73 * @param path plugin file path to be registered.
74 * recursive load plugins sub folders recursively.
75 * @return int, 1 is success, 0 is fail.
80 int registerAllPlugin(const std::string path);
86 * @param plugin plugin object to be unregistered.
87 * @return int, 1 is success, 0 is fail.
89 int unregisterPlugin(Plugin *const plugin);
93 * Unregister All plugin.
95 * @return int, 1 is success, 0 is fail.
97 int unregisterAllPlugin(void);
101 * get all plugins which currently registered.
103 * @return vector of currently registered plugins
106 std::vector<Plugin> &getAllPlugins(void);
110 * find plugins which have the key and value
112 * @return vector of currently registered plugins
114 std::vector<Plugin> *findPlugins(const std::string key, const std::string value);
118 * Get plugin which has the id
120 * @param pluginID plugin id to find
121 * @return Plugin instance
123 //Plugin *getPlugin(const std::string pluginID);
127 * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
130 * @param Platform pointer.
131 * @return int, 1 is success, 0 is fail.
133 int start(Plugin *const plugin, void *const arg);
138 * This function will call stop function of plugin and unload dynamic plugin library from memory.
141 * @return int, 1 is success, 0 is fail.
143 int stop(Plugin *const plugin);
147 * Check whether the plugin started or not
149 * @param Plugin to identify the Starting.
150 * @return true if started, false is stop.
153 bool isStarted(Plugin *plugin);
160 * @return Plugin state.
162 const std::string getState(const std::string plugID);
167 * new Singleton pattern instance.
169 * @return OICPluginManager pointer Address.
171 static FelixAdapter *Getinstance()
173 if (NULL == s_pinstance)
175 s_pinstance = new FelixAdapter();
185 typedef std::map<std::string, bool> File_list;
186 std::vector<Plugin> m_plugins;
187 boost::thread m_file_detect_thread;
189 cp_context_t *m_context;
190 cp_status_t m_status;
191 cp_plugin_info_t **m_cp_plugins;
192 cp_plugin_info_t *m_plugin;
193 boost::thread_group m_thread_g;
196 static FelixAdapter *s_pinstance;
199 * Constructor for FelixAdapter.
200 * During construction time, all plugins under the root plugin path will be loaded.
208 virtual ~FelixAdapter(void);
211 * delete Singleton pattern instance.
213 static void deleteinstance()
215 if (NULL != s_pinstance)
223 * detect plugins(add, delete, move)
225 * @param plugin file path.
228 //void observePluginPath(void *);
231 * Get whole "SO" file list.
233 * @param OUT, SO file list.
235 * @return true or false.
237 bool getFileList(File_list &list, const std::string strDir);
240 * print whole plugin info.
242 * @param Felix plugins
244 void printPluginList(cp_plugin_info_t **plugins);
247 * install plugin using c-pluff.
250 * @return int, 1 is success, 0 is fail.
252 int installPlugin(const std::string path);
256 * find Plugin and install plugin.(Recursive)
259 * @return int, 1 is success, 0 is fail.
261 int findPluginRecursive(const std::string path);
264 * load Plugin information to PluginManager table.
266 * @param path to observe
267 * @return int, 1 is success, 0 is fail.
269 int loadPluginInfoToManager(const std::string path);
273 #endif //__FELIXADAPTER_H__