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