aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/godbus/dbus/server_interfaces.go
blob: 01166f0bd2ac11fa176bd468117fdff54cd12b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package dbus

// Terminator allows a handler to implement a shutdown mechanism that
// is called when the connection terminates.
type Terminator interface {
	Terminate()
}

// Handler is the representation of a D-Bus Application.
//
// The Handler must have a way to lookup objects given
// an ObjectPath. The returned object must implement the
// ServerObject interface.
type Handler interface {
	LookupObject(path ObjectPath) (ServerObject, bool)
}

// ServerObject is the representation of an D-Bus Object.
//
// Objects are registered at a path for a given Handler.
// The Objects implement D-Bus interfaces. The semantics
// of Interface lookup is up to the implementation of
// the ServerObject. The ServerObject implementation may
// choose to implement empty string as a valid interface
// represeting all methods or not per the D-Bus specification.
type ServerObject interface {
	LookupInterface(name string) (Interface, bool)
}

// An Interface is the representation of a D-Bus Interface.
//
// Interfaces are a grouping of methods implemented by the Objects.
// Interfaces are responsible for routing method calls.
type Interface interface {
	LookupMethod(name string) (Method, bool)
}

// A Method represents the exposed methods on D-Bus.
type Method interface {
	// Call requires that all arguments are decoded before being passed to it.
	Call(args ...interface{}) ([]interface{}, error)
	NumArguments() int
	NumReturns() int
	// ArgumentValue returns a representative value for the argument at position
	// it should be of the proper type. reflect.Zero would be a good mechanism
	// to use for this Value.
	ArgumentValue(position int) interface{}
	// ReturnValue returns a representative value for the return at position
	// it should be of the proper type. reflect.Zero would be a good mechanism
	// to use for this Value.
	ReturnValue(position int) interface{}
}

// An Argument Decoder can decode arguments using the non-standard mechanism
//
// If a method implements this interface then the non-standard
// decoder will be used.
//
// Method arguments must be decoded from the message.
// The mechanism for doing this will vary based on the
// implementation of the method. A normal approach is provided
// as part of this library, but may be replaced with
// any other decoding scheme.
type ArgumentDecoder interface {
	// To decode the arguments of a method the sender and message are
	// provided incase the semantics of the implementer provides access
	// to these as part of the method invocation.
	DecodeArguments(conn *Conn, sender string, msg *Message, args []interface{}) ([]interface{}, error)
}

// A SignalHandler is responsible for delivering a signal.
//
// Signal delivery may be changed from the default channel
// based approach by Handlers implementing the SignalHandler
// interface.
type SignalHandler interface {
	DeliverSignal(iface, name string, signal *Signal)
}

// A DBusError is used to convert a generic object to a D-Bus error.
//
// Any custom error mechanism may implement this interface to provide
// a custom encoding of the error on D-Bus. By default if a normal
// error is returned, it will be encoded as the generic
// "org.freedesktop.DBus.Error.Failed" error. By implementing this
// interface as well a custom encoding may be provided.
type DBusError interface {
	DBusError() (string, []interface{})
}

// SerialGenerator is responsible for serials generation.
//
// Different approaches for the serial generation can be used,
// maintaining a map guarded with a mutex (the standard way) or
// simply increment an atomic counter.
type SerialGenerator interface {
	GetSerial() uint32
	RetireSerial(serial uint32)
}