dbus

package module
v0.0.0-...-72becbe Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2012 License: MIT Imports: 16 Imported by: 0

README

Documentation

Look at the API on GoPkgDoc.

Installation

goinstall github.com/norisatir/go-dbus

Usage

Methods

Methods is obtained with

meth, err := conn.Object(dest, path).Interface(iface).Method(method)

They are called with

out, err := conn.Call(meth)

Signals

Signals are obtained with

sig, err := conn.Object(dest, path).Interface(iface).Signal(signal)

they are emitted with

err = conn.Emit(sig)

TODO Add signal handling 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 "github.com/norisatir/go-dbus"
import "log"

func main() {
    var (
        err error
        conn *dbus.Connection
        method *dbus.Method
        out []interface{}
    )

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

    // Get objects.
    obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

    // Introspect objects.
    var intro dbus.Introspect
    method, err = obj.Interface("org.freedesktop.DBus.Introspectable").Method("Introspect")
    if err != nil {
        log.Fatal(err)
    }
    out, err = conn.Call(method)
    if err != nil {
        log.Fatal("Introspect error:", err)
    }
    intro, err = dbus.NewIntrospect(out[0].(string))
    m := intro.GetInterfaceData("org.freedesktop.Notifications").GetMethodData("Notify")
    log.Printf("%s in:%s out:%s", m.GetName(), m.GetInSignature(), m.GetOutSignature())

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(buff []byte, sig string, index int) (slice []interface{}, bufIdx int, err error)

Types

type AuthDbusCookieSha1

type AuthDbusCookieSha1 struct {
}

func (*AuthDbusCookieSha1) InitialResponse

func (p *AuthDbusCookieSha1) InitialResponse() []byte

func (*AuthDbusCookieSha1) Mechanism

func (p *AuthDbusCookieSha1) Mechanism() []byte

func (*AuthDbusCookieSha1) ProcessData

func (p *AuthDbusCookieSha1) ProcessData(mesg []byte) ([]byte, error)

type AuthExternal

type AuthExternal struct {
}

func (*AuthExternal) InitialResponse

func (p *AuthExternal) InitialResponse() []byte

func (*AuthExternal) Mechanism

func (p *AuthExternal) Mechanism() []byte

func (*AuthExternal) ProcessData

func (p *AuthExternal) ProcessData([]byte) ([]byte, error)

type Authenticator

type Authenticator interface {
	Mechanism() []byte
	InitialResponse() []byte
	ProcessData([]byte) ([]byte, error)
}

type Connection

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

func Connect

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

func (*Connection) Authenticate

func (p *Connection) Authenticate() error

func (*Connection) Call

func (p *Connection) Call(method *Method, args ...interface{}) ([]interface{}, error)

Call a method with the given arguments.

func (*Connection) Emit

func (p *Connection) Emit(signal *Signal, args ...interface{}) error

Emit a signal with the given arguments.

func (*Connection) Handle

func (p *Connection) Handle(rule *MatchRule, handler func(*Message))

Handle received signals.

func (*Connection) Object

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

Retrieve a specified object.

type Interface

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

func (*Interface) Method

func (iface *Interface) Method(name string) (*Method, error)

Retrieve a method by name.

func (*Interface) Signal

func (iface *Interface) Signal(name string) (*Signal, error)

Retrieve a signal by name.

type InterfaceData

type InterfaceData interface {
	GetMethodData(name string) MethodData
	GetSignalData(name string) SignalData
	GetName() string
}

type Introspect

type Introspect interface {
	GetInterfaceData(name string) InterfaceData
}

func NewIntrospect

func NewIntrospect(xmlIntro string) (Introspect, error)

type MatchRule

type MatchRule struct {
	Type      MessageType
	Interface string
	Member    string
	Path      string
}

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

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 int

	Path   string
	Dest   string
	Iface  string
	Member string
	Sig    string
	Params []interface{}

	ErrorName string
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage() *Message

Create a new message with Flags == 0 and Protocol == 1.

type MessageFlag

type MessageFlag uint8
const (
	FlagNoReplyExpected MessageFlag = 1 << iota
	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 Method

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

type MethodData

type MethodData interface {
	GetName() string
	GetInSignature() string
	GetOutSignature() string
}

type Object

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

func (*Object) Interface

func (obj *Object) Interface(name string) *Interface

Retrieve an interface by name.

type Signal

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

type SignalData

type SignalData interface {
	GetName() string
	GetSignature() string
}

type StandardBus

type StandardBus int
const (
	SessionBus StandardBus = iota
	SystemBus
)

Jump to

Keyboard shortcuts

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