procon_bypass_man 0.1.10 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +15 -12
  6. data/README.md +13 -9
  7. data/bin/console +4 -0
  8. data/bin/{report_receive_server.rb → dev_api_server.rb} +8 -1
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/job_runner.rb +45 -0
  11. data/lib/procon_bypass_man/background/jobs/base_job.rb +7 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  14. data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +16 -0
  15. data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +29 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +12 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +11 -0
  18. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +15 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +11 -0
  22. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  23. data/lib/procon_bypass_man/background.rb +14 -0
  24. data/lib/procon_bypass_man/boot_message.rb +16 -8
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +34 -29
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +5 -4
  27. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +0 -0
  28. data/lib/procon_bypass_man/buttons_setting_configuration.rb +8 -7
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +20 -2
  30. data/lib/procon_bypass_man/bypass.rb +15 -15
  31. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  32. data/lib/procon_bypass_man/commands/connect_device_command.rb +16 -0
  33. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  34. data/lib/procon_bypass_man/commands/run_local_shell_command.rb +6 -0
  35. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +19 -0
  36. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  37. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  38. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  39. data/lib/procon_bypass_man/commands/write_session_id_command.rb +7 -0
  40. data/lib/procon_bypass_man/commands.rb +8 -0
  41. data/lib/procon_bypass_man/configuration.rb +48 -8
  42. data/lib/procon_bypass_man/device_connector.rb +33 -26
  43. data/lib/procon_bypass_man/device_status.rb +44 -0
  44. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  45. data/lib/procon_bypass_man/procon/analog_stick.rb +31 -0
  46. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +9 -32
  47. data/lib/procon_bypass_man/procon/button_collection.rb +1 -0
  48. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  49. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  50. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  51. data/lib/procon_bypass_man/procon.rb +6 -10
  52. data/lib/procon_bypass_man/procon_reader.rb +31 -0
  53. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  54. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +21 -0
  55. data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
  56. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +17 -0
  57. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +17 -0
  58. data/lib/procon_bypass_man/remote_pbm_action.rb +31 -0
  59. data/lib/procon_bypass_man/runner.rb +14 -112
  60. data/lib/procon_bypass_man/scheduler.rb +92 -0
  61. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +15 -0
  62. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +15 -0
  63. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +15 -0
  64. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +15 -0
  65. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +57 -0
  66. data/lib/procon_bypass_man/splatoon2/version.rb +7 -0
  67. data/lib/procon_bypass_man/splatoon2.rb +11 -0
  68. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  69. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  70. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  71. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  72. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  73. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  74. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  75. data/lib/procon_bypass_man/support/server_pool.rb +42 -0
  76. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  77. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  78. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  79. data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
  80. data/lib/procon_bypass_man/version.rb +1 -1
  81. data/lib/procon_bypass_man.rb +57 -20
  82. data/procon_bypass_man.gemspec +3 -3
  83. data/project_template/README.md +18 -11
  84. data/project_template/app.rb +3 -4
  85. data/project_template/web.rb +1 -1
  86. data/sig/{README.rb → README.md} +0 -0
  87. data/sig/main.rbs +12 -13
  88. metadata +82 -26
  89. data/examples/practical/app.rb +0 -21
  90. data/examples/practical/setting.yml +0 -24
  91. data/lib/procon_bypass_man/analog_stick_position.rb +0 -8
  92. data/lib/procon_bypass_man/outbound/base.rb +0 -40
  93. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  94. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  95. data/lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb +0 -13
  96. data/lib/procon_bypass_man/procon/debug_dumper.rb +0 -17
  97. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  98. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  99. data/lib/procon_bypass_man/uptime.rb +0 -15
@@ -1,8 +1,10 @@
1
- require "procon_bypass_man/configuration/validator"
2
- require "procon_bypass_man/configuration/loader"
3
- require "procon_bypass_man/configuration/layer"
1
+ require "procon_bypass_man/buttons_setting_configuration/validator"
2
+ require "procon_bypass_man/buttons_setting_configuration/loader"
3
+ require "procon_bypass_man/buttons_setting_configuration/layer"
4
4
 
5
5
  module ProconBypassMan
6
+ class AnalogStickPosition < Struct.new(:x, :y); end
7
+
6
8
  class ButtonsSettingConfiguration
7
9
  attr_accessor :layers,
8
10
  :setting_path,
@@ -40,7 +42,6 @@ module ProconBypassMan
40
42
  'manual'
41
43
  end
42
44
  end
43
- MODES = [:manual]
44
45
  def layer(direction, mode: ManualMode, &block)
45
46
  mode_name = case mode
46
47
  when String
@@ -50,7 +51,7 @@ module ProconBypassMan
50
51
  else
51
52
  mode.name.to_sym
52
53
  end
53
- unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
54
+ unless ([ManualMode.name.to_sym] + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
54
55
  raise("#{mode_name} mode is unknown")
55
56
  end
56
57
 
@@ -76,7 +77,7 @@ module ProconBypassMan
76
77
  end
77
78
 
78
79
  def set_neutral_position(x, y)
79
- self.neutral_position = AnalogStickPosition.new(x: x, y: y)
80
+ self.neutral_position = AnalogStickPosition.new(x, y).freeze
80
81
  self
81
82
  end
82
83
 
@@ -94,7 +95,7 @@ module ProconBypassMan
94
95
  left: Layer.new,
95
96
  right: Layer.new,
96
97
  }
97
- @neutral_position = AnalogStickPosition.new(x: 2124, y: 1808)
98
+ @neutral_position = AnalogStickPosition.new(2124, 1808).freeze
98
99
  end
99
100
  end
100
101
  end
@@ -10,11 +10,29 @@ class ProconBypassMan::Bypass
10
10
  set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
11
 
12
12
  def log_send_gadget_to_procon
13
- ProconBypassMan.logger.debug { ">>> #{bypass_status.to_text}" }
13
+ if ProconBypassMan.config.verbose_bypass_log
14
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
15
+ else
16
+ ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
17
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  def log_procon_to_gadget
17
- ProconBypassMan.logger.debug { "<<< #{bypass_status.to_text}" }
23
+ if ProconBypassMan.config.verbose_bypass_log
24
+ ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
25
+ else
26
+ ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
27
+ ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
28
+ end
29
+ end
30
+
31
+ ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
32
+ ProconBypassMan::ReportPressedButtonsJob.perform_async(
33
+ ProconBypassMan::ProconReader.new(binary: bypass_value.binary).to_hash
34
+ )
35
+ end
18
36
  end
19
37
  end
20
38
  end
@@ -3,13 +3,13 @@ require "procon_bypass_man/bypass/usb_hid_logger"
3
3
  class ProconBypassMan::Bypass
4
4
  include ProconBypassMan::Bypass::UsbHidLogger
5
5
 
6
- class BypassStatus < Struct.new(:binary, :sent)
6
+ class BypassValue < Struct.new(:binary, :sent)
7
7
  def to_text
8
8
  "#{binary.unpack("H*").first} #{'x' unless sent}"
9
9
  end
10
10
  end
11
11
 
12
- attr_accessor :gadget, :procon, :monitor, :bypass_status
12
+ attr_accessor :gadget, :procon, :monitor, :bypass_value
13
13
 
14
14
  def initialize(gadget: , procon: , monitor: )
15
15
  self.gadget = gadget
@@ -21,14 +21,14 @@ class ProconBypassMan::Bypass
21
21
  def send_gadget_to_procon!
22
22
  monitor.record(:start_function)
23
23
  input = nil
24
- self.bypass_status = BypassStatus.new(input, sent = false)
24
+ self.bypass_value = BypassValue.new(input, sent = false)
25
25
 
26
- run_callbacks :send_gadget_to_procon do
26
+ run_callbacks(:send_gadget_to_procon) do
27
27
  begin
28
- return if $will_terminate_token
29
- # TODO blocking readにしたいが、接続時のフェーズによって長さが違宇野で厳しい
28
+ break if $will_terminate_token
29
+ # TODO blocking readにしたいが、接続時のフェーズによって長さが違うので厳しい
30
30
  input = self.gadget.read_nonblock(64)
31
- self.bypass_status.binary = input
31
+ self.bypass_value.binary = input
32
32
  rescue IO::EAGAINWaitReadable
33
33
  monitor.record(:eagain_wait_readable_on_read)
34
34
  sleep(0.001)
@@ -37,10 +37,10 @@ class ProconBypassMan::Bypass
37
37
 
38
38
  begin
39
39
  self.procon.write_nonblock(input)
40
- self.bypass_status.sent = true
40
+ self.bypass_value.sent = true
41
41
  rescue IO::EAGAINWaitReadable
42
42
  monitor.record(:eagain_wait_readable_on_write)
43
- return
43
+ break
44
44
  end
45
45
  end
46
46
 
@@ -50,18 +50,19 @@ class ProconBypassMan::Bypass
50
50
  def send_procon_to_gadget!
51
51
  monitor.record(:start_function)
52
52
  output = nil
53
- self.bypass_status = BypassStatus.new(output, sent = false)
53
+ self.bypass_value = BypassValue.new(output, sent = false)
54
54
 
55
55
  run_callbacks(:send_procon_to_gadget) do
56
56
  begin
57
- return if $will_terminate_token
57
+ break if $will_terminate_token
58
58
  Timeout.timeout(1) do
59
59
  output = self.procon.read(64)
60
- self.bypass_status.binary = output
60
+ self.bypass_value.binary = output
61
61
  end
62
62
  rescue Timeout::Error
63
63
  ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
64
64
  ProconBypassMan.error_logger.error { "read timeout! do sleep. by send_procon_to_gadget!" }
65
+ ProconBypassMan::SendErrorCommand.execute(error: "read timeout! do sleep. by send_procon_to_gadget!")
65
66
  monitor.record(:eagain_wait_readable_on_read)
66
67
  retry
67
68
  rescue IO::EAGAINWaitReadable
@@ -72,12 +73,11 @@ class ProconBypassMan::Bypass
72
73
  end
73
74
 
74
75
  begin
75
- # ProconBypassMan::Procon::DebugDumper.new(binary: output).dump_analog_sticks
76
76
  self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
77
- self.bypass_status.sent = true
77
+ self.bypass_value.sent = true
78
78
  rescue IO::EAGAINWaitReadable
79
79
  monitor.record(:eagain_wait_readable_on_write)
80
- return
80
+ break
81
81
  end
82
82
  end
83
83
  monitor.record(:end_function)
@@ -0,0 +1,86 @@
1
+ class ProconBypassMan::BypassCommand
2
+ include ProconBypassMan::SignalHandler
3
+
4
+ def initialize(gadget:, procon:)
5
+ @gadget = gadget
6
+ @procon = procon
7
+
8
+ ProconBypassMan::IOMonitor.start!
9
+ ProconBypassMan::Background::JobRunner.queue.clear # forkしたときに残留物も移ってしまうため
10
+ ProconBypassMan::Background::JobRunner.start!
11
+ end
12
+
13
+ def execute
14
+ self_read, self_write = IO.pipe
15
+ %w(TERM INT).each do |sig|
16
+ begin
17
+ trap sig do
18
+ self_write.puts(sig)
19
+ end
20
+ rescue ArgumentError
21
+ puts "プロセスでSignal #{sig} not supported"
22
+ end
23
+ end
24
+
25
+ # gadget => procon
26
+ # 遅くていい
27
+ monitor1 = ProconBypassMan::IOMonitor.new(label: "switch -> procon")
28
+ monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
29
+ ProconBypassMan.logger.info "Thread1を起動します"
30
+ t1 = Thread.new do
31
+ timer = ProconBypassMan::SafeTimeout.new(timeout: Time.now + 10)
32
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
33
+ loop do
34
+ break if $will_terminate_token
35
+ timer.throw_if_timeout!
36
+ bypass.send_gadget_to_procon!
37
+ sleep(0.005)
38
+ rescue ProconBypassMan::SafeTimeout::Timeout
39
+ ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
40
+ monitor1.shutdown
41
+ puts "10秒経過したのでThread1を終了します"
42
+ break
43
+ rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
44
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
45
+ Process.kill "TERM", Process.ppid
46
+ rescue Errno::ETIMEDOUT => e
47
+ # TODO まれにこれが発生する. 再接続したい
48
+ ProconBypassMan::SendErrorCommand.execute(error: "Switchと意図せず切断されました.終了処理を開始します. #{e.full_message}")
49
+ Process.kill "TERM", Process.ppid
50
+ end
51
+ ProconBypassMan.logger.info "Thread1を終了します"
52
+ end
53
+
54
+ # procon => gadget
55
+ # シビア
56
+ ProconBypassMan.logger.info "Thread2を起動します"
57
+ t2 = Thread.new do
58
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
59
+ loop do
60
+ break if $will_terminate_token
61
+ bypass.send_procon_to_gadget!
62
+ rescue EOFError => e
63
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します. #{e.full_message}")
64
+ Process.kill "TERM", Process.ppid
65
+ rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
66
+ ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します2. #{e.full_message}")
67
+ Process.kill "TERM", Process.ppid
68
+ end
69
+ ProconBypassMan.logger.info "Thread2を終了します"
70
+ end
71
+
72
+ ProconBypassMan.logger.info "子プロセスでgraceful shutdownの準備ができました"
73
+ begin
74
+ while(readable_io = IO.select([self_read]))
75
+ signal = readable_io.first[0].gets.strip
76
+ handle_signal(signal)
77
+ end
78
+ rescue Interrupt
79
+ $will_terminate_token = true
80
+ [t1, t2].each(&:join)
81
+ @gadget&.close
82
+ @procon&.close
83
+ exit 1
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,16 @@
1
+ class ProconBypassMan::ConnectDeviceCommand
2
+ # @return [void]
3
+ def self.execute!
4
+ gadget, procon = ProconBypassMan::DeviceConnector.connect
5
+ rescue ProconBypassMan::DeviceConnector::NotFoundProconError => e
6
+ ProconBypassMan.logger.error e
7
+ gadget&.close
8
+ procon&.close
9
+ raise ProconBypassMan::NotFoundProconError
10
+ rescue ProconBypassMan::SafeTimeout::Timeout
11
+ ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
12
+ gadget&.close
13
+ procon&.close
14
+ raise ::ProconBypassMan::EternalConnectionError
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class ProconBypassMan::PrintBootMessageCommand
2
+ # @return [void]
3
+ def self.execute
4
+ message = ProconBypassMan::BootMessage.new
5
+ ProconBypassMan::ReportBootJob.perform_async(message.to_hash)
6
+ ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
7
+ puts message.to_s
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class ProconBypassMan::RunLocalShellCommand
2
+ class LocalCommandError < StandardError; end
3
+
4
+ def self.execute(action: , uuid: )
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ class ProconBypassMan::RunRemotePbmActionDispatchCommand
2
+ # @param [String] action
3
+ # @param [String] uuid
4
+ # @return [void]
5
+ def self.execute(action: , uuid: , job_args: )
6
+ case action
7
+ when ProconBypassMan::RemotePbmAction::ACTION_CHANGE_PBM_VERSION
8
+ ProconBypassMan::RemotePbmAction::ChangePbmVersionAction.new(pbm_job_uuid: uuid).run!(job_args: job_args)
9
+ when ProconBypassMan::RemotePbmAction::ACTION_STOP_PBM
10
+ ProconBypassMan::RemotePbmAction::StopPbmAction.new(pbm_job_uuid: uuid).run!(job_args: {})
11
+ when ProconBypassMan::RemotePbmAction::ACTION_REBOOT_OS
12
+ ProconBypassMan::RemotePbmAction::RebootOsAction.new(pbm_job_uuid: uuid).run!(job_args: {})
13
+ else
14
+ ProconBypassMan::SendErrorCommand.execute(error: "#{action}は対応していないアクションです")
15
+ end
16
+ rescue ProconBypassMan::RemotePbmAction::ActionUnexpectedError => e
17
+ ProconBypassMan::SendErrorCommand.execute(error: e)
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class ProconBypassMan::SendErrorCommand
2
+ # @param [String, Hash, Exception] error
3
+ # @return [void]
4
+ def self.execute(error: )
5
+ body =
6
+ case error
7
+ when String, Hash
8
+ error
9
+ else
10
+ error.full_message
11
+ end
12
+
13
+ ProconBypassMan.logger.error body
14
+ ProconBypassMan.error_logger.error body
15
+ puts body
16
+
17
+ ProconBypassMan::ReportErrorJob.perform(error)
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::SendReloadConfigEventCommand
2
+ # @return [void]
3
+ def self.execute
4
+ puts "設定ファイルの再読み込みができました"
5
+ ProconBypassMan.logger.info "設定ファイルの再読み込みができました"
6
+ ProconBypassMan::ReportReloadConfigJob.perform_async(
7
+ ProconBypassMan.config.raw_setting
8
+ )
9
+ end
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ class ProconBypassMan::WriteDeviceIdCommand
2
+ # @return [String]
3
+ def self.execute
4
+ path = "#{ProconBypassMan.root}/device_id"
5
+ if(sid = File.read(path))
6
+ return sid
7
+ end
8
+ rescue Errno::ENOENT
9
+ File.write(path, "m_#{SecureRandom.uuid}")
10
+ return SecureRandom.uuid
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class ProconBypassMan::WriteSessionIdCommand
2
+ # @return [String] session_id ラズパイが起動してからshutdownするまで同じ文字列を返す
3
+ # 起動すると/tmp がなくなる前提の実装
4
+ def self.execute
5
+ @@session_id ||= "s_#{SecureRandom.uuid}"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require "procon_bypass_man/commands/print_boot_message_command"
2
+ require "procon_bypass_man/commands/write_session_id_command"
3
+ require "procon_bypass_man/commands/write_device_id_command"
4
+ require "procon_bypass_man/commands/send_reload_config_event_command"
5
+ require "procon_bypass_man/commands/send_error_command"
6
+ require "procon_bypass_man/commands/connect_device_command"
7
+ require "procon_bypass_man/commands/bypass_command"
8
+ require "procon_bypass_man/commands/run_remote_pbm_action_dispatch_command"
@@ -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
@@ -16,6 +16,11 @@ class ProconBypassMan::Configuration
16
16
  @@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
17
17
  end
18
18
 
19
+ # @return [Integer]
20
+ def pid
21
+ File.read(pid_path).to_i
22
+ end
23
+
19
24
  def digest_path
20
25
  config.digest_path
21
26
  end
@@ -23,10 +28,20 @@ class ProconBypassMan::Configuration
23
28
  def cache
24
29
  @@cache_table ||= ProconBypassMan::OnMemoryCache.new
25
30
  end
31
+
32
+ # @return [String]
33
+ def session_id
34
+ ProconBypassMan::WriteSessionIdCommand.execute
35
+ end
36
+
37
+ # @return [String]
38
+ def device_id
39
+ ENV["DEBUG_DEVICE_ID"] || ProconBypassMan::WriteDeviceIdCommand.execute
40
+ end
26
41
  end
27
42
 
28
- attr_reader :api_server
29
43
  attr_accessor :enable_critical_error_logging
44
+ attr_writer :verbose_bypass_log, :raw_setting
30
45
 
31
46
  def root=(path)
32
47
  @root = path
@@ -41,8 +56,8 @@ class ProconBypassMan::Configuration
41
56
  end
42
57
  end
43
58
 
44
- def api_server=(api_server)
45
- @api_server = api_server
59
+ def api_servers=(api_servers)
60
+ @api_servers = api_servers
46
61
  return self
47
62
  end
48
63
 
@@ -65,11 +80,10 @@ class ProconBypassMan::Configuration
65
80
 
66
81
  def error_logger
67
82
  if enable_critical_error_logging
68
- @@error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
83
+ @error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
69
84
  else
70
85
  Logger.new(File.open("/dev/null"))
71
86
  end
72
- self
73
87
  end
74
88
 
75
89
  def digest_path
@@ -81,10 +95,36 @@ class ProconBypassMan::Configuration
81
95
  if !!ENV["INTERNAL_API_SERVER"]
82
96
  [ENV["INTERNAL_API_SERVER"]]
83
97
  else
84
- [ ENV["INTERNAL_API_SERVER"],
85
- 'http://localhost:9090',
98
+ [ 'http://localhost:9090',
86
99
  'http://localhost:8080',
87
100
  ].compact
88
101
  end
89
102
  end
103
+
104
+ # @return [Array<ProconBypassMan::ServerPool>]
105
+ def internal_server_pool
106
+ @internal_server_pool ||= ProconBypassMan::ServerPool.new(servers: internal_api_servers)
107
+ end
108
+
109
+ # @return [Array<ProconBypassMan::ServerPool>]
110
+ def server_pool
111
+ @server_pool ||= ProconBypassMan::ServerPool.new(servers: api_servers)
112
+ end
113
+
114
+ # @return [Array<String>]
115
+ def api_servers
116
+ if !!ENV["API_SERVER"]
117
+ [ENV["API_SERVER"]].reject(&:nil?)
118
+ else
119
+ [@api_servers].flatten.reject(&:nil?)
120
+ end
121
+ end
122
+
123
+ def verbose_bypass_log
124
+ @verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
125
+ end
126
+
127
+ def raw_setting
128
+ @raw_setting ||= {}
129
+ end
90
130
  end