diff options
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianGrid.cs')
-rw-r--r-- | OpenSim/Services/Connectors/SimianGrid/SimianGrid.cs | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGrid.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGrid.cs new file mode 100644 index 0000000..a35d749 --- /dev/null +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGrid.cs | |||
@@ -0,0 +1,147 @@ | |||
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.Collections.Specialized; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | |||
42 | [assembly: Addin("SimianGrid", OpenSim.VersionInfo.VersionNumber)] | ||
43 | [assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)] | ||
44 | |||
45 | namespace OpenSim.Services.Connectors.SimianGrid | ||
46 | { | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimianExternalCapsModule")] | ||
48 | public class SimianGrid : ISharedRegionModule | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IConfig m_config = null; | ||
53 | |||
54 | private String m_simianURL; | ||
55 | |||
56 | #region IRegionModule Members | ||
57 | |||
58 | public string Name | ||
59 | { | ||
60 | get { return this.GetType().Name; } | ||
61 | } | ||
62 | |||
63 | public void Initialise(IConfigSource config) | ||
64 | { | ||
65 | try | ||
66 | { | ||
67 | m_config = config.Configs["SimianGrid"]; | ||
68 | |||
69 | if (m_config != null) | ||
70 | { | ||
71 | m_simianURL = m_config.GetString("SimianServiceURL"); | ||
72 | if (String.IsNullOrEmpty(m_simianURL)) | ||
73 | { | ||
74 | // m_log.DebugFormat("[SimianGrid] service URL is not defined"); | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | InitialiseSimCap(); | ||
79 | SimulatorCapability = SimulatorCapability.Trim(); | ||
80 | m_log.InfoFormat("[SimianExternalCaps] using {0} as simulator capability",SimulatorCapability); | ||
81 | } | ||
82 | } | ||
83 | catch (Exception e) | ||
84 | { | ||
85 | m_log.ErrorFormat("[SimianExternalCaps] initialization error: {0}",e.Message); | ||
86 | return; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | public void PostInitialise() { } | ||
91 | public void Close() { } | ||
92 | public void AddRegion(Scene scene) { } | ||
93 | public void RemoveRegion(Scene scene) { } | ||
94 | public void RegionLoaded(Scene scene) { } | ||
95 | |||
96 | public Type ReplaceableInterface | ||
97 | { | ||
98 | get { return null; } | ||
99 | } | ||
100 | |||
101 | ///<summary> | ||
102 | /// Try a variety of methods for finding the simian simulator capability; first check the | ||
103 | /// configuration itself, then look for a file that contains the cap, then finally look | ||
104 | /// for an environment variable that contains it. | ||
105 | ///</summary> | ||
106 | private void InitialiseSimCap() | ||
107 | { | ||
108 | if (m_config.Contains("SimulatorCapability")) | ||
109 | { | ||
110 | SimulatorCapability = m_config.GetString("SimulatorCapability"); | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | if (m_config.Contains("SimulatorCapabilityFile")) | ||
115 | { | ||
116 | String filename = m_config.GetString("SimulatorCapabilityFile"); | ||
117 | if (System.IO.File.Exists(filename)) | ||
118 | { | ||
119 | SimulatorCapability = System.IO.File.ReadAllText(filename); | ||
120 | return; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | if (m_config.Contains("SimulatorCapabilityVariable")) | ||
125 | { | ||
126 | String envname = m_config.GetString("SimulatorCapabilityVariable"); | ||
127 | String envvalue = System.Environment.GetEnvironmentVariable(envname); | ||
128 | if (envvalue != null) | ||
129 | { | ||
130 | SimulatorCapability = envvalue; | ||
131 | return; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | m_log.WarnFormat("[SimianExternalCaps] no method specified for simulator capability"); | ||
136 | } | ||
137 | |||
138 | #endregion | ||
139 | |||
140 | public static String SimulatorCapability = UUID.Zero.ToString(); | ||
141 | public static OSDMap PostToService(string url, NameValueCollection data) | ||
142 | { | ||
143 | data["cap"] = SimulatorCapability; | ||
144 | return WebUtil.PostToService(url, data); | ||
145 | } | ||
146 | } | ||
147 | } \ No newline at end of file | ||