diff options
author | Justin Clark-Casey (justincc) | 2010-07-26 21:09:54 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-07-26 21:09:54 +0100 |
commit | d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7 (patch) | |
tree | 5ed373d0ec1f5e027c005c9a3d03b4e5150920a4 | |
parent | Add EventManager.OnSceneObjectPreSave() for future use. This is triggered im... (diff) | |
download | opensim-SC_OLD-d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7.zip opensim-SC_OLD-d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7.tar.gz opensim-SC_OLD-d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7.tar.bz2 opensim-SC_OLD-d5e8272ad44e87a4ac1a7b142ca36b5c5978fca7.tar.xz |
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.
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteRegionData.cs | 55 | ||||
-rw-r--r-- | OpenSim/Framework/PrimitiveBaseShape.cs | 6 | ||||
-rw-r--r-- | OpenSim/Region/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; | |||
31 | using System.Drawing; | 31 | using System.Drawing; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using System.Xml; | ||
35 | using log4net; | 34 | using log4net; |
36 | using Mono.Data.Sqlite; | 35 | using Mono.Data.Sqlite; |
37 | using OpenMetaverse; | 36 | using OpenMetaverse; |
@@ -1862,28 +1861,7 @@ namespace OpenSim.Data.SQLite | |||
1862 | s.ExtraParams = (byte[]) row["ExtraParams"]; | 1861 | s.ExtraParams = (byte[]) row["ExtraParams"]; |
1863 | 1862 | ||
1864 | if (!(row["Media"] is System.DBNull)) | 1863 | if (!(row["Media"] is System.DBNull)) |
1865 | { | 1864 | s.MediaRaw = (string)row["Media"]; |
1866 | using (StringReader sr = new StringReader((string)row["Media"])) | ||
1867 | { | ||
1868 | using (XmlTextReader xtr = new XmlTextReader(sr)) | ||
1869 | { | ||
1870 | xtr.ReadStartElement("osmedia"); | ||
1871 | |||
1872 | OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); | ||
1873 | |||
1874 | List<MediaEntry> mediaEntries = new List<MediaEntry>(); | ||
1875 | foreach (OSD osdMe in osdMeArray) | ||
1876 | { | ||
1877 | MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); | ||
1878 | mediaEntries.Add(me); | ||
1879 | } | ||
1880 | |||
1881 | s.Media = mediaEntries; | ||
1882 | |||
1883 | xtr.ReadEndElement(); | ||
1884 | } | ||
1885 | } | ||
1886 | } | ||
1887 | 1865 | ||
1888 | return s; | 1866 | return s; |
1889 | } | 1867 | } |
@@ -1928,36 +1906,7 @@ namespace OpenSim.Data.SQLite | |||
1928 | 1906 | ||
1929 | row["Texture"] = s.TextureEntry; | 1907 | row["Texture"] = s.TextureEntry; |
1930 | row["ExtraParams"] = s.ExtraParams; | 1908 | row["ExtraParams"] = s.ExtraParams; |
1931 | 1909 | row["Media"] = s.MediaRaw; | |
1932 | if (null != s.Media) | ||
1933 | { | ||
1934 | using (StringWriter sw = new StringWriter()) | ||
1935 | { | ||
1936 | using (XmlTextWriter xtw = new XmlTextWriter(sw)) | ||
1937 | { | ||
1938 | xtw.WriteStartElement("osmedia"); | ||
1939 | xtw.WriteAttributeString("type", "sl"); | ||
1940 | xtw.WriteAttributeString("major_version", "0"); | ||
1941 | xtw.WriteAttributeString("minor_version", "1"); | ||
1942 | |||
1943 | OSDArray meArray = new OSDArray(); | ||
1944 | foreach (MediaEntry me in s.Media) | ||
1945 | { | ||
1946 | OSD osd = (null == me ? new OSD() : me.GetOSD()); | ||
1947 | meArray.Add(osd); | ||
1948 | } | ||
1949 | |||
1950 | xtw.WriteStartElement("osdata"); | ||
1951 | xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); | ||
1952 | xtw.WriteEndElement(); | ||
1953 | |||
1954 | xtw.WriteEndElement(); | ||
1955 | |||
1956 | xtw.Flush(); | ||
1957 | row["Media"] = sw.ToString(); | ||
1958 | } | ||
1959 | } | ||
1960 | } | ||
1961 | } | 1910 | } |
1962 | 1911 | ||
1963 | /// <summary> | 1912 | /// <summary> |
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 | |||
174 | } | 174 | } |
175 | 175 | ||
176 | /// <summary> | 176 | /// <summary> |
177 | /// Raw media data suitable for serialization operations. This should only ever be used by an IMoapModule. | ||
178 | /// </summary> | ||
179 | [XmlIgnore] | ||
180 | public string MediaRaw { get; set; } | ||
181 | |||
182 | /// <summary> | ||
177 | /// Entries to store media textures on each face | 183 | /// Entries to store media textures on each face |
178 | /// </summary> | 184 | /// </summary> |
179 | /// Do not change this value directly - always do it through an IMoapModule. | 185 | /// 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; | |||
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Web; | 34 | using System.Web; |
35 | using System.Xml; | ||
35 | using log4net; | 36 | using log4net; |
36 | using Mono.Addins; | 37 | using Mono.Addins; |
37 | using Nini.Config; | 38 | using Nini.Config; |
@@ -46,6 +47,7 @@ using OpenSim.Region.Framework.Interfaces; | |||
46 | using OpenSim.Region.Framework.Scenes; | 47 | using OpenSim.Region.Framework.Scenes; |
47 | using OpenSim.Services.Interfaces; | 48 | using OpenSim.Services.Interfaces; |
48 | using Caps = OpenSim.Framework.Capabilities.Caps; | 49 | using Caps = OpenSim.Framework.Capabilities.Caps; |
50 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
49 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | 51 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; |
50 | 52 | ||
51 | namespace OpenSim.Region.CoreModules.Media.Moap | 53 | namespace OpenSim.Region.CoreModules.Media.Moap |
@@ -162,12 +164,76 @@ namespace OpenSim.Region.CoreModules.Media.Moap | |||
162 | public void OnSceneObjectLoaded(SceneObjectGroup so) | 164 | public void OnSceneObjectLoaded(SceneObjectGroup so) |
163 | { | 165 | { |
164 | m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID); | 166 | m_log.DebugFormat("[MOAP]: OnSceneObjectLoaded fired for {0} {1}", so.Name, so.UUID); |
167 | |||
168 | so.ForEachPart(OnSceneObjectPartLoaded); | ||
165 | } | 169 | } |
166 | 170 | ||
167 | public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo) | 171 | public void OnSceneObjectPreSave(SceneObjectGroup persistingSo, SceneObjectGroup originalSo) |
168 | { | 172 | { |
169 | m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); | 173 | m_log.DebugFormat("[MOAP]: OnSceneObjectPreSave fired for {0} {1}", persistingSo.Name, persistingSo.UUID); |
170 | } | 174 | |
175 | persistingSo.ForEachPart(OnSceneObjectPartPreSave); | ||
176 | } | ||
177 | |||
178 | protected void OnSceneObjectPartLoaded(SceneObjectPart part) | ||
179 | { | ||
180 | if (null == part.Shape.MediaRaw) | ||
181 | return; | ||
182 | |||
183 | using (StringReader sr = new StringReader(part.Shape.MediaRaw)) | ||
184 | { | ||
185 | using (XmlTextReader xtr = new XmlTextReader(sr)) | ||
186 | { | ||
187 | xtr.ReadStartElement("osmedia"); | ||
188 | |||
189 | OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); | ||
190 | |||
191 | List<MediaEntry> mediaEntries = new List<MediaEntry>(); | ||
192 | foreach (OSD osdMe in osdMeArray) | ||
193 | { | ||
194 | MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); | ||
195 | mediaEntries.Add(me); | ||
196 | } | ||
197 | |||
198 | xtr.ReadEndElement(); | ||
199 | |||
200 | part.Shape.Media = mediaEntries; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
205 | protected void OnSceneObjectPartPreSave(SceneObjectPart part) | ||
206 | { | ||
207 | if (null == part.Shape.Media) | ||
208 | return; | ||
209 | |||
210 | using (StringWriter sw = new StringWriter()) | ||
211 | { | ||
212 | using (XmlTextWriter xtw = new XmlTextWriter(sw)) | ||
213 | { | ||
214 | xtw.WriteStartElement("osmedia"); | ||
215 | xtw.WriteAttributeString("type", "sl"); | ||
216 | xtw.WriteAttributeString("major_version", "0"); | ||
217 | xtw.WriteAttributeString("minor_version", "1"); | ||
218 | |||
219 | OSDArray meArray = new OSDArray(); | ||
220 | foreach (MediaEntry me in part.Shape.Media) | ||
221 | { | ||
222 | OSD osd = (null == me ? new OSD() : me.GetOSD()); | ||
223 | meArray.Add(osd); | ||
224 | } | ||
225 | |||
226 | xtw.WriteStartElement("osdata"); | ||
227 | xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); | ||
228 | xtw.WriteEndElement(); | ||
229 | |||
230 | xtw.WriteEndElement(); | ||
231 | |||
232 | xtw.Flush(); | ||
233 | part.Shape.MediaRaw = sw.ToString(); | ||
234 | } | ||
235 | } | ||
236 | } | ||
171 | 237 | ||
172 | public MediaEntry GetMediaEntry(SceneObjectPart part, int face) | 238 | public MediaEntry GetMediaEntry(SceneObjectPart part, int face) |
173 | { | 239 | { |