Skip to content

Instantly share code, notes, and snippets.

@Merovius
Created September 19, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Merovius/6628215 to your computer and use it in GitHub Desktop.
Save Merovius/6628215 to your computer and use it in GitHub Desktop.
Dbus minimal example in go, rudimentary implementation of http://www.galago-project.org/specs/notification/0.9/
package main
import (
"github.com/guelfey/go.dbus"
)
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
// func (conn *Conn) Object(dest string, path ObjectPath) *Object
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
// Interface from the specification:
// UINT32 org.freedesktop.Notifications.Notify (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body, ARRAY actions, DICT hints, INT32 expire_timeout);
// func (o *Object) Call(method string, flags Flags, args ...interface{}) *Call
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "c¼h", uint32(0), "", "Hallo Chaostreff!", "Ich begrüße euch herzlich zu meiner c¼h!", []string{}, map[string]dbus.Variant{}, int32(1000))
if call.Err != nil {
panic(call.Err)
}
}
package main
import (
"fmt"
"github.com/guelfey/go.dbus"
)
type Server struct {
id uint32
}
func (s Server) Notify(appName string, replacesId uint32, appIcon string, summary string, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) (ret uint32, err *dbus.Error) {
fmt.Printf("Got Notification from %s:\n", appName)
fmt.Printf("==== %s ====\n", summary)
fmt.Println(body)
fmt.Printf("==== END %s ====\n", summary)
s.id++
return s.id, nil
}
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
reply, err := conn.RequestName("org.freedesktop.Notifications", dbus.NameFlagDoNotQueue)
if err != nil {
panic(err)
}
if reply != dbus.RequestNameReplyPrimaryOwner {
panic("Name already taken")
}
s := Server{ id: 0 }
conn.Export(s, "/org/freedesktop/Notifications", "org.freedesktop.Notifications")
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment