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