Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / 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 typedef std::list<Plugin*> PluginsList;
33 typedef std::shared_ptr<PluginsList> PluginsListPtr;
34 typedef std::map< std::string, PluginsListPtr> PluginsSet;
35
36 class PluginRegistry : public SignalsSupport
37 {
38   public:
39     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
40     DECLARE_EXCEPTION_TYPE(Base, PluginNotFound)
41
42     template <typename T, typename ... Args>
43     void Call(Args ... args)
44     {
45         Invoke<T>(args ...);
46     }
47
48     template <typename T, typename ... Args>
49     void CallGroup(const typename CallbackSupport<T>::GroupType& type,
50                    Args ... args)
51     {
52         InvokeGroup<T>(type, args ...);
53     }
54
55     void AddPlugin(const std::string& libraryName, Plugin& plugin);
56
57     /*
58      * @throw PluginNotFound
59      * */
60     Plugin* GetPlugin(const std::string& libraryName);
61
62     void RemovePlugin(const std::string& libraryName, Plugin& plugin);
63
64     void UnloadAll();
65
66     ~PluginRegistry();
67
68   private:
69     bool LoadFromFile(const std::string& libraryName);
70
71     typedef void* Symbol;
72
73     std::map<std::string, Plugin*> m_plugins;
74     std::map<std::string, void*> m_libraries;
75 };
76
77 typedef std::shared_ptr<PluginRegistry> PluginRegistryPtr;
78 }
79
80 #endif