Skip to content

Commit

Permalink
Merge pull request #408 from ilyam8/login1_context_aware_some_methods
Browse files Browse the repository at this point in the history
login1: add context-aware ListSessions and ListUsers methods
  • Loading branch information
lucab authored Aug 31, 2022
2 parents 458b399 + 7bb8d0d commit 1d04472
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions login1/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package login1

import (
"context"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -253,10 +254,15 @@ func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
return ret, nil
}

// ListSessions returns an array with all current sessions.
// Deprecated: use ListSessionsContext instead.
func (c *Conn) ListSessions() ([]Session, error) {
return c.ListSessionsContext(context.Background())
}

// ListSessionsContext returns an array with all current sessions.
func (c *Conn) ListSessionsContext(ctx context.Context) ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
if err := c.object.CallWithContext(ctx, dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}

Expand All @@ -271,10 +277,15 @@ func (c *Conn) ListSessions() ([]Session, error) {
return ret, nil
}

// ListUsers returns an array with all currently logged in users.
// Deprecated: use ListUsersContext instead.
func (c *Conn) ListUsers() ([]User, error) {
return c.ListUsersContext(context.Background())
}

// ListUsersContext returns an array with all currently logged-in users.
func (c *Conn) ListUsersContext(ctx context.Context) ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
if err := c.object.CallWithContext(ctx, dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}

Expand Down

0 comments on commit 1d04472

Please sign in to comment.