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