forked from Elara6331/itd
Make sure modemmanager exists for call notifications
This commit is contained in:
parent
3a16bff83f
commit
be99136bb5
35
calls.go
35
calls.go
@ -7,14 +7,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func initCallNotifs(dev *infinitime.Device) error {
|
func initCallNotifs(dev *infinitime.Device) error {
|
||||||
// Connect to system bus. This connection is for monitoring.
|
// Connect to system bus. This connection is for method calls.
|
||||||
monitorConn, err := newSystemBusConn()
|
conn, err := newSystemBusConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to system bus. This connection is for method calls.
|
// Check if modem manager interface exists
|
||||||
conn, err := newSystemBusConn()
|
exists, err := modemManagerExists(conn)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it does not exist, stop function
|
||||||
|
if !exists {
|
||||||
|
conn.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to system bus. This connection is for monitoring.
|
||||||
|
monitorConn, err := newSystemBusConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -28,6 +40,7 @@ func initCallNotifs(dev *infinitime.Device) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
conn.Names()
|
||||||
|
|
||||||
// Create channel to receive calls
|
// Create channel to receive calls
|
||||||
callCh := make(chan *dbus.Message, 5)
|
callCh := make(chan *dbus.Message, 5)
|
||||||
@ -45,7 +58,8 @@ func initCallNotifs(dev *infinitime.Device) error {
|
|||||||
// Get phone number from call object using method call connection
|
// 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.Error().Err(err).Msg("Error getting phone number")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send call notification to InfiniTime
|
// Send call notification to InfiniTime
|
||||||
@ -77,9 +91,20 @@ func initCallNotifs(dev *infinitime.Device) error {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
log.Info().Msg("Relaying calls to InfiniTime")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func modemManagerExists(conn *dbus.Conn) (bool, error) {
|
||||||
|
var names []string
|
||||||
|
err := conn.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&names)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return strSlcContains(names, "org.freedesktop.ModemManager1"), nil
|
||||||
|
}
|
||||||
|
|
||||||
// getPhoneNum gets a phone number from a call object using a DBus connection
|
// 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
|
||||||
|
Loading…
Reference in New Issue
Block a user