diff options
author | Oren Hurvitz | 2013-01-22 08:41:32 +0200 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-01-25 04:03:18 +0000 |
commit | 8b4441d940a55da90645580477ece33d15849078 (patch) | |
tree | c68976caa7a0f848d48c999bc13dc6af93c93341 | |
parent | Added missing DynAttrs references in MySQL (diff) | |
download | opensim-SC_OLD-8b4441d940a55da90645580477ece33d15849078.zip opensim-SC_OLD-8b4441d940a55da90645580477ece33d15849078.tar.gz opensim-SC_OLD-8b4441d940a55da90645580477ece33d15849078.tar.bz2 opensim-SC_OLD-8b4441d940a55da90645580477ece33d15849078.tar.xz |
Changed DAMap to be the container of "data stores", which are OSDMaps. Store names must have at least 4 characters.
-rw-r--r-- | OpenSim/Framework/DAMap.cs | 104 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs | 25 |
2 files changed, 97 insertions, 32 deletions
diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs index 7551a10..c256230 100644 --- a/OpenSim/Framework/DAMap.cs +++ b/OpenSim/Framework/DAMap.cs | |||
@@ -39,10 +39,19 @@ using OpenMetaverse.StructuredData; | |||
39 | namespace OpenSim.Framework | 39 | namespace OpenSim.Framework |
40 | { | 40 | { |
41 | /// <summary> | 41 | /// <summary> |
42 | /// This is the map for storing and retrieving dynamic attributes. | 42 | /// This class stores and retrieves dynamic attributes. |
43 | /// </summary> | 43 | /// </summary> |
44 | public class DAMap : IDictionary<string, OSD>, IXmlSerializable | 44 | /// <remarks> |
45 | { | 45 | /// Modules that want to use dynamic attributes need to do so in a private data store |
46 | /// which is accessed using a unique name. DAMap provides access to the data stores, | ||
47 | /// each of which is an OSDMap. Modules are free to store any type of data they want | ||
48 | /// within their data store. However, avoid storing large amounts of data because that | ||
49 | /// would slow down database access. | ||
50 | /// </remarks> | ||
51 | public class DAMap : IDictionary<string, OSDMap>, IXmlSerializable | ||
52 | { | ||
53 | private static readonly int MIN_STORE_NAME_LENGTH = 4; | ||
54 | |||
46 | protected OSDMap m_map; | 55 | protected OSDMap m_map; |
47 | 56 | ||
48 | public DAMap() { m_map = new OSDMap(); } | 57 | public DAMap() { m_map = new OSDMap(); } |
@@ -79,12 +88,42 @@ namespace OpenSim.Framework | |||
79 | { | 88 | { |
80 | writer.WriteRaw(ToXml()); | 89 | writer.WriteRaw(ToXml()); |
81 | } | 90 | } |
82 | 91 | ||
92 | /// <summary> | ||
93 | /// Returns the number of data stores. | ||
94 | /// </summary> | ||
83 | public int Count { get { lock (this) { return m_map.Count; } } } | 95 | public int Count { get { lock (this) { return m_map.Count; } } } |
96 | |||
84 | public bool IsReadOnly { get { return false; } } | 97 | public bool IsReadOnly { get { return false; } } |
98 | |||
99 | /// <summary> | ||
100 | /// Returns the names of the data stores. | ||
101 | /// </summary> | ||
85 | public ICollection<string> Keys { get { lock (this) { return m_map.Keys; } } } | 102 | public ICollection<string> Keys { get { lock (this) { return m_map.Keys; } } } |
86 | public ICollection<OSD> Values { get { lock (this) { return m_map.Values; } } } | 103 | |
87 | public OSD this[string key] | 104 | /// <summary> |
105 | /// Returns all the data stores. | ||
106 | /// </summary> | ||
107 | public ICollection<OSDMap> Values | ||
108 | { | ||
109 | get | ||
110 | { | ||
111 | lock (this) | ||
112 | { | ||
113 | List<OSDMap> stores = new List<OSDMap>(m_map.Count); | ||
114 | foreach (OSD llsd in m_map.Values) | ||
115 | stores.Add((OSDMap)llsd); | ||
116 | return stores; | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// Gets or sets one data store. | ||
123 | /// </summary> | ||
124 | /// <param name="key">Store name</param> | ||
125 | /// <returns></returns> | ||
126 | public OSDMap this[string key] | ||
88 | { | 127 | { |
89 | get | 128 | get |
90 | { | 129 | { |
@@ -93,13 +132,25 @@ namespace OpenSim.Framework | |||
93 | lock (this) | 132 | lock (this) |
94 | { | 133 | { |
95 | if (m_map.TryGetValue(key, out llsd)) | 134 | if (m_map.TryGetValue(key, out llsd)) |
96 | return llsd; | 135 | return (OSDMap)llsd; |
97 | else | 136 | else |
98 | return null; | 137 | return null; |
99 | } | 138 | } |
100 | } | 139 | } |
101 | set { lock (this) { m_map[key] = value; } } | 140 | |
102 | } | 141 | set |
142 | { | ||
143 | ValidateKey(key); | ||
144 | lock (this) | ||
145 | m_map[key] = value; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | private static void ValidateKey(string key) | ||
150 | { | ||
151 | if (key.Length < MIN_STORE_NAME_LENGTH) | ||
152 | throw new Exception("Minimum store name length is " + MIN_STORE_NAME_LENGTH); | ||
153 | } | ||
103 | 154 | ||
104 | public bool ContainsKey(string key) | 155 | public bool ContainsKey(string key) |
105 | { | 156 | { |
@@ -107,13 +158,14 @@ namespace OpenSim.Framework | |||
107 | return m_map.ContainsKey(key); | 158 | return m_map.ContainsKey(key); |
108 | } | 159 | } |
109 | 160 | ||
110 | public void Add(string key, OSD llsd) | 161 | public void Add(string key, OSDMap store) |
111 | { | 162 | { |
163 | ValidateKey(key); | ||
112 | lock (this) | 164 | lock (this) |
113 | m_map.Add(key, llsd); | 165 | m_map.Add(key, store); |
114 | } | 166 | } |
115 | 167 | ||
116 | public void Add(KeyValuePair<string, OSD> kvp) | 168 | public void Add(KeyValuePair<string, OSDMap> kvp) |
117 | { | 169 | { |
118 | lock (this) | 170 | lock (this) |
119 | m_map.Add(kvp.Key, kvp.Value); | 171 | m_map.Add(kvp.Key, kvp.Value); |
@@ -125,10 +177,22 @@ namespace OpenSim.Framework | |||
125 | return m_map.Remove(key); | 177 | return m_map.Remove(key); |
126 | } | 178 | } |
127 | 179 | ||
128 | public bool TryGetValue(string key, out OSD llsd) | 180 | public bool TryGetValue(string key, out OSDMap store) |
129 | { | 181 | { |
130 | lock (this) | 182 | lock (this) |
131 | return m_map.TryGetValue(key, out llsd); | 183 | { |
184 | OSD llsd; | ||
185 | if (m_map.TryGetValue(key, out llsd)) | ||
186 | { | ||
187 | store = (OSDMap)llsd; | ||
188 | return true; | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | store = null; | ||
193 | return false; | ||
194 | } | ||
195 | } | ||
132 | } | 196 | } |
133 | 197 | ||
134 | public void Clear() | 198 | public void Clear() |
@@ -137,18 +201,18 @@ namespace OpenSim.Framework | |||
137 | m_map.Clear(); | 201 | m_map.Clear(); |
138 | } | 202 | } |
139 | 203 | ||
140 | public bool Contains(KeyValuePair<string, OSD> kvp) | 204 | public bool Contains(KeyValuePair<string, OSDMap> kvp) |
141 | { | 205 | { |
142 | lock (this) | 206 | lock (this) |
143 | return m_map.ContainsKey(kvp.Key); | 207 | return m_map.ContainsKey(kvp.Key); |
144 | } | 208 | } |
145 | 209 | ||
146 | public void CopyTo(KeyValuePair<string, OSD>[] array, int index) | 210 | public void CopyTo(KeyValuePair<string, OSDMap>[] array, int index) |
147 | { | 211 | { |
148 | throw new NotImplementedException(); | 212 | throw new NotImplementedException(); |
149 | } | 213 | } |
150 | 214 | ||
151 | public bool Remove(KeyValuePair<string, OSD> kvp) | 215 | public bool Remove(KeyValuePair<string, OSDMap> kvp) |
152 | { | 216 | { |
153 | lock (this) | 217 | lock (this) |
154 | return m_map.Remove(kvp.Key); | 218 | return m_map.Remove(kvp.Key); |
@@ -160,7 +224,7 @@ namespace OpenSim.Framework | |||
160 | return m_map.GetEnumerator(); | 224 | return m_map.GetEnumerator(); |
161 | } | 225 | } |
162 | 226 | ||
163 | IEnumerator<KeyValuePair<string, OSD>> IEnumerable<KeyValuePair<string, OSD>>.GetEnumerator() | 227 | IEnumerator<KeyValuePair<string, OSDMap>> IEnumerable<KeyValuePair<string, OSDMap>>.GetEnumerator() |
164 | { | 228 | { |
165 | return null; | 229 | return null; |
166 | } | 230 | } |
diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs index d6fb15b..084fb5f 100644 --- a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs | |||
@@ -75,22 +75,23 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule | |||
75 | 75 | ||
76 | protected bool OnSceneGroupMove(UUID groupId, Vector3 delta) | 76 | protected bool OnSceneGroupMove(UUID groupId, Vector3 delta) |
77 | { | 77 | { |
78 | OSDMap attrs = null; | ||
78 | SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); | 79 | SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); |
79 | DAMap attrs = sop.DynAttrs; | 80 | if (!sop.DynAttrs.TryGetValue(Name, out attrs)) |
81 | attrs = new OSDMap(); | ||
80 | 82 | ||
81 | lock (attrs) | 83 | OSDInteger newValue; |
82 | { | ||
83 | OSDInteger newValue; | ||
84 | 84 | ||
85 | if (!attrs.ContainsKey("moves")) | 85 | if (!attrs.ContainsKey("moves")) |
86 | newValue = new OSDInteger(1); | 86 | newValue = new OSDInteger(1); |
87 | else | 87 | else |
88 | newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); | 88 | newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); |
89 | 89 | ||
90 | attrs["moves"] = newValue; | 90 | attrs["moves"] = newValue; |
91 | 91 | ||
92 | m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue)); | 92 | sop.DynAttrs[Name] = attrs; |
93 | } | 93 | |
94 | m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue)); | ||
94 | 95 | ||
95 | return true; | 96 | return true; |
96 | } | 97 | } |