procon_bypass_man 0.1.13 → 0.1.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +33 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +26 -6
- data/README.md +27 -3
- data/docs/setup_raspi.md +2 -0
- data/docs/setup_raspi.mitamae.rb +7 -8
- data/docs/setup_raspi_by_mitamae.md +37 -1
- data/lib/ext/em_pure_ruby.rb +25 -0
- data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
- data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
- data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
- data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
- data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
- data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
- data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
- data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +5 -4
- data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
- data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
- data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
- data/lib/procon_bypass_man/background.rb +5 -4
- data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +2 -6
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +6 -8
- data/lib/procon_bypass_man/bypass.rb +13 -6
- data/lib/procon_bypass_man/commands/connect_device_command.rb +6 -1
- data/lib/procon_bypass_man/commands/print_boot_message_command.rb +50 -1
- data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
- data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
- data/lib/procon_bypass_man/commands/send_error_command.rb +1 -1
- data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +1 -2
- data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
- data/lib/procon_bypass_man/commands.rb +2 -0
- data/lib/procon_bypass_man/configuration.rb +49 -2
- data/lib/procon_bypass_man/device_connector.rb +2 -1
- data/lib/procon_bypass_man/device_status.rb +44 -0
- data/lib/procon_bypass_man/domains/binary/base.rb +11 -0
- data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
- data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
- data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +23 -0
- data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +80 -0
- data/lib/procon_bypass_man/domains.rb +11 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
- data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
- data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
- data/lib/procon_bypass_man/plugins.rb +11 -0
- data/lib/procon_bypass_man/processor.rb +4 -5
- data/lib/procon_bypass_man/procon/button.rb +11 -0
- data/lib/procon_bypass_man/procon/button_collection.rb +2 -12
- data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
- data/lib/procon_bypass_man/procon/press_button_aware.rb +5 -4
- data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
- data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
- data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
- data/lib/procon_bypass_man/procon.rb +16 -14
- data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
- data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
- data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +24 -0
- data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
- data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
- data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
- data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +38 -0
- data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
- data/lib/procon_bypass_man/runner.rb +4 -4
- data/lib/procon_bypass_man/scheduler.rb +85 -0
- data/lib/procon_bypass_man/support/http_client.rb +102 -0
- data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
- data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
- data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
- data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/pbm_job_client.rb +79 -0
- data/lib/procon_bypass_man.rb +60 -31
- data/procon_bypass_man.gemspec +3 -1
- data/project_template/README.md +10 -5
- data/project_template/app.rb +1 -1
- data/project_template/setting.yml +8 -8
- data/sig/main.rbs +16 -1
- metadata +90 -21
- data/lib/procon_bypass_man/background/http_client.rb +0 -67
- data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
- data/lib/procon_bypass_man/boot_message.rb +0 -44
- data/lib/procon_bypass_man/procon_reader.rb +0 -31
- data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +0 -15
- data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +0 -57
- data/lib/procon_bypass_man/splatoon2/version.rb +0 -7
- data/lib/procon_bypass_man/splatoon2.rb +0 -11
@@ -1,13 +1,14 @@
|
|
1
|
-
class ProconBypassMan::
|
1
|
+
class ProconBypassMan::PressButtonAware
|
2
2
|
def initialize(binary)
|
3
3
|
@binary = binary
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
6
|
+
def pressing_button?(button)
|
7
|
+
button_obj = ProconBypassMan::Procon::Button.new(button)
|
7
8
|
@binary[
|
8
|
-
|
9
|
+
button_obj.byte_position
|
9
10
|
].unpack("H*").first.to_i(16).to_s(2).reverse[
|
10
|
-
|
11
|
+
button_obj.bit_position
|
11
12
|
] == '1'
|
12
13
|
end
|
13
14
|
end
|
@@ -1,77 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# ボタンを押しているか判断するクラス。バイナリの書き換えはしない
|
2
|
+
class ProconBypassMan::Procon::UserOperation
|
3
|
+
attr_reader :binary
|
4
4
|
|
5
|
-
|
6
|
-
define_method "pressed_#{button}?" do
|
7
|
-
pressed_button?(button)
|
8
|
-
end
|
9
|
-
end
|
5
|
+
ASCII_ENCODING = "ASCII-8BIT"
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@binary = binary
|
7
|
+
# @param [String] binary
|
8
|
+
def initialize(binary)
|
9
|
+
unless binary.encoding.name == ASCII_ENCODING
|
10
|
+
raise "おかしいです"
|
16
11
|
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def set_no_action!
|
22
|
-
binary[3] = ZERO_BIT
|
23
|
-
binary[4] = ZERO_BIT
|
24
|
-
binary[5] = ZERO_BIT
|
25
|
-
end
|
13
|
+
@binary = ProconBypassMan::Domains::ProcessingProconBinary.new(binary: binary)
|
14
|
+
end
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
def set_no_action!
|
17
|
+
binary.set_no_action!
|
18
|
+
end
|
30
19
|
|
31
|
-
|
32
|
-
|
20
|
+
def apply_left_analog_stick_cap(cap: )
|
21
|
+
binary.write_as_apply_left_analog_stick_cap(cap: cap)
|
22
|
+
end
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
# @param [Symbol] button
|
25
|
+
def unpress_button(button)
|
26
|
+
return if not pressing_button?(button)
|
27
|
+
binary.write_as_unpress_button(button)
|
28
|
+
end
|
38
29
|
|
39
|
-
|
40
|
-
|
30
|
+
# @param [Symbol] button
|
31
|
+
def press_button(button)
|
32
|
+
return if pressing_button?(button)
|
33
|
+
binary.write_as_press_button(button)
|
34
|
+
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
# @param [Symbol] button
|
37
|
+
def press_button_only(button)
|
38
|
+
binary.write_as_press_button_only(button)
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
binary[3] = no_action_binary[3]
|
54
|
-
binary[4] = no_action_binary[4]
|
55
|
-
binary[5] = no_action_binary[5]
|
56
|
-
end
|
57
|
-
end
|
41
|
+
# @return [void]
|
42
|
+
def merge(target_binary)
|
43
|
+
binary.write_as_merge!(
|
44
|
+
ProconBypassMan::Domains::ProcessingProconBinary.new(binary: target_binary)
|
45
|
+
)
|
46
|
+
end
|
58
47
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
binary[6] = tb[6]
|
65
|
-
binary[7] = tb[7]
|
66
|
-
binary[8] = tb[8]
|
67
|
-
binary[9] = tb[9]
|
68
|
-
binary[10] = tb[10]
|
69
|
-
binary[11] = tb[11]
|
70
|
-
self.binary
|
71
|
-
end
|
48
|
+
# @param [Symbol] button
|
49
|
+
# @return [Boolean]
|
50
|
+
def pressing_button?(button)
|
51
|
+
ProconBypassMan::PressButtonAware.new(@binary.raw).pressing_button?(button)
|
52
|
+
end
|
72
53
|
|
73
|
-
|
74
|
-
|
75
|
-
|
54
|
+
# @param [Array<Symbol>] buttons
|
55
|
+
# @return [Boolean]
|
56
|
+
def pressing_all_buttons?(buttons)
|
57
|
+
aware = ProconBypassMan::PressButtonAware.new(@binary.raw)
|
58
|
+
buttons.all? { |b| aware.pressing_button?(b) }
|
76
59
|
end
|
77
60
|
end
|
@@ -4,13 +4,12 @@ class ProconBypassMan::Procon::AnalogStick
|
|
4
4
|
|
5
5
|
def initialize(binary: )
|
6
6
|
@neutral_position = ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position
|
7
|
-
|
8
|
-
byte6 =
|
9
|
-
byte7 = binary[7].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
|
10
|
-
byte8 = binary[8].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
|
7
|
+
bytes = binary[ProconBypassMan::Procon::ButtonCollection::LEFT_ANALOG_STICK.fetch(:byte_position)]
|
8
|
+
byte6, byte7, byte8 = bytes.each_char.map { |x| x.unpack("H*").first.to_i(16).to_s(2).rjust(8, "0") }
|
11
9
|
|
12
10
|
self.bin_x = "#{byte7[4..7]}#{byte6}"
|
13
11
|
self.bin_y = "#{byte8}#{byte7[0..3]}"
|
12
|
+
freeze
|
14
13
|
end
|
15
14
|
|
16
15
|
def abs_x
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class ProconReader
|
3
|
+
def initialize(binary: )
|
4
|
+
@binary = binary
|
5
|
+
@analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
|
6
|
+
freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [Array<Symbol>]
|
10
|
+
def pressing
|
11
|
+
aware = ProconBypassMan::PressButtonAware.new(@binary)
|
12
|
+
pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
|
13
|
+
acc[button] = aware.pressing_button?(button)
|
14
|
+
acc
|
15
|
+
end
|
16
|
+
pressed_table.select { |_key, value| value }.keys
|
17
|
+
end
|
18
|
+
|
19
|
+
def left_analog_stick
|
20
|
+
{ x: @analog_stick.relative_x, y: @analog_stick.relative_y }
|
21
|
+
end
|
22
|
+
|
23
|
+
def left_analog_stick_by_abs
|
24
|
+
{ x: @analog_stick.abs_x, y: @analog_stick.abs_y }
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{ left_analog_stick: left_analog_stick,
|
29
|
+
left_analog_stick_by_abs: left_analog_stick_by_abs,
|
30
|
+
buttons: pressing,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -20,8 +20,11 @@ class ProconBypassMan::Procon
|
|
20
20
|
end
|
21
21
|
reset!
|
22
22
|
|
23
|
+
# @param [string] binary
|
23
24
|
def initialize(binary)
|
24
|
-
self.user_operation = ProconBypassMan::Procon::UserOperation.new(
|
25
|
+
self.user_operation = ProconBypassMan::Procon::UserOperation.new(
|
26
|
+
binary.dup
|
27
|
+
)
|
25
28
|
end
|
26
29
|
|
27
30
|
def status; @@status[:buttons]; end
|
@@ -43,7 +46,7 @@ class ProconBypassMan::Procon
|
|
43
46
|
|
44
47
|
if ongoing_macro.finished?
|
45
48
|
current_layer.macros.each do |macro_name, options|
|
46
|
-
if options[:if_pressed]
|
49
|
+
if user_operation.pressing_all_buttons?(options[:if_pressed])
|
47
50
|
@@status[:ongoing_macro] = MacroRegistry.load(macro_name)
|
48
51
|
end
|
49
52
|
end
|
@@ -60,7 +63,7 @@ class ProconBypassMan::Procon
|
|
60
63
|
next
|
61
64
|
end
|
62
65
|
|
63
|
-
if options[:if_pressed] && options[:if_pressed]
|
66
|
+
if options[:if_pressed] && user_operation.pressing_all_buttons?(options[:if_pressed])
|
64
67
|
FlipCache.fetch(key: button, expires_in: options[:flip_interval]) do
|
65
68
|
status[button] = !status[button]
|
66
69
|
end
|
@@ -75,7 +78,7 @@ class ProconBypassMan::Procon
|
|
75
78
|
@@status[:ongoing_mode] = ProconBypassMan::Procon::ModeRegistry.load(current_layer.mode)
|
76
79
|
end
|
77
80
|
if(binary = ongoing_mode.next_binary)
|
78
|
-
self.user_operation.merge(
|
81
|
+
self.user_operation.merge([binary].pack("H*"))
|
79
82
|
end
|
80
83
|
return
|
81
84
|
end
|
@@ -83,24 +86,24 @@ class ProconBypassMan::Procon
|
|
83
86
|
status
|
84
87
|
end
|
85
88
|
|
86
|
-
# @return [
|
89
|
+
# @return [ProconBypassMan::Domains::ProcessingProconBinary]
|
87
90
|
def to_binary
|
88
91
|
if ongoing_mode.name != :manual
|
89
|
-
return user_operation.binary
|
92
|
+
return user_operation.binary.raw
|
90
93
|
end
|
91
94
|
|
92
95
|
if ongoing_macro.ongoing?
|
93
|
-
step = ongoing_macro.next_step or return(user_operation.binary)
|
96
|
+
step = ongoing_macro.next_step or return(user_operation.binary.raw)
|
94
97
|
user_operation.press_button_only(step)
|
95
|
-
return user_operation.binary
|
98
|
+
return user_operation.binary.raw
|
96
99
|
end
|
97
100
|
|
98
101
|
current_layer.disables.each do |button|
|
99
102
|
user_operation.unpress_button(button)
|
100
103
|
end
|
101
104
|
|
102
|
-
current_layer.left_analog_stick_caps.each do |
|
103
|
-
if
|
105
|
+
current_layer.left_analog_stick_caps.each do |buttons, options|
|
106
|
+
if buttons.nil? || user_operation.pressing_all_buttons?(buttons)
|
104
107
|
options[:force_neutral]&.each do |force_neutral_button|
|
105
108
|
user_operation.unpress_button(force_neutral_button)
|
106
109
|
end
|
@@ -116,7 +119,7 @@ class ProconBypassMan::Procon
|
|
116
119
|
end
|
117
120
|
|
118
121
|
# 押している時だけ連打
|
119
|
-
if options[:if_pressed] && options[:if_pressed]
|
122
|
+
if options[:if_pressed] && user_operation.pressing_all_buttons?(options[:if_pressed])
|
120
123
|
if !status[button]
|
121
124
|
user_operation.unpress_button(button)
|
122
125
|
end
|
@@ -128,16 +131,15 @@ class ProconBypassMan::Procon
|
|
128
131
|
end
|
129
132
|
|
130
133
|
current_layer.remaps.each do |from_button, to_buttons|
|
131
|
-
if user_operation.
|
134
|
+
if user_operation.pressing_button?(from_button)
|
132
135
|
user_operation.unpress_button(from_button)
|
133
|
-
# TODO 2重でpressしないようにしたい
|
134
136
|
to_buttons[:to].each do |to_button|
|
135
137
|
user_operation.press_button(to_button)
|
136
138
|
end
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
140
|
-
user_operation.binary
|
142
|
+
user_operation.binary.raw
|
141
143
|
end
|
142
144
|
|
143
145
|
private
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class ActionUnexpectedError < StandardError; end
|
4
|
+
class NeedPbmVersionError < ActionUnexpectedError; end
|
5
|
+
|
6
|
+
class BaseAction
|
7
|
+
attr_accessor :pbm_job_uuid
|
8
|
+
|
9
|
+
# @param [String] pbm_job_uuid
|
10
|
+
def initialize(pbm_job_uuid: )
|
11
|
+
self.pbm_job_uuid = pbm_job_uuid
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [void]
|
15
|
+
def action_content(_args)
|
16
|
+
raise NotImplementedError, nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [Hash] args
|
20
|
+
# @return [void]
|
21
|
+
def run!(job_args: )
|
22
|
+
before_action_callback
|
23
|
+
action_content(args: job_args)
|
24
|
+
after_action_callback
|
25
|
+
rescue => e
|
26
|
+
be_failed
|
27
|
+
ProconBypassMan::SendErrorCommand.execute(error: e)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @return [void]
|
33
|
+
def before_action_callback; end
|
34
|
+
# @return [void]
|
35
|
+
def after_action_callback; end
|
36
|
+
|
37
|
+
# @return [void]
|
38
|
+
def be_failed
|
39
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :failed)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [void]
|
43
|
+
def be_in_progress
|
44
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :in_progress)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [void]
|
48
|
+
def be_processed
|
49
|
+
ProconBypassMan::UpdateRemotePbmActionStatusCommand.new(pbm_job_uuid: pbm_job_uuid).execute(to_status: :processed)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class ChangePbmVersionAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(args: )
|
6
|
+
require "pbmenv"
|
7
|
+
ProconBypassMan.logger.info "execute ChangePbmVersionAction!"
|
8
|
+
pbm_version = args["pbm_version"] or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "pbm_versionが必要です, #{args.inspect}")
|
9
|
+
Pbmenv.install(pbm_version)
|
10
|
+
Pbmenv.use(pbm_version)
|
11
|
+
`reboot` # symlinkの参照先が変わるのでrebootする必要がある
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def before_action_callback
|
17
|
+
be_processed
|
18
|
+
end
|
19
|
+
|
20
|
+
def after_action_callback
|
21
|
+
# no-op
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class UpdateRemotePbmActionStatusCommand
|
3
|
+
# @param [String] pbm_job_uuid
|
4
|
+
def initialize(pbm_job_uuid: )
|
5
|
+
@pbm_job_uuid = pbm_job_uuid
|
6
|
+
end
|
7
|
+
|
8
|
+
# @param [String] to_status
|
9
|
+
# @return [void]
|
10
|
+
def execute(to_status: )
|
11
|
+
ProconBypassMan::UpdateRemotePbmActionStatusHttpClient.new(
|
12
|
+
path: path,
|
13
|
+
server_pool: ProconBypassMan.config.server_pool,
|
14
|
+
).put(to_status: to_status)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def path
|
21
|
+
"/api/devices/#{ProconBypassMan.device_id}/pbm_jobs/#{@pbm_job_uuid}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class RebootOsAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(_args)
|
6
|
+
ProconBypassMan.logger.info "execute RebootOsAction!"
|
7
|
+
`reboot`
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def before_action_callback
|
13
|
+
be_processed
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_action_callback
|
17
|
+
# no-op
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class RestorePbmSettingAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(args: )
|
6
|
+
require "pbmenv"
|
7
|
+
ProconBypassMan.logger.info "execute RestorePbmSettingAction!"
|
8
|
+
setting = args.dig("setting") or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "settingが必要です, #{args.inspect}")
|
9
|
+
File.write(
|
10
|
+
ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
11
|
+
setting.to_yaml,
|
12
|
+
)
|
13
|
+
ProconBypassMan.hot_reload!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def before_action_callback
|
19
|
+
be_in_progress
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_action_callback
|
23
|
+
be_processed
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
class StopPbmAction < BaseAction
|
4
|
+
|
5
|
+
def action_content(_args)
|
6
|
+
ProconBypassMan.logger.info "execute StopPbmAction!"
|
7
|
+
Process.kill("TERM", ProconBypassMan.pid)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def before_action_callback
|
13
|
+
be_processed
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_action_callback
|
17
|
+
# no-op
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class RemotePbmActionObject
|
3
|
+
# valueobjectがvalidatorの責務も持っている. 今度分離する
|
4
|
+
class ValidationError < StandardError; end
|
5
|
+
class MustBeNotNilError < ValidationError; end
|
6
|
+
class NonSupportAction < ValidationError; end
|
7
|
+
|
8
|
+
attr_accessor :action, :status, :uuid, :created_at, :job_args
|
9
|
+
|
10
|
+
# @param [String] action
|
11
|
+
# @param [String] status
|
12
|
+
# @param [String] #uuid
|
13
|
+
# @param [Time] created_at
|
14
|
+
# @return [Hash] job_args
|
15
|
+
def initialize(action: , status:, uuid:, created_at:, job_args: )
|
16
|
+
self.action = action
|
17
|
+
self.status = status
|
18
|
+
self.uuid = uuid
|
19
|
+
self.created_at = created_at
|
20
|
+
self.job_args = job_args
|
21
|
+
|
22
|
+
freeze
|
23
|
+
end
|
24
|
+
|
25
|
+
# @raise [MustBeNotNilError]
|
26
|
+
# @raise [NonSupportAction]
|
27
|
+
# @return [void]
|
28
|
+
def validate!
|
29
|
+
self.action or raise MustBeNotNilError, "actionは値が必須です"
|
30
|
+
self.status or raise MustBeNotNilError, "statusは値が必須です"
|
31
|
+
self.uuid or raise MustBeNotNilError, "uuidは値が必須です"
|
32
|
+
|
33
|
+
unless ProconBypassMan::RemotePbmAction::ACTIONS.include?(action)
|
34
|
+
raise NonSupportAction, "知らないアクションです"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
module RemotePbmAction
|
3
|
+
require "procon_bypass_man/remote_pbm_action/base_action"
|
4
|
+
require "procon_bypass_man/remote_pbm_action/change_pbm_version_action"
|
5
|
+
require "procon_bypass_man/remote_pbm_action/reboot_os_action"
|
6
|
+
require "procon_bypass_man/remote_pbm_action/stop_pbm_action"
|
7
|
+
require "procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb"
|
8
|
+
require "procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command"
|
9
|
+
|
10
|
+
ACTION_CHANGE_PBM_VERSION = "change_pbm_version"
|
11
|
+
ACTION_REBOOT_OS = "reboot_os"
|
12
|
+
ACTION_STOP_PBM = "stop_pbm"
|
13
|
+
ACTION_RESTORE_SETTING = "restore_pbm_setting"
|
14
|
+
|
15
|
+
ACTIONS = [
|
16
|
+
ACTION_CHANGE_PBM_VERSION,
|
17
|
+
ACTION_REBOOT_OS,
|
18
|
+
ACTION_STOP_PBM,
|
19
|
+
ACTION_RESTORE_SETTING,
|
20
|
+
]
|
21
|
+
|
22
|
+
STATUS_FAILED = :failed
|
23
|
+
STATUS_IN_PROGRESS = :in_progress
|
24
|
+
STATUS_PROCESSED = :processed
|
25
|
+
|
26
|
+
ACTION_STATUSES = [
|
27
|
+
STATUS_FAILED,
|
28
|
+
STATUS_IN_PROGRESS,
|
29
|
+
STATUS_PROCESSED,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative "io_monitor"
|
2
|
-
require_relative "boot_message"
|
3
2
|
|
4
3
|
class ProconBypassMan::Runner
|
5
4
|
class InterruptForRestart < StandardError; end
|
@@ -27,10 +26,11 @@ class ProconBypassMan::Runner
|
|
27
26
|
|
28
27
|
loop do
|
29
28
|
$will_terminate_token = false
|
30
|
-
#
|
29
|
+
# NOTE メインプロセスではThreadをいくつか起動しているので念のためパフォーマンスを優先するためにforkしていく
|
31
30
|
main_loop_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
|
32
31
|
|
33
32
|
begin
|
33
|
+
# TODO 小プロセスが消滅した時に、メインプロセスは生き続けてしまい、何もできなくなる問題がある
|
34
34
|
while(readable_io = IO.select([self_read]))
|
35
35
|
signal = readable_io.first[0].gets.strip
|
36
36
|
handle_signal(signal)
|
@@ -39,14 +39,14 @@ class ProconBypassMan::Runner
|
|
39
39
|
$will_terminate_token = true
|
40
40
|
Process.kill("TERM", main_loop_pid)
|
41
41
|
Process.wait
|
42
|
-
ProconBypassMan.
|
42
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "Reloading config file")
|
43
43
|
begin
|
44
44
|
ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
|
45
45
|
ProconBypassMan::SendReloadConfigEventCommand.execute
|
46
46
|
rescue ProconBypassMan::CouldNotLoadConfigError
|
47
47
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
|
48
48
|
end
|
49
|
-
ProconBypassMan.
|
49
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "バイパス処理を再開します")
|
50
50
|
rescue Interrupt
|
51
51
|
$will_terminate_token = true
|
52
52
|
Process.kill("TERM", main_loop_pid)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Scheduler
|
3
|
+
class Schedule
|
4
|
+
attr_accessor :klass, :args, :interval, :next_enqueue_at
|
5
|
+
|
6
|
+
# @param [any] klass
|
7
|
+
# @param [Array] args
|
8
|
+
# @param [Integer] interval
|
9
|
+
def initialize(klass: , args: , interval: )
|
10
|
+
self.klass = klass
|
11
|
+
self.args = args
|
12
|
+
self.interval = interval
|
13
|
+
self.next_enqueue_at = Time.now
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [void]
|
17
|
+
def enqueue
|
18
|
+
klass.perform_async(*unwrap_args(args))
|
19
|
+
set_next_enqueue_at!
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [boolean]
|
23
|
+
def past_interval?
|
24
|
+
next_enqueue_at < Time.now
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @return [void]
|
30
|
+
def set_next_enqueue_at!
|
31
|
+
self.next_enqueue_at = Time.now + interval
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Array] args
|
35
|
+
# @return [void]
|
36
|
+
def unwrap_args(args)
|
37
|
+
args.map do |arg|
|
38
|
+
case arg
|
39
|
+
when Proc
|
40
|
+
arg.call
|
41
|
+
else
|
42
|
+
arg
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Hash]
|
49
|
+
def self.schedules
|
50
|
+
@@schedules
|
51
|
+
end
|
52
|
+
|
53
|
+
@@schedules = {}
|
54
|
+
|
55
|
+
def self.start!
|
56
|
+
register_schedules
|
57
|
+
|
58
|
+
@@thread = Thread.start do
|
59
|
+
loop do
|
60
|
+
schedules.each do |_key, schedule|
|
61
|
+
if schedule.past_interval?
|
62
|
+
schedule.enqueue
|
63
|
+
end
|
64
|
+
end
|
65
|
+
sleep 10
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.register_schedules
|
71
|
+
register(
|
72
|
+
schedule: Schedule.new(
|
73
|
+
klass: ProconBypassMan::SyncDeviceStatsJob,
|
74
|
+
args: [->{ ProconBypassMan::DeviceStatus.current }],
|
75
|
+
interval: 60,
|
76
|
+
)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param [Schedule] schedule
|
81
|
+
def self.register(schedule: )
|
82
|
+
schedules[schedule.klass] = schedule
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|