diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2022-06-15 19:43:53 -0400 |
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2022-06-15 19:43:53 -0400 |
| commit | a4ff9caf69cb8fbbf3e5d40a258ec99a070b0f94 (patch) | |
| tree | 88ca26a0c87d4c5745908f54d283ada8f6f54ba8 /indra/llcommon/llevents.h | |
| parent | cdbd06e8ed6e3f4285a61f5c0b607a65dfdf8dfd (diff) | |
DRTVWR-564: WIP: add LLEventPumps::registerPumpFactory()
and registerTypeFactory().
Untested.
This will support registering just-in-time LLEventAPI instances, instantiated
on demand.
Diffstat (limited to 'indra/llcommon/llevents.h')
| -rw-r--r-- | indra/llcommon/llevents.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index ae6e5aabc9..38adc31121 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -268,6 +268,43 @@ public: LLEventPump& make(const std::string& name, bool tweak=false, const std::string& type=std::string()); + /// function passed to registerTypeFactory() + typedef std::function<LLEventPump*(const std::string& name, bool tweak, const std::string& type)> TypeFactory; + + /** + * Register a TypeFactory for use with make(). When make() is called with + * the specified @a type string, call @a factory(name, tweak, type) to + * instantiate it. + * + * Returns true if successfully registered, false if there already exists + * a TypeFactory for the specified @a type name. + */ + bool registerTypeFactory(const std::string& type, const TypeFactory& factory); + + /// function passed to registerPumpFactory() + typedef std::function<LLEventPump*(const std::string&)> PumpFactory; + + /** + * Register a PumpFactory for use with obtain(). When obtain() is called + * with the specified @a name string, if an LLEventPump with the specified + * @a name doesn't already exist, call @a factory(name) to instantiate it. + * + * Returns true if successfully registered, false if there already exists + * a factory override for the specified @a name. + * + * PumpFactory does not support @a tweak because it's only called when + * <i>that particular</i> @a name is passed to obtain(). Bear in mind that + * <tt>obtain(name)</tt> might still bypass the caller's PumpFactory for a + * couple different reasons: + * + * * registerPumpFactory() returns false because there's already a factory + * override for the specified @name + * * between a successful <tt>registerPumpFactory(name)</tt> call (returns + * true) and a call to <tt>obtain(name)</tt>, someone explicitly + * instantiated an LLEventPump(name), so obtain(name) returned that. + */ + bool registerPumpFactory(const std::string& name, const PumpFactory& factory); + /** * Find the named LLEventPump instance. If it exists post the message to it. * If the pump does not exist, do nothing. @@ -325,7 +362,7 @@ testable: typedef std::set<LLEventPump*> PumpSet; PumpSet mOurPumps; // for make(), map string type name to LLEventPump subclass factory function - typedef std::map<std::string, std::function<LLEventPump*(const std::string&, bool)>> PumpFactories; + typedef std::map<std::string, PumpFactory> PumpFactories; // Data used by make(). // One might think mFactories and mTypes could reasonably be static. So // they could -- if not for the fact that make() or obtain() might be |
