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