summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dynref.h16
-rw-r--r--src/modules.cpp12
2 files changed, 26 insertions, 2 deletions
diff --git a/include/dynref.h b/include/dynref.h
index a3d2f9966..2069a87eb 100644
--- a/include/dynref.h
+++ b/include/dynref.h
@@ -24,8 +24,18 @@
class CoreExport dynamic_reference_base : public interfacebase, public insp::intrusive_list_node<dynamic_reference_base>
{
+ public:
+ class CaptureHook
+ {
+ public:
+ /** Called when the target of the dynamic_reference has been acquired
+ */
+ virtual void OnCapture() = 0;
+ };
+
private:
std::string name;
+ CaptureHook* hook;
void resolve();
protected:
ServiceProvider* value;
@@ -35,6 +45,12 @@ class CoreExport dynamic_reference_base : public interfacebase, public insp::int
~dynamic_reference_base();
inline const std::string& GetProvider() { return name; }
void SetProvider(const std::string& newname);
+
+ /** Set handler to call when the target object becomes available
+ * @param h Handler to call
+ */
+ void SetCaptureHook(CaptureHook* h) { hook = h; }
+
void check();
operator bool() { return (value != NULL); }
static void reset_all();
diff --git a/src/modules.cpp b/src/modules.cpp
index 6510c9423..55d41674b 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -655,7 +655,7 @@ ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string&
}
dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::string& Name)
- : name(Name), value(NULL), creator(Creator)
+ : name(Name), hook(NULL), value(NULL), creator(Creator)
{
if (!dynrefs)
dynrefs = new insp::intrusive_list<dynamic_reference_base>;
@@ -688,7 +688,15 @@ void dynamic_reference_base::resolve()
// to ensure a dynref with the same name as another one resolves to the same object
std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules.DataProviders.lower_bound(name);
if ((i != ServerInstance->Modules.DataProviders.end()) && (i->first == this->name))
- value = static_cast<DataProvider*>(i->second);
+ {
+ ServiceProvider* newvalue = i->second;
+ if (value != newvalue)
+ {
+ value = newvalue;
+ if (hook)
+ hook->OnCapture();
+ }
+ }
else
value = NULL;
}