Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions login1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ type User struct {
Path dbus.ObjectPath
}

type Inhibitor struct {
What string
Who string
Why string
Mode string
Pid int64
Uid int64
}

func (s Session) toInterface() []interface{} {
return []interface{}{s.ID, s.UID, s.User, s.Seat, s.Path}
}
Expand Down Expand Up @@ -166,6 +175,39 @@ func userFromInterfaces(user []interface{}) (*User, error) {
return &ret, nil
}

func inhibitorFromInterfaces(inhibitor []interface{}) (*Inhibitor, error) {
if len(inhibitor) < 6 {
return nil, fmt.Errorf("invalid number of inhibitor fields: %d", len(inhibitor))
}
values := []string{}
fieldToString := func(index int) error {
if val, ok := inhibitor[index].(string); !ok {
return fmt.Errorf("failed to typecast inhibitor field %d to string", index)
} else {
values[index] = val
}
return nil
}
for i := 0; i < 4; i += 1 {
if err := fieldToString(i); err != nil {
return nil, err
}
}
pid, ok := inhibitor[4].(int64)
if !ok {
return nil, fmt.Errorf("failed to typecast inhibitor field 5 to int64")
}
uid, ok := inhibitor[5].(int64)
if !ok {
return nil, fmt.Errorf("failed to typecast inhibitor field 6 to int64")
}

return &Inhibitor{What: values[0], Who: values[1],
Why: values[2], Mode: values[3],
Pid: pid, Uid: uid,
}, nil
}

// GetActiveSession may be used to get the session object path for the current active session
func (c *Conn) GetActiveSession() (dbus.ObjectPath, error) {
var seat0Path dbus.ObjectPath
Expand Down Expand Up @@ -365,6 +407,24 @@ func (c *Conn) ScheduleShutdown(typ ScheduleShutdownType, when time.Time) error
return call.Err
}

// ListInhibitors lists the current active inhibitors.
func (c *Conn) ListInhibitors() ([]Inhibitor, error) {
out := [][]interface{}{}

if err := c.object.Call(dbusManagerInterface+".ListInhibitors", 0).Store(&out); err != nil {
return nil, err
}
result := []Inhibitor{}
for _, v := range out {
if inhibitor, err := inhibitorFromInterfaces(v); err != nil {
return nil, err
} else {
result = append(result, *inhibitor)
}
}
return result, nil
}

func (c *Conn) SetWallMessage(message string, enable bool) error {
call := c.object.Call(dbusManagerInterface+".SetWallMessage", 0, message, enable)
return call.Err
Expand Down