-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathmanager.rb
135 lines (113 loc) · 3.7 KB
/
manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "dbus"
module DInstaller
module DBus
# D-Bus object to manage the installation process
class Manager < ::DBus::Object
PATH = "/org/opensuse/DInstaller/Manager1"
private_constant :PATH
MANAGER_INTERFACE = "org.opensuse.DInstaller.Manager1"
private_constant :MANAGER_INTERFACE
# Constructor
#
# @param backend [DInstaller::Manager] Installation manager
# @param logger [Logger]
def initialize(backend, logger)
@logger = logger
@backend = backend
register_status_callback
register_progress_callback
super(PATH)
end
dbus_interface MANAGER_INTERFACE do
dbus_method(:Probe, "") { backend.probe }
dbus_method(:Commit, "") { backend.install }
# Current status
#
# TODO: these values come from the id of statuses, see {DInstaller::Status::Base}. This
# D-Bus class should explicitly convert statuses to integer instead of relying on the id
# value, which could change.
#
# Possible values:
# 0 : error
# 1 : probing
# 2 : probed
# 3 : installing
# 4 : installed
dbus_reader :status, "u"
# Error messages when the status is 0
dbus_reader :error_messages, "as"
# Progress has struct with values:
# s message
# t total major steps to do
# t current major step (0-based)
# t total minor steps. Can be zero which means no minor steps
# t current minor step
dbus_reader :progress, "(stttt)"
end
# Id of the current status
#
# @return [Integer]
def status
backend.status_manager.status.id
end
# Error messages from the error status
#
# @return [Array<String>]
def error_messages
return [] unless backend.status_manager.error?
backend.status_manager.status.messages
end
# @see DInstaller::Manager#progress
def progress
prg = backend.progress
[
prg.message,
prg.total_steps,
prg.current_step,
prg.total_minor_steps,
prg.current_minor_step
].freeze
end
private
# @return [Logger]
attr_reader :logger
# @return [DInstaller::Manager]
attr_reader :backend
# Registers callback to be called when the status changes
#
# The callback will emit a signal
def register_status_callback
backend.status_manager.on_change do
PropertiesChanged(MANAGER_INTERFACE, { "Status" => status }, ["ErrorMessages"])
end
end
# Registers callback to be called when the progress changes
#
# The callback will emit a signal
def register_progress_callback
backend.progress.on_change do
PropertiesChanged(MANAGER_INTERFACE, { "Progress" => progress }, [])
end
end
end
end
end