Add EventManager.OnSceneObjectPreSave() for future use. This is triggered immediately before a copy of the group is persisted to storage

prebuild-update
Justin Clark-Casey (justincc) 2010-07-26 20:36:28 +01:00
parent 491b8181ad
commit c70d57ff98
3 changed files with 46 additions and 5 deletions

View File

@ -101,6 +101,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; m_scene.EventManager.OnRegisterCaps += OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps += OnDeregisterCaps; m_scene.EventManager.OnDeregisterCaps += OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectLoaded += OnSceneObjectLoaded; m_scene.EventManager.OnSceneObjectLoaded += OnSceneObjectLoaded;
m_scene.EventManager.OnSceneObjectPreSave += OnSceneObjectPreSave;
} }
public void Close() public void Close()
@ -108,6 +109,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps -= OnDeregisterCaps; m_scene.EventManager.OnDeregisterCaps -= OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectLoaded -= OnSceneObjectLoaded; m_scene.EventManager.OnSceneObjectLoaded -= OnSceneObjectLoaded;
m_scene.EventManager.OnSceneObjectPreSave -= OnSceneObjectPreSave;
} }
public void OnRegisterCaps(UUID agentID, Caps caps) 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) public MediaEntry GetMediaEntry(SceneObjectPart part, int face)
{ {
MediaEntry me = null; MediaEntry me = null;

View File

@ -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 /// 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). /// 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 delegate void Attach(uint localID, UUID itemID, UUID avatarID);
public event Attach OnAttach; public event Attach OnAttach;
public delegate void SceneObjectDelegate(SceneObjectGroup so);
/// <summary> /// <summary>
/// Called immediately after an object is loaded from storage. /// Called immediately after an object is loaded from storage.
/// </summary> /// </summary>
public event SceneObjectDelegate OnSceneObjectLoaded; public event SceneObjectDelegate OnSceneObjectLoaded;
public delegate void SceneObjectDelegate(SceneObjectGroup so);
/// <summary>
/// Called immediately before an object is saved to storage.
/// </summary>
/// <param name="persistingSo">
/// 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.
/// </param>
/// <param name="originalSo">
/// The original scene object being persisted. Changes here will stay in memory but will not be saved to storage on this save.
/// </param>
public event SceneObjectPreSaveDelegate OnSceneObjectPreSave;
public delegate void SceneObjectPreSaveDelegate(SceneObjectGroup persistingSo, SceneObjectGroup originalSo);
public delegate void RegionUp(GridRegion region); public delegate void RegionUp(GridRegion region);
public event RegionUp OnRegionUp; 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);
}
}
}
} }
} }
} }

View File

@ -1479,6 +1479,7 @@ namespace OpenSim.Region.Framework.Scenes
backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem; backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
HasGroupChanged = false; HasGroupChanged = false;
m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID); datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
backup_group.ForEachPart(delegate(SceneObjectPart part) backup_group.ForEachPart(delegate(SceneObjectPart part)