aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetServerBase.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs374
1 files changed, 187 insertions, 187 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index 858019f..08d5b87 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -1,188 +1,188 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.IO; 3using System.IO;
4using System.Threading; 4using System.Threading;
5using libsecondlife; 5using libsecondlife;
6using Nini.Config; 6using Nini.Config;
7using OpenSim.Framework.Console; 7using OpenSim.Framework.Console;
8using OpenSim.Framework.Interfaces; 8using OpenSim.Framework.Interfaces;
9using OpenSim.Framework.Types; 9using OpenSim.Framework.Types;
10using OpenSim.Framework.Utilities; 10using OpenSim.Framework.Utilities;
11 11
12namespace OpenSim.Framework.Communications.Cache 12namespace OpenSim.Framework.Communications.Cache
13{ 13{
14 public abstract class AssetServerBase : IAssetServer 14 public abstract class AssetServerBase : IAssetServer
15 { 15 {
16 protected IAssetReceiver _receiver; 16 protected IAssetReceiver _receiver;
17 protected BlockingQueue<ARequest> _assetRequests; 17 protected BlockingQueue<ARequest> _assetRequests;
18 protected Thread _localAssetServerThread; 18 protected Thread _localAssetServerThread;
19 protected IAssetProvider m_assetProviderPlugin; 19 protected IAssetProvider m_assetProviderPlugin;
20 protected object syncLock = new object(); 20 protected object syncLock = new object();
21 21
22 protected abstract void StoreAsset(AssetBase asset); 22 protected abstract void StoreAsset(AssetBase asset);
23 protected abstract void CommitAssets(); 23 protected abstract void CommitAssets();
24 24
25 protected abstract void RunRequests(); 25 protected abstract void RunRequests();
26 26
27 public void LoadDefaultAssets() 27 public void LoadDefaultAssets()
28 { 28 {
29 MainLog.Instance.Verbose("SQL ASSET SERVER", "Setting up asset database"); 29 MainLog.Instance.Verbose("SQL ASSET SERVER", "Setting up asset database");
30 30
31 ForEachDefaultAsset(StoreAsset ); 31 ForEachDefaultAsset(StoreAsset );
32 ForEachXmlAsset(StoreAsset ); 32 ForEachXmlAsset(StoreAsset );
33 33
34 CommitAssets(); 34 CommitAssets();
35 } 35 }
36 36
37 37
38 public AssetServerBase() 38 public AssetServerBase()
39 { 39 {
40 System.Console.WriteLine("Starting Db4o asset storage system"); 40 System.Console.WriteLine("Starting Db4o asset storage system");
41 this._assetRequests = new BlockingQueue<ARequest>(); 41 this._assetRequests = new BlockingQueue<ARequest>();
42 42
43 this._localAssetServerThread = new Thread( RunRequests ); 43 this._localAssetServerThread = new Thread( RunRequests );
44 this._localAssetServerThread.IsBackground = true; 44 this._localAssetServerThread.IsBackground = true;
45 this._localAssetServerThread.Start(); 45 this._localAssetServerThread.Start();
46 } 46 }
47 47
48 public void LoadAsset(AssetBase info, bool image, string filename) 48 public void LoadAsset(AssetBase info, bool image, string filename)
49 { 49 {
50 //should request Asset from storage manager 50 //should request Asset from storage manager
51 //but for now read from file 51 //but for now read from file
52 52
53 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; 53 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
54 string fileName = Path.Combine(dataPath, filename); 54 string fileName = Path.Combine(dataPath, filename);
55 FileInfo fInfo = new FileInfo(fileName); 55 FileInfo fInfo = new FileInfo(fileName);
56 long numBytes = fInfo.Length; 56 long numBytes = fInfo.Length;
57 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); 57 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
58 byte[] idata = new byte[numBytes]; 58 byte[] idata = new byte[numBytes];
59 BinaryReader br = new BinaryReader(fStream); 59 BinaryReader br = new BinaryReader(fStream);
60 idata = br.ReadBytes((int)numBytes); 60 idata = br.ReadBytes((int)numBytes);
61 br.Close(); 61 br.Close();
62 fStream.Close(); 62 fStream.Close();
63 info.Data = idata; 63 info.Data = idata;
64 //info.loaded=true; 64 //info.loaded=true;
65 } 65 }
66 66
67 public void SetReceiver(IAssetReceiver receiver) 67 public void SetReceiver(IAssetReceiver receiver)
68 { 68 {
69 this._receiver = receiver; 69 this._receiver = receiver;
70 } 70 }
71 71
72 public void FetchAsset(LLUUID assetID, bool isTexture) 72 public void FetchAsset(LLUUID assetID, bool isTexture)
73 { 73 {
74 ARequest req = new ARequest(); 74 ARequest req = new ARequest();
75 req.AssetID = assetID; 75 req.AssetID = assetID;
76 req.IsTexture = isTexture; 76 req.IsTexture = isTexture;
77 this._assetRequests.Enqueue(req); 77 this._assetRequests.Enqueue(req);
78 } 78 }
79 79
80 public void UpdateAsset(AssetBase asset) 80 public void UpdateAsset(AssetBase asset)
81 { 81 {
82 lock (syncLock) 82 lock (syncLock)
83 { 83 {
84 m_assetProviderPlugin.UpdateAsset(asset); 84 m_assetProviderPlugin.UpdateAsset(asset);
85 m_assetProviderPlugin.CommitAssets(); 85 m_assetProviderPlugin.CommitAssets();
86 } 86 }
87 } 87 }
88 88
89 public void StoreAndCommitAsset(AssetBase asset) 89 public void StoreAndCommitAsset(AssetBase asset)
90 { 90 {
91 lock (syncLock) 91 lock (syncLock)
92 { 92 {
93 StoreAsset(asset); 93 StoreAsset(asset);
94 CommitAssets(); 94 CommitAssets();
95 } 95 }
96 } 96 }
97 97
98 public virtual void Close() 98 public virtual void Close()
99 { 99 {
100 _localAssetServerThread.Abort( ); 100 _localAssetServerThread.Abort( );
101 } 101 }
102 102
103 public void SetServerInfo(string ServerUrl, string ServerKey) 103 public void SetServerInfo(string ServerUrl, string ServerKey)
104 { 104 {
105 105
106 } 106 }
107 107
108 public virtual List<AssetBase> GetDefaultAssets() 108 public virtual List<AssetBase> GetDefaultAssets()
109 { 109 {
110 List<AssetBase> assets = new List<AssetBase>(); 110 List<AssetBase> assets = new List<AssetBase>();
111 111
112 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000001", "Bricks", "bricks.jp2")); 112 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000001", "Bricks", "bricks.jp2"));
113 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000002", "Plywood", "plywood.jp2")); 113 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000002", "Plywood", "plywood.jp2"));
114 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000003", "Rocks", "rocks.jp2")); 114 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000003", "Rocks", "rocks.jp2"));
115 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000004", "Granite", "granite.jp2")); 115 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000004", "Granite", "granite.jp2"));
116 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000005", "Hardwood", "hardwood.jp2")); 116 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000005", "Hardwood", "hardwood.jp2"));
117 assets.Add(CreateImageAsset("00000000-0000-0000-5005-000000000005", "Prim Base Texture", "plywood.jp2")); 117 assets.Add(CreateImageAsset("00000000-0000-0000-5005-000000000005", "Prim Base Texture", "plywood.jp2"));
118 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000006", "Map Base Texture", "map_base.jp2")); 118 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000006", "Map Base Texture", "map_base.jp2"));
119 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000007", "Map Texture", "map1.jp2")); 119 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000007", "Map Texture", "map1.jp2"));
120 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000010", "Female Body Texture", "femalebody.jp2")); 120 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000010", "Female Body Texture", "femalebody.jp2"));
121 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000011", "Female Bottom Texture", "femalebottom.jp2")); 121 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000011", "Female Bottom Texture", "femalebottom.jp2"));
122 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000012", "Female Face Texture", "femaleface.jp2")); 122 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000012", "Female Face Texture", "femaleface.jp2"));
123 123
124 assets.Add(CreateAsset("77c41e39-38f9-f75a-024e-585989bbabbb", "Skin", "base_skin.dat", false)); 124 assets.Add(CreateAsset("77c41e39-38f9-f75a-024e-585989bbabbb", "Skin", "base_skin.dat", false));
125 assets.Add(CreateAsset("66c41e39-38f9-f75a-024e-585989bfab73", "Shape", "base_shape.dat", false)); 125 assets.Add(CreateAsset("66c41e39-38f9-f75a-024e-585989bfab73", "Shape", "base_shape.dat", false));
126 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111110", "Shirt", "newshirt.dat", false)); 126 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111110", "Shirt", "newshirt.dat", false));
127 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111120", "Shirt", "newpants.dat", false)); 127 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111120", "Shirt", "newpants.dat", false));
128 128
129 return assets; 129 return assets;
130 } 130 }
131 131
132 public AssetBase CreateImageAsset(string assetIdStr, string name, string filename) 132 public AssetBase CreateImageAsset(string assetIdStr, string name, string filename)
133 { 133 {
134 return CreateAsset(assetIdStr, name, filename, true); 134 return CreateAsset(assetIdStr, name, filename, true);
135 } 135 }
136 136
137 public void ForEachDefaultAsset(Action<AssetBase> action) 137 public void ForEachDefaultAsset(Action<AssetBase> action)
138 { 138 {
139 List<AssetBase> assets = GetDefaultAssets(); 139 List<AssetBase> assets = GetDefaultAssets();
140 assets.ForEach(action); 140 assets.ForEach(action);
141 } 141 }
142 142
143 public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage) 143 public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
144 { 144 {
145 AssetBase asset = new AssetBase( 145 AssetBase asset = new AssetBase(
146 new LLUUID(assetIdStr), 146 new LLUUID(assetIdStr),
147 name 147 name
148 ); 148 );
149 149
150 if (!String.IsNullOrEmpty(filename)) 150 if (!String.IsNullOrEmpty(filename))
151 { 151 {
152 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename ); 152 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename );
153 153
154 LoadAsset(asset, isImage, filename); 154 LoadAsset(asset, isImage, filename);
155 } 155 }
156 else 156 else
157 { 157 {
158 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name ); 158 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name );
159 } 159 }
160 160
161 return asset; 161 return asset;
162 } 162 }
163 163
164 public void ForEachXmlAsset(Action<AssetBase> action) 164 public void ForEachXmlAsset(Action<AssetBase> action)
165 { 165 {
166 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); 166 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
167 if (File.Exists(filePath)) 167 if (File.Exists(filePath))
168 { 168 {
169 XmlConfigSource source = new XmlConfigSource(filePath); 169 XmlConfigSource source = new XmlConfigSource(filePath);
170 170
171 for (int i = 0; i < source.Configs.Count; i++) 171 for (int i = 0; i < source.Configs.Count; i++)
172 { 172 {
173 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated()); 173 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated());
174 string name = source.Configs[i].GetString("name", ""); 174 string name = source.Configs[i].GetString("name", "");
175 sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0); 175 sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0);
176 sbyte invType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); 176 sbyte invType = (sbyte)source.Configs[i].GetInt("inventoryType", 0);
177 string fileName = source.Configs[i].GetString("fileName", ""); 177 string fileName = source.Configs[i].GetString("fileName", "");
178 178
179 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false); 179 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false);
180 180
181 newAsset.Type = type; 181 newAsset.Type = type;
182 newAsset.InvType = invType; 182 newAsset.InvType = invType;
183 183
184 } 184 }
185 } 185 }
186 } 186 }
187 } 187 }
188} \ No newline at end of file 188} \ No newline at end of file