dbuscommon

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 7 Imported by: 0

Documentation

Overview

Package dbuscommon provides a common dbus server and client base to extend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EavesDrop

func EavesDrop(match string) (chan *dbus.Message, error)

EavesDrop registers to receive Dbus events for custom parsing.

func NewError

func NewError(msg string) *dbus.Error

NewError creates a dbus error.

func SessionBus

func SessionBus() (*dbus.Conn, chan *dbus.Signal, error)

SessionBus creates a Dbus session with a listening chan.

func ToMapInterface

func ToMapInterface(input map[string]dbus.Variant) map[string]interface{}

ToMapInterface recasts a map of dbus.Variant to a map of interface.

func ToMapVariant

func ToMapVariant(input map[string]interface{}) map[string]dbus.Variant

ToMapVariant recasts a list of args to map[string]dbus.Variant as requested by the DBus API.

Types

type Client

type Client struct {
	dbus.BusObject
	// contains filtered or unexported fields
}

Client is a Dbus client to connect to the internal Dbus server.

func GetClient

func GetClient(SrvObj, SrvPath string, InterfacePath ...string) (*Client, error)

GetClient return a connection to the active instance of the internal Dbus service if any. Return nil, nil if none found. InterfacePath is an optional string to provide if the object use an interface path different from SrvObj

func (*Client) Call

func (cl *Client) Call(method string, args ...interface{}) error

Call calls a method on a Dbus object.

func (*Client) Get

func (cl *Client) Get(method string, answers []interface{}, args ...interface{}) error

Get calls a method on a Dbus object with returned values. The list of answers has to be provided before the command arguments. The type of each field in answer must be a pointer to a value of the same type as expected to be returned by the Dbus method called (its go version).

func (*Client) Go

func (cl *Client) Go(method string, args ...interface{}) error

Go calls a method on a Dbus object without waiting for an answer.

func (*Client) SetTestErr

func (cl *Client) SetTestErr(testErr func(e error, method string))

SetTestErr sets a test error function.

type Server

type Server struct {
	Conn   *dbus.Conn          // Dbus connection.
	Events <-chan *dbus.Signal // Dbus incoming signals channel.
	Log    cdtype.Logger
	// contains filtered or unexported fields
}

Server is a Dbus server with applets service management.

func NewServer

func NewServer(srvObj, srvPath string, log cdtype.Logger) *Server

NewServer creates a Dbus service.

func (*Server) Introspect

func (load *Server) Introspect(obj interface{}, propsSpec map[string]map[string]*prop.Prop) *introspect.Node

Introspect provides introspection data for the DBus service to start.

propsSpec example:

var propsSpec = map[string]map[string]*prop.Prop{
	SrvObj: {
		"Restart": {
			int32(0),
			true,
			prop.EmitTrue,
			func(c *prop.Change) *dbus.Error {
				fmt.Println(c.Name, "changed to", c.Value)
				return nil
			},
		},
	},
}

func (*Server) Start

func (load *Server) Start(obj interface{}, propsSpec map[string]map[string]*prop.Prop) (bool, error)

Start starts the DBus service with the given object. Introspection will be managed and the provided properties exposed. Methods will also be auto discovered.

Jump to

Keyboard shortcuts

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