Corrected @file tags and restored 'Files' section.
[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 /**
22  * @file
23  *
24  */
25
26 #ifndef __PLUGINMANAGERIMPL_H__
27 #define __PLUGINMANAGERIMPL_H__
28
29 #include "Plugin.h"
30 #include "CpluffAdapter.h"
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             /**
70             * A function to register pluins in the path.
71             * This function will load plugins in plugin manager table.
72             *
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.
76             *
77             * NOTE:
78             *
79             */
80             int registerAllPlugin(std::string path);
81
82             /**
83             * Unregister plugin.
84             *
85             * @param plugin plugin object to be unregistered.
86             * @return int, 1 is success, 0 is fail.
87             */
88             int unregisterPlugin(std::string path);
89
90             /**
91             * Unregister All plugin.
92             *
93             * @return int, 1 is success, 0 is fail.
94             */
95             int unregisterAllPlugin(void);
96
97             /**
98             * find plugins which have the key and value
99             *
100             * @return vector of currently registered plugins
101             */
102             std::vector<Plugin> *findPlugins(const std::string key, const std::string value);
103
104             /**
105             * Get plugin which has the id
106             *
107             * @param pluginID plugin id to find
108             * @return Plugin instance
109             */
110             Plugin *getPlugin(const std::string pluginID);
111
112             /**
113             * Check whether the plugin started or not
114             *
115             * @param Plugin to identify the Starting.
116             * @return true if started, false is stop.
117             *
118             */
119             bool isStarted(Plugin *plugin);
120
121             /**
122             * Get Plugin state.
123             *
124             * @param Plugin ID
125             * @return Plugin state.
126             */
127             virtual std::string getState(const std::string plugID);
128
129             /**
130             * Start  plugins by resource type
131             *
132             * @param type resouce type string to be started.
133             *
134             */
135             virtual int startPlugins(const std::string key, const std::string value);
136
137             /**
138             * Stop  plugins by resource type
139             *
140             * @param type resouce type string to be started.
141             *
142             */
143             virtual int stopPlugins(const std::string key, const std::string value);
144
145             /**
146             * Start plugin
147             * This function will load dynamic plugin library on memory and call start function of plugin to be initialized.
148             *
149             * @param Plugin
150             * @return int, 1 is success, 0 is fail.
151             */
152             int startPlugins(Plugin *const plugin);
153
154
155             /**
156             * Stop Plugin.
157             * This function will call stop function of plugin and unload dynamic plugin library from memory.
158             *
159             * @param Plugin
160             * @return int, 1 is success, 0 is fail.
161             */
162             int stopPlugins(Plugin *const plugin);
163
164             /**
165             * Rescan Plugin.
166             * This function will call rescan function of plugins in the configuration folder
167             *
168             * @param Plugin
169             * @return int, 1 is success, 0 is fail.
170             */
171             virtual int rescanPlugin();
172
173             /**
174             * get all plugins which currently registered.
175             *
176             * @return vector of currently registered plugins
177             *
178             */
179             virtual std::vector<Plugin> &getAllPlugins(void);
180
181             static PluginManagerImpl *Getinstance(void *arg)
182             {
183                 if (NULL == s_pinstance)
184                 {
185                     s_pinstance = new PluginManagerImpl(arg);
186                 }
187
188                 return s_pinstance;
189             }
190
191         private:
192
193             CpluffAdapter *cppm;
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__