Go bindings for D-Bus

Related tags

Network go-dbus
Overview

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])
}
Issues
  • Message cleanup

    Message cleanup

    This does various things to improve the Message interface.

    • The MessageType and MessageFlag constants are properly typed (no longer int types). This wasn't causing problems. But, it's cleaner and it formats the godoc documentation better.
    • The MessageType and MessageFlag constant names are more idiomatic Go names. The MessageType names are prefixed with "Type" (to be more explicit and to avoid naming conflicts). The MessageFlag names have not been prefixed. They seem unambiguous enough to me. Any thoughts about that?
    • The MessageType now uses method String, instead of _ToString. This is more idiomatic Go. It also allows fmt.Printf to format it better with the flag "%v".
    • The Message type's field, Type, is now a MessageType. This speeds up comparison operations. It's also a little clearer than the previous string-based approach (not that it was overly complicated before).

    I'm always open to feedback. Let me know what you think

    Bryan

    opened by bmatsuo 7
  • Hide the internal authStatus constants. Give more idiomatic names.

    Hide the internal authStatus constants. Give more idiomatic names.

    The names needed to be changed (unexported) so they wouldn't appear in the godoc documentation.

    I took the liberty of renaming them as "statusNameOfStatus", where "NAME_OF_STATUS" was the previous name.

    opened by bmatsuo 2
  • Objectify API

    Objectify API

    Description

    This patch will alter the top level API. It would be prudent to discuss it before merging into the master repository. The test code in the patch is altered for the new API, as is the README example.

    Aside from these changes, I refactored the test code in dbus_test.go while I was fixing API calls. It's now a table-driven test that allows more method-call tests to be written.

    I've also introduced two new types which I discuss at the bottom of this document.

    Please look everything over and give me your feedback. An important part of this should process be planning for future changes the API needs (there are certainly a few).

    Thanks.

    Changes

    Changes to the existing API affect the *Connection interface. *Object and *Interface have new methods, but otherwise function the same way.

    Connection.Interface

    The Connection.Interface method is now Object.Interface. The method did not rely on the connection. Using it as a *Connection method only made things more cumbersome.

    Method calls and signal emitting

    The way methods/signals are called/emitted has changed. A method/signal is obtained from *Interface, using method Method/Signal. This object is then passed to the *Connection method Call/Emit (formerly CallMethod/EmitSignal) along with a list of arguments. The new Call/Emit API is outlined in the updated README.

    Signal handling

    The Connection.AddSignalHandler method has been renamed Connection.Handle. It is slightly more ambiguous. It could be renamed Connection.HandleSignal. I think a more appropriate solution might be let it be named Connection.Handle, but make its argument a 'SignalHandler'. I don't think this type exists (not publicly). But a simple wrapper could take care of that.

    New types

    Finally, there are new types Method and Signal. These types combine *Interface objects with MethodData/SignalData objects. This solution is probably not ideal. The MethodData and SignalData types should probably not be exported (either before this request is merged, or sometime in the near future).

    opened by bmatsuo 2
  • Sha1

    Sha1

    Re-wrote the authentication processing to simplify it and allow mechanisms that require data exchanges.

    Implemented the DBUS_COOKIE_SHA1 authentication mechanism.

    opened by tones111 1
  • Add readme

    Add readme

    Add content to the README file, which is renamed README.markdown to enable github markup.

    Adds README sections

    • Documentation pointing to GoPkgDoc
    • Installation telling people that goinstall works as expected.
    • Usage containing a basic example (OSD notifications)

    See my branch's page for a preview of how things are get marked-up.

    opened by bmatsuo 1
  • Beef up connecting to a well known bus

    Beef up connecting to a well known bus

    Here's some code I wrote that consolidates connecting to one of the well known d-bus busses. It adheres more closely with the documentation at http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-types.

    Additionally I added a .gitignore file to exclude build system generated files and removed the external library dependency on pretty.go which was not providing much value.

    opened by tones111 1
  • Connecting to SystemBus fails, docs are unclear on how to specify authenticators

    Connecting to SystemBus fails, docs are unclear on how to specify authenticators

    I'm attempting to connect to a system bus using the following:

    var (
    conn   *dbus.Connection
    method *dbus.Method
    out    []interface{}
    )
    
    // Initializes connection to System D-Bus, to talk to Avahi.
    func Init() error {
    var err error
    // Connect to Session or System buses.
    if conn, err = dbus.Connect(dbus.SystemBus); err != nil {
        return err
    }
    if err = conn.Authenticate(); err != nil {
        return err
    }
    
    return nil
    }
    

    This fails with the following error returned:

    Rejected: EXTERNAL DBUS_COOKIE_SHA1 ANONYMOUS
    

    Not sure why a default connection to the system bus fails, but I also don't see an obvious way from the API docs to specify one of the supported authenticators to attempt a connection.

    opened by nergdron 2
Owner
nori satir
nori satir
A rate limiter for Golang, with ETCD data bindings

Go Rate limiter This package allows us to have a distributed rate limiter, using Redis as a central counter. The limits that are set are only "soft" l

Nadir Hamid 0 Dec 9, 2021
Go-aspell - GNU Aspell spell checking library bindings for golang

Aspell library bindings for Go GNU Aspell is a spell checking tool written in C/

Vladimir Sibirov 44 Nov 29, 2021
Native Go bindings for D-Bus

dbus dbus is a simple library that implements native Go client bindings for the D-Bus message bus system. Features Complete native implementation of t

null 737 Aug 2, 2022
Native Go bindings for D-Bus

go.dbus go.dbus is a simple library that implements native Go client bindings for the D-Bus message bus system. Features Complete native implementatio

Georg Reinke 122 Jul 18, 2022
Go bindings to systemd socket activation, journal, D-Bus, and unit files

go-systemd Go bindings to systemd. The project has several packages: activation - for writing and using socket activation from Go daemon - for notifyi

CoreOS 1.9k Aug 9, 2022
🔊Minimalist message bus implementation for internal communication

?? Bus Bus is a minimalist event/message bus implementation for internal communication. It is heavily inspired from my event_bus package for Elixir la

Mustafa Turan 272 Aug 5, 2022
Go simple async message bus

?? message-bus Go simple async message bus. ?? ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free to send pull requests! Have problems, b

Rafał Lorenz 225 Jul 18, 2022
A lightweight transactional message bus on top of RabbitMQ

grabbit A lightweight transactional message bus on top of RabbitMQ supporting: Supported Messaging Styles One Way (Fire and forget) Publish/Subscribe

WeWork 86 Jul 1, 2022
Gin best practices, gin development scaffolding, too late to explain, get on the bus.

Table of Contents generated with DocToc gin_scaffold 现在开始 文件分层 log / redis / mysql / http.client 常用方法 swagger文档生成 gin_scaffold Gin best practices, gin

niuyufu 523 Aug 2, 2022
Easy to use distributed event bus similar to Kafka

chukcha Easy to use distributed event bus similar to Kafka. The event bus is designed to be used as a persistent intermediate storage buffer for any k

Yuriy Nasretdinov 73 Jul 28, 2022
simple golang event bus structure

super simple and small event bus structure for golang that allows emissions as go routines.

bfu4 5 Dec 11, 2021
Go-turing-i2c-cmdline - Controlling the i2c management bus of the turing pi with i2c works fine

go-turing-i2c-cmdline What is it? Controlling the i2c management bus of the turi

null 2 Jan 24, 2022
Govent is an event bus framework for DDD event source implement

Govent is an event bus framework for DDD event source implement. Govent can also solve the package circular dependency problem.

Michaelyn 2 Jan 28, 2022
Messagebus - Simple Message Bus Written in Golang

MessageBus Simple Message Bus Written in Golang How to Use go get gopkg.io/Usada

Usada Pekora 2 Apr 21, 2022
A reimplementation of the TinyGo drivers package for communicating with multiples of the same (supported) devices on one individual I2C bus.

tinygo-multi-i2c A reimplementation of the TinyGo drivers package for communicating with multiples of the same (supported) devices on one individual I

Quinn Millican 3 Mar 10, 2022
libsox bindings for go

gosox "SoX − Sound eXchange, the Swiss Army knife of audio manipulation" Go bindings for the libsox sound library For more information and documentati

Kristoffer Grönlund 123 Apr 9, 2022
Go bindings for the PortAudio audio I/O library

portaudio This package provides an interface to the PortAudio audio I/O library. See the package documentation for details. To build this package you

Gordon Klaus 521 Aug 2, 2022
Go bindings for libportmidi

portmidi Want to output to an MIDI device or listen your MIDI device as an input? This package contains Go bindings for PortMidi. libportmidi (v. 217)

Jaana Dogan 267 Jun 28, 2022
Golang bindings for the Telegram Bot API

Golang bindings for the Telegram Bot API All methods are fairly self explanatory, and reading the godoc page should explain everything. If something i

null 3.9k Aug 11, 2022
OpenSSL bindings for Go

OpenSSL bindings for Go Please see http://godoc.org/github.com/spacemonkeygo/openssl for more info License Copyright (C) 2017. See AUTHORS. Licensed u

Space Monkey Go 436 Jun 1, 2022
Golang bindings for libxlsxwriter for writing XLSX files

goxlsxwriter provides Go bindings for the libxlsxwriter C library. Install goxlsxwriter requires the libxslxwriter library to be installe

Frank Terragna 18 Jun 27, 2022
Go bindings for ForestDB

goforestdb Go bindings for ForestDB Building Obtain and build forestdb: https://github.com/couchbaselabs/forestdb (run make install to install the lib

null 32 Apr 5, 2022
Go bindings for GLib type system.

Go bindings for GLib type system. This package is designed for building bindings to C libraries based on GLib type system (like GTK, GStreamer, and ot

Michał Derkacz 24 Aug 13, 2019
Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files.

tabby Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files. screenshot: depend

Mikhail Trushnikov 49 Dec 30, 2021
Duktape JavaScript engine bindings for Go

Duktape bindings for Go(Golang) Duktape is a thin, embeddable javascript engine. Most of the api is implemented. The exceptions are listed here. Usage

Oleg Lebedev 781 Jul 13, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 868 Aug 10, 2022
naive go bindings to the CPython C-API

go-python Naive go bindings towards the C-API of CPython-2. this package provides a go package named "python" under which most of the PyXYZ functions

Sebastien Binet 1.4k Aug 1, 2022
Go bindings for Lua C API - in progress

Go Bindings for the lua C API Simplest way to install: # go get github.com/aarzilli/golua/lua You can then try to run the examples: $ cd golua/_examp

Alessandro Arzilli 590 Jul 29, 2022
Go bindings for libmagic to detect MIME types

magicmime magicmime is a Go package which allows you to discover a file's mimetype by looking for magic numbers in its content. It could be used as a

Jaana Dogan 209 Jul 19, 2022