diff options
author | Dr Scofield | 2008-07-28 12:18:48 +0000 |
---|---|---|
committer | Dr Scofield | 2008-07-28 12:18:48 +0000 |
commit | 03efaff60e2c4204bfac33de22e69377ba28be7c (patch) | |
tree | 711c9515a16d241b87857093876ebeafa91ae4cf /OpenSim/Common/Communications/GridInfoService.cs | |
parent | Add Shared/LSL_Types* tests to Bamboo. (diff) | |
download | opensim-SC-03efaff60e2c4204bfac33de22e69377ba28be7c.zip opensim-SC-03efaff60e2c4204bfac33de22e69377ba28be7c.tar.gz opensim-SC-03efaff60e2c4204bfac33de22e69377ba28be7c.tar.bz2 opensim-SC-03efaff60e2c4204bfac33de22e69377ba28be7c.tar.xz |
moving GridInfo application plugin into a common standalone/grid
service, adding a plain REST GET handler returning XML (no LLSD),
adding appropriate add handler calls to OpenSimBase and UserServer.
Diffstat (limited to 'OpenSim/Common/Communications/GridInfoService.cs')
-rw-r--r-- | OpenSim/Common/Communications/GridInfoService.cs | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/OpenSim/Common/Communications/GridInfoService.cs b/OpenSim/Common/Communications/GridInfoService.cs new file mode 100644 index 0000000..f8208ad --- /dev/null +++ b/OpenSim/Common/Communications/GridInfoService.cs | |||
@@ -0,0 +1,125 @@ | |||
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 OpenSim 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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Framework; | ||
38 | |||
39 | namespace OpenSim.Common.Communications | ||
40 | { | ||
41 | public class GridInfoService | ||
42 | { | ||
43 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private Hashtable _info = new Hashtable(); | ||
46 | |||
47 | /// <summary> | ||
48 | /// Instantiate a GridInfoService object. | ||
49 | /// </summary> | ||
50 | /// <param name="configPath">path to config path containing | ||
51 | /// grid information</param> | ||
52 | /// <remarks> | ||
53 | /// GridInfoService uses the [GridInfo] section of the | ||
54 | /// standard OpenSim.ini file --- which is not optimal, but | ||
55 | /// anything else requires a general redesign of the config | ||
56 | /// system. | ||
57 | /// </remarks> | ||
58 | public GridInfoService(string configPath) | ||
59 | { | ||
60 | _info["platform"] = "OpenSim"; | ||
61 | if (File.Exists(configPath)) | ||
62 | { | ||
63 | try | ||
64 | { | ||
65 | IConfigSource _configSource = new IniConfigSource(configPath); | ||
66 | IConfig startupCfg = _configSource.Configs["Startup"]; | ||
67 | IConfig gridCfg = _configSource.Configs["GridInfo"]; | ||
68 | |||
69 | if (!startupCfg.GetBoolean("gridmode", false)) | ||
70 | _info["mode"] = "standalone"; | ||
71 | else | ||
72 | _info["mode"] = "grid"; | ||
73 | |||
74 | foreach (string k in gridCfg.GetKeys()) | ||
75 | { | ||
76 | _info[k] = gridCfg.GetString(k); | ||
77 | } | ||
78 | } | ||
79 | catch (Exception) | ||
80 | { | ||
81 | _log.DebugFormat("[GridInfoService] cannot get grid info from {0}, using minimal defaults", configPath); | ||
82 | } | ||
83 | } | ||
84 | _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// Default constructor, uses OpenSim.ini. | ||
89 | /// </summary> | ||
90 | public GridInfoService() : this(Path.Combine(Util.configDir(), "OpenSim.ini")) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) | ||
95 | { | ||
96 | XmlRpcResponse response = new XmlRpcResponse(); | ||
97 | Hashtable responseData = new Hashtable(); | ||
98 | |||
99 | _log.Info("[GridInfo]: Request for grid info"); | ||
100 | |||
101 | foreach (string k in _info.Keys) | ||
102 | { | ||
103 | responseData[k] = _info[k]; | ||
104 | } | ||
105 | response.Value = responseData; | ||
106 | |||
107 | return response; | ||
108 | } | ||
109 | |||
110 | public string RestGetGridInfoMethod(string request, string path, string param, | ||
111 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
112 | { | ||
113 | StringBuilder sb = new StringBuilder(); | ||
114 | |||
115 | sb.Append("<gridinfo>\n"); | ||
116 | foreach (string k in _info.Keys) | ||
117 | { | ||
118 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]); | ||
119 | } | ||
120 | sb.Append("</gridinfo>\n"); | ||
121 | |||
122 | return sb.ToString(); | ||
123 | } | ||
124 | } | ||
125 | } | ||