-
Notifications
You must be signed in to change notification settings - Fork 2
/
dbus.go
72 lines (55 loc) · 1.29 KB
/
dbus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"errors"
//"path"
"github.com/godbus/dbus"
// "github.com/godbus/dbus/introspect"
// "log"
// "github.com/op/go-logging"
"github.com/gotk3/gotk3/glib"
)
const busName = "com.subgraph.EventNotifier"
const objectPath = "/com/subgraph/EventNotifier"
const interfaceName = "com.subgraph.EventNotifier"
type dbusServer struct {
conn *dbus.Conn
run bool
}
type slmData struct {
EventID string
LogLevel string
Timestamp int64
LogLine string
OrigLogLine string
Metadata map[string]string
}
func newDbusServer() (*dbusServer, error) {
conn, err := dbus.SystemBus()
if err != nil {
return nil, err
}
reply, err := conn.RequestName(busName, dbus.NameFlagDoNotQueue)
if err != nil {
return nil, err
}
if reply != dbus.RequestNameReplyPrimaryOwner {
return nil, errors.New("Bus name is already owned")
}
ds := &dbusServer{}
if err := conn.Export(ds, objectPath, interfaceName); err != nil {
return nil, err
}
ds.conn = conn
ds.run = true
return ds, nil
}
func (ds *dbusServer) Alert(data slmData) *dbus.Error {
// log.Printf(message)
if data.LogLevel == "critical" {
// dn.show("sysevent", data.LogLine, true)
} else {
// log.Println("Skipping event bubble for non-critical log item")
}
glib.IdleAdd(guiLog, data)
return nil
}