summaryrefslogtreecommitdiff
path: root/vendor/github.com/godbus/dbus/v5/export.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2021-04-02 07:58:47 +0000
committerGitHub <noreply@github.com>2021-04-02 07:58:47 +0000
commit5a7a1a1673c3735033a7d27d26b96c8d3eb9a14c (patch)
treef7427403d0fa4938fc519a4f0a68251e49c0ee82 /vendor/github.com/godbus/dbus/v5/export.go
parent23ee8b1df1f70aaad4fc4bc9c0c6b17f7aae5c8a (diff)
downloadpodman-5a7a1a1673c3735033a7d27d26b96c8d3eb9a14c.tar.gz
podman-5a7a1a1673c3735033a7d27d26b96c8d3eb9a14c.tar.bz2
podman-5a7a1a1673c3735033a7d27d26b96c8d3eb9a14c.zip
Bump github.com/coreos/go-systemd/v22 from 22.3.0 to 22.3.1
Bumps [github.com/coreos/go-systemd/v22](https://github.com/coreos/go-systemd) from 22.3.0 to 22.3.1. - [Release notes](https://github.com/coreos/go-systemd/releases) - [Commits](https://github.com/coreos/go-systemd/compare/v22.3.0...v22.3.1) Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/godbus/dbus/v5/export.go')
-rw-r--r--vendor/github.com/godbus/dbus/v5/export.go61
1 files changed, 45 insertions, 16 deletions
diff --git a/vendor/github.com/godbus/dbus/v5/export.go b/vendor/github.com/godbus/dbus/v5/export.go
index c277ab142..2447b51d4 100644
--- a/vendor/github.com/godbus/dbus/v5/export.go
+++ b/vendor/github.com/godbus/dbus/v5/export.go
@@ -69,6 +69,22 @@ func getMethods(in interface{}, mapping map[string]string) map[string]reflect.Va
return methods
}
+func getAllMethods(in interface{}, mapping map[string]string) map[string]reflect.Value {
+ if in == nil {
+ return nil
+ }
+ methods := make(map[string]reflect.Value)
+ val := reflect.ValueOf(in)
+ typ := val.Type()
+ for i := 0; i < typ.NumMethod(); i++ {
+ methtype := typ.Method(i)
+ method := val.Method(i)
+ // map names while building table
+ methods[computeMethodName(methtype.Name, mapping)] = method
+ }
+ return methods
+}
+
func standardMethodArgumentDecode(m Method, sender string, msg *Message, body []interface{}) ([]interface{}, error) {
pointers := make([]interface{}, m.NumArguments())
decode := make([]interface{}, 0, len(body))
@@ -159,7 +175,6 @@ func (conn *Conn) handleCall(msg *Message) {
if msg.Flags&FlagNoReplyExpected == 0 {
reply := new(Message)
reply.Type = TypeMethodReply
- reply.serial = conn.getSerial()
reply.Headers = make(map[HeaderField]Variant)
if hasSender {
reply.Headers[FieldDestination] = msg.Headers[FieldSender]
@@ -195,7 +210,6 @@ func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) erro
}
msg := new(Message)
msg.Type = TypeSignal
- msg.serial = conn.getSerial()
msg.Headers = make(map[HeaderField]Variant)
msg.Headers[FieldInterface] = MakeVariant(iface)
msg.Headers[FieldMember] = MakeVariant(member)
@@ -247,6 +261,18 @@ func (conn *Conn) Export(v interface{}, path ObjectPath, iface string) error {
return conn.ExportWithMap(v, nil, path, iface)
}
+// ExportAll registers all exported methods defined by the given object on
+// the message bus.
+//
+// Unlike Export there is no requirement to have the last parameter as type
+// *Error. If you want to be able to return error then you can append an error
+// type parameter to your method signature. If the error returned is not nil,
+// it is sent back to the caller as an error. Otherwise, a method reply is
+// sent with the other return values as its body.
+func (conn *Conn) ExportAll(v interface{}, path ObjectPath, iface string) error {
+ return conn.export(getAllMethods(v, nil), path, iface, false)
+}
+
// ExportWithMap works exactly like Export but provides the ability to remap
// method names (e.g. export a lower-case method).
//
@@ -299,19 +325,22 @@ func (conn *Conn) ExportSubtreeMethodTable(methods map[string]interface{}, path
}
func (conn *Conn) exportMethodTable(methods map[string]interface{}, path ObjectPath, iface string, includeSubtree bool) error {
- out := make(map[string]reflect.Value)
- for name, method := range methods {
- rval := reflect.ValueOf(method)
- if rval.Kind() != reflect.Func {
- continue
- }
- t := rval.Type()
- // only track valid methods must return *Error as last arg
- if t.NumOut() == 0 ||
- t.Out(t.NumOut()-1) != reflect.TypeOf(&ErrMsgInvalidArg) {
- continue
+ var out map[string]reflect.Value
+ if methods != nil {
+ out = make(map[string]reflect.Value)
+ for name, method := range methods {
+ rval := reflect.ValueOf(method)
+ if rval.Kind() != reflect.Func {
+ continue
+ }
+ t := rval.Type()
+ // only track valid methods must return *Error as last arg
+ if t.NumOut() == 0 ||
+ t.Out(t.NumOut()-1) != reflect.TypeOf(&ErrMsgInvalidArg) {
+ continue
+ }
+ out[name] = rval
}
- out[name] = rval
}
return conn.export(out, path, iface, includeSubtree)
}
@@ -327,12 +356,12 @@ func (conn *Conn) unexport(h *defaultHandler, path ObjectPath, iface string) err
return nil
}
-// exportWithMap is the worker function for all exports/registrations.
+// export is the worker function for all exports/registrations.
func (conn *Conn) export(methods map[string]reflect.Value, path ObjectPath, iface string, includeSubtree bool) error {
h, ok := conn.handler.(*defaultHandler)
if !ok {
return fmt.Errorf(
- `dbus: export only allowed on the default hander handler have %T"`,
+ `dbus: export only allowed on the default handler. Received: %T"`,
conn.handler)
}