dbus

package module
v0.0.0-...-c022b8b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2017 License: MIT Imports: 20 Imported by: 1

README

Documentation

Look at the API on GoPkgDoc.

Installation

go get launchpad.net/go-dbus/v1

Usage

An example

// Issue OSD notifications according to the Desktop Notifications Specification 1.1
//      http://people.canonical.com/~agateau/notifications-1.1/spec/index.html
// See also
//      https://wiki.ubuntu.com/NotifyOSD#org.freedesktop.Notifications.Notify
package main

import "launchpad.net/go-dbus/v1"
import "log"

func main() {
    var (
        err error
        conn *dbus.Connection
    )

    // Connect to Session or System buses.
    if conn, err = dbus.Connect(dbus.SessionBus); err != nil {
        log.Fatal("Connection error:", err)
    }

    // Create an object proxy
    obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

    // Call object methods.
    reply, err := obj.Call("org.freedesktop.Notifications", "Notify",
        "dbus-tutorial", uint32(0), "",
        "dbus-tutorial", "You've been notified!",
	[]string{}, map[string]dbus.Variant{}, int32(-1))
    if err != nil {
        log.Fatal("Notification error:", err)
    }

    // Parse the reply message
    var notification_id uint32
    if err := reply.GetArgs(&notification_id); err != nil {
        log.Fatal(err)
    }
    log.Print("Notification id:", notification_id)
}

Documentation

Overview

Package dbus provides a client interface to the D-Bus IPC system. It can be used to talk to system services (via the "system bus") or services within the user's session (via the "session bus").

Index

Constants

View Source
const (
	BUS_DAEMON_NAME  = "org.freedesktop.DBus"
	BUS_DAEMON_PATH  = ObjectPath("/org/freedesktop/DBus")
	BUS_DAEMON_IFACE = "org.freedesktop.DBus"
)

Variables

View Source
var (
	ErrNameLost         = errors.New("name ownership lost")
	ErrNameInQueue      = errors.New("in queue for name ownership")
	ErrNameExists       = errors.New("name exists")
	ErrNameAlreadyOwned = errors.New("name already owned")
)

Functions

This section is empty.

Types

type BusDaemon

type BusDaemon struct {
	*ObjectProxy
}

func (*BusDaemon) AddMatch

func (o *BusDaemon) AddMatch(rule string) (err error)

func (*BusDaemon) GetConnectionUnixProcessID

func (o *BusDaemon) GetConnectionUnixProcessID(busName string) (process uint32, err error)

func (*BusDaemon) GetConnectionUnixUser

func (o *BusDaemon) GetConnectionUnixUser(busName string) (user uint32, err error)

func (*BusDaemon) GetId

func (o *BusDaemon) GetId() (busId string, err error)

func (*BusDaemon) GetNameOwner

func (o *BusDaemon) GetNameOwner(name string) (owner string, err error)

func (*BusDaemon) Hello

func (o *BusDaemon) Hello() (uniqueName string, err error)

func (*BusDaemon) ListActivatableNames

func (o *BusDaemon) ListActivatableNames() (names []string, err error)

func (*BusDaemon) ListNames

func (o *BusDaemon) ListNames() (names []string, err error)

func (*BusDaemon) ListQueuedOwners

func (o *BusDaemon) ListQueuedOwners(name string) (owners []string, err error)

func (*BusDaemon) NameHasOwner

func (o *BusDaemon) NameHasOwner(name string) (hasOwner bool, err error)

func (*BusDaemon) ReleaseName

func (o *BusDaemon) ReleaseName(name string) (result uint32, err error)

func (*BusDaemon) RemoveMatch

func (o *BusDaemon) RemoveMatch(rule string) (err error)

func (*BusDaemon) RequestName

func (o *BusDaemon) RequestName(name string, flags uint32) (result uint32, err error)

func (*BusDaemon) StartServiceByName

func (o *BusDaemon) StartServiceByName(name string, flags uint32) (result uint32, err error)

func (*BusDaemon) UpdateActivationEnvironment

func (o *BusDaemon) UpdateActivationEnvironment(env map[string]string) (err error)

type BusName

type BusName struct {
	Name  string
	Flags NameFlags
	C     chan error
	// contains filtered or unexported fields
}

BusName acts as a handle for a well known bus name owned by this client.

func (*BusName) Release

func (name *BusName) Release() error

Release releases well known name on the message bus.

type Connection

type Connection struct {
	// The unique name of this connection on the message bus.
	UniqueName string
	// contains filtered or unexported fields
}

Connection represents a connection to a message bus.

func Connect

func Connect(busType StandardBus) (*Connection, error)

Connect returns a connection to the message bus identified by busType.

func (*Connection) Authenticate

func (p *Connection) Authenticate() error

func (*Connection) Close

func (p *Connection) Close() error

func (*Connection) Object

func (p *Connection) Object(dest string, path ObjectPath) *ObjectProxy

Object returns a proxy for the object identified by the given destination address and path

func (*Connection) RegisterMessageFilter

func (p *Connection) RegisterMessageFilter(filter func(*Message) *Message) *MessageFilter

func (*Connection) RegisterObjectPath

func (p *Connection) RegisterObjectPath(path ObjectPath, handler chan<- *Message)

func (*Connection) RequestName

func (p *Connection) RequestName(busName string, flags NameFlags) *BusName

RequestName requests ownership of a well known bus name.

Name ownership is communicated over the the BusName's channel: a nil value indicates that the name was successfully acquired, and a non-nil value indicates that the name was lost or could not be acquired.

func (*Connection) Send

func (p *Connection) Send(msg *Message) error

func (*Connection) SendWithReply

func (p *Connection) SendWithReply(msg *Message) (*Message, error)

func (*Connection) UnregisterMessageFilter

func (p *Connection) UnregisterMessageFilter(filter *MessageFilter)

func (*Connection) UnregisterObjectPath

func (p *Connection) UnregisterObjectPath(path ObjectPath)

func (*Connection) WatchName

func (p *Connection) WatchName(busName string) (watch *NameWatch, err error)

func (*Connection) WatchSignal

func (p *Connection) WatchSignal(rule *MatchRule) (*SignalWatch, error)

Handle received signals.

type Error

type Error struct {
	Name    string
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Introspectable

type Introspectable struct {
	*ObjectProxy
}

func (*Introspectable) Introspect

func (o *Introspectable) Introspect() (data string, err error)

type MatchRule

type MatchRule struct {
	Type      MessageType
	Sender    string
	Path      ObjectPath
	Interface string
	Member    string
	Arg0      string
	// contains filtered or unexported fields
}

Matches all messages with equal type, interface, member, or path. Any missing/invalid fields are not matched against.

func (*MatchRule) Match

func (p *MatchRule) Match(msg *Message) bool

func (*MatchRule) String

func (p *MatchRule) String() string

A string representation af the MatchRule (D-Bus variant map).

type Message

type Message struct {
	Type     MessageType
	Flags    MessageFlag
	Protocol uint8

	// header fields
	Path      ObjectPath
	Interface string
	Member    string
	ErrorName string

	Dest   string
	Sender string
	// contains filtered or unexported fields
}

Message represents a D-Bus message.

It is used to both construct messages for sending on the bus, and to represent messages received from the bus.

There type does not use locks to protect its internal members. Instead, it is expected that users either (a) only modify a message from a single thread (usually the case when constructing a message to send), or (b) treat the message as read only (usually the case when processing a received message).

func NewErrorMessage

func NewErrorMessage(methodCall *Message, errorName string, message string) *Message

NewErrorMessage creates an error message.

This message type should be sent in response to a method call message in the case of a failure.

func NewMethodCallMessage

func NewMethodCallMessage(destination string, path ObjectPath, iface string, member string) *Message

NewMethodCallMessage creates a method call message.

Method arguments can be appended to the message via AppendArgs.

func NewMethodReturnMessage

func NewMethodReturnMessage(methodCall *Message) *Message

NewMethodReturnMessage creates a method return message.

This message type represents a successful reply to the method call message passed as an argument.

Return arguments should be appended to the message via AppendArgs.

func NewSignalMessage

func NewSignalMessage(path ObjectPath, iface string, member string) *Message

NewSignalMessage creates a signal message.

Signal messages are used to broadcast messages to interested listeners.

Arguments can be appended to the signal with AppendArgs.

func (*Message) AllArgs

func (p *Message) AllArgs() []interface{}

AllArgs returns all arguments in the message.

This method is equivalent to calling Args and passing pointers to blank interface values for each message argument.

func (*Message) AppendArgs

func (p *Message) AppendArgs(args ...interface{}) error

AppendArgs appends arguments to a message.

Native Go types are converted to equivalent D-Bus types:

  • uint8 represents a byte.
  • bool represents a boolean value.
  • int16, uint16, int32, uint32, int64 and uint64 represent the equivalent integer types.
  • string represents a string.
  • The dbus.ObjectPath type or any type conforming to the dbus.ObjectPather interface represents an object path.
  • arrays and slices represent arrays of the element type.
  • maps represent equivalent D-Bus dictionaries.
  • structures represent a structure comprising the public members.
  • the dbus.Variant type represents a variant.

If an argument can not be serialised in the message, an error is returned. When multiple arguments are being appended, it is possible for some arguments to be successfully appended before the error is generated.

func (*Message) Args

func (p *Message) Args(args ...interface{}) error

Args decodes one or more arguments from the message.

The arguments should be pointers to variables used to hold the arguments. If the type of the argument does not match the corresponding argument in the message, then an error will be raised.

As a special case, arguments may be decoded into a blank interface value. This may result in a less useful decoded version though (e.g. an "ai" message argument would be decoded as []interface{} instead of []int32).

func (*Message) AsError

func (p *Message) AsError() error

AsError creates a Go error value corresponding to a message.

This method should only be called on messages of the error type.

func (*Message) WriteTo

func (p *Message) WriteTo(w io.Writer) (int64, error)

WriteTo serialises the message and writes it to the given writer. Not atomic!

type MessageFilter

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

type MessageFlag

type MessageFlag uint8
const (
	// When applied to method call messages, indicates that no
	// method return or error message is expected.
	FlagNoReplyExpected MessageFlag = 1 << iota
	// Indicates that the message should not autostart the service
	// if the destination service is not currently running.
	FlagNoAutoStart
)

type MessageType

type MessageType uint8

See the D-Bus tutorial for information about message types.

http://dbus.freedesktop.org/doc/dbus-tutorial.html#messages
const (
	TypeInvalid MessageType = iota
	TypeMethodCall
	TypeMethodReturn
	TypeError
	TypeSignal
)

func (MessageType) String

func (t MessageType) String() string

type NameFlags

type NameFlags uint32
const (
	NameFlagAllowReplacement NameFlags = 1 << iota
	NameFlagReplaceExisting
	NameFlagDoNotQueue
)

type NameWatch

type NameWatch struct {
	C chan string
	// contains filtered or unexported fields
}

func (*NameWatch) Cancel

func (watch *NameWatch) Cancel() error

type ObjectPath

type ObjectPath string

func (ObjectPath) ObjectPath

func (o ObjectPath) ObjectPath() ObjectPath

type ObjectPather

type ObjectPather interface {
	ObjectPath() ObjectPath
}

type ObjectProxy

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

ObjectProxy represents a remote object on the bus. It can be used to simplify constructing method calls, and acts as a basis for D-Bus interface client stubs.

func (*ObjectProxy) Call

func (o *ObjectProxy) Call(iface, method string, args ...interface{}) (*Message, error)

Call the given method on the remote object.

On success, the reply message will be returned, whose arguments can be unpacked with its Args() method.

On failure (both network failures and D-Bus level errors), an error will be returned.

func (*ObjectProxy) ObjectPath

func (o *ObjectProxy) ObjectPath() ObjectPath

func (*ObjectProxy) WatchSignal

func (o *ObjectProxy) WatchSignal(iface, member string) (*SignalWatch, error)

type Properties

type Properties struct {
	*ObjectProxy
}

func (*Properties) Get

func (o *Properties) Get(interfaceName string, propertyName string) (value interface{}, err error)

func (*Properties) GetAll

func (o *Properties) GetAll(interfaceName string) (props map[string]Variant, err error)

func (*Properties) Set

func (o *Properties) Set(interfaceName string, propertyName string, value interface{}) (err error)

type SignalWatch

type SignalWatch struct {
	C chan *Message
	// contains filtered or unexported fields
}

func (*SignalWatch) Cancel

func (watch *SignalWatch) Cancel() error

type Signature

type Signature string

func SignatureOf

func SignatureOf(t reflect.Type) (Signature, error)

func (Signature) NextType

func (sig Signature) NextType(offset int) (next int, err error)

func (Signature) Validate

func (sig Signature) Validate() (err error)

Validate that the signature is a valid string of type codes

type StandardBus

type StandardBus int
const (
	SessionBus StandardBus = iota
	SystemBus
)

type Variant

type Variant struct {
	Value interface{}
}

func (*Variant) GetVariantSignature

func (v *Variant) GetVariantSignature() (Signature, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL