IpcChannel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // System.Runtime.Remoting.Channels.Ipc.Win32.IpcChannel.cs
  3. //
  4. // Author: Robert Jordan ([email protected])
  5. //
  6. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections;
  31. using System.Runtime.Remoting;
  32. using System.Runtime.Remoting.Channels;
  33. using System.Runtime.Remoting.Messaging;
  34. namespace System.Runtime.Remoting.Channels.Ipc.Win32
  35. {
  36. internal class IpcChannel : IChannelSender, IChannelReceiver, IChannel
  37. {
  38. readonly IpcClientChannel clientChannel;
  39. readonly IpcServerChannel serverChannel;
  40. /// <summary>
  41. /// Creates a client channel.
  42. /// </summary>
  43. public IpcChannel()
  44. {
  45. clientChannel = new IpcClientChannel();
  46. }
  47. /// <summary>
  48. /// Creates a server channel.
  49. /// </summary>
  50. /// <param name="portName">The port name.</param>
  51. public IpcChannel(string portName)
  52. {
  53. serverChannel = new IpcServerChannel(portName);
  54. }
  55. /// <summary>
  56. /// Creates both server and client channels.
  57. /// </summary>
  58. /// <param name="properties">The channel properties.</param>
  59. /// <param name="clientProvider">The client sink provider. It may be <c>null</c>.</param>
  60. /// <param name="serverProvider">The server sink provider. It may be <c>null</c>.</param>
  61. public IpcChannel(IDictionary properties,
  62. IClientChannelSinkProvider clientProvider,
  63. IServerChannelSinkProvider serverProvider
  64. )
  65. {
  66. clientChannel = new IpcClientChannel(properties, clientProvider);
  67. serverChannel = new IpcServerChannel(properties, serverProvider);
  68. }
  69. #region IChannelSender Members
  70. public IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI)
  71. {
  72. return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
  73. }
  74. #endregion
  75. #region IChannel Members
  76. public string ChannelName
  77. {
  78. get
  79. {
  80. return serverChannel != null
  81. ? serverChannel.ChannelName
  82. : clientChannel.ChannelName;
  83. }
  84. }
  85. public int ChannelPriority
  86. {
  87. get
  88. {
  89. return serverChannel != null
  90. ? serverChannel.ChannelPriority
  91. : clientChannel.ChannelPriority;
  92. }
  93. }
  94. public string Parse(string url, out string objectURI)
  95. {
  96. return IpcChannelHelper.Parse(url, out objectURI);
  97. }
  98. #endregion
  99. #region IChannelReceiver Members
  100. public void StartListening(object data)
  101. {
  102. serverChannel.StartListening(data);
  103. }
  104. public object ChannelData
  105. {
  106. get
  107. {
  108. return serverChannel != null ? serverChannel.ChannelData : null;
  109. }
  110. }
  111. public void StopListening(object data)
  112. {
  113. serverChannel.StopListening(data);
  114. }
  115. public string[] GetUrlsForUri(string objectURI)
  116. {
  117. return serverChannel.GetUrlsForUri(objectURI);
  118. }
  119. #endregion
  120. }
  121. }
  122. #endif