package prop

import "github.com/godbus/dbus/v5/prop"

Package prop provides the Properties struct which can be used to implement org.freedesktop.DBus.Properties.

Index

Constants

const IntrospectDataString = "" /* 757 byte string literal not displayed */

The introspection data for the org.freedesktop.DBus.Properties interface, as a string.

Variables

var ErrIfaceNotFound = dbus.NewError("org.freedesktop.DBus.Properties.Error.InterfaceNotFound", nil)

ErrIfaceNotFound is the error returned to peers who try to access properties on interfaces that aren't found.

var ErrInvalidArg = dbus.NewError("org.freedesktop.DBus.Properties.Error.InvalidArg", nil)

ErrInvalidArg is returned to peers if the type of the property that is being changed and the argument don't match.

var ErrPropNotFound = dbus.NewError("org.freedesktop.DBus.Properties.Error.PropertyNotFound", nil)

ErrPropNotFound is the error returned to peers trying to access properties that aren't found.

var ErrReadOnly = dbus.NewError("org.freedesktop.DBus.Properties.Error.ReadOnly", nil)

ErrReadOnly is the error returned to peers trying to set a read-only property.

var IntrospectData = introspect.Interface{
	Name: "org.freedesktop.DBus.Properties",
	Methods: []introspect.Method{
		{
			Name: "Get",
			Args: []introspect.Arg{
				{Name: "interface", Type: "s", Direction: "in"},
				{Name: "property", Type: "s", Direction: "in"},
				{Name: "value", Type: "v", Direction: "out"},
			},
		},
		{
			Name: "GetAll",
			Args: []introspect.Arg{
				{Name: "interface", Type: "s", Direction: "in"},
				{Name: "props", Type: "a{sv}", Direction: "out"},
			},
		},
		{
			Name: "Set",
			Args: []introspect.Arg{
				{Name: "interface", Type: "s", Direction: "in"},
				{Name: "property", Type: "s", Direction: "in"},
				{Name: "value", Type: "v", Direction: "in"},
			},
		},
	},
	Signals: []introspect.Signal{
		{
			Name: "PropertiesChanged",
			Args: []introspect.Arg{
				{Name: "interface", Type: "s", Direction: "out"},
				{Name: "changed_properties", Type: "a{sv}", Direction: "out"},
				{Name: "invalidates_properties", Type: "as", Direction: "out"},
			},
		},
	},
}

The introspection data for the org.freedesktop.DBus.Properties interface.

Types

type Change

type Change struct {
	Props *Properties
	Iface string
	Name  string
	Value interface{}
}

Change represents a change of a property by a call to Set.

type EmitType

type EmitType byte

EmitType controls how org.freedesktop.DBus.Properties.PropertiesChanged is emitted for a property. If it is EmitTrue, the signal is emitted. If it is EmitInvalidates, the signal is also emitted, but the new value of the property is not disclosed. If it is EmitConst, the property never changes value during the lifetime of the object it belongs to, and hence the signal is never emitted for it.

const (
	EmitFalse EmitType = iota
	EmitTrue
	EmitInvalidates
	EmitConst
)

func (EmitType) String

func (e EmitType) String() (str string)

type Prop

type Prop struct {
	// Initial value. Must be a DBus-representable type.
	Value interface{}

	// If true, the value can be modified by calls to Set.
	Writable bool

	// Controls how org.freedesktop.DBus.Properties.PropertiesChanged is
	// emitted if this property changes.
	Emit EmitType

	// If not nil, anytime this property is changed by Set, this function is
	// called with an appropriate Change as its argument. If the returned error
	// is not nil, it is sent back to the caller of Set and the property is not
	// changed.
	Callback func(*Change) *dbus.Error
}

Prop represents a single property. It is used for creating a Properties value.

type Properties

type Properties struct {
	// contains filtered or unexported fields
}

Properties is a set of values that can be made available to the message bus using the org.freedesktop.DBus.Properties interface. It is safe for concurrent use by multiple goroutines.

func Export

func Export(
	conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop,
) (*Properties, error)

Export returns a new Properties structure that manages the given properties. The key for the first-level map of props is the name of the interface; the second-level key is the name of the property. The returned structure will be exported as org.freedesktop.DBus.Properties on path.

func New

func New(conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop) *Properties

New falls back to Export, but it returns nil if properties export fails, swallowing the error, shouldn't be used.

Deprecated: use Export instead.

func (*Properties) Get

func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error)

Get implements org.freedesktop.DBus.Properties.Get.

func (*Properties) GetAll

func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error)

GetAll implements org.freedesktop.DBus.Properties.GetAll.

func (*Properties) GetMust

func (p *Properties) GetMust(iface, property string) interface{}

GetMust returns the value of the given property and panics if either the interface or the property name are invalid.

func (*Properties) Introspection

func (p *Properties) Introspection(iface string) []introspect.Property

Introspection returns the introspection data that represents the properties of iface.

func (*Properties) Set

func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error

Set implements org.freedesktop.Properties.Set.

func (*Properties) SetMust

func (p *Properties) SetMust(iface, property string, v interface{})

SetMust sets the value of the given property and panics if the interface or the property name are invalid.

Source Files

prop.go

Version
v5.0.6
Published
Oct 26, 2021
Platform
linux/amd64
Imports
4 packages
Last checked
1 hour ago

Tools for package owners.