Class: DBus::Systemd::Logind::Manager

Inherits:
Object
  • Object
show all
Includes:
Mixin::MethodMissing, Mixin::Properties
Defined in:
lib/dbus/systemd/logind/manager.rb

Constant Summary collapse

NODE =

the logind manager object dbus node path

'/org/freedesktop/login1'.freeze
INTERFACE =

the logind manager object dbus interface

'org.freedesktop.login1.Manager'.freeze
SESSION_INDICES =

session array index map as returned by ListSessions

{
  id: 0,
  user_id: 1,
  user_name: 2,
  seat_id: 3,
  object_path: 4
}.freeze
USER_INDICES =

user array index map as returned by ListUsers

{
  id: 0,
  name: 1,
  object_path: 2
}.freeze
SEAT_INDICES =

seat array index map as returned by ListSeats

{
  id: 0,
  object_path: 1
}.freeze
INHIBITOR_INDICES =

inhibitor array index map as returned by ListInhibitors

{
  what: 0,
  who: 1,
  why: 2,
  mode: 3,
  user_id: 4,
  process_id: 5
}.freeze

Instance Attribute Summary collapse

Attributes included from Mixin::MethodMissing

#object

Instance Method Summary collapse

Methods included from Mixin::Properties

#properties

Methods included from Mixin::MethodMissing

#method_missing, #respond_to_missing?

Constructor Details

#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager

Create a logind manager dbus proxy object

Parameters:

  • bus (DBus::SystemBus, DBus::SessionBus) (defaults to: Systemd::Helpers.system_bus)

    dbus instance



83
84
85
86
87
88
# File 'lib/dbus/systemd/logind/manager.rb', line 83

def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Logind::SERVICE)
  @object = @service.object(NODE)
  @object.default_iface = INTERFACE
  @object.introspect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DBus::Systemd::Mixin::MethodMissing

Instance Attribute Details

#serviceDBus::Service (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (DBus::Service)


77
78
79
# File 'lib/dbus/systemd/logind/manager.rb', line 77

def service
  @service
end

Instance Method Details

#get_seat_by_path(path) ⇒ DBus::Systemd::Logind::Seat

get seat object from dbus node path

Parameters:

  • path (String)

    seat dbus node path

Returns:



112
113
114
115
116
# File 'lib/dbus/systemd/logind/manager.rb', line 112

def get_seat_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Seat.new(obj.Get(Seat::INTERFACE, 'Id').first, self)
end

#get_session_by_path(path) ⇒ DBus::Systemd::Logind::Session

get session object by dbus node path

Parameters:

  • path (String)

    session dbus node path

Returns:



149
150
151
152
153
# File 'lib/dbus/systemd/logind/manager.rb', line 149

def get_session_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Session.new(obj.Get(Session::INTERFACE, 'Id').first, self)
end

#get_user_by_path(path) ⇒ DBus::Systemd::Logind::User

get user dbus object from dbus node path

Parameters:

  • path (String)

    dbus node path for user

Returns:



186
187
188
189
190
# File 'lib/dbus/systemd/logind/manager.rb', line 186

def get_user_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  User.new(obj.Get(User::INTERFACE, 'Id').first, self)
end

#map_seat(seat_array) ⇒ Hash

map seat array to named field hash

Parameters:

  • seat_array (Array)

    seat array as returned from ListSeats

Returns:

  • (Hash)

    mapped array as hash



123
124
125
# File 'lib/dbus/systemd/logind/manager.rb', line 123

def map_seat(seat_array)
  Systemd::Helpers.map_array(seat_array, SEAT_INDICES)
end

#map_session(session_array) ⇒ Hash

convert session array to mapped hash

Parameters:

  • session_array (Array)

    session array as returned by ListSessions

Returns:

  • (Hash)

    mapped session property hash



160
161
162
# File 'lib/dbus/systemd/logind/manager.rb', line 160

def map_session(session_array)
  Systemd::Helpers.map_array(session_array, SESSION_INDICES)
end

#map_user(user_array) ⇒ Hash

convert user array to hash with mapped properties

Parameters:

  • user_array (Array)

    user array as returned by ListUsers

Returns:

  • (Hash)

    hash with mapped user properties



197
198
199
# File 'lib/dbus/systemd/logind/manager.rb', line 197

def map_user(user_array)
  Systemd::Helpers.map_array(user_array, USER_INDICES)
end

#seat(id) ⇒ DBus::Systemd::Logind::Seat

get seat object

Parameters:

  • id (String)

    seat id (e.g. ‘seat0’)

Returns:



103
104
105
# File 'lib/dbus/systemd/logind/manager.rb', line 103

def seat(id)
  Seat.new(id, self)
end

#seatsArray

get mapped list of seats

Returns:

  • (Array)

    array of mapped seat hashes



94
95
96
# File 'lib/dbus/systemd/logind/manager.rb', line 94

def seats
  self.ListSeats.first.map { |s| map_seat(s) }
end

#session(id) ⇒ DBus::Systemd::Logind::Session

dbus session object by id

Parameters:

  • id (String)

    session id

Returns:



140
141
142
# File 'lib/dbus/systemd/logind/manager.rb', line 140

def session(id)
  Session.new(id, self)
end

#sessionsArray

array of property-mapped seat hashes

Returns:

  • (Array)

    array of seat-property hashes



131
132
133
# File 'lib/dbus/systemd/logind/manager.rb', line 131

def sessions
  self.ListSessions.first.map { |s| map_session(s) }
end

#user(id) ⇒ DBus::Systemd::Logind::User

get user dbus object

Parameters:

  • id (Integer)

    user id

Returns:



177
178
179
# File 'lib/dbus/systemd/logind/manager.rb', line 177

def user(id)
  User.new(id, self)
end

#usersArray

get logind users

Returns:

  • (Array)

    array of mapped logind user property hashes



168
169
170
# File 'lib/dbus/systemd/logind/manager.rb', line 168

def users
  self.ListUsers.first.map { |u| map_user(u) }
end