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,13 +185,15 @@ 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)
{ {
if (me != null) foreach (MediaEntry me in original.Shape.Media)
dupeMedia.Add(MediaEntry.FromOSD(me.GetOSD())); {
else if (me != null)
dupeMedia.Add(null); dupeMedia.Add(MediaEntry.FromOSD(me.GetOSD()));
else
dupeMedia.Add(null);
}
} }
copy.Shape.Media = dupeMedia; copy.Shape.Media = dupeMedia;
@ -211,8 +213,9 @@ namespace OpenSim.Region.CoreModules.Media.Moap
me = null; me = null;
} }
else else
{ {
me = media[face]; lock (media)
me = media[face];
// TODO: Really need a proper copy constructor down in libopenmetaverse // TODO: Really need a proper copy constructor down in libopenmetaverse
if (me != null) if (me != null)
@ -230,11 +233,13 @@ 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()]);
part.Shape.Media[face] = me; lock (part.Shape.Media)
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);
} }
public void ClearMediaEntry(SceneObjectPart part, int face) public void ClearMediaEntry(SceneObjectPart part, int face)
@ -296,7 +301,10 @@ namespace OpenSim.Region.CoreModules.Media.Moap
ObjectMediaResponse resp = new ObjectMediaResponse(); ObjectMediaResponse resp = new ObjectMediaResponse();
resp.PrimID = primId; resp.PrimID = primId;
resp.FaceMedia = part.Shape.Media.ToArray();
lock (part.Shape.Media)
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,24 +390,27 @@ namespace OpenSim.Region.CoreModules.Media.Moap
// directly. // directly.
Primitive.TextureEntry te = part.Shape.Textures; Primitive.TextureEntry te = part.Shape.Textures;
for (int i = 0; i < media.Count; i++) lock (media)
{ {
if (m_scene.Permissions.CanControlPrimMedia(agentId, part.UUID, i)) for (int i = 0; i < media.Count; i++)
{ {
media[i] = omu.FaceMedia[i]; if (m_scene.Permissions.CanControlPrimMedia(agentId, part.UUID, i))
{
// When a face is cleared this is done by setting the MediaFlags in the TextureEntry via a normal media[i] = omu.FaceMedia[i];
// texture update, so we don't need to worry about clearing MediaFlags here.
if (null == media[i]) // When a face is cleared this is done by setting the MediaFlags in the TextureEntry via a normal
continue; // texture update, so we don't need to worry about clearing MediaFlags here.
if (null == media[i])
Primitive.TextureEntryFace face = te.CreateFace((uint)i); continue;
face.MediaFlags = true;
Primitive.TextureEntryFace face = te.CreateFace((uint)i);
// m_log.DebugFormat( face.MediaFlags = true;
// "[MOAP]: Media flags for face {0} is {1}",
// i, face.MediaFlags); // m_log.DebugFormat(
// m_log.DebugFormat("[MOAP]: Set media entry for face {0} on {1}", i, part.Name); // "[MOAP]: Media flags for face {0} is {1}",
// i, face.MediaFlags);
// m_log.DebugFormat("[MOAP]: Set media entry for face {0} on {1}", i, part.Name);
}
} }
} }
@ -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)