IRpcController.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #region Copyright notice and license
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2008 Google Inc. All rights reserved.
  4. // http://github.com/jskeet/dotnet-protobufs/
  5. // Original C++/Java/Python code:
  6. // http://code.google.com/p/protobuf/
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. //
  12. // * Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. // * Redistributions in binary form must reproduce the above
  15. // copyright notice, this list of conditions and the following disclaimer
  16. // in the documentation and/or other materials provided with the
  17. // distribution.
  18. // * Neither the name of Google Inc. nor the names of its
  19. // contributors may be used to endorse or promote products derived from
  20. // this software without specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. #endregion
  34. using System;
  35. namespace Google.ProtocolBuffers
  36. {
  37. /// <summary>
  38. /// Mediates a single method call. The primary purpose of the controller
  39. /// is to provide a way to manipulate settings specific to the
  40. /// RPC implementation and to find out about RPC-level errors.
  41. ///
  42. /// The methods provided by this interface are intended to be a "least
  43. /// common denominator" set of features which we expect all implementations to
  44. /// support. Specific implementations may provide more advanced features,
  45. /// (e.g. deadline propagation).
  46. /// </summary>
  47. public interface IRpcController
  48. {
  49. #region Client side calls
  50. // These calls may be made from the client side only. Their results
  51. // are undefined on the server side (may throw exceptions).
  52. /// <summary>
  53. /// Resets the controller to its initial state so that it may be reused in
  54. /// a new call. This can be called from the client side only. It must not
  55. /// be called while an RPC is in progress.
  56. /// </summary>
  57. void Reset();
  58. /// <summary>
  59. /// After a call has finished, returns true if the call failed. The possible
  60. /// reasons for failure depend on the RPC implementation. Failed must
  61. /// only be called on the client side, and must not be called before a call has
  62. /// finished.
  63. /// </summary>
  64. bool Failed { get; }
  65. /// <summary>
  66. /// If Failed is true, ErrorText returns a human-readable description of the error.
  67. /// </summary>
  68. string ErrorText { get; }
  69. /// <summary>
  70. /// Advises the RPC system that the caller desires that the RPC call be
  71. /// canceled. The RPC system may cancel it immediately, may wait awhile and
  72. /// then cancel it, or may not even cancel the call at all. If the call is
  73. /// canceled, the "done" callback will still be called and the RpcController
  74. /// will indicate that the call failed at that time.
  75. /// </summary>
  76. void StartCancel();
  77. #endregion
  78. #region Server side calls
  79. // These calls may be made from the server side only. Their results
  80. // are undefined on the client side (may throw exceptions).
  81. /// <summary>
  82. /// Causes Failed to return true on the client side. <paramref name="reason"/>
  83. /// will be incorporated into the message returned by ErrorText.
  84. /// If you find you need to return machine-readable information about
  85. /// failures, you should incorporate it into your response protocol buffer
  86. /// and should *not* call SetFailed.
  87. /// </summary>
  88. void SetFailed(string reason);
  89. /// <summary>
  90. /// If true, indicates that the client canceled the RPC, so the server may as
  91. /// well give up on replying to it. This method must be called on the server
  92. /// side only. The server should still call the final "done" callback.
  93. /// </summary>
  94. bool IsCanceled();
  95. /// <summary>
  96. /// Requests that the given callback be called when the RPC is canceled.
  97. /// The parameter passed to the callback will always be null. The callback will
  98. /// be called exactly once. If the RPC completes without being canceled, the
  99. /// callback will be called after completion. If the RPC has already been canceled
  100. /// when NotifyOnCancel is called, the callback will be called immediately.
  101. ///
  102. /// NotifyOnCancel must be called no more than once per request. It must be
  103. /// called on the server side only.
  104. /// </summary>
  105. /// <param name="callback"></param>
  106. void NotifyOnCancel(Action<object> callback);
  107. #endregion
  108. }
  109. }