implmented dbus server
This commit is contained in:
parent
42d5dec6d9
commit
9548c74fc5
@ -1,12 +1,59 @@
|
||||
package tsgo
|
||||
|
||||
import "github.com/godbus/dbus"
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/godbus/dbus"
|
||||
"github.com/godbus/dbus/introspect"
|
||||
)
|
||||
|
||||
var dbusConn *dbus.Conn
|
||||
|
||||
func initDbus() {
|
||||
dbusConn, _ = dbus.ConnectSessionBus()
|
||||
// Add error handling
|
||||
const intro = `
|
||||
<node>
|
||||
<interface name="org.kapelle.ts3">
|
||||
<method name="ToggleMute"></method>
|
||||
</interface>` + introspect.IntrospectDataString + `
|
||||
</node> `
|
||||
|
||||
type dbusHandler int
|
||||
|
||||
func (d dbusHandler) ToggleMute() *dbus.Error {
|
||||
Ts3Functions.PrintMessage(1, "toggle", PLUGIN_MESSAGE_TARGET_SERVER) // TODO placeholder
|
||||
return nil
|
||||
}
|
||||
|
||||
func initDbus() error {
|
||||
var err error
|
||||
dbusConn, err = dbus.ConnectSessionBus()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dbusConn.Export(introspect.Introspectable(intro), "/", "org.freedesktop.DBus.Introspectable")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dbusConn.Export(dbusHandler(1), "/", "org.kapelle.ts3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reply, err2 := dbusConn.RequestName("org.kapelle.ts3", dbus.NameFlagDoNotQueue)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
if reply != dbus.RequestNameReplyPrimaryOwner {
|
||||
return errors.New("name already taken")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func closeConn() {
|
||||
dbusConn.Close()
|
||||
}
|
||||
|
||||
func notifyPoke(from, message string) {
|
||||
|
@ -36,7 +36,7 @@ func Ts3pluginInit() int {
|
||||
|
||||
//Ts3pluginShutdown shutdown plugin function
|
||||
func Ts3pluginShutdown() {
|
||||
|
||||
closeConn()
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user