Class: RosettAi::DBus::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/dbus/service.rb

Overview

Main D-Bus session service for Rosett-AI.

Exports interfaces under be.neatnerds.rosettai bus name:

  • be.neatnerds.rosettai.Manager: compile, context switching, status
  • be.neatnerds.rosettai.FocusMonitor: active window tracking
  • org.kde.StatusNotifierItem: system tray presence

The service is designed to gracefully degrade when D-Bus is unavailable.

Constant Summary collapse

BUS_NAME =
'be.neatnerds.rosettai'
OBJECT_PATH =
'/be/neatnerds/rosett-ai'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



24
25
26
27
# File 'lib/rosett_ai/dbus/service.rb', line 24

def initialize
  @running = false
  @main_loop = nil
end

Instance Attribute Details

#busObject (readonly)

Returns the value of attribute bus.



22
23
24
# File 'lib/rosett_ai/dbus/service.rb', line 22

def bus
  @bus
end

#focus_monitorObject (readonly)

Returns the value of attribute focus_monitor.



22
23
24
# File 'lib/rosett_ai/dbus/service.rb', line 22

def focus_monitor
  @focus_monitor
end

#main_loopObject (readonly)

Returns the value of attribute main_loop.



22
23
24
# File 'lib/rosett_ai/dbus/service.rb', line 22

def main_loop
  @main_loop
end

#managerObject (readonly)

Returns the value of attribute manager.



22
23
24
# File 'lib/rosett_ai/dbus/service.rb', line 22

def manager
  @manager
end

#status_notifierObject (readonly)

Returns the value of attribute status_notifier.



22
23
24
# File 'lib/rosett_ai/dbus/service.rb', line 22

def status_notifier
  @status_notifier
end

Class Method Details

.dbus_available?Boolean

Check if D-Bus session bus is available

Returns:

  • (Boolean)


77
78
79
80
81
82
# File 'lib/rosett_ai/dbus/service.rb', line 77

def self.dbus_available?
  ::DBus::SessionBus.instance
  true
rescue ::DBus::Error
  false
end

Instance Method Details

#runObject

Run the event loop (blocking)



46
47
48
49
50
51
52
53
54
55
# File 'lib/rosett_ai/dbus/service.rb', line 46

def run
  return unless @running

  @main_loop = ::DBus::Main.new
  @main_loop << @bus
  RosettAi.logger.info("D-Bus service running on #{BUS_NAME}")
  @main_loop.run
rescue Interrupt
  stop
end

#running?Boolean

Check if the service is running

Returns:

  • (Boolean)


70
71
72
# File 'lib/rosett_ai/dbus/service.rb', line 70

def running?
  @running
end

#startBoolean

Start the D-Bus service

Returns:

  • (Boolean)

    true if started successfully



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rosett_ai/dbus/service.rb', line 32

def start
  return false if @running

  connect_to_session_bus
  export_interfaces
  request_bus_name
  @running = true
  true
rescue ::DBus::Error => e
  RosettAi.logger.error("D-Bus service failed to start: #{e.message}")
  false
end

#stopObject

Stop the D-Bus service



58
59
60
61
62
63
64
65
# File 'lib/rosett_ai/dbus/service.rb', line 58

def stop
  return unless @running

  @main_loop&.quit
  @focus_monitor&.stop
  @running = false
  RosettAi.logger.info('D-Bus service stopped')
end