From d3095e26493c15ce146e36fe38443722e86ac832 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 16 Aug 2010 21:31:36 +0100 Subject: Add DAExampleModule to demonstrate dynamic attributes This module demonstrates that we can add an arbitrary persisted value to SOP without any changes to core code. Every time the object is moved, the move record is updated and the users in the scene alerted The number of moves is persisted over server restarts in sqlite --- .../Framework/DynamicAttributes/DAExampleModule.cs | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs new file mode 100644 index 0000000..2aca93a --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs @@ -0,0 +1,98 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Mono.Addins; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.Packets; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Region.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DAExampleModule")] + public class DAExampleModule : INonSharedRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected Scene m_scene; + protected IDialogModule m_dialogMod; + + public string Name { get { return "DAExample Module"; } } + public Type ReplaceableInterface { get { return null; } } + + public void Initialise(IConfigSource source) {} + + public void AddRegion(Scene scene) + { + m_scene = scene; + m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove; + m_dialogMod = m_scene.RequestModuleInterface(); + } + + public void RemoveRegion(Scene scene) + { + m_scene.EventManager.OnSceneGroupMove -= OnSceneGroupMove; + } + + public void RegionLoaded(Scene scene) {} + + public void Close() + { + RemoveRegion(m_scene); + } + + protected bool OnSceneGroupMove(UUID groupId, Vector3 delta) + { + SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); + OSDMap attrs = sop.DynAttrs; + + lock (attrs) + { + OSDInteger newValue; + + if (!attrs.ContainsKey("moves")) + newValue = new OSDInteger(1); + else + newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); + + attrs["moves"] = newValue; + + m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue)); + } + + return true; + } + } +} \ No newline at end of file -- cgit v1.1 From a6d9c263650cc23d60f941718f87a64aa2f360b2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 16 Aug 2010 22:21:46 +0100 Subject: Encapsulate an OSDMap in DAMap (was DynAttrsOSDMap) rather than inheriting from it This is the easier way to give us control over locking, rather than asking that OSDMap IDictionary methods be virtual --- .../Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs index 2aca93a..d6fb15b 100644 --- a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs @@ -76,7 +76,7 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule protected bool OnSceneGroupMove(UUID groupId, Vector3 delta) { SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); - OSDMap attrs = sop.DynAttrs; + DAMap attrs = sop.DynAttrs; lock (attrs) { -- cgit v1.1 From 8b4441d940a55da90645580477ece33d15849078 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 22 Jan 2013 08:41:32 +0200 Subject: Changed DAMap to be the container of "data stores", which are OSDMaps. Store names must have at least 4 characters. --- .../Framework/DynamicAttributes/DAExampleModule.cs | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs index d6fb15b..084fb5f 100644 --- a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs @@ -75,22 +75,23 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule protected bool OnSceneGroupMove(UUID groupId, Vector3 delta) { + OSDMap attrs = null; SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); - DAMap attrs = sop.DynAttrs; + if (!sop.DynAttrs.TryGetValue(Name, out attrs)) + attrs = new OSDMap(); - lock (attrs) - { - OSDInteger newValue; + OSDInteger newValue; - if (!attrs.ContainsKey("moves")) - newValue = new OSDInteger(1); - else - newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); + if (!attrs.ContainsKey("moves")) + newValue = new OSDInteger(1); + else + newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); - attrs["moves"] = newValue; - - m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue)); - } + attrs["moves"] = newValue; + + sop.DynAttrs[Name] = attrs; + + m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue)); return true; } -- cgit v1.1 From 23f0610f0ce33a7308fc2c9190204b2d8882ce85 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 22 Jan 2013 12:17:16 +0200 Subject: Disabled DAExampleModule --- .../Framework/DynamicAttributes/DAExampleModule.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs index 084fb5f..d36f65a 100644 --- a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs @@ -45,7 +45,9 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule public class DAExampleModule : INonSharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + + private static readonly bool ENABLED = false; // enable for testing + protected Scene m_scene; protected IDialogModule m_dialogMod; @@ -56,14 +58,20 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule public void AddRegion(Scene scene) { - m_scene = scene; - m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove; - m_dialogMod = m_scene.RequestModuleInterface(); + if (ENABLED) + { + m_scene = scene; + m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove; + m_dialogMod = m_scene.RequestModuleInterface(); + } } public void RemoveRegion(Scene scene) { - m_scene.EventManager.OnSceneGroupMove -= OnSceneGroupMove; + if (ENABLED) + { + m_scene.EventManager.OnSceneGroupMove -= OnSceneGroupMove; + } } public void RegionLoaded(Scene scene) {} -- cgit v1.1