summaryrefslogtreecommitdiff
path: root/libadhocutil/plugins.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-17 21:34:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-18 02:09:57 +0100
commit8da1334746a7bf34924b1264a309309ea6148027 (patch)
treee1b7a3784dd3b3058dd1ebd61194a3483c7f47c2 /libadhocutil/plugins.h
parentTest loading and unloading a library containing a plugin (diff)
downloadlibadhocutil-8da1334746a7bf34924b1264a309309ea6148027.tar.bz2
libadhocutil-8da1334746a7bf34924b1264a309309ea6148027.tar.xz
libadhocutil-8da1334746a7bf34924b1264a309309ea6148027.zip
Support addition and removal of plugin resolver functions
Diffstat (limited to 'libadhocutil/plugins.h')
-rw-r--r--libadhocutil/plugins.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/libadhocutil/plugins.h b/libadhocutil/plugins.h
index 5efd5b5..8b8efac 100644
--- a/libadhocutil/plugins.h
+++ b/libadhocutil/plugins.h
@@ -2,6 +2,8 @@
#define ADHOCUTIL_PLUGINS_H
#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
+#include <boost/optional.hpp>
#include <boost/multi_index_container_fwd.hpp>
#include <boost/multi_index/ordered_index_fwd.hpp>
#include <boost/multi_index/member.hpp>
@@ -9,6 +11,7 @@
#include <boost/multi_index/composite_key.hpp>
#include <typeinfo>
#include <set>
+#include <map>
#include <algorithm>
#include "visibility.h"
#include "unique.h"
@@ -53,6 +56,13 @@ namespace AdHoc {
DuplicatePluginException(PluginPtr p1, PluginPtr p2);
};
+ /// Thrown when a resolver function is added a second time.
+ class DuplicateResolverException : public std::runtime_error {
+ public:
+ /// Constuctor taking resolver type.
+ DuplicateResolverException(const std::type_info &);
+ };
+
template <typename T>
/// Typed plugin and handle to implementation.
class DLL_PUBLIC PluginOf : public Plugin {
@@ -73,6 +83,8 @@ namespace AdHoc {
/// Container for loaded plugins.
class DLL_PUBLIC PluginManager {
public:
+ typedef boost::function<boost::optional<std::string> (const std::type_info &, const std::string &)> PluginResolver;
+
PluginManager();
virtual ~PluginManager();
@@ -125,6 +137,35 @@ namespace AdHoc {
size_t count() const;
/**
+ * Add a type plugin resolver function.
+ * @param t The resolver type.
+ * @param f The resolver function.
+ */
+ void addResolver(const std::type_info & t, const PluginResolver & f);
+
+ /**
+ * Add a type plugin resolver function.
+ * @param f The resolver function.
+ */
+ template<typename T> void addResolver(const PluginResolver & f);
+
+ /**
+ * Remove a type plugin resolver function.
+ * @param f The resolver type.
+ */
+ void removeResolver(const std::type_info & t);
+
+ /**
+ * Remove a type plugin resolver function.
+ */
+ template<typename T> void removeResolver();
+
+ /**
+ * The number of installed plugins.
+ */
+ size_t countResolvers() const;
+
+ /**
* Get the default plugin manager instance.
*/
static PluginManager * getDefault();
@@ -142,7 +183,10 @@ namespace AdHoc {
>>
>> PluginStore;
+ typedef std::map<size_t, PluginResolver> TypePluginResolvers;
+
PluginStore * plugins;
+ TypePluginResolvers * resolvers;
};
}