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