ChannelServices.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // System.Runtime.Remoting.Channels.ChannelServices.cs
  3. //
  4. // Author: Rodrigo Moya ([email protected])
  5. // Dietmar Maurer ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // 2002 (C) Copyright, Ximian, Inc.
  9. //
  10. using System.Collections;
  11. using System.Runtime.Remoting.Messaging;
  12. namespace System.Runtime.Remoting.Channels
  13. {
  14. internal class ChannelInfoStore : IChannelInfo
  15. {
  16. object [] data = null;
  17. public ChannelInfoStore ()
  18. {
  19. this.data = ChannelServices.GetCurrentChannelInfo ();
  20. }
  21. public object[] ChannelData {
  22. get {
  23. return data;
  24. }
  25. set {
  26. data = value;
  27. }
  28. }
  29. }
  30. public sealed class ChannelServices
  31. {
  32. private static ArrayList registeredChannels = new ArrayList ();
  33. private ChannelServices ()
  34. {
  35. }
  36. public static IMessageSink CreateClientChannelSinkChain(string url, object remoteChannelData, out string objectUri)
  37. {
  38. // Locate a channel that can parse the url. This channel will be used to
  39. // create the sink chain.
  40. foreach (IChannel c in registeredChannels)
  41. {
  42. IChannelSender sender = c as IChannelSender;
  43. if (sender != null)
  44. {
  45. IMessageSink sink = sender.CreateMessageSink (url, remoteChannelData, out objectUri);
  46. if (sink != null) return sink; // URL is ok, this is the channel and the sink
  47. }
  48. }
  49. objectUri = null;
  50. return null;
  51. }
  52. public static IChannel[] RegisteredChannels
  53. {
  54. get {
  55. IChannel[] channels = new IChannel[registeredChannels.Count];
  56. for (int i = 0; i < registeredChannels.Count; i++)
  57. channels[i] = (IChannel) registeredChannels[i];
  58. return channels;
  59. }
  60. }
  61. [MonoTODO]
  62. public static IMessageCtrl AsyncDispatchMessage (IMessage msg,
  63. IMessageSink replySink)
  64. {
  65. throw new NotImplementedException ();
  66. }
  67. public static IServerChannelSink CreateServerChannelSinkChain (
  68. IServerChannelSinkProvider provider, IChannelReceiver channel)
  69. {
  70. IServerChannelSinkProvider tmp = provider;
  71. while (tmp.Next != null) tmp = tmp.Next;
  72. tmp.Next = new ServerDispatchSinkProvider ();
  73. // Every provider has to call CreateSink() of its next provider
  74. return provider.CreateSink (channel);
  75. }
  76. [MonoTODO]
  77. public static ServerProcessing DispatchMessage (
  78. IServerChannelSinkStack sinkStack,
  79. IMessage msg,
  80. out IMessage replyMsg)
  81. {
  82. // TODO: put Identity in message
  83. // TODO: Async processing
  84. IMethodMessage call = (IMethodMessage)msg;
  85. Identity identity = RemotingServices.GetIdentityForUri(call.Uri);
  86. if (identity == null) throw new RemotingException ("No receiver for uri " + call.Uri);
  87. replyMsg = identity.Context.GetServerContextSinkChain().SyncProcessMessage (msg);
  88. return ServerProcessing.Complete;
  89. }
  90. [MonoTODO]
  91. public static IChannel GetChannel (string name)
  92. {
  93. throw new NotImplementedException ();
  94. }
  95. [MonoTODO]
  96. public static IDictionary GetChannelSinkProperties (object obj)
  97. {
  98. throw new NotImplementedException ();
  99. }
  100. [MonoTODO]
  101. public static string[] GetUrlsForObject (MarshalByRefObject obj)
  102. {
  103. throw new NotImplementedException ();
  104. }
  105. public static void RegisterChannel (IChannel chnl)
  106. {
  107. // Put the channel in the correct place according to its priority.
  108. // Since there are not many channels, a linear search is ok.
  109. for (int n = 0; n < registeredChannels.Count; n++) {
  110. if ( ((IChannel)registeredChannels[n]).ChannelPriority < chnl.ChannelPriority)
  111. {
  112. registeredChannels.Insert (n, chnl);
  113. return;
  114. }
  115. }
  116. registeredChannels.Add (chnl);
  117. }
  118. [MonoTODO]
  119. public static IMessage SyncDispatchMessage (IMessage msg)
  120. {
  121. throw new NotImplementedException ();
  122. }
  123. public static void UnregisterChannel (IChannel chnl)
  124. {
  125. if (chnl == null)
  126. throw new ArgumentNullException ();
  127. if (!registeredChannels.Contains ((object) chnl))
  128. throw new RemotingException ();
  129. registeredChannels.Remove ((object) chnl);
  130. }
  131. internal static object [] GetCurrentChannelInfo ()
  132. {
  133. ArrayList list = new ArrayList ();
  134. foreach (object chnl_obj in registeredChannels) {
  135. IChannelReceiver chnl = chnl_obj as IChannelReceiver;
  136. if (chnl != null) {
  137. object chnl_data = chnl.ChannelData;
  138. if (chnl_data != null)
  139. list.Add (chnl_data);
  140. }
  141. }
  142. return list.ToArray ();
  143. }
  144. }
  145. }