diff options
Diffstat (limited to 'util/fbcompose/PluginManager.hh')
-rw-r--r-- | util/fbcompose/PluginManager.hh | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/util/fbcompose/PluginManager.hh b/util/fbcompose/PluginManager.hh new file mode 100644 index 0000000..904f9ad --- /dev/null +++ b/util/fbcompose/PluginManager.hh | |||
@@ -0,0 +1,148 @@ | |||
1 | /** PluginManager.hh file for the fluxbox compositor. */ | ||
2 | |||
3 | // Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | // of this software and associated documentation files (the "Software"), to deal | ||
7 | // in the Software without restriction, including without limitation the rights | ||
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | // copies of the Software, and to permit persons to whom the Software is | ||
10 | // furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | // THE SOFTWARE. | ||
22 | |||
23 | |||
24 | #ifndef FBCOMPOSITOR_PLUGINMANAGER_HH | ||
25 | #define FBCOMPOSITOR_PLUGINMANAGER_HH | ||
26 | |||
27 | #include "Enumerations.hh" | ||
28 | |||
29 | #include "FbTk/FbString.hh" | ||
30 | |||
31 | #include <map> | ||
32 | #include <vector> | ||
33 | |||
34 | |||
35 | namespace FbCompositor { | ||
36 | |||
37 | class BasePlugin; | ||
38 | class BaseScreen; | ||
39 | |||
40 | |||
41 | //--- TYPEDEFS ------------------------------------------------------------- | ||
42 | |||
43 | /** A pointer to a function that creates a plugin class instance. */ | ||
44 | typedef BasePlugin* (*CreatePluginFunction)(const BaseScreen&, const std::vector<FbTk::FbString>&); | ||
45 | |||
46 | /** A pointer to a function that returns the rendering mode the plugin operates in. */ | ||
47 | typedef PluginType (*PluginTypeFunction)(); | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Responsible for plugin loading, unloading and availibility. | ||
52 | */ | ||
53 | class PluginManager { | ||
54 | struct PluginLibData; | ||
55 | |||
56 | public : | ||
57 | //--- CONSTRUCTORS AND DESTRUCTORS ------------------------------------- | ||
58 | |||
59 | /** Constructor. */ | ||
60 | PluginManager(PluginType plugin_type, const BaseScreen &screen, const FbTk::FbString user_plugin_dir); | ||
61 | |||
62 | /** Destructor. */ | ||
63 | ~PluginManager(); | ||
64 | |||
65 | |||
66 | //--- PLUGIN MANIPULATION ---------------------------------------------- | ||
67 | |||
68 | /** Create a plugin object, load the appropriate library if needed. */ | ||
69 | void createPluginObject(FbTk::FbString name, std::vector<FbTk::FbString> args = std::vector<FbTk::FbString>()); | ||
70 | |||
71 | /** \returns a reference to a vector with plugin objects. */ | ||
72 | std::vector<BasePlugin*> &plugins(); | ||
73 | |||
74 | /** \returns a reference to a vector with plugin objects (const version). */ | ||
75 | const std::vector<BasePlugin*> &plugins() const; | ||
76 | |||
77 | |||
78 | private : | ||
79 | //--- CONSTRUCTORS ----------------------------------------------------- | ||
80 | |||
81 | /** Copy constructor. */ | ||
82 | PluginManager(const PluginManager&); | ||
83 | |||
84 | /** Assignment operator. */ | ||
85 | PluginManager &operator=(const PluginManager&); | ||
86 | |||
87 | |||
88 | //--- INTERNAL PLUGIN MANIPULATION ------------------------------------- | ||
89 | |||
90 | /** Load a plugin. */ | ||
91 | void loadPlugin(FbTk::FbString name); | ||
92 | |||
93 | /** Unload a plugin. */ | ||
94 | void unloadPlugin(FbTk::FbString name); | ||
95 | |||
96 | /** Unload a plugin (actual worker function). */ | ||
97 | void unloadPlugin(std::map<FbTk::FbString, PluginLibData>::iterator it); | ||
98 | |||
99 | |||
100 | //--- CONVENIENCE FUNCTIONS -------------------------------------------- | ||
101 | |||
102 | /** Build a vector of search paths for a given plugin. */ | ||
103 | std::vector<FbTk::FbString> buildPluginPaths(const FbTk::FbString &name); | ||
104 | |||
105 | /** \returns some object from the given library handle. */ | ||
106 | void *getLibraryObject(void *handle, const char *object_name, const char *plugin_name, | ||
107 | const char *verbose_object_name); | ||
108 | |||
109 | |||
110 | //--- PLUGINS AND METADATA --------------------------------------------- | ||
111 | |||
112 | /** Specific plugin-related data. */ | ||
113 | struct PluginLibData { | ||
114 | void *handle; ///< Handle to the loaded library. | ||
115 | CreatePluginFunction create_function; ///< Plugin creation function. | ||
116 | }; | ||
117 | |||
118 | /** A map, containing all loaded plugins. */ | ||
119 | std::map<FbTk::FbString, PluginLibData> m_plugin_libs; | ||
120 | |||
121 | /** A vector with active plugin objects. */ | ||
122 | std::vector<BasePlugin*> m_plugin_objects; | ||
123 | |||
124 | /** Type of the plugins this object manages. */ | ||
125 | PluginType m_plugin_type; | ||
126 | |||
127 | /** The screen this manager operates on. */ | ||
128 | const BaseScreen &m_screen; | ||
129 | |||
130 | /** User plugin directory. */ | ||
131 | FbTk::FbString m_user_plugin_dir; | ||
132 | }; | ||
133 | |||
134 | |||
135 | //--- INLINE FUNCTIONS ----------------------------------------------------- | ||
136 | |||
137 | // Returns a reference to a vector with plugin objects. | ||
138 | inline std::vector<BasePlugin*> &PluginManager::plugins() { | ||
139 | return m_plugin_objects; | ||
140 | } | ||
141 | |||
142 | // Returns a reference to a vector with plugin objects (const version). | ||
143 | inline const std::vector<BasePlugin*> &PluginManager::plugins() const { | ||
144 | return m_plugin_objects; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | #endif // FBCOMPOSITOR_PLUGINMANAGER_HH | ||