Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / PluginManagerImpl.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file PluginManagerImpl.h
22
23 /// @brief PluginManagerImple provides abstraction of the plugin manager interface
24
25 #ifndef __PLUGINMANAGERIMPL_H__
26 #define __PLUGINMANAGERIMPL_H__
27
28 #include "Plugin.h"
29 #include "CpluffAdapter.h"
30 #include <algorithm>
31
32 #ifdef ANDROID
33 #include "FelixAdapter.h"
34 #endif
35
36 namespace OIC
37 {
38     class PluginManagerImpl
39     {
40         public:
41
42             /**
43             * Constructor for PluginManagerImpl.
44             * During construction time, all plugins under the root plugin path will be loaded.
45             *
46             */
47             PluginManagerImpl(void *args);
48
49             /**
50             * Virtual destructor
51             */
52             virtual ~PluginManagerImpl(void);
53
54
55             /**
56             * A function to register pluins in the path.
57             * This function will load plugins in plugin manager table.
58             *
59             * @param path plugin file path to be registered.
60             * @return int, 1 is success, 0 is fail.
61             *
62             * NOTE:
63             *
64             */
65             int registerPlugin(std::string path);
66
67
68             /**
69             * A function to register pluins in the path.
70             * This function will load plugins in plugin manager table.
71             *
72             * @param path plugin file path to be registered.
73             * recursive load plugins sub folders recursively.
74             * @return int, 1 is success, 0 is fail.
75             *
76             * NOTE:
77             *
78             */
79             int registerAllPlugin(std::string path);
80
81             /**
82             * Unregister plugin.
83             *
84             * @param plugin plugin object to be unregistered.
85             * @return int, 1 is success, 0 is fail.
86             */
87             int unregisterPlugin(std::string path);
88
89             /**
90             * Unregister All plugin.
91             *
92             * @return int, 1 is success, 0 is fail.
93             */
94             int unregisterAllPlugin(void);
95
96             /**
97             * find plugins which have the key and value
98             *
99             * @return vector of currently registered plugins
100             */
101             std::vector<Plugin> *findPlugins(const std::string key, const std::string value);
102
103             /**
104             * Get plugin which has the id
105             *
106             * @param pluginID plugin id to find
107             * @return Plugin instance
108             */
109             Plugin *getPlugin(const std::string pluginID);
110
111             /**
112             * Check whether the plugin started or not
113             *
114             * @param Plugin to identify the Starting.
115             * @return true if started, false is stop.
116             *
117             */
118             bool isStarted(Plugin *plugin);
119
120             /**
121             * Get Plugin state.
122             *
123             * @param Plugin ID
124             * @return Plugin state.
125             */
126             virtual std::string getState(const std::string plugID);
127
128             /**
129             * Start  plugins by resource type
130             *
131             * @param type resouce type string to be started.
132             *
133             */
134             virtual int startPlugins(const std::string key, const std::string value);
135
136             /**
137             * Stop  plugins by resource type
138             *
139             * @param type resouce type string to be started.
140             *
141             */
142             virtual int stopPlugins(const std::string key, const std::string value);
143
144             /**
145             * Start plugin
146             * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
147             *
148             * @param Plugin
149             * @return int, 1 is success, 0 is fail.
150             */
151             int startPlugins(Plugin *const plugin);
152
153
154             /**
155             * Stop Plugin.
156             * This function will call stop function of plugin and unload dynamic plugin library from memory.
157             *
158             * @param Plugin
159             * @return int, 1 is success, 0 is fail.
160             */
161             int stopPlugins(Plugin *const plugin);
162
163             /**
164             * Rescan Plugin.
165             * This function will call rescan function of plugins in the configuration folder
166             *
167             * @param Plugin
168             * @return int, 1 is success, 0 is fail.
169             */
170             virtual int rescanPlugin();
171
172             /**
173             * get all plugins which currently registered.
174             *
175             * @return vector of currently registered plugins
176             *
177             */
178             virtual std::vector<Plugin> &getAllPlugins(void);
179
180             static PluginManagerImpl *Getinstance(void *args)
181             {
182                 if (NULL == s_pinstance)
183                 {
184                     s_pinstance = new PluginManagerImpl(args);
185                 }
186
187                 return s_pinstance;
188             }
189
190         private:
191
192             CpluffAdapter *cppm;
193             void *m_args;
194 #ifdef ANDROID
195             FelixAdapter *javappm;
196 #endif
197
198             std::vector<Plugin> m_plugins;
199             static PluginManagerImpl *s_pinstance;
200
201             static void deleteinstance()
202             {
203                 if (NULL != s_pinstance)
204                 {
205                     delete s_pinstance;
206                     s_pinstance = NULL;
207                 }
208             }
209
210             /*
211             * refresh All Plugin information.
212             *
213             * @return vector<Plugin> is all Plugin.
214             */
215             std::vector<Plugin> refreshPluginInfo();
216
217             /**
218             * Start plugin by platform.
219             * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
220             *
221             * @param Plugin
222             * @param Platform pointer.
223             * @return int, 1 is success, 0 is fail.
224             */
225             int startbyPlatform(Plugin *const plugin, void *const arg);
226
227             /**
228             * Stop Plugin by platform.
229             * This function will call stop function of plugin and unload dynamic plugin library from memory.
230             *
231             * @param Plugin
232             * @return int, 1 is success, 0 is fail.
233             */
234             int stopbyPlatform(Plugin *const plugin);
235     };
236 }
237
238 #endif //__PLUGINMANAGERIMPL_H__