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 CpluffAdapter.h
25 #ifndef __CPLUFFADAPTER_H
26 #define __CPLUFFADAPTER_H
35 #include <sys/types.h>
37 #include <boost/thread.hpp>
38 #include <boost/bind.hpp>
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);
165 * print whole plugin info.
167 * @param cpluff plugins
169 void printPluginList();
174 * new Singleton pattern instance.
176 * @return OICPluginManager pointer Address.
178 static CpluffAdapter *Getinstance(void *args = NULL)
180 if (NULL == s_pinstance)
182 s_pinstance = new CpluffAdapter(args);
193 typedef std::map<std::string, bool> File_list;
194 std::vector<Plugin> m_plugins;
195 cp_context_t *m_context;
196 cp_status_t m_status;
197 cp_plugin_info_t **m_cp_plugins;
198 cp_plugin_info_t *m_plugin;
199 //boost::thread_group m_thread_g;
200 static CpluffAdapter *s_pinstance;
203 * Constructor for CpluffAdapter.
204 * During construction time, all plugins under the root plugin path will be loaded.
207 CpluffAdapter(void *args = NULL);
212 virtual ~CpluffAdapter(void);
215 * delete Singleton pattern instance.
217 static void deleteinstance()
219 if (NULL != s_pinstance)
227 * detect plugins(add, delete, move)
229 * @param plugin file path.
232 //void observePluginPath(void *);
236 * change Number to String.
239 * @return State String.
241 const char *state_to_string(int state);
244 * Get whole "SO" file list.
246 * @param OUT, SO file list.
248 * @return true or false.
250 bool getFileList(File_list &list, const std::string strDir);
253 * install plugin using c-pluff.
256 * @return int, 1 is success, 0 is fail.
258 int installPlugin(const std::string path);
262 * find Plugin and install plugin.(Recursive)
265 * @return int, 1 is success, 0 is fail.
267 int findPluginRecursive(const std::string path);
270 * load Plugin information to PluginManager table.
272 * @param path to observe
273 * @return int, 1 is success, 0 is fail.
275 int loadPluginInfoToManager(const std::string path);
279 #endif //__CPLUFFADAPTER_H