procon_bypass_man 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +3 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +3 -2
  6. data/bin/dev_api_server.rb +1 -1
  7. data/lib/procon_bypass_man/background/has_server_pool.rb +54 -0
  8. data/lib/procon_bypass_man/background/http_client.rb +70 -0
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/job_runnable.rb +16 -0
  11. data/lib/procon_bypass_man/background/{report_thread.rb → job_runner.rb} +10 -8
  12. data/lib/procon_bypass_man/background/jobs/base_job.rb +12 -0
  13. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +10 -0
  14. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +10 -0
  15. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +10 -0
  16. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +18 -0
  17. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +10 -0
  18. data/lib/procon_bypass_man/background.rb +10 -0
  19. data/lib/procon_bypass_man/boot_message.rb +9 -7
  20. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +0 -0
  21. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +5 -4
  22. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +0 -0
  23. data/lib/procon_bypass_man/buttons_setting_configuration.rb +4 -5
  24. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +16 -7
  25. data/lib/procon_bypass_man/bypass.rb +15 -14
  26. data/lib/procon_bypass_man/commands/connect_device_command.rb +11 -0
  27. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  28. data/lib/procon_bypass_man/commands/send_error_command.rb +18 -0
  29. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +10 -0
  30. data/lib/procon_bypass_man/commands/write_device_id_command.rb +11 -0
  31. data/lib/procon_bypass_man/commands/write_session_id_command.rb +13 -0
  32. data/lib/procon_bypass_man/commands.rb +6 -0
  33. data/lib/procon_bypass_man/configuration.rb +27 -5
  34. data/lib/procon_bypass_man/device_connector.rb +1 -2
  35. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  36. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  37. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  38. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  39. data/lib/procon_bypass_man/procon.rb +6 -12
  40. data/lib/procon_bypass_man/{readonly_procon.rb → procon_reader.rb} +3 -4
  41. data/lib/procon_bypass_man/runner.rb +18 -30
  42. data/lib/procon_bypass_man/uptime.rb +13 -3
  43. data/lib/procon_bypass_man/version.rb +1 -1
  44. data/lib/procon_bypass_man.rb +19 -12
  45. data/project_template/app.rb +2 -2
  46. data/sig/main.rbs +9 -11
  47. metadata +27 -14
  48. data/lib/procon_bypass_man/outbound/base.rb +0 -53
  49. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  50. data/lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb +0 -13
  51. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  52. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  53. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
@@ -1,5 +1,5 @@
1
1
  class ProconBypassMan::Configuration
2
- module ClassAttributes
2
+ module ClassMethods
3
3
  def root
4
4
  config.root
5
5
  end
@@ -23,10 +23,20 @@ class ProconBypassMan::Configuration
23
23
  def cache
24
24
  @@cache_table ||= ProconBypassMan::OnMemoryCache.new
25
25
  end
26
+
27
+ # @return [String]
28
+ def session_id
29
+ ProconBypassMan::WriteSessionIdCommand.execute
30
+ end
31
+
32
+ # @return [String]
33
+ def device_id
34
+ ProconBypassMan::WriteDeviceIdCommand.execute
35
+ end
26
36
  end
27
37
 
28
- attr_reader :api_server
29
- attr_accessor :enable_critical_error_logging
38
+ attr_accessor :enable_critical_error_logging, :raw_setting
39
+ attr_writer :verbose_bypass_log
30
40
 
31
41
  def root=(path)
32
42
  @root = path
@@ -41,8 +51,8 @@ class ProconBypassMan::Configuration
41
51
  end
42
52
  end
43
53
 
44
- def api_server=(api_server)
45
- @api_server = api_server
54
+ def api_servers=(api_servers)
55
+ @api_servers = api_servers
46
56
  return self
47
57
  end
48
58
 
@@ -86,4 +96,16 @@ class ProconBypassMan::Configuration
86
96
  ].compact
87
97
  end
88
98
  end
99
+
100
+ def api_servers
101
+ if !!ENV["API_SERVER"]
102
+ [ENV["API_SERVER"]].reject(&:nil?)
103
+ else
104
+ [@api_servers].flatten.reject(&:nil?)
105
+ end
106
+ end
107
+
108
+ def verbose_bypass_log
109
+ @verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
110
+ end
89
111
  end
@@ -309,8 +309,7 @@ class ProconBypassMan::DeviceConnector
309
309
  end
310
310
  rescue Errno::ENXIO => e
311
311
  # /dev/hidg0 をopenできないときがある
312
- ProconBypassMan.logger.error "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします"
313
- ProconBypassMan.logger.error e
312
+ ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします. #{e.full_message}")
314
313
  system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
315
314
  system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
316
315
  sleep 2
@@ -1,11 +1,12 @@
1
1
  module ProconBypassMan
2
2
  class Counter
3
- attr_accessor :label, :table, :previous_table
3
+ attr_accessor :label, :table, :previous_table, :active
4
4
 
5
5
  def initialize(label: )
6
6
  self.label = label
7
7
  self.table = {}
8
8
  self.previous_table = {}
9
+ self.active = true
9
10
  end
10
11
 
11
12
  # アクティブなバケットは1つだけ
@@ -24,7 +25,7 @@ module ProconBypassMan
24
25
  self
25
26
  end
26
27
 
27
- def formated_previous_table
28
+ def formatted_previous_table
28
29
  t = previous_table.dup
29
30
  start_function = t[:start_function] || 0
30
31
  end_function = t[:end_function] || 0
@@ -32,6 +33,10 @@ module ProconBypassMan
32
33
  eagain_wait_readable_on_write = t[:eagain_wait_readable_on_write] || 0
33
34
  "(#{(end_function / start_function.to_f * 100).floor(1)}%(#{end_function}/#{start_function}), loss: #{eagain_wait_readable_on_read}, #{eagain_wait_readable_on_write})"
34
35
  end
36
+
37
+ def shutdown
38
+ self.active = false
39
+ end
35
40
  end
36
41
 
37
42
  module IOMonitor
@@ -51,14 +56,14 @@ module ProconBypassMan
51
56
  Thread.start do
52
57
  max_output_length = 0
53
58
  loop do
54
- list = @@list.dup
59
+ list = @@list.select(&:active).dup
55
60
  unless list.all? { |x| x&.previous_table.is_a?(Hash) }
56
61
  sleep 0.5
57
62
  next
58
63
  end
59
64
 
60
65
  line = list.map { |counter|
61
- "#{counter.label}(#{counter.formated_previous_table})"
66
+ "#{counter.label}(#{counter.formatted_previous_table})"
62
67
  }.join(", ")
63
68
  max_output_length = line.length
64
69
  sleep 0.7
@@ -1,5 +1,5 @@
1
1
  class ProconBypassMan::Procon
2
- module Data
2
+ module Consts
3
3
  NO_ACTION = "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,40 @@
1
+ class ProconBypassMan::Procon::LayerChanger
2
+ def initialize(binary: )
3
+ @procon_reader = ProconBypassMan::ProconReader.new(binary: binary)
4
+ end
5
+
6
+ # @return [Symbol]
7
+ def next_layer_key
8
+ case
9
+ when pressed?(button: :up)
10
+ :up
11
+ when pressed?(button: :right)
12
+ :right
13
+ when pressed?(button: :left)
14
+ :left
15
+ when pressed?(button: :down)
16
+ :down
17
+ else
18
+ ProconBypassMan.logger.warn("next_layer_key is unknown")
19
+ :up
20
+ end
21
+ end
22
+
23
+ # @return [Boolean]
24
+ def change_layer?
25
+ if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
26
+ raise "prefix_keysが未設定です"
27
+ end
28
+ ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed?(button: b) }.all?
29
+ end
30
+
31
+ # @return [Boolean]
32
+ def pressed_next_layer?
33
+ change_layer? && (pressed?(button: :up) || pressed?(button: :right) || pressed?(button: :left) || pressed?(button: :down))
34
+ end
35
+
36
+ # @return [Boolean]
37
+ def pressed?(button: )
38
+ @procon_reader.pressed.include?(button)
39
+ end
40
+ end
@@ -1,12 +1,14 @@
1
1
  class ProconBypassMan::Procon
2
2
  class UserOperation
3
- include LayerChangeable
4
- extend PressedButtonHelper::Dynamic
5
-
6
3
  attr_reader :binary
7
4
 
5
+ ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
6
+ define_method "pressed_#{button}?" do
7
+ pressed_button?(button)
8
+ end
9
+ end
10
+
8
11
  def initialize(binary)
9
- self.class.compile_if_not_compile_yet!
10
12
  unless binary.encoding.name == ASCII_ENCODING
11
13
  raise "おかしいです"
12
14
  end
@@ -16,20 +18,16 @@ class ProconBypassMan::Procon
16
18
  ZERO_BIT = ["0"].pack("H*").freeze
17
19
  ASCII_ENCODING = "ASCII-8BIT"
18
20
 
19
- # @depilicate
20
- def binary=(binary)
21
- unless binary.encoding.name == ASCII_ENCODING
22
- raise "おかしいです"
23
- end
24
- @binary = binary
25
- end
26
-
27
21
  def set_no_action!
28
22
  binary[3] = ZERO_BIT
29
23
  binary[4] = ZERO_BIT
30
24
  binary[5] = ZERO_BIT
31
25
  end
32
26
 
27
+ def apply_left_analog_stick_cap(cap: )
28
+ binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
29
+ end
30
+
33
31
  def unpress_button(button)
34
32
  return if not pressed_button?(button)
35
33
 
@@ -38,10 +36,6 @@ class ProconBypassMan::Procon
38
36
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
39
37
  end
40
38
 
41
- def apply_left_analog_stick_cap(cap: )
42
- binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
43
- end
44
-
45
39
  def press_button(button)
46
40
  return if pressed_button?(button)
47
41
 
@@ -51,7 +45,7 @@ class ProconBypassMan::Procon
51
45
  end
52
46
 
53
47
  def press_button_only(button)
54
- [ProconBypassMan::Procon::Data::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
48
+ [ProconBypassMan::Procon::Consts::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
55
49
  ButtonCollection.load(button).byte_position
56
50
  byte_position = ButtonCollection.load(button).byte_position
57
51
  value = 2**ButtonCollection.load(button).bit_position
@@ -1,10 +1,9 @@
1
1
  class ProconBypassMan::Procon
2
- require "procon_bypass_man/procon/data"
2
+ require "procon_bypass_man/procon/consts"
3
3
  require "procon_bypass_man/procon/mode_registry"
4
4
  require "procon_bypass_man/procon/macro_registry"
5
- require "procon_bypass_man/procon/layer_changeable"
5
+ require "procon_bypass_man/procon/layer_changer"
6
6
  require "procon_bypass_man/procon/button_collection"
7
- require "procon_bypass_man/procon/pressed_button_helper"
8
7
  require "procon_bypass_man/procon/user_operation"
9
8
  require "procon_bypass_man/procon/flip_cache"
10
9
  require "procon_bypass_man/procon/press_button_aware"
@@ -35,8 +34,9 @@ class ProconBypassMan::Procon
35
34
  end
36
35
 
37
36
  def apply!
38
- if user_operation.change_layer?
39
- @@status[:current_layer_key] = user_operation.next_layer_key if user_operation.pressed_next_layer?
37
+ layer_changer = ProconBypassMan::Procon::LayerChanger.new(binary: user_operation.binary)
38
+ if layer_changer.change_layer?
39
+ @@status[:current_layer_key] = layer_changer.next_layer_key if layer_changer.pressed_next_layer?
40
40
  user_operation.set_no_action!
41
41
  return
42
42
  end
@@ -137,13 +137,7 @@ class ProconBypassMan::Procon
137
137
  end
138
138
  end
139
139
 
140
- b = user_operation.binary
141
- ProconBypassMan.cache.fetch key: 'user_operation.binary', expires_in: 60 do
142
- left_analog_stick = ProconBypassMan::ReadonlyProcon.new(binary: b).left_analog_stick
143
- ProconBypassMan.logger.debug "x: #{left_analog_stick[:x]}, val: #{left_analog_stick[:x].to_s(2)}"
144
- ProconBypassMan.logger.debug "y: #{left_analog_stick[:y]}, val: #{left_analog_stick[:y].to_s(2)}"
145
- end
146
- b
140
+ user_operation.binary
147
141
  end
148
142
 
149
143
  private
@@ -1,15 +1,14 @@
1
- # read
2
- class ProconBypassMan::ReadonlyProcon
1
+ class ProconBypassMan::ProconReader
3
2
  def initialize(binary: )
4
3
  @binary = binary
5
- @user_operation = ProconBypassMan::Procon::UserOperation.new(binary.dup)
6
4
  @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
7
5
  end
8
6
 
9
7
  # @return [Array<Symbol>]
10
8
  def pressed
9
+ aware = ProconBypassMan::PpressButtonAware.new(@binary)
11
10
  pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
12
- acc[button] = @user_operation.pressed_button?(button)
11
+ acc[button] = aware.pressed_button?(button)
13
12
  acc
14
13
  end
15
14
  pressed_table.select { |_key, value| value }.keys
@@ -1,15 +1,20 @@
1
1
  require_relative "io_monitor"
2
2
  require_relative "uptime"
3
3
  require_relative "boot_message"
4
- require_relative "background/report_thread"
4
+ require_relative "background/job_runner"
5
5
 
6
6
  class ProconBypassMan::Runner
7
7
  class InterruptForRestart < StandardError; end
8
8
 
9
- def run
10
- first_negotiation
11
- print_booted_message
9
+ def initialize(gadget: , procon: )
10
+ @gadget = gadget
11
+ @procon = procon
12
+
13
+ ProconBypassMan::PrintBootMessageCommand.execute
14
+ ProconBypassMan::Background::JobRunner.start!
15
+ end
12
16
 
17
+ def run
13
18
  self_read, self_write = IO.pipe
14
19
  %w(TERM INT USR1 USR2).each do |sig|
15
20
  begin
@@ -17,7 +22,7 @@ class ProconBypassMan::Runner
17
22
  self_write.puts(sig)
18
23
  end
19
24
  rescue ArgumentError
20
- ProconBypassMan.logger.error("Signal #{sig} not supported")
25
+ ProconBypassMan::SendErrorCommand.execute(error: "Signal #{sig} not supported")
21
26
  end
22
27
  end
23
28
 
@@ -37,10 +42,10 @@ class ProconBypassMan::Runner
37
42
  ProconBypassMan.logger.info("Reloading config file")
38
43
  begin
39
44
  ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
40
- puts "設定ファイルの再読み込みができました"
41
45
  rescue ProconBypassMan::CouldNotLoadConfigError
42
- ProconBypassMan.logger.error "設定ファイルが不正です。再読み込みができませんでした"
46
+ ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
43
47
  end
48
+ ProconBypassMan::SendReloadConfigEventCommand.execute
44
49
  ProconBypassMan.logger.info("バイパス処理を再開します")
45
50
  rescue Interrupt
46
51
  $will_terminate_token = true
@@ -59,7 +64,7 @@ class ProconBypassMan::Runner
59
64
 
60
65
  def main_loop
61
66
  ProconBypassMan::IOMonitor.start!
62
- ProconBypassMan::Background::Reporter.start!
67
+ ProconBypassMan::Background::JobRunner.start!
63
68
 
64
69
  # gadget => procon
65
70
  # 遅くていい
@@ -76,15 +81,15 @@ class ProconBypassMan::Runner
76
81
  sleep(0.005)
77
82
  rescue ProconBypassMan::Timer::Timeout
78
83
  ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
84
+ monitor1.shutdown
79
85
  puts "10秒経過したのでThread1を終了します"
80
86
  break
81
87
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
82
- ProconBypassMan.logger.error "Proconが切断されました.終了処理を開始します"
88
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
83
89
  Process.kill "TERM", Process.ppid
84
90
  rescue Errno::ETIMEDOUT => e
85
91
  # TODO まれにこれが発生する. 再接続したい
86
- ProconBypassMan::ErrorReporter.report(body: e)
87
- ProconBypassMan.logger.error "Switchとの切断されました.終了処理を開始します"
92
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchと意図せず切断されました.終了処理を開始します. #{e.full_message}")
88
93
  Process.kill "TERM", Process.ppid
89
94
  end
90
95
  ProconBypassMan.logger.info "Thread1を終了します"
@@ -99,10 +104,10 @@ class ProconBypassMan::Runner
99
104
  break if $will_terminate_token
100
105
  bypass.send_procon_to_gadget!
101
106
  rescue EOFError => e
102
- ProconBypassMan.logger.error "Proconと通信ができませんでした.終了処理を開始します"
107
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します. #{e.full_message}")
103
108
  Process.kill "TERM", Process.ppid
104
109
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
105
- ProconBypassMan.logger.error "Proconが切断されました。終了処理を開始します"
110
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します2. #{e.full_message}")
106
111
  Process.kill "TERM", Process.ppid
107
112
  end
108
113
  ProconBypassMan.logger.info "Thread2を終了します"
@@ -134,15 +139,6 @@ class ProconBypassMan::Runner
134
139
  end
135
140
  end
136
141
 
137
- def first_negotiation
138
- @gadget, @procon = ProconBypassMan::DeviceConnector.connect
139
- rescue ProconBypassMan::Timer::Timeout
140
- ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
141
- @gadget&.close
142
- @procon&.close
143
- raise ::ProconBypassMan::EternalConnectionError
144
- end
145
-
146
142
  def handle_signal(sig)
147
143
  ProconBypassMan.logger.info "#{$$}で#{sig}を受け取りました"
148
144
  case sig
@@ -152,12 +148,4 @@ class ProconBypassMan::Runner
152
148
  raise Interrupt
153
149
  end
154
150
  end
155
-
156
- # @return [void]
157
- def print_booted_message
158
- message = ProconBypassMan::BootMessage.new
159
- ProconBypassMan.logger.info(message.to_s)
160
- Thread.new { ProconBypassMan::Reporter.report(body: message.to_hash) }
161
- puts message.to_s
162
- end
163
151
  end
@@ -2,10 +2,20 @@ require "time"
2
2
 
3
3
  module ProconBypassMan
4
4
  class Uptime
5
+ # @return [Integer]
5
6
  def self.from_boot
6
- result = `uptime -s`.chomp
7
- return -1 if result == '' # darwin系だとsオプションが使えない
8
- boot_time = result.to_i
7
+ new(uptime_cmd_result: `uptime -s`.chomp).from_boot
8
+ end
9
+
10
+ # @param [String] uptime_cmd_result
11
+ def initialize(uptime_cmd_result: )
12
+ @result = uptime_cmd_result
13
+ end
14
+
15
+ # @return [Integer]
16
+ def from_boot
17
+ return -1 if @result == '' # darwin系だとsオプションが使えない
18
+ boot_time = Time.parse(@result).to_i
9
19
  return Time.now.to_i - boot_time.to_i
10
20
  rescue => e
11
21
  ProconBypassMan.logger.error(e)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProconBypassMan
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.12"
5
5
  end
@@ -3,6 +3,7 @@ require 'yaml'
3
3
  require "json"
4
4
  require "net/http"
5
5
  require "fileutils"
6
+ require "securerandom"
6
7
 
7
8
  require_relative "procon_bypass_man/version"
8
9
  require_relative "procon_bypass_man/callbacks"
@@ -13,22 +14,20 @@ require_relative "procon_bypass_man/runner"
13
14
  require_relative "procon_bypass_man/processor"
14
15
  require_relative "procon_bypass_man/configuration"
15
16
  require_relative "procon_bypass_man/buttons_setting_configuration"
16
- require_relative "procon_bypass_man/readonly_procon"
17
+ require_relative "procon_bypass_man/procon_reader"
17
18
  require_relative "procon_bypass_man/procon"
18
19
  require_relative "procon_bypass_man/procon/analog_stick"
19
20
  require_relative "procon_bypass_man/procon/analog_stick_cap"
20
- require_relative "procon_bypass_man/outbound/reporter"
21
- require_relative "procon_bypass_man/outbound/error_reporter"
22
- require_relative "procon_bypass_man/outbound/pressed_buttons_reporter"
21
+ require_relative "procon_bypass_man/background"
22
+ require_relative "procon_bypass_man/commands"
23
23
  require_relative "procon_bypass_man/on_memory_cache"
24
24
 
25
25
  STDOUT.sync = true
26
26
  Thread.abort_on_exception = true
27
27
 
28
28
  module ProconBypassMan
29
- extend ProconBypassMan::Configuration::ClassAttributes
29
+ extend ProconBypassMan::Configuration::ClassMethods
30
30
 
31
- class ProConRejected < StandardError; end
32
31
  class CouldNotLoadConfigError < StandardError; end
33
32
  class FirstConnectionError < StandardError; end
34
33
  class EternalConnectionError < StandardError; end
@@ -45,25 +44,27 @@ module ProconBypassMan
45
44
  end
46
45
  end
47
46
 
47
+ # @return [void]
48
48
  def self.run(setting_path: nil, &block)
49
49
  ProconBypassMan.logger.info "PBMを起動しています"
50
50
  puts "PBMを起動しています"
51
51
  buttons_setting_configure(setting_path: setting_path, &block)
52
+ initialize_pbm
52
53
  File.write(pid_path, $$)
53
- Runner.new.run
54
+ ProconBypassMan::WriteSessionIdCommand.execute
55
+ gadget, procon = ProconBypassMan::ConnectDeviceCommand.execute!
56
+ Runner.new(gadget: gadget, procon: procon).run
54
57
  rescue CouldNotLoadConfigError
55
- ProconBypassMan.logger.error "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
56
- puts "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
58
+ ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。設定ファイルの読み込みに失敗しました")
57
59
  FileUtils.rm_rf(ProconBypassMan.pid_path)
58
60
  FileUtils.rm_rf(ProconBypassMan.digest_path)
59
61
  exit 1
60
62
  rescue EternalConnectionError
61
- ProconBypassMan.logger.error "接続の見込みがないのでsleepしまくります"
62
- puts "接続の見込みがないのでsleepしまくります"
63
+ ProconBypassMan::SendErrorCommand.execute(error: "接続の見込みがないのでsleepしまくります")
63
64
  FileUtils.rm_rf(ProconBypassMan.pid_path)
64
65
  sleep(999999999)
65
66
  rescue FirstConnectionError
66
- puts "接続を確立できませんでした。やりなおします。"
67
+ ProconBypassMan::SendErrorCommand.execute(error: "接続を確立できませんでした。やりなおします。")
67
68
  retry
68
69
  end
69
70
 
@@ -73,10 +74,12 @@ module ProconBypassMan
73
74
  @@configuration
74
75
  end
75
76
 
77
+ # @return [ProconBypassMan::Configuration]
76
78
  def self.config
77
79
  @@configuration ||= ProconBypassMan::Configuration.new
78
80
  end
79
81
 
82
+ # @return [void]
80
83
  def self.reset!
81
84
  ProconBypassMan::Procon::MacroRegistry.reset!
82
85
  ProconBypassMan::Procon::ModeRegistry.reset!
@@ -84,4 +87,8 @@ module ProconBypassMan
84
87
  ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
85
88
  ProconBypassMan::IOMonitor.reset!
86
89
  end
90
+
91
+ def self.initialize_pbm
92
+ ProconBypassMan::WriteDeviceIdCommand.execute
93
+ end
87
94
  end
@@ -5,7 +5,7 @@ require 'bundler/inline'
5
5
  gemfile do
6
6
  source 'https://rubygems.org'
7
7
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
8
- gem 'procon_bypass_man', '0.1.11'
8
+ gem 'procon_bypass_man', '0.1.12'
9
9
  gem 'procon_bypass_man-splatoon2', github: 'splaplapla/procon_bypass_man-splatoon2', tag: "0.1.1"
10
10
  end
11
11
 
@@ -13,7 +13,7 @@ ProconBypassMan.configure do |config|
13
13
  config.root = File.expand_path(__dir__)
14
14
  config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
15
15
  config.logger.level = :debug
16
- # pbm.api_server = 'https://...'
16
+ # config.api_servers = ['https://...']
17
17
  config.enable_critical_error_logging = true
18
18
  end
19
19
 
data/sig/main.rbs CHANGED
@@ -8,9 +8,6 @@ interface _Pluginable
8
8
  end
9
9
 
10
10
  module ProconBypassMan
11
- class ProConRejected < StandardError
12
- end
13
-
14
11
  class CouldNotLoadConfigError < StandardError
15
12
  end
16
13
 
@@ -168,7 +165,7 @@ module ProconBypassMan
168
165
  end
169
166
 
170
167
  class ProconBypassMan::Configuration
171
- module ClassAttributes
168
+ module ClassMethods
172
169
  def root: () -> untyped
173
170
 
174
171
  def logger: () -> untyped
@@ -427,10 +424,6 @@ module ProconBypassMan::Procon::PressedButtonHelper
427
424
  module Static
428
425
  def pressed_button?: (untyped button) -> untyped
429
426
  end
430
-
431
- module Dynamic
432
- def compile_if_not_compile_yet!: () -> untyped
433
- end
434
427
  end
435
428
 
436
429
  class ProconBypassMan::Procon
@@ -439,8 +432,6 @@ class ProconBypassMan::Procon
439
432
 
440
433
  include PressedButtonHelper::Static
441
434
 
442
- extend PressedButtonHelper::Dynamic
443
-
444
435
  attr_reader binary: untyped
445
436
 
446
437
  def initialize: (untyped binary) -> untyped
@@ -498,7 +489,14 @@ end
498
489
 
499
490
  module ProconBypassMan
500
491
  class Uptime
501
- def self.from_boot: () -> untyped
492
+ # @return [Integer]
493
+ def self.from_boot: () -> Integer
494
+
495
+ # @param [String] uptime_cmd_result
496
+ def initialize: (uptime_cmd_result: String uptime_cmd_result) -> void
497
+
498
+ # @return [Integer]
499
+ def from_boot: () -> Integer
502
500
  end
503
501
  end
504
502