[Release] wrt-plugins-common_0.3.66
[platform/framework/web/wrt-plugins-common.git] / src / plugins-api-support / PluginRegistry.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    PluginRegistry.h
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @version
20  * @brief
21  */
22 #ifndef _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
23 #define _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
24
25 #include <map>
26 #include <string>
27 #include "SignalsSupport.h"
28 #include "Plugin.h"
29 #include <dpl/exception.h>
30
31 namespace WrtPluginsApi
32 {
33
34 typedef std::list<Plugin*> PluginsList;
35 typedef std::shared_ptr<PluginsList> PluginsListPtr;
36 typedef std::map< std::string, PluginsListPtr> PluginsSet;
37
38 class PluginRegistry : public SignalsSupport
39 {
40 public:
41     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
42     DECLARE_EXCEPTION_TYPE(Base, PluginNotFound)
43
44     template <typename T, typename ...Args>
45     void Call(Args... args)
46     {
47         Invoke<T>(args...);
48     }
49
50     template <typename T, typename ...Args>
51     void CallGroup(const typename CallbackSupport<T>::GroupType& type,
52                    Args... args)
53     {
54         InvokeGroup<T>(type, args...);
55     }
56
57     void AddPlugin(const std::string& libraryName, Plugin& plugin);
58
59     /*
60      * @throw PluginNotFound
61      * */
62     Plugin* GetPlugin(const std::string& libraryName);
63
64     void RemovePlugin(const std::string& libraryName, Plugin& plugin);
65
66     void UnloadAll();
67
68     ~PluginRegistry();
69 private:
70     bool LoadFromFile(const std::string& libraryName);
71
72     typedef void* Symbol;
73
74     std::map<std::string, Plugin*> m_plugins;
75     std::map<std::string, void*> m_libraries;
76 };
77
78 typedef std::shared_ptr<PluginRegistry> PluginRegistryPtr;
79
80 }
81
82 #endif