clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using Nini.Config;
33 using log4net;
34 using OpenSim.Framework;
35 using OpenSim.Data;
36 using OpenSim.Services.Interfaces;
37 using OpenMetaverse;
38  
39 namespace OpenSim.Services.AssetService
40 {
41 public class AssetService : AssetServiceBase, IAssetService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46  
47 protected static AssetService m_RootInstance;
48  
49 public AssetService(IConfigSource config)
50 : this(config, "AssetService")
51 {
52 }
53  
54 public AssetService(IConfigSource config, string configName) : base(config, configName)
55 {
56 if (m_RootInstance == null)
57 {
58 m_RootInstance = this;
59  
60 if (m_AssetLoader != null)
61 {
62 IConfig assetConfig = config.Configs[m_ConfigName];
63 if (assetConfig == null)
64 throw new Exception("No " + m_ConfigName + " configuration");
65  
66 string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
67 String.Empty);
68  
69 bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);
70  
71 if (assetLoaderEnabled)
72 {
73 m_log.DebugFormat("[ASSET SERVICE]: Loading default asset set from {0}", loaderArgs);
74  
75 m_AssetLoader.ForEachDefaultXmlAsset(
76 loaderArgs,
77 delegate(AssetBase a)
78 {
79 AssetBase existingAsset = Get(a.ID);
80 // AssetMetadata existingMetadata = GetMetadata(a.ID);
81  
82 if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
83 {
84 // m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
85 Store(a);
86 }
87 });
88 }
89  
90 m_log.Debug("[ASSET SERVICE]: Local asset service enabled");
91 }
92 }
93 }
94  
95 public virtual AssetBase Get(string id)
96 {
97 // m_log.DebugFormat("[ASSET SERVICE]: Get asset for {0}", id);
98  
99 UUID assetID;
100  
101 if (!UUID.TryParse(id, out assetID))
102 {
103 m_log.WarnFormat("[ASSET SERVICE]: Could not parse requested asset id {0}", id);
104 return null;
105 }
106  
107 try
108 {
109 return m_Database.GetAsset(assetID);
110 }
111 catch (Exception e)
112 {
113 m_log.ErrorFormat("[ASSET SERVICE]: Exception getting asset {0} {1}", assetID, e);
114 return null;
115 }
116 }
117  
118 public virtual AssetBase GetCached(string id)
119 {
120 return Get(id);
121 }
122  
123 public virtual AssetMetadata GetMetadata(string id)
124 {
125 // m_log.DebugFormat("[ASSET SERVICE]: Get asset metadata for {0}", id);
126  
127 AssetBase asset = Get(id);
128  
129 if (asset != null)
130 return asset.Metadata;
131 else
132 return null;
133 }
134  
135 public virtual byte[] GetData(string id)
136 {
137 // m_log.DebugFormat("[ASSET SERVICE]: Get asset data for {0}", id);
138  
139 AssetBase asset = Get(id);
140  
141 if (asset != null)
142 return asset.Data;
143 else
144 return null;
145 }
146  
147 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
148 {
149 //m_log.DebugFormat("[AssetService]: Get asset async {0}", id);
150  
151 handler(id, sender, Get(id));
152  
153 return true;
154 }
155  
156 public virtual string Store(AssetBase asset)
157 {
158 if (!m_Database.ExistsAsset(asset.FullID))
159 {
160 // m_log.DebugFormat(
161 // "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
162 m_Database.StoreAsset(asset);
163 }
164 // else
165 // {
166 // m_log.DebugFormat(
167 // "[ASSET SERVICE]: Not storing asset {0} {1}, bytes {2} as it already exists", asset.Name, asset.FullID, asset.Data.Length);
168 // }
169  
170 return asset.ID;
171 }
172  
173 public bool UpdateContent(string id, byte[] data)
174 {
175 return false;
176 }
177  
178 public virtual bool Delete(string id)
179 {
180 // m_log.DebugFormat("[ASSET SERVICE]: Deleting asset {0}", id);
181  
182 UUID assetID;
183 if (!UUID.TryParse(id, out assetID))
184 return false;
185  
186 return m_Database.Delete(id);
187 }
188 }
189 }