From c70d57ff983d42b6898d766eb5536e56868b3213 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Mon, 26 Jul 2010 20:36:28 +0100
Subject: Add EventManager.OnSceneObjectPreSave() for future use. This is
triggered immediately before a copy of the group is persisted to storage
---
.../CoreModules/World/Media/Moap/MoapModule.cs | 11 ++++--
OpenSim/Region/Framework/Scenes/EventManager.cs | 39 ++++++++++++++++++++--
.../Region/Framework/Scenes/SceneObjectGroup.cs | 1 +
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
index 2771492..263ee57 100644
--- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
+++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
@@ -101,6 +101,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
m_scene.EventManager.OnRegisterCaps += OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps += OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectLoaded += OnSceneObjectLoaded;
+ m_scene.EventManager.OnSceneObjectPreSave += OnSceneObjectPreSave;
}
public void Close()
@@ -108,6 +109,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps -= OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectLoaded -= OnSceneObjectLoaded;
+ m_scene.EventManager.OnSceneObjectPreSave -= OnSceneObjectPreSave;
}
public void OnRegisterCaps(UUID agentID, Caps caps)
@@ -157,11 +159,16 @@ namespace OpenSim.Region.CoreModules.Media.Moap
}
}
- public void OnSceneObjectLoaded(SceneObjectGroup sog)
+ public void OnSceneObjectLoaded(SceneObjectGroup so)
{
- m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", sog.Name, sog.UUID);
+ m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID);
}
+ public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo)
+ {
+ m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID);
+ }
+
public MediaEntry GetMediaEntry(SceneObjectPart part, int face)
{
MediaEntry me = null;
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 46e17c5..a4dd170 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -330,14 +330,26 @@ namespace OpenSim.Region.Framework.Scenes
/// If the object is being attached, then the avatarID will be present. If the object is being detached then
/// the avatarID is UUID.Zero (I know, this doesn't make much sense but now it's historical).
public delegate void Attach(uint localID, UUID itemID, UUID avatarID);
- public event Attach OnAttach;
-
- public delegate void SceneObjectDelegate(SceneObjectGroup so);
+ public event Attach OnAttach;
///
/// Called immediately after an object is loaded from storage.
///
public event SceneObjectDelegate OnSceneObjectLoaded;
+ public delegate void SceneObjectDelegate(SceneObjectGroup so);
+
+ ///
+ /// Called immediately before an object is saved to storage.
+ ///
+ ///
+ /// The scene object being persisted.
+ /// This is actually a copy of the original scene object so changes made here will be saved to storage but will not be kept in memory.
+ ///
+ ///
+ /// The original scene object being persisted. Changes here will stay in memory but will not be saved to storage on this save.
+ ///
+ public event SceneObjectPreSaveDelegate OnSceneObjectPreSave;
+ public delegate void SceneObjectPreSaveDelegate(SceneObjectGroup persistingSo, SceneObjectGroup originalSo);
public delegate void RegionUp(GridRegion region);
public event RegionUp OnRegionUp;
@@ -2040,6 +2052,27 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
+ }
+
+ public void TriggerOnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo)
+ {
+ SceneObjectPreSaveDelegate handler = OnSceneObjectPreSave;
+ if (handler != null)
+ {
+ foreach (SceneObjectPreSaveDelegate d in handler.GetInvocationList())
+ {
+ try
+ {
+ d(persistingSo, originalSo);
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat(
+ "[EVENT MANAGER]: Delegate for TriggerOnSceneObjectPreSave failed - continuing. {0} {1}",
+ e.Message, e.StackTrace);
+ }
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 1ca390a..451b93e 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -1479,6 +1479,7 @@ namespace OpenSim.Region.Framework.Scenes
backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
HasGroupChanged = false;
+ m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
backup_group.ForEachPart(delegate(SceneObjectPart part)
--
cgit v1.1