implmented dbus server

This commit is contained in:
Niklas 2020-09-09 23:40:59 +02:00
parent 42d5dec6d9
commit 9548c74fc5
2 changed files with 52 additions and 5 deletions

View File

@ -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) {

View File

@ -36,7 +36,7 @@ func Ts3pluginInit() int {
//Ts3pluginShutdown shutdown plugin function
func Ts3pluginShutdown() {
closeConn()
}
/*