From d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 26 Jul 2010 21:09:54 +0100 Subject: relocate serialization code from SQLiteRegionData to MoapModule using load and save events. This is better modularity. It also allows MoapModule to be replaced with some other media module that may behave completely differently in the future. Remaining non-modularity: PrimitiveBaseShape needs explicit Media and MediaRaw fields. MediaRaw is required in order to shuttle the pre-serialization data back and forth from the database layer. The database also needs to know about MediaRaw though not about Media. IMO, it would be extremely nice to remove these hard codings but this is a bridge too far at the present time. --- OpenSim/Data/SQLite/SQLiteRegionData.cs | 55 +---------------- OpenSim/Framework/PrimitiveBaseShape.cs | 6 ++ .../CoreModules/World/Media/Moap/MoapModule.cs | 70 +++++++++++++++++++++- 3 files changed, 76 insertions(+), 55 deletions(-) diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index b564419..f63d35e 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -31,7 +31,6 @@ using System.Data; using System.Drawing; using System.IO; using System.Reflection; -using System.Xml; using log4net; using Mono.Data.Sqlite; using OpenMetaverse; @@ -1862,28 +1861,7 @@ namespace OpenSim.Data.SQLite s.ExtraParams = (byte[]) row["ExtraParams"]; if (!(row["Media"] is System.DBNull)) - { - using (StringReader sr = new StringReader((string)row["Media"])) - { - using (XmlTextReader xtr = new XmlTextReader(sr)) - { - xtr.ReadStartElement("osmedia"); - - OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); - - List mediaEntries = new List(); - foreach (OSD osdMe in osdMeArray) - { - MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); - mediaEntries.Add(me); - } - - s.Media = mediaEntries; - - xtr.ReadEndElement(); - } - } - } + s.MediaRaw = (string)row["Media"]; return s; } @@ -1928,36 +1906,7 @@ namespace OpenSim.Data.SQLite row["Texture"] = s.TextureEntry; row["ExtraParams"] = s.ExtraParams; - - if (null != s.Media) - { - using (StringWriter sw = new StringWriter()) - { - using (XmlTextWriter xtw = new XmlTextWriter(sw)) - { - xtw.WriteStartElement("osmedia"); - xtw.WriteAttributeString("type", "sl"); - xtw.WriteAttributeString("major_version", "0"); - xtw.WriteAttributeString("minor_version", "1"); - - OSDArray meArray = new OSDArray(); - foreach (MediaEntry me in s.Media) - { - OSD osd = (null == me ? new OSD() : me.GetOSD()); - meArray.Add(osd); - } - - xtw.WriteStartElement("osdata"); - xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); - xtw.WriteEndElement(); - - xtw.WriteEndElement(); - - xtw.Flush(); - row["Media"] = sw.ToString(); - } - } - } + row["Media"] = s.MediaRaw; } /// diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 85638ca..03ddb33 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -174,6 +174,12 @@ namespace OpenSim.Framework } /// + /// Raw media data suitable for serialization operations. This should only ever be used by an IMoapModule. + /// + [XmlIgnore] + public string MediaRaw { get; set; } + + /// /// Entries to store media textures on each face /// /// Do not change this value directly - always do it through an IMoapModule. diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs index 263ee57..0e03318 100644 --- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs +++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs @@ -32,6 +32,7 @@ using System.Collections.Specialized; using System.Reflection; using System.IO; using System.Web; +using System.Xml; using log4net; using Mono.Addins; using Nini.Config; @@ -46,6 +47,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; using Caps = OpenSim.Framework.Capabilities.Caps; +using OSDArray = OpenMetaverse.StructuredData.OSDArray; using OSDMap = OpenMetaverse.StructuredData.OSDMap; namespace OpenSim.Region.CoreModules.Media.Moap @@ -162,12 +164,76 @@ namespace OpenSim.Region.CoreModules.Media.Moap public void OnSceneObjectLoaded(SceneObjectGroup so) { m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID); + + so.ForEachPart(OnSceneObjectPartLoaded); } public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo) { - m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); - } + m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); + + persistingSo.ForEachPart(OnSceneObjectPartPreSave); + } + + protected void OnSceneObjectPartLoaded(SceneObjectPart part) + { + if (null == part.Shape.MediaRaw) + return; + + using (StringReader sr = new StringReader(part.Shape.MediaRaw)) + { + using (XmlTextReader xtr = new XmlTextReader(sr)) + { + xtr.ReadStartElement("osmedia"); + + OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); + + List mediaEntries = new List(); + foreach (OSD osdMe in osdMeArray) + { + MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); + mediaEntries.Add(me); + } + + xtr.ReadEndElement(); + + part.Shape.Media = mediaEntries; + } + } + } + + protected void OnSceneObjectPartPreSave(SceneObjectPart part) + { + if (null == part.Shape.Media) + return; + + using (StringWriter sw = new StringWriter()) + { + using (XmlTextWriter xtw = new XmlTextWriter(sw)) + { + xtw.WriteStartElement("osmedia"); + xtw.WriteAttributeString("type", "sl"); + xtw.WriteAttributeString("major_version", "0"); + xtw.WriteAttributeString("minor_version", "1"); + + OSDArray meArray = new OSDArray(); + foreach (MediaEntry me in part.Shape.Media) + { + OSD osd = (null == me ? new OSD() : me.GetOSD()); + meArray.Add(osd); + } + + xtw.WriteStartElement("osdata"); + xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); + xtw.WriteEndElement(); + + xtw.WriteEndElement(); + + xtw.Flush(); + part.Shape.MediaRaw = sw.ToString(); + } + } + } public MediaEntry GetMediaEntry(SceneObjectPart part, int face) { -- cgit v1.1