Simplify serialized version string. Change element capitalization for consistency

THIS CHANGE ALTERS THE SERIALIZATION FORMAT, HOPEFULLY FOR THE LAST TIME.  If you're testing, please start with a new database.
This commit also improves locking for manipulation of media entries.
prebuild-update
Justin Clark-Casey (justincc) 2010-08-03 17:09:20 +01:00
parent 9d8a67fe13
commit 99c0f4c9c7
2 changed files with 55 additions and 36 deletions

View File

@ -180,6 +180,7 @@ namespace OpenSim.Framework
/// Entries to store media textures on each face /// Entries to store media textures on each face
/// </summary> /// </summary>
/// Do not change this value directly - always do it through an IMoapModule. /// Do not change this value directly - always do it through an IMoapModule.
/// Lock before manipulating.
public MediaList Media { get; set; } public MediaList Media { get; set; }
public PrimitiveBaseShape() public PrimitiveBaseShape()
@ -1219,6 +1220,11 @@ namespace OpenSim.Framework
return prim; return prim;
} }
/// <summary>
/// Encapsulates a list of media entries.
/// </summary>
/// This class is necessary because we want to replace auto-serialization of MediaEntry with something more
/// OSD like and less vulnerable to change.
public class MediaList : List<MediaEntry>, IXmlSerializable public class MediaList : List<MediaEntry>, IXmlSerializable
{ {
public const string MEDIA_TEXTURE_TYPE = "sl"; public const string MEDIA_TEXTURE_TYPE = "sl";
@ -1240,10 +1246,9 @@ namespace OpenSim.Framework
{ {
using (XmlTextWriter xtw = new XmlTextWriter(sw)) using (XmlTextWriter xtw = new XmlTextWriter(sw))
{ {
xtw.WriteStartElement("osmedia"); xtw.WriteStartElement("OSMedia");
xtw.WriteAttributeString("type", MEDIA_TEXTURE_TYPE); xtw.WriteAttributeString("type", MEDIA_TEXTURE_TYPE);
xtw.WriteAttributeString("major_version", "0"); xtw.WriteAttributeString("version", "0.1");
xtw.WriteAttributeString("minor_version", "1");
OSDArray meArray = new OSDArray(); OSDArray meArray = new OSDArray();
foreach (MediaEntry me in this) foreach (MediaEntry me in this)
@ -1252,7 +1257,7 @@ namespace OpenSim.Framework
meArray.Add(osd); meArray.Add(osd);
} }
xtw.WriteStartElement("osdata"); xtw.WriteStartElement("OSData");
xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray));
xtw.WriteEndElement(); xtw.WriteEndElement();
@ -1291,7 +1296,7 @@ namespace OpenSim.Framework
if (type != MEDIA_TEXTURE_TYPE) if (type != MEDIA_TEXTURE_TYPE)
return; return;
xtr.ReadStartElement("osmedia"); xtr.ReadStartElement("OSMedia");
OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
foreach (OSD osdMe in osdMeArray) foreach (OSD osdMe in osdMeArray)

View File

@ -185,7 +185,8 @@ namespace OpenSim.Region.CoreModules.Media.Moap
if (original.Shape.Media != null) if (original.Shape.Media != null)
{ {
PrimitiveBaseShape.MediaList dupeMedia = new PrimitiveBaseShape.MediaList(); PrimitiveBaseShape.MediaList dupeMedia = new PrimitiveBaseShape.MediaList();
lock (original.Shape.Media)
{
foreach (MediaEntry me in original.Shape.Media) foreach (MediaEntry me in original.Shape.Media)
{ {
if (me != null) if (me != null)
@ -193,6 +194,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
else else
dupeMedia.Add(null); dupeMedia.Add(null);
} }
}
copy.Shape.Media = dupeMedia; copy.Shape.Media = dupeMedia;
} }
@ -212,6 +214,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
} }
else else
{ {
lock (media)
me = media[face]; me = media[face];
// TODO: Really need a proper copy constructor down in libopenmetaverse // TODO: Really need a proper copy constructor down in libopenmetaverse
@ -231,7 +234,9 @@ namespace OpenSim.Region.CoreModules.Media.Moap
if (null == part.Shape.Media) if (null == part.Shape.Media)
part.Shape.Media = new PrimitiveBaseShape.MediaList(new MediaEntry[part.GetNumberOfSides()]); part.Shape.Media = new PrimitiveBaseShape.MediaList(new MediaEntry[part.GetNumberOfSides()]);
lock (part.Shape.Media)
part.Shape.Media[face] = me; part.Shape.Media[face] = me;
UpdateMediaUrl(part, UUID.Zero); UpdateMediaUrl(part, UUID.Zero);
part.ScheduleFullUpdate(); part.ScheduleFullUpdate();
part.TriggerScriptChangedEvent(Changed.MEDIA); part.TriggerScriptChangedEvent(Changed.MEDIA);
@ -296,7 +301,10 @@ namespace OpenSim.Region.CoreModules.Media.Moap
ObjectMediaResponse resp = new ObjectMediaResponse(); ObjectMediaResponse resp = new ObjectMediaResponse();
resp.PrimID = primId; resp.PrimID = primId;
lock (part.Shape.Media)
resp.FaceMedia = part.Shape.Media.ToArray(); resp.FaceMedia = part.Shape.Media.ToArray();
resp.Version = part.MediaUrl; resp.Version = part.MediaUrl;
string rawResp = OSDParser.SerializeLLSDXmlString(resp.Serialize()); string rawResp = OSDParser.SerializeLLSDXmlString(resp.Serialize());
@ -382,6 +390,8 @@ namespace OpenSim.Region.CoreModules.Media.Moap
// directly. // directly.
Primitive.TextureEntry te = part.Shape.Textures; Primitive.TextureEntry te = part.Shape.Textures;
lock (media)
{
for (int i = 0; i < media.Count; i++) for (int i = 0; i < media.Count; i++)
{ {
if (m_scene.Permissions.CanControlPrimMedia(agentId, part.UUID, i)) if (m_scene.Permissions.CanControlPrimMedia(agentId, part.UUID, i))
@ -402,6 +412,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
// m_log.DebugFormat("[MOAP]: Set media entry for face {0} on {1}", i, part.Name); // m_log.DebugFormat("[MOAP]: Set media entry for face {0} on {1}", i, part.Name);
} }
} }
}
part.Shape.Textures = te; part.Shape.Textures = te;
@ -465,7 +476,10 @@ namespace OpenSim.Region.CoreModules.Media.Moap
if (null == part.Shape.Media) if (null == part.Shape.Media)
return string.Empty; return string.Empty;
MediaEntry me = part.Shape.Media[omn.Face]; MediaEntry me = null;
lock (part.Shape.Media)
me = part.Shape.Media[omn.Face];
// Do the same if media has not been set up for a specific face // Do the same if media has not been set up for a specific face
if (null == me) if (null == me)