diff options
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/SQLAssetServer.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/SQLAssetServer.cs | 206 |
1 files changed, 10 insertions, 196 deletions
diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index 35ec1cf..cf54b81 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs | |||
@@ -36,32 +36,22 @@ using OpenSim.Framework.Interfaces; | |||
36 | using OpenSim.Framework.Types; | 36 | using OpenSim.Framework.Types; |
37 | using OpenSim.Framework.Utilities; | 37 | using OpenSim.Framework.Utilities; |
38 | 38 | ||
39 | namespace OpenSim.Framework.Communications.Caches | 39 | namespace OpenSim.Framework.Communications.Cache |
40 | { | 40 | { |
41 | 41 | public class SQLAssetServer : AssetServerBase | |
42 | public class SQLAssetServer : IAssetServer | ||
43 | { | 42 | { |
44 | private IAssetReceiver _receiver; | ||
45 | private BlockingQueue<ARequest> _assetRequests; | ||
46 | private Thread _localAssetServerThread; | ||
47 | protected IAssetProvider m_assetProviderPlugin; | ||
48 | private object syncLock = new object(); | ||
49 | |||
50 | |||
51 | public SQLAssetServer(string pluginName) | 43 | public SQLAssetServer(string pluginName) |
52 | { | 44 | { |
53 | _assetRequests = new BlockingQueue<ARequest>(); | 45 | _assetRequests = new BlockingQueue<ARequest>(); |
54 | AddPlugin(pluginName); | 46 | AddPlugin(pluginName); |
55 | 47 | ||
56 | SetUpAssetDatabase(); | ||
57 | |||
58 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); | 48 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); |
59 | this._localAssetServerThread.IsBackground = true; | 49 | this._localAssetServerThread.IsBackground = true; |
60 | this._localAssetServerThread.Start(); | 50 | this._localAssetServerThread.Start(); |
61 | 51 | ||
62 | } | 52 | } |
63 | 53 | ||
64 | public SQLAssetServer( IAssetProvider assetProvider ) | 54 | public SQLAssetServer(IAssetProvider assetProvider) |
65 | { | 55 | { |
66 | m_assetProviderPlugin = assetProvider; | 56 | m_assetProviderPlugin = assetProvider; |
67 | } | 57 | } |
@@ -93,49 +83,15 @@ namespace OpenSim.Framework.Communications.Caches | |||
93 | pluginAssembly = null; | 83 | pluginAssembly = null; |
94 | } | 84 | } |
95 | 85 | ||
96 | public void SetReceiver(IAssetReceiver receiver) | ||
97 | { | ||
98 | this._receiver = receiver; | ||
99 | } | ||
100 | |||
101 | public void FetchAsset(LLUUID assetID, bool isTexture) | ||
102 | { | ||
103 | ARequest req = new ARequest(); | ||
104 | req.AssetID = assetID; | ||
105 | req.IsTexture = isTexture; | ||
106 | this._assetRequests.Enqueue(req); | ||
107 | } | ||
108 | |||
109 | public void UpdateAsset(AssetBase asset) | ||
110 | { | ||
111 | lock (syncLock) | ||
112 | { | ||
113 | m_assetProviderPlugin.UpdateAsset(asset); | ||
114 | m_assetProviderPlugin.CommitAssets(); | ||
115 | } | ||
116 | } | ||
117 | 86 | ||
118 | public void CreateAsset(AssetBase asset) | 87 | public override void Close() |
119 | { | ||
120 | lock (syncLock) | ||
121 | { | ||
122 | m_assetProviderPlugin.CreateAsset(asset); | ||
123 | m_assetProviderPlugin.CommitAssets(); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public void SetServerInfo(string ServerUrl, string ServerKey) | ||
128 | { | ||
129 | |||
130 | } | ||
131 | public void Close() | ||
132 | { | 88 | { |
133 | m_assetProviderPlugin.CommitAssets(); | 89 | m_assetProviderPlugin.CommitAssets(); |
134 | } | 90 | } |
135 | 91 | ||
136 | private void RunRequests() | 92 | private void RunRequests() |
137 | { | 93 | { |
138 | 94 | ||
139 | while (true) | 95 | while (true) |
140 | { | 96 | { |
141 | ARequest req = this._assetRequests.Dequeue(); | 97 | ARequest req = this._assetRequests.Dequeue(); |
@@ -160,156 +116,14 @@ namespace OpenSim.Framework.Communications.Caches | |||
160 | 116 | ||
161 | } | 117 | } |
162 | 118 | ||
163 | private void SetUpAssetDatabase() | 119 | protected override void StoreAsset(AssetBase asset) |
164 | { | 120 | { |
165 | MainLog.Instance.Verbose("Setting up asset database"); | 121 | m_assetProviderPlugin.CreateAsset(asset); |
166 | |||
167 | AssetBase Image = new AssetBase(); | ||
168 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); | ||
169 | Image.Name = "Bricks"; | ||
170 | this.LoadAsset(Image, true, "bricks.jp2"); | ||
171 | m_assetProviderPlugin.CreateAsset(Image); | ||
172 | |||
173 | Image = new AssetBase(); | ||
174 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
175 | Image.Name = "Plywood"; | ||
176 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
177 | m_assetProviderPlugin.CreateAsset(Image); | ||
178 | |||
179 | Image = new AssetBase(); | ||
180 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
181 | Image.Name = "Rocks"; | ||
182 | this.LoadAsset(Image, true, "rocks.jp2"); | ||
183 | m_assetProviderPlugin.CreateAsset(Image); | ||
184 | |||
185 | Image = new AssetBase(); | ||
186 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
187 | Image.Name = "Granite"; | ||
188 | this.LoadAsset(Image, true, "granite.jp2"); | ||
189 | m_assetProviderPlugin.CreateAsset(Image); | ||
190 | |||
191 | Image = new AssetBase(); | ||
192 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
193 | Image.Name = "Hardwood"; | ||
194 | this.LoadAsset(Image, true, "hardwood.jp2"); | ||
195 | m_assetProviderPlugin.CreateAsset(Image); | ||
196 | |||
197 | Image = new AssetBase(); | ||
198 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
199 | Image.Name = "Prim Base Texture"; | ||
200 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
201 | m_assetProviderPlugin.CreateAsset(Image); | ||
202 | |||
203 | Image = new AssetBase(); | ||
204 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); | ||
205 | Image.Name = "Map Base Texture"; | ||
206 | this.LoadAsset(Image, true, "map_base.jp2"); | ||
207 | m_assetProviderPlugin.CreateAsset(Image); | ||
208 | |||
209 | Image = new AssetBase(); | ||
210 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); | ||
211 | Image.Name = "Map Texture"; | ||
212 | this.LoadAsset(Image, true, "map1.jp2"); | ||
213 | m_assetProviderPlugin.CreateAsset(Image); | ||
214 | |||
215 | Image = new AssetBase(); | ||
216 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); | ||
217 | Image.Name = "Female Body Texture"; | ||
218 | this.LoadAsset(Image, true, "femalebody.jp2"); | ||
219 | m_assetProviderPlugin.CreateAsset(Image); | ||
220 | |||
221 | Image = new AssetBase(); | ||
222 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); | ||
223 | Image.Name = "Female Bottom Texture"; | ||
224 | this.LoadAsset(Image, true, "femalebottom.jp2"); | ||
225 | m_assetProviderPlugin.CreateAsset(Image); | ||
226 | |||
227 | Image = new AssetBase(); | ||
228 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); | ||
229 | Image.Name = "Female Face Texture"; | ||
230 | this.LoadAsset(Image, true, "femaleface.jp2"); | ||
231 | m_assetProviderPlugin.CreateAsset(Image); | ||
232 | |||
233 | Image = new AssetBase(); | ||
234 | Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||
235 | Image.Name = "Skin"; | ||
236 | Image.Type = 13; | ||
237 | Image.InvType = 13; | ||
238 | this.LoadAsset(Image, false, "base_skin.dat"); | ||
239 | m_assetProviderPlugin.CreateAsset(Image); | ||
240 | |||
241 | Image = new AssetBase(); | ||
242 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
243 | Image.Name = "Shape"; | ||
244 | Image.Type = 13; | ||
245 | Image.InvType = 13; | ||
246 | this.LoadAsset(Image, false, "base_shape.dat"); | ||
247 | m_assetProviderPlugin.CreateAsset(Image); | ||
248 | |||
249 | Image = new AssetBase(); | ||
250 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | ||
251 | Image.Name = "Shirt"; | ||
252 | Image.Type = 5; | ||
253 | Image.InvType = 18; | ||
254 | this.LoadAsset(Image, false, "newshirt.dat"); | ||
255 | m_assetProviderPlugin.CreateAsset(Image); | ||
256 | |||
257 | Image = new AssetBase(); | ||
258 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | ||
259 | Image.Name = "Shirt"; | ||
260 | Image.Type = 5; | ||
261 | Image.InvType = 18; | ||
262 | this.LoadAsset(Image, false, "newpants.dat"); | ||
263 | m_assetProviderPlugin.CreateAsset(Image); | ||
264 | |||
265 | string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); | ||
266 | if (File.Exists(filePath)) | ||
267 | { | ||
268 | XmlConfigSource source = new XmlConfigSource(filePath); | ||
269 | ReadAssetDetails(source); | ||
270 | } | ||
271 | |||
272 | m_assetProviderPlugin.CommitAssets(); | ||
273 | } | 122 | } |
274 | 123 | ||
275 | protected void ReadAssetDetails(IConfigSource source) | 124 | protected override void CommitAssets() |
276 | { | 125 | { |
277 | AssetBase newAsset = null; | 126 | m_assetProviderPlugin.CommitAssets(); |
278 | for (int i = 0; i < source.Configs.Count; i++) | ||
279 | { | ||
280 | newAsset = new AssetBase(); | ||
281 | newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated())); | ||
282 | newAsset.Name = source.Configs[i].GetString("name", ""); | ||
283 | newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0); | ||
284 | newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); | ||
285 | string fileName = source.Configs[i].GetString("fileName", ""); | ||
286 | if (fileName != "") | ||
287 | { | ||
288 | MainLog.Instance.Verbose("Creating new asset: " + newAsset.Name); | ||
289 | this.LoadAsset(newAsset, false, fileName); | ||
290 | m_assetProviderPlugin.CreateAsset(newAsset); | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | private void LoadAsset(AssetBase info, bool image, string filename) | ||
296 | { | ||
297 | //should request Asset from storage manager | ||
298 | //but for now read from file | ||
299 | |||
300 | string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; | ||
301 | string fileName = Path.Combine(dataPath, filename); | ||
302 | FileInfo fInfo = new FileInfo(fileName); | ||
303 | long numBytes = fInfo.Length; | ||
304 | FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); | ||
305 | byte[] idata = new byte[numBytes]; | ||
306 | BinaryReader br = new BinaryReader(fStream); | ||
307 | idata = br.ReadBytes((int)numBytes); | ||
308 | br.Close(); | ||
309 | fStream.Close(); | ||
310 | info.Data = idata; | ||
311 | //info.loaded=true; | ||
312 | } | 127 | } |
313 | } | 128 | } |
314 | 129 | } \ No newline at end of file | |
315 | } | ||