Skip to content

Commit

Permalink
[yastd] Run probing and installation on separate threads
Browse files Browse the repository at this point in the history
* Use EventMachine to do polling on the D-Bus socket.
  • Loading branch information
imobachgs committed Dec 24, 2021
1 parent 0558c0c commit 3098e80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
11 changes: 10 additions & 1 deletion yastd/bin/yastd
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)

require "rubygems"
require "bundler/setup"

require "eventmachine"
require "yast2/dbus/service"
Yast2::DBus::Service.new.run

EM.run do
service = Yast2::DBus::Service.new
service.export
EventMachine::PeriodicTimer.new(0.1) { service.dispatch }
end
8 changes: 4 additions & 4 deletions yastd/lib/yast2/dbus/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def initialize(installer, logger, *args)

dbus_method :Probe, "out result:b" do
logger.info "Probe"

installer.probe
Thread.new { installer.probe }
true
end

dbus_method :Start, "out result:b" do
logger.info "Start"

installer.install
Thread.new { installer.install }
true
end

dbus_signal :StatusChanged, "status:n"
end

dbus_interface PROPERTY_INTERFACE do
Expand Down
20 changes: 13 additions & 7 deletions yastd/lib/yast2/dbus/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ class Service
# @return [String] D-Bus object path
OBJECT_PATH = "/org/opensuse/YaST/Installer"

attr_reader :bus

def initialize(logger = nil)
@logger = logger || Logger.new(STDOUT)
@bus = ::DBus::SystemBus.instance
end

def run
bus = ::DBus.system_bus
# Exports the installer object through the D-Bus service
def export
service = bus.request_service(SERVICE_NAME)
installer_obj = Yast2::DBus::Installer.new(build_installer, logger, OBJECT_PATH)
installer_obj = Yast2::DBus::Installer.new(
build_installer, logger, OBJECT_PATH
)
service.export(installer_obj)
dbus_loop = ::DBus::Main.new
dbus_loop << bus
logger.info "Listening on #{OBJECT_PATH}"
dbus_loop.run
logger.info "Exported #{OBJECT_PATH} object"
end

def dispatch
bus.dispatch_message_queue
end

private
Expand Down

0 comments on commit 3098e80

Please sign in to comment.