diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Communications/Interregion/InterregionModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Communications/Interregion/InterregionModule.cs | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/OpenSim/Region/Environment/Modules/Communications/Interregion/InterregionModule.cs b/OpenSim/Region/Environment/Modules/Communications/Interregion/InterregionModule.cs deleted file mode 100644 index 8d040c4..0000000 --- a/OpenSim/Region/Environment/Modules/Communications/Interregion/InterregionModule.cs +++ /dev/null | |||
@@ -1,174 +0,0 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Runtime.Remoting; | ||
4 | using System.Runtime.Remoting.Channels; | ||
5 | using System.Runtime.Remoting.Channels.Tcp; | ||
6 | using Nini.Config; | ||
7 | using OpenSim.Framework; | ||
8 | using OpenSim.Region.Environment.Interfaces; | ||
9 | using OpenSim.Region.Environment.Scenes; | ||
10 | |||
11 | namespace OpenSim.Region.Environment.Modules.Communications.Interregion | ||
12 | { | ||
13 | public class InterregionModule : IInterregionModule, IRegionModule | ||
14 | { | ||
15 | #region Direction enum | ||
16 | |||
17 | public enum Direction | ||
18 | { | ||
19 | North, | ||
20 | NorthEast, | ||
21 | East, | ||
22 | SouthEast, | ||
23 | South, | ||
24 | SouthWest, | ||
25 | West, | ||
26 | NorthWest | ||
27 | } | ||
28 | |||
29 | #endregion | ||
30 | |||
31 | private readonly Dictionary<Type, Object> m_interfaces = new Dictionary<Type, object>(); | ||
32 | private readonly List<Location> m_myLocations = new List<Location>(); | ||
33 | |||
34 | private readonly Dictionary<Location, string[]> m_neighbourInterfaces = new Dictionary<Location, string[]>(); | ||
35 | private readonly Dictionary<Location, RemotingObject> m_neighbourRemote = new Dictionary<Location, RemotingObject>(); | ||
36 | private IConfigSource m_config; | ||
37 | private RemotingObject m_myRemote; | ||
38 | |||
39 | private Object m_lockObject = new object(); | ||
40 | private TcpChannel m_tcpChannel; | ||
41 | private int m_tcpPort = 10101; | ||
42 | private bool m_enabled = false; | ||
43 | |||
44 | #region IRegionModule Members | ||
45 | |||
46 | //TODO: This prevents us from registering new scenes after PostInitialise if we want comms updated. | ||
47 | public void Initialise(Scene scene, IConfigSource source) | ||
48 | { | ||
49 | if (m_enabled) | ||
50 | { | ||
51 | m_myLocations.Add(new Location((int) scene.RegionInfo.RegionLocX, | ||
52 | (int) scene.RegionInfo.RegionLocY)); | ||
53 | m_config = source; | ||
54 | |||
55 | scene.RegisterModuleInterface<IInterregionModule>(this); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | //TODO: This prevents us from registering new scenes after PostInitialise if we want comms updated. | ||
60 | public void PostInitialise() | ||
61 | { | ||
62 | if (m_enabled) | ||
63 | { | ||
64 | try | ||
65 | { | ||
66 | m_tcpPort = m_config.Configs["Comms"].GetInt("remoting_port", m_tcpPort); | ||
67 | } | ||
68 | catch | ||
69 | { | ||
70 | } | ||
71 | |||
72 | internal_CreateRemotingObjects(); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public void Close() | ||
77 | { | ||
78 | ChannelServices.UnregisterChannel(m_tcpChannel); | ||
79 | } | ||
80 | |||
81 | public string Name | ||
82 | { | ||
83 | get { return "InterregionModule"; } | ||
84 | } | ||
85 | |||
86 | public bool IsSharedModule | ||
87 | { | ||
88 | get { return true; } | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | |||
93 | public void internal_CreateRemotingObjects() | ||
94 | { | ||
95 | lock (m_lockObject) | ||
96 | { | ||
97 | if (m_tcpChannel == null) | ||
98 | { | ||
99 | m_myRemote = new RemotingObject(m_interfaces, m_myLocations.ToArray()); | ||
100 | m_tcpChannel = new TcpChannel(m_tcpPort); | ||
101 | |||
102 | ChannelServices.RegisterChannel(m_tcpChannel, false); | ||
103 | RemotingServices.Marshal(m_myRemote, "OpenSimRemote2", typeof (RemotingObject)); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | public void RegisterRemoteRegion(string uri) | ||
109 | { | ||
110 | RegisterRemotingInterface((RemotingObject) Activator.GetObject(typeof (RemotingObject), uri)); | ||
111 | } | ||
112 | |||
113 | private void RegisterRemotingInterface(RemotingObject remote) | ||
114 | { | ||
115 | Location[] locs = remote.GetLocations(); | ||
116 | string[] interfaces = remote.GetInterfaces(); | ||
117 | foreach (Location loc in locs) | ||
118 | { | ||
119 | m_neighbourInterfaces[loc] = interfaces; | ||
120 | m_neighbourRemote[loc] = remote; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public void RegisterMethod<T>(T e) | ||
125 | { | ||
126 | m_interfaces[typeof (T)] = e; | ||
127 | } | ||
128 | |||
129 | public bool HasInterface<T>(Location loc) | ||
130 | { | ||
131 | foreach (string val in m_neighbourInterfaces[loc]) | ||
132 | { | ||
133 | if (val == typeof (T).FullName) | ||
134 | { | ||
135 | return true; | ||
136 | } | ||
137 | } | ||
138 | return false; | ||
139 | } | ||
140 | |||
141 | public T RequestInterface<T>(Location loc) | ||
142 | { | ||
143 | if (m_neighbourRemote.ContainsKey(loc)) | ||
144 | { | ||
145 | return m_neighbourRemote[loc].RequestInterface<T>(); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | throw new IndexOutOfRangeException("No neighbour availible at that location"); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | public T[] RequestInterface<T>() | ||
154 | { | ||
155 | List<T> m_t = new List<T>(); | ||
156 | foreach (RemotingObject remote in m_neighbourRemote.Values) | ||
157 | { | ||
158 | try | ||
159 | { | ||
160 | m_t.Add(remote.RequestInterface<T>()); | ||
161 | } | ||
162 | catch (NotSupportedException) | ||
163 | { | ||
164 | } | ||
165 | } | ||
166 | return m_t.ToArray(); | ||
167 | } | ||
168 | |||
169 | public Location GetLocationByDirection(Scene scene, Direction dir) | ||
170 | { | ||
171 | return new Location(0, 0); | ||
172 | } | ||
173 | } | ||
174 | } \ No newline at end of file | ||