IpcChannel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // System.Runtime.Remoting.Channels.Ipc.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.Messaging;
  33. using Unix = System.Runtime.Remoting.Channels.Ipc.Unix;
  34. using Win32 = System.Runtime.Remoting.Channels.Ipc.Win32;
  35. namespace System.Runtime.Remoting.Channels.Ipc
  36. {
  37. public class IpcChannel : IChannelReceiver, IChannelSender, IChannel
  38. {
  39. IChannel _innerChannel;
  40. internal static bool IsUnix
  41. {
  42. get {
  43. int p = (int) Environment.OSVersion.Platform;
  44. return ((p == 4) || (p == 128) || (p == 6));
  45. }
  46. }
  47. public IpcChannel ()
  48. {
  49. if (IsUnix)
  50. _innerChannel = new Unix.IpcChannel ();
  51. else
  52. _innerChannel = new Win32.IpcChannel ();
  53. }
  54. public IpcChannel (string portName)
  55. {
  56. if (IsUnix)
  57. _innerChannel = new Unix.IpcChannel (portName);
  58. else
  59. _innerChannel = new Win32.IpcChannel (portName);
  60. }
  61. public IpcChannel (IDictionary properties,
  62. IClientChannelSinkProvider clientSinkProvider,
  63. IServerChannelSinkProvider serverSinkProvider)
  64. {
  65. if (IsUnix)
  66. _innerChannel = new Unix.IpcChannel (properties, clientSinkProvider, serverSinkProvider);
  67. else
  68. _innerChannel = new Win32.IpcChannel (properties, clientSinkProvider, serverSinkProvider);
  69. }
  70. public string ChannelName
  71. {
  72. get { return _innerChannel.ChannelName; }
  73. }
  74. public int ChannelPriority
  75. {
  76. get { return _innerChannel.ChannelPriority; }
  77. }
  78. public string Parse (string url, out string objectURI)
  79. {
  80. return _innerChannel.Parse (url, out objectURI);
  81. }
  82. public IMessageSink CreateMessageSink (string url,
  83. object remoteChannelData,
  84. out string objectURI)
  85. {
  86. return ((IChannelSender)_innerChannel).CreateMessageSink (url, remoteChannelData, out objectURI);
  87. }
  88. public object ChannelData
  89. {
  90. get { return ((IChannelReceiver)_innerChannel).ChannelData; }
  91. }
  92. public string[] GetUrlsForUri (string objectURI)
  93. {
  94. return ((IChannelReceiver)_innerChannel).GetUrlsForUri (objectURI);
  95. }
  96. public void StartListening (object data)
  97. {
  98. ((IChannelReceiver)_innerChannel).StartListening (data);
  99. }
  100. public void StopListening (object data)
  101. {
  102. ((IChannelReceiver)_innerChannel).StopListening (data);
  103. }
  104. }
  105. }
  106. #endif