call.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // tracks context and canceler
  21. ctx context.Context
  22. ctxCanceler context.CancelFunc
  23. }
  24. func (c *Call) Context() context.Context {
  25. if c.ctx == nil {
  26. return context.Background()
  27. }
  28. return c.ctx
  29. }
  30. func (c *Call) ContextCancel() {
  31. if c.ctxCanceler != nil {
  32. c.ctxCanceler()
  33. }
  34. }
  35. // Store stores the body of the reply into the provided pointers. It returns
  36. // an error if the signatures of the body and retvalues don't match, or if
  37. // the error status is not nil.
  38. func (c *Call) Store(retvalues ...interface{}) error {
  39. if c.Err != nil {
  40. return c.Err
  41. }
  42. return Store(c.Body, retvalues...)
  43. }
  44. func (c *Call) done() {
  45. c.Done <- c
  46. c.ContextCancel()
  47. }