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