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.Reflection;
31  
32 using log4net;
33 using Nini.Config;
34 using OpenMetaverse;
35 using Mono.Addins;
36  
37 using OpenSim.Framework;
38 using OpenSim.Framework.Communications;
39 using OpenSim.Framework.Servers;
40 using OpenSim.Framework.Servers.HttpServer;
41 using OpenSim.Framework.Client;
42 using OpenSim.Region.Framework.Interfaces;
43 using OpenSim.Region.Framework.Scenes;
44  
45 namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule
46 {
47 public class XmlRpcInfo
48 {
49 public UUID item;
50 public UUID channel;
51 public string uri;
52 }
53  
54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcGridRouter")]
55 public class XmlRpcGridRouter : INonSharedRegionModule, IXmlRpcRouter
56 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58  
59 private Dictionary<UUID, UUID> m_Channels =
60 new Dictionary<UUID, UUID>();
61  
62 private bool m_Enabled = false;
63 private string m_ServerURI = String.Empty;
64  
65 #region INonSharedRegionModule
66  
67 public void Initialise(IConfigSource config)
68 {
69 IConfig startupConfig = config.Configs["XMLRPC"];
70 if (startupConfig == null)
71 return;
72  
73 if (startupConfig.GetString("XmlRpcRouterModule",
74 "XmlRpcRouterModule") == "XmlRpcGridRouterModule")
75 {
76 m_ServerURI = startupConfig.GetString("XmlRpcHubURI", String.Empty);
77 if (m_ServerURI == String.Empty)
78 {
79 m_log.Error("[XMLRPC GRID ROUTER] Module configured but no URI given. Disabling");
80 return;
81 }
82 m_Enabled = true;
83 }
84 }
85  
86 public void AddRegion(Scene scene)
87 {
88 if (!m_Enabled)
89 return;
90  
91 scene.RegisterModuleInterface<IXmlRpcRouter>(this);
92  
93 IScriptModule scriptEngine = scene.RequestModuleInterface<IScriptModule>();
94 if ( scriptEngine != null )
95 {
96 scriptEngine.OnScriptRemoved += this.ScriptRemoved;
97 scriptEngine.OnObjectRemoved += this.ObjectRemoved;
98  
99 }
100 }
101  
102 public void RegionLoaded(Scene scene)
103 {
104 }
105  
106 public void RemoveRegion(Scene scene)
107 {
108 if (!m_Enabled)
109 return;
110  
111 scene.UnregisterModuleInterface<IXmlRpcRouter>(this);
112 }
113  
114 public void Close()
115 {
116 }
117  
118 public string Name
119 {
120 get { return "XmlRpcGridRouterModule"; }
121 }
122  
123 public Type ReplaceableInterface
124 {
125 get { return null; }
126 }
127  
128 #endregion
129  
130 public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri)
131 {
132 if (!m_Enabled)
133 return;
134  
135 m_log.InfoFormat("[XMLRPC GRID ROUTER]: New receiver Obj: {0} Ch: {1} ID: {2} URI: {3}",
136 objectID.ToString(), channel.ToString(), itemID.ToString(), uri);
137  
138 XmlRpcInfo info = new XmlRpcInfo();
139 info.channel = channel;
140 info.uri = uri;
141 info.item = itemID;
142  
143 bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>(
144 "POST", m_ServerURI+"/RegisterChannel/", info);
145  
146 if (!success)
147 {
148 m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
149 }
150  
151 m_Channels[itemID] = channel;
152  
153 }
154  
155 public void UnRegisterReceiver(string channelID, UUID itemID)
156 {
157 if (!m_Enabled)
158 return;
159  
160 RemoveChannel(itemID);
161  
162 }
163  
164 public void ScriptRemoved(UUID itemID)
165 {
166 if (!m_Enabled)
167 return;
168  
169 RemoveChannel(itemID);
170  
171 }
172  
173 public void ObjectRemoved(UUID objectID)
174 {
175 // m_log.InfoFormat("[XMLRPC GRID ROUTER]: Object Removed {0}",objectID.ToString());
176 }
177  
178 private bool RemoveChannel(UUID itemID)
179 {
180 if(!m_Channels.ContainsKey(itemID))
181 {
182 m_log.InfoFormat("[XMLRPC GRID ROUTER]: Attempted to unregister non-existing Item: {0}", itemID.ToString());
183 return false;
184 }
185  
186 XmlRpcInfo info = new XmlRpcInfo();
187  
188 info.channel = m_Channels[itemID];
189 info.item = itemID;
190 info.uri = "http://0.0.0.0:00";
191  
192 if (info != null)
193 {
194 bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>(
195 "POST", m_ServerURI+"/RemoveChannel/", info);
196  
197 if (!success)
198 {
199 m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
200 }
201  
202 m_Channels.Remove(itemID);
203 return true;
204 }
205 return false;
206 }
207 }
208 }