call.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dbus
  2. import (
  3. "context"
  4. "errors"
  5. )
  6. var errSignature = errors.New("dbus: mismatched signature")
  7. // Call represents a pending or completed method call.
  8. type Call struct {
  9. Destination string
  10. Path ObjectPath
  11. Method string
  12. Args []interface{}
  13. // Strobes when the call is complete.
  14. Done chan *Call
  15. // After completion, the error status. If this is non-nil, it may be an
  16. // error message from the peer (with Error as its type) or some other error.
  17. Err error
  18. // Holds the response once the call is done.
  19. Body []interface{}
  20. // ResponseSequence stores the sequence number of the DBus message containing
  21. // the call response (or error). This can be compared to the sequence number
  22. // of other call responses and signals on this connection to determine their
  23. // relative ordering on the underlying DBus connection.
  24. // For errors, ResponseSequence is populated only if the error came from a
  25. // DBusMessage that was received or if there was an error receiving. In case of
  26. // failure to make the call, ResponseSequence will be NoSequence.
  27. ResponseSequence Sequence
  28. // tracks context and canceler
  29. ctx context.Context
  30. ctxCanceler context.CancelFunc
  31. }
  32. func (c *Call) Context() context.Context {
  33. if c.ctx == nil {
  34. return context.Background()
  35. }
  36. return c.ctx
  37. }
  38. func (c *Call) ContextCancel() {
  39. if c.ctxCanceler != nil {
  40. c.ctxCanceler()
  41. }
  42. }
  43. // Store stores the body of the reply into the provided pointers. It returns
  44. // an error if the signatures of the body and retvalues don't match, or if
  45. // the error status is not nil.
  46. func (c *Call) Store(retvalues ...interface{}) error {
  47. if c.Err != nil {
  48. return c.Err
  49. }
  50. return Store(c.Body, retvalues...)
  51. }
  52. func (c *Call) done() {
  53. c.Done <- c
  54. c.ContextCancel()
  55. }