IRpcController.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. namespace Google.ProtocolBuffers {
  3. /// <summary>
  4. /// Mediates a single method call. The primary purpose of the controller
  5. /// is to provide a way to manipulate settings specific to the
  6. /// RPC implementation and to find out about RPC-level errors.
  7. ///
  8. /// The methods provided by this interface are intended to be a "least
  9. /// common denominator" set of features which we expect all implementations to
  10. /// support. Specific implementations may provide more advanced features,
  11. /// (e.g. deadline propagation).
  12. /// </summary>
  13. public interface IRpcController {
  14. #region Client side calls
  15. // These calls may be made from the client side only. Their results
  16. // are undefined on the server side (may throw exceptions).
  17. /// <summary>
  18. /// Resets the controller to its initial state so that it may be reused in
  19. /// a new call. This can be called from the client side only. It must not
  20. /// be called while an RPC is in progress.
  21. /// </summary>
  22. void Reset();
  23. /// <summary>
  24. /// After a call has finished, returns true if the call failed. The possible
  25. /// reasons for failure depend on the RPC implementation. Failed must
  26. /// only be called on the client side, and must not be called before a call has
  27. /// finished.
  28. /// </summary>
  29. bool Failed { get; }
  30. /// <summary>
  31. /// If Failed is true, ErrorText returns a human-readable description of the error.
  32. /// </summary>
  33. string ErrorText { get; }
  34. /// <summary>
  35. /// Advises the RPC system that the caller desires that the RPC call be
  36. /// canceled. The RPC system may cancel it immediately, may wait awhile and
  37. /// then cancel it, or may not even cancel the call at all. If the call is
  38. /// canceled, the "done" callback will still be called and the RpcController
  39. /// will indicate that the call failed at that time.
  40. /// </summary>
  41. void StartCancel();
  42. #endregion
  43. #region Server side calls
  44. // These calls may be made from the server side only. Their results
  45. // are undefined on the client side (may throw exceptions).
  46. /// <summary>
  47. /// Causes Failed to return true on the client side. <paramref name="reason"/>
  48. /// will be incorporated into the message returned by ErrorText.
  49. /// If you find you need to return machine-readable information about
  50. /// failures, you should incorporate it into your response protocol buffer
  51. /// and should *not* call SetFailed.
  52. /// </summary>
  53. void SetFailed(string reason);
  54. /// <summary>
  55. /// If true, indicates that the client canceled the RPC, so the server may as
  56. /// well give up on replying to it. This method must be called on the server
  57. /// side only. The server should still call the final "done" callback.
  58. /// </summary>
  59. bool isCanceled();
  60. /// <summary>
  61. /// Requests that the given callback be called when the RPC is canceled.
  62. /// The parameter passed to the callback will always be null. The callback will
  63. /// be called exactly once. If the RPC completes without being canceled, the
  64. /// callback will be called after completion. If the RPC has already been canceled
  65. /// when NotifyOnCancel is called, the callback will be called immediately.
  66. ///
  67. /// NotifyOnCancel must be called no more than once per request. It must be
  68. /// called on the server side only.
  69. /// </summary>
  70. /// <param name="callback"></param>
  71. void NotifyOnCancel(Action<object> callback);
  72. #endregion
  73. }
  74. }