Add comments
This commit is contained in:
parent
9bd78bccce
commit
3a16bff83f
22
calls.go
22
calls.go
@ -7,17 +7,19 @@ import (
|
||||
)
|
||||
|
||||
func initCallNotifs(dev *infinitime.Device) error {
|
||||
// Connect to dbus session monitorConn
|
||||
// Connect to system bus. This connection is for monitoring.
|
||||
monitorConn, err := newSystemBusConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Connect to system bus. This connection is for method calls.
|
||||
conn, err := newSystemBusConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Add match for new calls to monitor connection
|
||||
err = monitorConn.AddMatchSignal(
|
||||
dbus.WithMatchSender("org.freedesktop.ModemManager1"),
|
||||
dbus.WithMatchInterface("org.freedesktop.ModemManager1.Modem.Voice"),
|
||||
@ -27,18 +29,26 @@ func initCallNotifs(dev *infinitime.Device) error {
|
||||
return err
|
||||
}
|
||||
|
||||
callCh := make(chan *dbus.Message, 10)
|
||||
// Create channel to receive calls
|
||||
callCh := make(chan *dbus.Message, 5)
|
||||
// Notify channel upon received message
|
||||
monitorConn.Eavesdrop(callCh)
|
||||
|
||||
go func() {
|
||||
// For every message received
|
||||
for event := range callCh {
|
||||
// Get path to call object
|
||||
callPath := event.Body[0].(dbus.ObjectPath)
|
||||
// Get call object
|
||||
callObj := conn.Object("org.freedesktop.ModemManager1", callPath)
|
||||
|
||||
// Get phone number from call object using method call connection
|
||||
phoneNum, err := getPhoneNum(conn, callObj)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Send()
|
||||
}
|
||||
|
||||
// Send call notification to InfiniTime
|
||||
resCh, err := dev.NotifyCall(phoneNum)
|
||||
if err != nil {
|
||||
continue
|
||||
@ -70,8 +80,10 @@ func initCallNotifs(dev *infinitime.Device) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getPhoneNum gets a phone number from a call object using a DBus connection
|
||||
func getPhoneNum(conn *dbus.Conn, callObj dbus.BusObject) (string, error) {
|
||||
var out string
|
||||
// Get number property on DBus object and store return value in out
|
||||
err := callObj.StoreProperty("org.freedesktop.ModemManager1.Call.Number", &out)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -79,7 +91,9 @@ func getPhoneNum(conn *dbus.Conn, callObj dbus.BusObject) (string, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// getPhoneNum accepts a call using a DBus connection
|
||||
func acceptCall(conn *dbus.Conn, callObj dbus.BusObject) error {
|
||||
// Call Accept() method on DBus object
|
||||
call := callObj.Call("org.freedesktop.ModemManager1.Call.Accept", 0)
|
||||
if call.Err != nil {
|
||||
return call.Err
|
||||
@ -87,10 +101,12 @@ func acceptCall(conn *dbus.Conn, callObj dbus.BusObject) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getPhoneNum declines a call using a DBus connection
|
||||
func declineCall(conn *dbus.Conn, callObj dbus.BusObject) error {
|
||||
// Call Hangup() method on DBus object
|
||||
call := callObj.Call("org.freedesktop.ModemManager1.Call.Hangup", 0)
|
||||
if call.Err != nil {
|
||||
return call.Err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user