aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/SQLAssetServer.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/SQLAssetServer.cs597
1 files changed, 299 insertions, 298 deletions
diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
index ac22573..fc4efc5 100644
--- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
@@ -1,298 +1,299 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Threading; 30using System.Threading;
31using System.Reflection; 31using System.Reflection;
32using libsecondlife; 32using libsecondlife;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
35using OpenSim.Framework.Interfaces; 35using OpenSim.Framework.Interfaces;
36using OpenSim.Framework.Types; 36using OpenSim.Framework.Types;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38 38
39namespace OpenSim.Framework.Communications.Caches 39namespace OpenSim.Framework.Communications.Caches
40{ 40{
41 41
42 public class SQLAssetServer : IAssetServer 42 public class SQLAssetServer : IAssetServer
43 { 43 {
44 private IAssetReceiver _receiver; 44 private IAssetReceiver _receiver;
45 private BlockingQueue<ARequest> _assetRequests; 45 private BlockingQueue<ARequest> _assetRequests;
46 private Thread _localAssetServerThread; 46 private Thread _localAssetServerThread;
47 protected IAssetProvider m_plugin; 47 protected IAssetProvider m_plugin;
48 48
49 49
50 public SQLAssetServer() 50 public SQLAssetServer()
51 { 51 {
52 System.Console.WriteLine("Starting sqlite asset storage system"); 52 System.Console.WriteLine("Starting sqlite asset storage system");
53 _assetRequests = new BlockingQueue<ARequest>(); 53 _assetRequests = new BlockingQueue<ARequest>();
54 AddPlugin("OpenSim.Framework.Data.SQLite.dll"); 54 AddPlugin("OpenSim.Framework.Data.SQLite.dll");
55 this.SetUpAssetDatabase(); 55 this.SetUpAssetDatabase();
56 56
57 this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); 57 this._localAssetServerThread = new Thread(new ThreadStart(RunRequests));
58 this._localAssetServerThread.IsBackground = true; 58 this._localAssetServerThread.IsBackground = true;
59 this._localAssetServerThread.Start(); 59 this._localAssetServerThread.Start();
60 60
61 } 61 }
62 62
63 public void AddPlugin(string FileName) 63 public void AddPlugin(string FileName)
64 { 64 {
65 //MainLog.Instance.Verbose("SQLAssetServer", "AssetStorage: Attempting to load " + FileName); 65 //MainLog.Instance.Verbose("SQLAssetServer", "AssetStorage: Attempting to load " + FileName);
66 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 66 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
67 67
68 foreach (Type pluginType in pluginAssembly.GetTypes()) 68 foreach (Type pluginType in pluginAssembly.GetTypes())
69 { 69 {
70 if (!pluginType.IsAbstract) 70 if (!pluginType.IsAbstract)
71 { 71 {
72 Type typeInterface = pluginType.GetInterface("IAssetProvider", true); 72 Type typeInterface = pluginType.GetInterface("IAssetProvider", true);
73 73
74 if (typeInterface != null) 74 if (typeInterface != null)
75 { 75 {
76 IAssetProvider plug = (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 76 IAssetProvider plug = (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
77 m_plugin = plug; 77 m_plugin = plug;
78 m_plugin.Initialise("AssetStorage.db", ""); 78 m_plugin.Initialise("AssetStorage.db", "");
79 79
80 //MainLog.Instance.Verbose("AssetStorage: Added IAssetProvider Interface"); 80 //MainLog.Instance.Verbose("AssetStorage: Added IAssetProvider Interface");
81 } 81 }
82 82
83 typeInterface = null; 83 typeInterface = null;
84 } 84 }
85 } 85 }
86 86
87 pluginAssembly = null; 87 pluginAssembly = null;
88 } 88 }
89 89
90 public void SetReceiver(IAssetReceiver receiver) 90 public void SetReceiver(IAssetReceiver receiver)
91 { 91 {
92 this._receiver = receiver; 92 this._receiver = receiver;
93 } 93 }
94 94
95 public void FetchAsset(LLUUID assetID, bool isTexture) 95 public void FetchAsset(LLUUID assetID, bool isTexture)
96 { 96 {
97 ARequest req = new ARequest(); 97 ARequest req = new ARequest();
98 req.AssetID = assetID; 98 req.AssetID = assetID;
99 req.IsTexture = isTexture; 99 req.IsTexture = isTexture;
100 this._assetRequests.Enqueue(req); 100 this._assetRequests.Enqueue(req);
101 } 101 }
102 102
103 public void UpdateAsset(AssetBase asset) 103 public void UpdateAsset(AssetBase asset)
104 { 104 {
105 m_plugin.UpdateAsset(asset); 105 m_plugin.UpdateAsset(asset);
106 m_plugin.CommitAssets(); 106 m_plugin.CommitAssets();
107 } 107 }
108 108
109 public void CreateAsset(AssetBase asset) 109 public void CreateAsset(AssetBase asset)
110 { 110 {
111 m_plugin.CreateAsset(asset); 111 m_plugin.CreateAsset(asset);
112 m_plugin.CommitAssets(); 112 m_plugin.CommitAssets();
113 } 113 }
114 114
115 public void SetServerInfo(string ServerUrl, string ServerKey) 115 public void SetServerInfo(string ServerUrl, string ServerKey)
116 { 116 {
117 117
118 } 118 }
119 public void Close() 119 public void Close()
120 { 120 {
121 m_plugin.CommitAssets(); 121 m_plugin.CommitAssets();
122 } 122 }
123 123
124 private void RunRequests() 124 private void RunRequests()
125 { 125 {
126 126
127 while (true) 127 while (true)
128 { 128 {
129 ARequest req = this._assetRequests.Dequeue(); 129 ARequest req = this._assetRequests.Dequeue();
130 130
131 m_plugin.FetchAsset(req.AssetID); 131 MainLog.Instance.Verbose("Requesting asset: " + req.AssetID);
132 132
133 AssetBase asset = m_plugin.FetchAsset(req.AssetID); 133 AssetBase asset = m_plugin.FetchAsset(req.AssetID);
134 if (asset != null) 134 if (asset != null)
135 { 135 {
136 _receiver.AssetReceived(asset, req.IsTexture); 136 _receiver.AssetReceived(asset, req.IsTexture);
137 } 137 }
138 else 138 else
139 { 139 {
140 _receiver.AssetNotFound(req.AssetID); 140 _receiver.AssetNotFound(req.AssetID);
141 } 141 }
142 142
143 } 143 }
144 144
145 } 145 }
146 146
147 private void SetUpAssetDatabase() 147 private void SetUpAssetDatabase()
148 { 148 {
149 MainLog.Instance.Verbose("Setting up asset database"); 149 MainLog.Instance.Verbose("Setting up asset database");
150 150
151 AssetBase Image = new AssetBase(); 151 AssetBase Image = new AssetBase();
152 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); 152 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
153 Image.Name = "Bricks"; 153 Image.Name = "Bricks";
154 this.LoadAsset(Image, true, "bricks.jp2"); 154 this.LoadAsset(Image, true, "bricks.jp2");
155 m_plugin.CreateAsset(Image); 155 m_plugin.CreateAsset(Image);
156 156
157 Image = new AssetBase(); 157 Image = new AssetBase();
158 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); 158 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002");
159 Image.Name = "Plywood"; 159 Image.Name = "Plywood";
160 this.LoadAsset(Image, true, "plywood.jp2"); 160 this.LoadAsset(Image, true, "plywood.jp2");
161 m_plugin.CreateAsset(Image); 161 m_plugin.CreateAsset(Image);
162 162
163 Image = new AssetBase(); 163 Image = new AssetBase();
164 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); 164 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003");
165 Image.Name = "Rocks"; 165 Image.Name = "Rocks";
166 this.LoadAsset(Image, true, "rocks.jp2"); 166 this.LoadAsset(Image, true, "rocks.jp2");
167 m_plugin.CreateAsset(Image); 167 m_plugin.CreateAsset(Image);
168 168
169 Image = new AssetBase(); 169 Image = new AssetBase();
170 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); 170 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004");
171 Image.Name = "Granite"; 171 Image.Name = "Granite";
172 this.LoadAsset(Image, true, "granite.jp2"); 172 this.LoadAsset(Image, true, "granite.jp2");
173 m_plugin.CreateAsset(Image); 173 m_plugin.CreateAsset(Image);
174 174
175 Image = new AssetBase(); 175 Image = new AssetBase();
176 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); 176 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005");
177 Image.Name = "Hardwood"; 177 Image.Name = "Hardwood";
178 this.LoadAsset(Image, true, "hardwood.jp2"); 178 this.LoadAsset(Image, true, "hardwood.jp2");
179 m_plugin.CreateAsset(Image); 179 m_plugin.CreateAsset(Image);
180 180
181 Image = new AssetBase(); 181 Image = new AssetBase();
182 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); 182 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
183 Image.Name = "Prim Base Texture"; 183 Image.Name = "Prim Base Texture";
184 this.LoadAsset(Image, true, "plywood.jp2"); 184 this.LoadAsset(Image, true, "plywood.jp2");
185 m_plugin.CreateAsset(Image); 185 m_plugin.CreateAsset(Image);
186 186
187 Image = new AssetBase(); 187 Image = new AssetBase();
188 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); 188 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006");
189 Image.Name = "Map Base Texture"; 189 Image.Name = "Map Base Texture";
190 this.LoadAsset(Image, true, "map_base.jp2"); 190 this.LoadAsset(Image, true, "map_base.jp2");
191 m_plugin.CreateAsset(Image); 191 m_plugin.CreateAsset(Image);
192 192
193 Image = new AssetBase(); 193 Image = new AssetBase();
194 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); 194 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007");
195 Image.Name = "Map Texture"; 195 Image.Name = "Map Texture";
196 this.LoadAsset(Image, true, "map1.jp2"); 196 this.LoadAsset(Image, true, "map1.jp2");
197 m_plugin.CreateAsset(Image); 197 m_plugin.CreateAsset(Image);
198 198
199 Image = new AssetBase(); 199 Image = new AssetBase();
200 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); 200 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010");
201 Image.Name = "Female Body Texture"; 201 Image.Name = "Female Body Texture";
202 this.LoadAsset(Image, true, "femalebody.jp2"); 202 this.LoadAsset(Image, true, "femalebody.jp2");
203 m_plugin.CreateAsset(Image); 203 m_plugin.CreateAsset(Image);
204 204
205 Image = new AssetBase(); 205 Image = new AssetBase();
206 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); 206 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011");
207 Image.Name = "Female Bottom Texture"; 207 Image.Name = "Female Bottom Texture";
208 this.LoadAsset(Image, true, "femalebottom.jp2"); 208 this.LoadAsset(Image, true, "femalebottom.jp2");
209 m_plugin.CreateAsset(Image); 209 m_plugin.CreateAsset(Image);
210 210
211 Image = new AssetBase(); 211 Image = new AssetBase();
212 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); 212 Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012");
213 Image.Name = "Female Face Texture"; 213 Image.Name = "Female Face Texture";
214 this.LoadAsset(Image, true, "femaleface.jp2"); 214 this.LoadAsset(Image, true, "femaleface.jp2");
215 m_plugin.CreateAsset(Image); 215 m_plugin.CreateAsset(Image);
216 216
217 Image = new AssetBase(); 217 Image = new AssetBase();
218 Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); 218 Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb");
219 Image.Name = "Skin"; 219 Image.Name = "Skin";
220 Image.Type = 13; 220 Image.Type = 13;
221 Image.InvType = 13; 221 Image.InvType = 13;
222 this.LoadAsset(Image, false, "base_skin.dat"); 222 this.LoadAsset(Image, false, "base_skin.dat");
223 m_plugin.CreateAsset(Image); 223 m_plugin.CreateAsset(Image);
224 224
225 Image = new AssetBase(); 225 Image = new AssetBase();
226 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); 226 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
227 Image.Name = "Shape"; 227 Image.Name = "Shape";
228 Image.Type = 13; 228 Image.Type = 13;
229 Image.InvType = 13; 229 Image.InvType = 13;
230 this.LoadAsset(Image, false, "base_shape.dat"); 230 this.LoadAsset(Image, false, "base_shape.dat");
231 m_plugin.CreateAsset(Image); 231 m_plugin.CreateAsset(Image);
232 232
233 Image = new AssetBase(); 233 Image = new AssetBase();
234 Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); 234 Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110");
235 Image.Name = "Shirt"; 235 Image.Name = "Shirt";
236 Image.Type = 5; 236 Image.Type = 5;
237 Image.InvType = 18; 237 Image.InvType = 18;
238 this.LoadAsset(Image, false, "newshirt.dat"); 238 this.LoadAsset(Image, false, "newshirt.dat");
239 m_plugin.CreateAsset(Image); 239 m_plugin.CreateAsset(Image);
240 240
241 Image = new AssetBase(); 241 Image = new AssetBase();
242 Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); 242 Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120");
243 Image.Name = "Shirt"; 243 Image.Name = "Shirt";
244 Image.Type = 5; 244 Image.Type = 5;
245 Image.InvType = 18; 245 Image.InvType = 18;
246 this.LoadAsset(Image, false, "newpants.dat"); 246 this.LoadAsset(Image, false, "newpants.dat");
247 m_plugin.CreateAsset(Image); 247 m_plugin.CreateAsset(Image);
248 248
249 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); 249 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
250 if (File.Exists(filePath)) 250 if (File.Exists(filePath))
251 { 251 {
252 XmlConfigSource source = new XmlConfigSource(filePath); 252 XmlConfigSource source = new XmlConfigSource(filePath);
253 ReadAssetDetails(source); 253 ReadAssetDetails(source);
254 } 254 }
255 255
256 m_plugin.CommitAssets(); 256 m_plugin.CommitAssets();
257 } 257 }
258 258
259 protected void ReadAssetDetails(IConfigSource source) 259 protected void ReadAssetDetails(IConfigSource source)
260 { 260 {
261 AssetBase newAsset = null; 261 AssetBase newAsset = null;
262 for (int i = 0; i < source.Configs.Count; i++) 262 for (int i = 0; i < source.Configs.Count; i++)
263 { 263 {
264 newAsset = new AssetBase(); 264 newAsset = new AssetBase();
265 newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated())); 265 newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated()));
266 newAsset.Name = source.Configs[i].GetString("name", ""); 266 newAsset.Name = source.Configs[i].GetString("name", "");
267 newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0); 267 newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0);
268 newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); 268 newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0);
269 string fileName = source.Configs[i].GetString("fileName", ""); 269 string fileName = source.Configs[i].GetString("fileName", "");
270 if (fileName != "") 270 if (fileName != "")
271 { 271 {
272 this.LoadAsset(newAsset, false, fileName); 272 MainLog.Instance.Verbose("Creating new asset: " + newAsset.Name);
273 m_plugin.CreateAsset(newAsset); 273 this.LoadAsset(newAsset, false, fileName);
274 } 274 m_plugin.CreateAsset(newAsset);
275 } 275 }
276 } 276 }
277 277 }
278 private void LoadAsset(AssetBase info, bool image, string filename) 278
279 { 279 private void LoadAsset(AssetBase info, bool image, string filename)
280 //should request Asset from storage manager 280 {
281 //but for now read from file 281 //should request Asset from storage manager
282 282 //but for now read from file
283 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; 283
284 string fileName = Path.Combine(dataPath, filename); 284 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
285 FileInfo fInfo = new FileInfo(fileName); 285 string fileName = Path.Combine(dataPath, filename);
286 long numBytes = fInfo.Length; 286 FileInfo fInfo = new FileInfo(fileName);
287 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); 287 long numBytes = fInfo.Length;
288 byte[] idata = new byte[numBytes]; 288 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
289 BinaryReader br = new BinaryReader(fStream); 289 byte[] idata = new byte[numBytes];
290 idata = br.ReadBytes((int)numBytes); 290 BinaryReader br = new BinaryReader(fStream);
291 br.Close(); 291 idata = br.ReadBytes((int)numBytes);
292 fStream.Close(); 292 br.Close();
293 info.Data = idata; 293 fStream.Close();
294 //info.loaded=true; 294 info.Data = idata;
295 } 295 //info.loaded=true;
296 } 296 }
297 297 }
298} 298
299}