RemotingObject.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using OpenSim.Framework;
  4. namespace OpenSim.Region.Environment.Modules.Grid.Interregion
  5. {
  6. public class RemotingObject : MarshalByRefObject
  7. {
  8. private readonly Location[] m_coords;
  9. private readonly Dictionary<Type, Object> m_interfaces = new Dictionary<Type, object>();
  10. public RemotingObject(Dictionary<Type, Object> myInterfaces, Location[] coords)
  11. {
  12. m_interfaces = myInterfaces;
  13. m_coords = coords;
  14. }
  15. public Location[] GetLocations()
  16. {
  17. return (Location[]) m_coords.Clone();
  18. }
  19. public string[] GetInterfaces()
  20. {
  21. string[] interfaces = new string[m_interfaces.Count];
  22. int i = 0;
  23. foreach (KeyValuePair<Type, object> pair in m_interfaces)
  24. {
  25. interfaces[i++] = pair.Key.FullName;
  26. }
  27. return interfaces;
  28. }
  29. /// <summary>
  30. /// Returns a registered interface availible to neighbouring regions.
  31. /// </summary>
  32. /// <typeparam name="T">The type of interface you wish to request</typeparam>
  33. /// <returns>A MarshalByRefObject inherited from this region inheriting the interface requested.</returns>
  34. /// <remarks>All registered interfaces <b>MUST</b> inherit from MarshalByRefObject and use only serialisable types.</remarks>
  35. public T RequestInterface<T>()
  36. {
  37. if (m_interfaces.ContainsKey(typeof (T)))
  38. return (T) m_interfaces[typeof (T)];
  39. throw new NotSupportedException("No such interface registered.");
  40. }
  41. }
  42. }