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
33 #include <sys/types.h>
35 #include <boost/thread.hpp>
36 #include <boost/bind.hpp>
42 #define BUF_LEN (int)( 1024 * ( EVENT_SIZE + 16 ) )
47 * @brief After installing a plug-in in a directory, each plug-ins can be managed by this class.
55 * A function to register pluins in the path.
56 * This function will load plugins in plugin manager table.
58 * @param path plugin file path to be registered.
59 * @return int, 1 is success, 0 is fail.
64 int registerPlugin(const std::string path);
68 * A function to register pluins in the path.
69 * This function will load plugins in plugin manager table.
71 * @param path plugin file path to be registered.
72 * recursive load plugins sub folders recursively.
73 * @return int, 1 is success, 0 is fail.
78 int registerAllPlugin(const std::string path);
84 * @param plugin plugin object to be unregistered.
85 * @return int, 1 is success, 0 is fail.
87 int unregisterPlugin(Plugin *const plugin);
91 * Unregister All plugin.
93 * @return int, 1 is success, 0 is fail.
95 int unregisterAllPlugin(void);
99 * get all plugins which currently registered.
101 * @return vector of currently registered plugins
104 std::vector<Plugin> &getAllPlugins(void);
108 * find plugins which have the key and value
110 * @return vector of currently registered plugins
112 std::vector<Plugin> *findPlugins(const std::string key, const std::string value);
116 * Get plugin which has the id
118 * @param pluginID plugin id to find
119 * @return Plugin instance
121 //Plugin *getPlugin(const std::string pluginID);
125 * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
128 * @param Platform pointer.
129 * @return int, 1 is success, 0 is fail.
131 int start(Plugin *const plugin, void *const arg);
136 * This function will call stop function of plugin and unload dynamic plugin library from memory.
139 * @return int, 1 is success, 0 is fail.
141 int stop(Plugin *const plugin);
145 * Check whether the plugin started or not
147 * @param Plugin to identify the Starting.
148 * @return true if started, false is stop.
151 bool isStarted(Plugin *plugin);
158 * @return Plugin state.
160 const std::string getState(const std::string plugID);
163 * print whole plugin info.
165 * @param cpluff plugins
167 void printPluginList();
172 * new Singleton pattern instance.
174 * @return OICPluginManager pointer Address.
176 static CpluffAdapter *Getinstance()
178 if (NULL == s_pinstance)
180 s_pinstance = new CpluffAdapter();
191 typedef std::map<std::string, bool> File_list;
192 std::vector<Plugin> m_plugins;
193 cp_context_t *m_context;
194 cp_status_t m_status;
195 cp_plugin_info_t **m_cp_plugins;
196 cp_plugin_info_t *m_plugin;
197 //boost::thread_group m_thread_g;
198 static CpluffAdapter *s_pinstance;
201 * Constructor for CpluffAdapter.
202 * During construction time, all plugins under the root plugin path will be loaded.
210 virtual ~CpluffAdapter(void);
213 * delete Singleton pattern instance.
215 static void deleteinstance()
217 if (NULL != s_pinstance)
225 * detect plugins(add, delete, move)
227 * @param plugin file path.
230 //void observePluginPath(void *);
234 * change Number to String.
237 * @return State String.
239 const char *state_to_string(int state);
242 * Get whole "SO" file list.
244 * @param OUT, SO file list.
246 * @return true or false.
248 bool getFileList(File_list &list, const std::string strDir);
251 * install plugin using c-pluff.
254 * @return int, 1 is success, 0 is fail.
256 int installPlugin(const std::string path);
260 * find Plugin and install plugin.(Recursive)
263 * @return int, 1 is success, 0 is fail.
265 int findPluginRecursive(const std::string path);
268 * load Plugin information to PluginManager table.
270 * @param path to observe
271 * @return int, 1 is success, 0 is fail.
273 int loadPluginInfoToManager(const std::string path);
277 #endif //__CPLUFFADAPTER_H