aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Services/GridInfoService.cs
diff options
context:
space:
mode:
authordiva2009-03-29 22:04:45 +0000
committerdiva2009-03-29 22:04:45 +0000
commitf7eac63e01d957bd9c115ac0f55d1dd6109f6aea (patch)
treee07355fb5e2a1c715b93fd5953dd78743157ccca /OpenSim/Framework/Communications/Services/GridInfoService.cs
parentMoved some files around, so that it's easier to share code between standalone... (diff)
downloadopensim-SC-f7eac63e01d957bd9c115ac0f55d1dd6109f6aea.zip
opensim-SC-f7eac63e01d957bd9c115ac0f55d1dd6109f6aea.tar.gz
opensim-SC-f7eac63e01d957bd9c115ac0f55d1dd6109f6aea.tar.bz2
opensim-SC-f7eac63e01d957bd9c115ac0f55d1dd6109f6aea.tar.xz
Another bit of refactoring to try to make sense of OpenSim.Framework.Communications. Everything that looks like a service, with service handlers, moved to .Services -- i.e. LoginService and Response, and GridInfoService. The rest of the changes were to adapt to the new locations of those files.
Diffstat (limited to 'OpenSim/Framework/Communications/Services/GridInfoService.cs')
-rw-r--r--OpenSim/Framework/Communications/Services/GridInfoService.cs172
1 files changed, 172 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Services/GridInfoService.cs b/OpenSim/Framework/Communications/Services/GridInfoService.cs
new file mode 100644
index 0000000..96fe0d8
--- /dev/null
+++ b/OpenSim/Framework/Communications/Services/GridInfoService.cs
@@ -0,0 +1,172 @@
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;
37
38namespace OpenSim.Framework.Communications.Services
39{
40 public class GridInfoService
41 {
42 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private Hashtable _info = new Hashtable();
45
46 /// <summary>
47 /// Instantiate a GridInfoService object.
48 /// </summary>
49 /// <param name="configPath">path to config path containing
50 /// grid information</param>
51 /// <remarks>
52 /// GridInfoService uses the [GridInfo] section of the
53 /// standard OpenSim.ini file --- which is not optimal, but
54 /// anything else requires a general redesign of the config
55 /// system.
56 /// </remarks>
57 public GridInfoService(IConfigSource configSource)
58 {
59 loadGridInfo(configSource);
60 }
61
62 /// <summary>
63 /// Default constructor, uses OpenSim.ini.
64 /// </summary>
65 public GridInfoService()
66 {
67 try
68 {
69 IConfigSource configSource = new IniConfigSource(Path.Combine(Util.configDir(), "OpenSim.ini"));
70 loadGridInfo(configSource);
71 }
72 catch (FileNotFoundException)
73 {
74 _log.Warn("[GridInfoService] no OpenSim.ini file found --- GridInfoServices WILL NOT BE AVAILABLE to your users");
75 }
76 }
77
78 private void loadGridInfo(IConfigSource configSource)
79 {
80 _info["platform"] = "OpenSim";
81 try
82 {
83 IConfig startupCfg = configSource.Configs["Startup"];
84 IConfig gridCfg = configSource.Configs["GridInfo"];
85 IConfig netCfg = configSource.Configs["Network"];
86
87 bool grid = startupCfg.GetBoolean("gridmode", false);
88
89 if (grid)
90 _info["mode"] = "grid";
91 else
92 _info["mode"] = "standalone";
93
94
95 if (null != gridCfg)
96 {
97 foreach (string k in gridCfg.GetKeys())
98 {
99 _info[k] = gridCfg.GetString(k);
100 }
101 }
102 else if (null != netCfg)
103 {
104 if (grid)
105 _info["login"]
106 = netCfg.GetString(
107 "user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString());
108 else
109 _info["login"]
110 = String.Format(
111 "http://127.0.0.1:{0}/",
112 netCfg.GetString(
113 "http_listener_port", NetworkServersInfo.DefaultHttpListenerPort.ToString()));
114
115 IssueWarning();
116 }
117 else
118 {
119 _info["login"] = "http://127.0.0.1:9000/";
120 IssueWarning();
121 }
122 }
123 catch (Exception)
124 {
125 _log.Debug("[GridInfoService] cannot get grid info from config source, using minimal defaults");
126 }
127 _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count);
128
129 }
130
131 private void IssueWarning()
132 {
133 _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini");
134 _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:");
135 foreach (string k in _info.Keys)
136 {
137 _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]);
138 }
139 }
140
141 public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request)
142 {
143 XmlRpcResponse response = new XmlRpcResponse();
144 Hashtable responseData = new Hashtable();
145
146 _log.Info("[GridInfo]: Request for grid info");
147
148 foreach (string k in _info.Keys)
149 {
150 responseData[k] = _info[k];
151 }
152 response.Value = responseData;
153
154 return response;
155 }
156
157 public string RestGetGridInfoMethod(string request, string path, string param,
158 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
159 {
160 StringBuilder sb = new StringBuilder();
161
162 sb.Append("<gridinfo>\n");
163 foreach (string k in _info.Keys)
164 {
165 sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]);
166 }
167 sb.Append("</gridinfo>\n");
168
169 return sb.ToString();
170 }
171 }
172}