Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
This branch starts the migration of the Manager service from Ruby to Rust code. For more details, see the associated HackWeek project https://hackweek.opensuse.org/23/projects/port-agamas-manager-to-rust.
Manager and progress reporting
Manager and other services implement the org.opensuse.Agama1.Progress D-Bus interface. That interface is used to report the progress of the current action being performed by the service.
That progress interface only has read-only properties:
And the code reporting progress should be able to
start
,step
andfinish
a progress. For example:The calls to
#start
,#step
or#finish
changes the data of the progess (e.g., total steps and current step), so aPropertiesChanged
signal should be properly emited in D-Bus in order to notify about changes inCurrentStep
andTotalSteps
properties.Typically, D-Bus libraries like ruby-dbus or zbus automatically emit a signal when a property is set by means of a D-Bus property setter. But, the progress interface lacks of such setters (it only has read-only properties). Therefore, the progress should implement any kind of strategy for emiting D-Bus signasl as part of the
#start
,#step
and#finish
methods.In short, the problem to solve consists on emiting a D-Bus signal from outside of the D-Bus interface.
Ruby solution in Agama
In the ruby code this problem was already solved by using callbacks:
Basically, the D-Bus object adds a callback to
Progress
in order to emit a signal when progress changes.RFC: Rust solution
This PR proposes a possible solution in Rust. In Agama we are using zbus crate for working with D-Bus. Again, emiting a property changed signal is trivial when you do it from the D-Bus interface implementation:
Note that for emiting a signal (e.g.,
#total_steps_changed
) we need the signal context reference, which is automatically provided by zbus as parameter of the methods defining the D-Bus interface. But we don't want#start
to be part of the D-Bus interface, so how could we get the signal context reference from outside the D-Bus interface?The solution proposed by this PR consists on recovering and storing a reference to the D-Bus interface. Having the interface reference we can get the signal context and emit signals:
Now
#start
does not belong to the D-Bus interface implementation. Services can call toProgress#start
, which automatically emits the proper D-Bus signals.