aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Common/Communications/GridInfoService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Common/Communications/GridInfoService.cs')
-rw-r--r--OpenSim/Common/Communications/GridInfoService.cs125
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
28using System;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32using System.Text;
33using log4net;
34using Nini.Config;
35using Nwc.XmlRpc;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework;
38
39namespace 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}