aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-08-16 22:21:46 +0100
committerJustin Clark-Casey (justincc)2013-01-25 04:03:11 +0000
commita6d9c263650cc23d60f941718f87a64aa2f360b2 (patch)
tree29bdd5df7bae66360e19a38c304e7197b6a55342 /OpenSim/Framework
parentImplement dynamic attribute persistence on mysql and mssql (diff)
downloadopensim-SC-a6d9c263650cc23d60f941718f87a64aa2f360b2.zip
opensim-SC-a6d9c263650cc23d60f941718f87a64aa2f360b2.tar.gz
opensim-SC-a6d9c263650cc23d60f941718f87a64aa2f360b2.tar.bz2
opensim-SC-a6d9c263650cc23d60f941718f87a64aa2f360b2.tar.xz
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
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/DAMap.cs173
-rw-r--r--OpenSim/Framework/DynAttrsOSDMap.cs79
-rw-r--r--OpenSim/Framework/PrimitiveBaseShape.cs6
3 files changed, 176 insertions, 82 deletions
diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs
new file mode 100644
index 0000000..a6fdf61
--- /dev/null
+++ b/OpenSim/Framework/DAMap.cs
@@ -0,0 +1,173 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using System.Xml;
34using System.Xml.Schema;
35using System.Xml.Serialization;
36using OpenMetaverse;
37using OpenMetaverse.StructuredData;
38
39namespace OpenSim.Framework
40{
41 /// <summary>
42 /// This is the map for storing and retrieving dynamic attributes.
43 /// </summary>
44 public class DAMap : IDictionary<string, OSD>, IXmlSerializable
45 {
46 protected OSDMap m_map;
47
48 public DAMap() { m_map = new OSDMap(); }
49
50 public XmlSchema GetSchema() { return null; }
51
52 public static DAMap FromXml(string rawXml)
53 {
54 DAMap map = new DAMap();
55 map.ReadXml(rawXml);
56 return map;
57 }
58
59 public void ReadXml(string rawXml)
60 {
61 //System.Console.WriteLine("Trying to deserialize [{0}]", rawXml);
62
63 m_map = (OSDMap)OSDParser.DeserializeLLSDXml(rawXml);
64 }
65
66 public void ReadXml(XmlReader reader)
67 {
68 ReadXml(reader.ReadInnerXml());
69 }
70
71 public string ToXml()
72 {
73 lock (m_map)
74 return OSDParser.SerializeLLSDXmlString(m_map);
75 }
76
77 public void WriteXml(XmlWriter writer)
78 {
79 writer.WriteRaw(ToXml());
80 }
81
82 public int Count { get { lock (m_map) { return m_map.Count; } } }
83 public bool IsReadOnly { get { return false; } }
84 public ICollection<string> Keys { get { lock (m_map) { return m_map.Keys; } } }
85 public ICollection<OSD> Values { get { lock (m_map) { return m_map.Values; } } }
86 public OSD this[string key]
87 {
88 get
89 {
90 OSD llsd;
91
92 lock (m_map)
93 {
94 if (m_map.TryGetValue(key, out llsd))
95 return llsd;
96 else
97 return null;
98 }
99 }
100 set { lock (m_map) { m_map[key] = value; } }
101 }
102
103 public bool ContainsKey(string key)
104 {
105 lock (m_map)
106 return m_map.ContainsKey(key);
107 }
108
109 public void Add(string key, OSD llsd)
110 {
111 lock (m_map)
112 m_map.Add(key, llsd);
113 }
114
115 public void Add(KeyValuePair<string, OSD> kvp)
116 {
117 lock (m_map)
118 m_map.Add(kvp.Key, kvp.Value);
119 }
120
121 public bool Remove(string key)
122 {
123 lock (m_map)
124 return m_map.Remove(key);
125 }
126
127 public bool TryGetValue(string key, out OSD llsd)
128 {
129 lock (m_map)
130 return m_map.TryGetValue(key, out llsd);
131 }
132
133 public void Clear()
134 {
135 lock (m_map)
136 m_map.Clear();
137 }
138
139 public bool Contains(KeyValuePair<string, OSD> kvp)
140 {
141 lock (m_map)
142 return m_map.ContainsKey(kvp.Key);
143 }
144
145 public void CopyTo(KeyValuePair<string, OSD>[] array, int index)
146 {
147 throw new NotImplementedException();
148 }
149
150 public bool Remove(KeyValuePair<string, OSD> kvp)
151 {
152 lock (m_map)
153 return m_map.Remove(kvp.Key);
154 }
155
156 public System.Collections.IDictionaryEnumerator GetEnumerator()
157 {
158 lock (m_map)
159 return m_map.GetEnumerator();
160 }
161
162 IEnumerator<KeyValuePair<string, OSD>> IEnumerable<KeyValuePair<string, OSD>>.GetEnumerator()
163 {
164 return null;
165 }
166
167 IEnumerator IEnumerable.GetEnumerator()
168 {
169 lock (m_map)
170 return m_map.GetEnumerator();
171 }
172 }
173} \ No newline at end of file
diff --git a/OpenSim/Framework/DynAttrsOSDMap.cs b/OpenSim/Framework/DynAttrsOSDMap.cs
deleted file mode 100644
index 2d45f66..0000000
--- a/OpenSim/Framework/DynAttrsOSDMap.cs
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Text;
32using System.Xml;
33using System.Xml.Schema;
34using System.Xml.Serialization;
35using OpenMetaverse;
36using OpenMetaverse.StructuredData;
37
38namespace OpenSim.Framework
39{
40 /// <summary>
41 /// This is the map for storing and retrieving dynamic attributes.
42 /// </summary>
43 public class DynAttrsOSDMap : OSDMap, IXmlSerializable
44 {
45 public XmlSchema GetSchema() { return null; }
46
47 public static DynAttrsOSDMap FromXml(string rawXml)
48 {
49 DynAttrsOSDMap map = new DynAttrsOSDMap();
50 map.ReadXml(rawXml);
51 return map;
52 }
53
54 public void ReadXml(string rawXml)
55 {
56 //System.Console.WriteLine("Trying to deserialize [{0}]", rawXml);
57
58 OSDMap map = (OSDMap)OSDParser.DeserializeLLSDXml(rawXml);
59
60 foreach (string key in map.Keys)
61 this[key] = map[key];
62 }
63
64 public void ReadXml(XmlReader reader)
65 {
66 ReadXml(reader.ReadInnerXml());
67 }
68
69 public string ToXml()
70 {
71 return OSDParser.SerializeLLSDXmlString(this);
72 }
73
74 public void WriteXml(XmlWriter writer)
75 {
76 writer.WriteRaw(ToXml());
77 }
78 }
79} \ No newline at end of file
diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs
index fb0255b..775412b 100644
--- a/OpenSim/Framework/PrimitiveBaseShape.cs
+++ b/OpenSim/Framework/PrimitiveBaseShape.cs
@@ -86,7 +86,7 @@ namespace OpenSim.Framework
86 /// <summary> 86 /// <summary>
87 /// Dynamic attributes can be created and deleted as required. 87 /// Dynamic attributes can be created and deleted as required.
88 /// </summary> 88 /// </summary>
89 public DynAttrsOSDMap DynAttrs { get; set; } 89 public DAMap DynAttrs { get; set; }
90 90
91 private byte[] m_textureEntry; 91 private byte[] m_textureEntry;
92 92
@@ -199,7 +199,7 @@ namespace OpenSim.Framework
199 { 199 {
200 PCode = (byte)PCodeEnum.Primitive; 200 PCode = (byte)PCodeEnum.Primitive;
201 m_textureEntry = DEFAULT_TEXTURE; 201 m_textureEntry = DEFAULT_TEXTURE;
202 DynAttrs = new DynAttrsOSDMap(); 202 DynAttrs = new DAMap();
203 } 203 }
204 204
205 /// <summary> 205 /// <summary>
@@ -211,7 +211,7 @@ namespace OpenSim.Framework
211// m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: Creating from {0}", prim.ID); 211// m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: Creating from {0}", prim.ID);
212 212
213 PCode = (byte)prim.PrimData.PCode; 213 PCode = (byte)prim.PrimData.PCode;
214 DynAttrs = new DynAttrsOSDMap(); 214 DynAttrs = new DAMap();
215 215
216 State = prim.PrimData.State; 216 State = prim.PrimData.State;
217 PathBegin = Primitive.PackBeginCut(prim.PrimData.PathBegin); 217 PathBegin = Primitive.PackBeginCut(prim.PrimData.PathBegin);