IpcChannel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // System.Runtime.Remoting.Channels.Ipc.Unix.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.IO;
  32. using System.Runtime.Remoting;
  33. using System.Runtime.Remoting.Messaging;
  34. namespace System.Runtime.Remoting.Channels.Ipc.Unix
  35. {
  36. internal class IpcChannel : IChannelReceiver, IChannelSender, IChannel
  37. {
  38. IChannelSender _clientChannel;
  39. IChannelReceiver _serverChannel;
  40. string _portName;
  41. string _name = "ipc";
  42. int _priority = 1;
  43. internal static IDictionary GetDefaultProperties (string portName)
  44. {
  45. Hashtable h = new Hashtable ();
  46. if (portName != null)
  47. h ["portName"] = portName;
  48. h ["name"] = "ipc";
  49. h ["priority"] = "1";
  50. return h;
  51. }
  52. public IpcChannel () : this (null)
  53. {
  54. }
  55. public IpcChannel (string portName)
  56. : this (GetDefaultProperties (portName), null, null)
  57. {
  58. }
  59. public IpcChannel (IDictionary properties,
  60. IClientChannelSinkProvider clientSinkProvider,
  61. IServerChannelSinkProvider serverSinkProvider)
  62. {
  63. if (properties != null) {
  64. _portName = properties ["portName"] as string;
  65. if (properties ["name"] != null)
  66. _name = properties ["name"] as string;
  67. else
  68. properties ["name"] = _name;
  69. if (properties ["priority"] != null)
  70. _priority = Convert.ToInt32 (properties ["priority"]);
  71. }
  72. if (_portName != null)
  73. _serverChannel = new IpcServerChannel (properties, serverSinkProvider);
  74. _clientChannel = new IpcClientChannel (properties, clientSinkProvider);
  75. }
  76. public string ChannelName
  77. {
  78. get { return _name; }
  79. }
  80. public int ChannelPriority
  81. {
  82. get { return _priority; }
  83. }
  84. public string Parse (string url, out string objectUri)
  85. {
  86. if (_serverChannel != null)
  87. return _serverChannel.Parse (url, out objectUri);
  88. else
  89. return _clientChannel.Parse (url, out objectUri);
  90. }
  91. public IMessageSink CreateMessageSink(string url,
  92. object remoteChannelData,
  93. out string objectUri)
  94. {
  95. return _clientChannel.CreateMessageSink (url, remoteChannelData, out objectUri);
  96. }
  97. public object ChannelData
  98. {
  99. get {
  100. if (_serverChannel != null)
  101. return _serverChannel.ChannelData;
  102. else
  103. return null;
  104. }
  105. }
  106. public string[] GetUrlsForUri(string objectUri)
  107. {
  108. if (_serverChannel != null)
  109. return _serverChannel.GetUrlsForUri (objectUri);
  110. else
  111. return null;
  112. }
  113. public void StartListening (object data)
  114. {
  115. if (_serverChannel != null)
  116. _serverChannel.StartListening (data);
  117. }
  118. public void StopListening(object data)
  119. {
  120. if (_serverChannel != null)
  121. _serverChannel.StopListening (data);
  122. }
  123. }
  124. }
  125. #endif