summaryrefslogtreecommitdiff
path: root/indra/llcommon/lleventdispatcher.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/lleventdispatcher.h')
-rw-r--r--indra/llcommon/lleventdispatcher.h76
1 files changed, 68 insertions, 8 deletions
diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h
index 5a86b90bff..c8c4fe0c3c 100644
--- a/indra/llcommon/lleventdispatcher.h
+++ b/indra/llcommon/lleventdispatcher.h
@@ -19,6 +19,7 @@
#include <map>
#include <boost/function.hpp>
#include <boost/bind.hpp>
+#include <boost/iterator/transform_iterator.hpp>
#include <typeinfo>
#include "llevents.h"
@@ -44,7 +45,10 @@ public:
* is used to validate the structure of each incoming event (see
* llsd_matches()).
*/
- void add(const std::string& name, const Callable& callable, const LLSD& required=LLSD());
+ void add(const std::string& name,
+ const std::string& desc,
+ const Callable& callable,
+ const LLSD& required=LLSD());
/**
* Special case: a subclass of this class can pass an unbound member
@@ -52,18 +56,32 @@ public:
* <tt>boost::bind()</tt> expression.
*/
template <class CLASS>
- void add(const std::string& name, void (CLASS::*method)(const LLSD&),
+ void add(const std::string& name,
+ const std::string& desc,
+ void (CLASS::*method)(const LLSD&),
const LLSD& required=LLSD())
{
- addMethod<CLASS>(name, method, required);
+ addMethod<CLASS>(name, desc, method, required);
}
/// Overload for both const and non-const methods
template <class CLASS>
- void add(const std::string& name, void (CLASS::*method)(const LLSD&) const,
+ void add(const std::string& name,
+ const std::string& desc,
+ void (CLASS::*method)(const LLSD&) const,
const LLSD& required=LLSD())
{
- addMethod<CLASS>(name, method, required);
+ addMethod<CLASS>(name, desc, method, required);
+ }
+
+ /// Convenience: for LLEventDispatcher, not every callable needs a
+ /// documentation string.
+ template <typename CALLABLE>
+ void add(const std::string& name,
+ CALLABLE callable,
+ const LLSD& required=LLSD())
+ {
+ add(name, "", callable, required);
}
/// Unregister a callable
@@ -80,13 +98,51 @@ public:
/// @a required prototype specified at add() time, die with LL_ERRS.
void operator()(const LLSD& event) const;
+ /// @name Iterate over defined names
+ //@{
+ typedef std::pair<std::string, std::string> NameDesc;
+
+private:
+ struct DispatchEntry
+ {
+ DispatchEntry(const Callable& func, const std::string& desc, const LLSD& required):
+ mFunc(func),
+ mDesc(desc),
+ mRequired(required)
+ {}
+ Callable mFunc;
+ std::string mDesc;
+ LLSD mRequired;
+ };
+ typedef std::map<std::string, DispatchEntry> DispatchMap;
+
+public:
+ /// We want the flexibility to redefine what data we store per name,
+ /// therefore our public interface doesn't expose DispatchMap iterators,
+ /// or DispatchMap itself, or DispatchEntry. Instead we explicitly
+ /// transform each DispatchMap item to NameDesc on dereferencing.
+ typedef boost::transform_iterator<NameDesc(*)(const DispatchMap::value_type&), DispatchMap::const_iterator> const_iterator;
+ const_iterator begin() const
+ {
+ return boost::make_transform_iterator(mDispatch.begin(), makeNameDesc);
+ }
+ const_iterator end() const
+ {
+ return boost::make_transform_iterator(mDispatch.end(), makeNameDesc);
+ }
+ //@}
+
/// Fetch the Callable for the specified name. If no such name was
/// registered, return an empty() Callable.
Callable get(const std::string& name) const;
+ /// Get information about a specific Callable
+ LLSD getMetadata(const std::string& name) const;
+
private:
template <class CLASS, typename METHOD>
- void addMethod(const std::string& name, const METHOD& method, const LLSD& required)
+ void addMethod(const std::string& name, const std::string& desc,
+ const METHOD& method, const LLSD& required)
{
CLASS* downcast = dynamic_cast<CLASS*>(this);
if (! downcast)
@@ -95,7 +151,7 @@ private:
}
else
{
- add(name, boost::bind(method, downcast, _1), required);
+ add(name, desc, boost::bind(method, downcast, _1), required);
}
}
void addFail(const std::string& name, const std::string& classname) const;
@@ -103,8 +159,12 @@ private:
bool attemptCall(const std::string& name, const LLSD& event) const;
std::string mDesc, mKey;
- typedef std::map<std::string, std::pair<Callable, LLSD> > DispatchMap;
DispatchMap mDispatch;
+
+ static NameDesc makeNameDesc(const DispatchMap::value_type& item)
+ {
+ return NameDesc(item.first, item.second.mDesc);
+ }
};
/**