procon_bypass_man 0.1.11 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +14 -12
  7. data/README.md +11 -7
  8. data/bin/dev_api_server.rb +1 -1
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/{report_thread.rb → job_runner.rb} +13 -10
  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 +6 -7
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +18 -7
  30. data/lib/procon_bypass_man/bypass.rb +15 -14
  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 +21 -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 +47 -6
  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/plugin/splatoon2/macro/fast_return.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  49. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  50. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  51. data/lib/procon_bypass_man/plugin.rb +11 -0
  52. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  53. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  54. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  55. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  56. data/lib/procon_bypass_man/procon.rb +6 -12
  57. data/lib/procon_bypass_man/{readonly_procon.rb → procon_reader.rb} +3 -4
  58. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  59. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  60. data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
  61. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  64. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  65. data/lib/procon_bypass_man/runner.rb +14 -115
  66. data/lib/procon_bypass_man/scheduler.rb +92 -0
  67. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  68. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  69. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  70. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  71. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  72. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  73. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  74. data/lib/procon_bypass_man/support/server_pool.rb +42 -0
  75. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  76. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  77. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  78. data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
  79. data/lib/procon_bypass_man/version.rb +1 -1
  80. data/lib/procon_bypass_man.rb +71 -36
  81. data/procon_bypass_man.gemspec +3 -3
  82. data/project_template/README.md +18 -11
  83. data/project_template/app.rb +2 -3
  84. data/project_template/setting.yml +8 -8
  85. data/sig/{README.rb → README.md} +0 -0
  86. data/sig/main.rbs +10 -11
  87. metadata +85 -26
  88. data/lib/procon_bypass_man/outbound/base.rb +0 -53
  89. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  90. data/lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb +0 -13
  91. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  92. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  93. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  94. data/lib/procon_bypass_man/uptime.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead44cd36352dba5f4bd97af9c99936657a1a896fb9793a6735ce730a045b6f1
4
- data.tar.gz: b8d115ef493d0b58a064fc7a0a7348a66e9e331e8173edd7543d96e9e213daba
3
+ metadata.gz: 7820b087d86ac7338128dbfdebba48f8e3100d4a2163894962296e6526ea6b6e
4
+ data.tar.gz: 43d3bd4d0b3d18a61edc2df29320ad345f6d9313de79b6bb732a2bf526a18e5a
5
5
  SHA512:
6
- metadata.gz: 3229e5e9f0fef53072b4869af2c6469b55703804d12bd8a9d077fe7c413d2198f747d482b30134daa4da55a0c5309eeda45d9928e46cd7778391ed865720ca00
7
- data.tar.gz: 2de07a44334162b54ca8ba2464286c12a7a21d6ef74cb36b39a97bd5e22a833a5a6a5af2dac5ba6382da99a8635cdd9bd196a98d7f63dac311a4e61c2387ecad
6
+ metadata.gz: 78f98474a1a3d6bf7a6a6420c36c51bc4c9ba835d35361b5bcd45623b3c9c5e3b8ef173d341bd026d324f78787bc020b6536e6deff658c8f073767d3ff0f664e
7
+ data.tar.gz: 341d4645b6650594533dcf23b32e24a8e5acd8413fea428d21fa2d2a2b4af1636d312a1ebc3472d5dbcbce193157a4da459eb1314619c27342b93dd30b8a96b3
@@ -0,0 +1,33 @@
1
+ name: Publish to RubyGems
2
+
3
+ on:
4
+ [workflow_dispatch]
5
+
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: write
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ token: ${{ secrets.GITHUB_TOKEN }}
16
+ - name: Set up Ruby 2.6
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ bundler-cache: true
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ git config --local user.email "action@github.com"
24
+ git config --local user.name "GitHub Action"
25
+
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_TOKEN}\n" > $HOME/.gem/credentials
30
+ bundle exec rake release
31
+ env:
32
+ RUBYGEMS_API_TOKEN: "${{secrets.RUBYGEMS_API_TOKEN}}"
33
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ todo.local.md
12
12
  .setting_yaml_digest
13
13
  pbm_pid
14
14
  setting.yml
15
+ device_id
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.1.15] - 2021-12-08
2
+ - 外部サーバから設定ファイルのリストアができるようになりました
3
+ - splatoon2 pluginのネームスペースを変更しました
4
+
5
+ ## [0.1.14] - 2021-12-02
6
+ - 外部サーバからOSの再起動やprocon_bypass_manのバージョンアップができるようになりました
7
+
8
+ ## [0.1.13] - 2021-11-24
9
+ - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
10
+
11
+ ## [0.1.12] - 2021-11-18
12
+ - 起動ログなどを設定した外部サーバに送信できるようにしました
13
+
1
14
  ## [0.1.11] - 2021-11-05
2
15
  - PBM-WEB(>= 0.1.3)でボタンの入力を見るためのスレッドが動くようになりました
3
16
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in procon_bypass_man.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
9
9
  gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.11)
4
+ procon_bypass_man (0.1.15)
5
+ pbmenv
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -17,7 +18,7 @@ GEM
17
18
  concurrent-ruby (1.1.9)
18
19
  diff-lcs (1.4.4)
19
20
  ffi (1.15.4)
20
- i18n (1.8.10)
21
+ i18n (1.8.11)
21
22
  concurrent-ruby (~> 1.0)
22
23
  language_server-protocol (3.16.0.3)
23
24
  listen (3.7.0)
@@ -27,9 +28,10 @@ GEM
27
28
  minitest (5.14.4)
28
29
  mustermann (1.1.1)
29
30
  ruby2_keywords (~> 0.0.1)
30
- parallel (1.20.1)
31
+ parallel (1.21.0)
31
32
  parser (3.0.2.0)
32
33
  ast (~> 2.4.1)
34
+ pbmenv (0.1.6)
33
35
  pry (0.14.1)
34
36
  coderay (~> 1.1)
35
37
  method_source (~> 1.0)
@@ -41,7 +43,7 @@ GEM
41
43
  rb-fsevent (0.11.0)
42
44
  rb-inotify (0.10.1)
43
45
  ffi (~> 1.0)
44
- rbs (1.6.2)
46
+ rbs (1.7.1)
45
47
  regexp_parser (2.1.1)
46
48
  rexml (3.2.5)
47
49
  rspec (3.10.0)
@@ -56,17 +58,17 @@ GEM
56
58
  rspec-mocks (3.10.2)
57
59
  diff-lcs (>= 1.2.0, < 2.0)
58
60
  rspec-support (~> 3.10.0)
59
- rspec-support (3.10.2)
60
- rubocop (1.20.0)
61
+ rspec-support (3.10.3)
62
+ rubocop (1.23.0)
61
63
  parallel (~> 1.10)
62
64
  parser (>= 3.0.0.0)
63
65
  rainbow (>= 2.2.2, < 4.0)
64
66
  regexp_parser (>= 1.8, < 3.0)
65
67
  rexml
66
- rubocop-ast (>= 1.9.1, < 2.0)
68
+ rubocop-ast (>= 1.12.0, < 2.0)
67
69
  ruby-progressbar (~> 1.7)
68
70
  unicode-display_width (>= 1.4.0, < 3.0)
69
- rubocop-ast (1.11.0)
71
+ rubocop-ast (1.13.0)
70
72
  parser (>= 3.0.1.1)
71
73
  ruby-progressbar (1.11.0)
72
74
  ruby2_keywords (0.0.5)
@@ -90,9 +92,9 @@ GEM
90
92
  timecop (0.9.4)
91
93
  tzinfo (2.0.4)
92
94
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (2.0.0)
95
+ unicode-display_width (2.1.0)
94
96
  webrick (1.7.0)
95
- zeitwerk (2.4.2)
97
+ zeitwerk (2.5.1)
96
98
 
97
99
  PLATFORMS
98
100
  arm-linux
@@ -104,7 +106,7 @@ PLATFORMS
104
106
  DEPENDENCIES
105
107
  procon_bypass_man!
106
108
  pry
107
- rake (~> 13.0)
109
+ rake
108
110
  rbs
109
111
  rspec
110
112
  rubocop
@@ -114,4 +116,4 @@ DEPENDENCIES
114
116
  webrick
115
117
 
116
118
  BUNDLED WITH
117
- 2.2.22
119
+ 2.2.30
data/README.md CHANGED
@@ -28,8 +28,8 @@ Switch <-- (PBM): ZR連打
28
28
  ## Usage
29
29
  * USBガジェットモードで起動するRaspberry Pi4を用意する
30
30
  * https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
31
- * Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
32
- * 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
31
+ * Raspberry Pi4 sudo pbmenv install latest && cd /usr/share/pbm/current && sudo ruby app.rb
32
+ * 動いたのを確認したらserviceとして登録にするなどしてください
33
33
 
34
34
  ## Plugins
35
35
  * https://github.com/splaplapla/procon_bypass_man-splatoon2
@@ -52,6 +52,8 @@ Switch <-- (PBM): ZR連打
52
52
  * 連射中には特定のキーの入力を無視したり、複数のキーをトリガーに連射することができます
53
53
  * どうしてsudoが必要なの?
54
54
  * 操作するdeviceファイルの所有者がrootだから
55
+ * 市販されているサードパーティ製連射機との違いは?
56
+ * サードパーティ製のコントローラーは、設定方法や形状が特殊で買い換えるたびに学習・設定コストが発生します。本ツールを使えば、設定内容はテキストで管理することができ、使い慣れたプロコンで同等のことができます。
55
57
 
56
58
  ## TODO
57
59
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
@@ -59,20 +61,18 @@ Switch <-- (PBM): ZR連打
59
61
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
60
62
 
61
63
  ## 開発系
62
- * pbmenvで生成するapp.rbに開発用ブランチを参照してください
63
-
64
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
65
65
  ```shell
66
66
  sudo kill -USR2 `cat ./pbm_pid`
67
67
  ```
68
68
 
69
69
  ### 起動ログをサーバに送信する
70
- * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/reports` に対して起動ログを送信するようになります
70
+ * `ProconBypassMan.api_servers = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
71
71
 
72
72
  ### 開発環境でログの送信を確認する方法
73
73
  * `bundle exec bin/dev_api_server.rb`
74
- * `INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
- * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
74
+ * `API_SERVER=http://localhost:4567 INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.perform(body: message.to_hash)`
76
76
 
77
77
  ### リリース手順
78
78
  * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
@@ -82,3 +82,7 @@ sudo kill -USR2 `cat ./pbm_pid`
82
82
  ## License
83
83
 
84
84
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+
87
+ ## Links
88
+ * https://discord.gg/bEcRNKf4ep
@@ -4,7 +4,7 @@ require "sinatra"
4
4
  require "webrick"
5
5
  require "pry"
6
6
 
7
- post '/api/reports' do
7
+ post '/api/events' do
8
8
  puts JSON.parse(request.body.read)
9
9
  status 200
10
10
  body ''
@@ -0,0 +1,16 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ class JobPerformer
4
+ def initialize(klass: , args: )
5
+ @klass = klass
6
+ @args = args
7
+ end
8
+
9
+ def perform
10
+ @klass.perform(*@args)
11
+ rescue => e
12
+ ProconBypassMan::ReportErrorJob.perform(e)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,32 +1,35 @@
1
1
  module ProconBypassMan
2
2
  module Background
3
- class Reporter
3
+ class JobRunner
4
4
  MAX_QUEUE_SIZE = 100
5
5
 
6
6
  def self.start!
7
7
  new.start!
8
8
  end
9
9
 
10
+ # for test
11
+ def stop!
12
+ return unless defined?(@thread)
13
+ @thread.kill
14
+ end
15
+
10
16
  def start!
11
- return if defined?(@@thread)
12
- @@latest_request_result = { stats: true, timestamp: Time.now }
13
- @@queue = Queue.new
14
- @@thread = Thread.new do
15
- while(item = @@queue.pop)
17
+ return if defined?(@thread)
18
+ @thread = Thread.new do
19
+ while(item = self.class.queue.pop)
16
20
  begin
17
- result = item[:reporter_class].report(body: item[:data])
18
- @@latest_request_result = { stats: result.stats, timestamp: Time.now }
21
+ JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
19
22
  sleep(1)
20
23
  rescue => e
21
24
  ProconBypassMan.logger.error(e)
22
25
  end
23
26
  end
24
27
  end
28
+ self
25
29
  end
26
30
 
27
31
  def self.queue
28
- raise "Do not start this thread yet" unless defined?(@@queue)
29
- @@queue
32
+ @@queue ||= Queue.new
30
33
  end
31
34
 
32
35
  def self.push(hash)
@@ -0,0 +1,7 @@
1
+ class ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::Background::JobRunnable
3
+
4
+ def self.servers
5
+ raise NotImplementedError
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasExternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.server_pool
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasInternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.internal_server_pool
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ module JobRunnable
4
+ def perform(*)
5
+ raise NotImplementedError, nil
6
+ end
7
+
8
+ def perform_async(*args)
9
+ ProconBypassMan::Background::JobRunner.push(
10
+ args: args,
11
+ reporter_class: self,
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ class ProconBypassMan::FetchAndRunRemotePbmActionJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ def self.perform
5
+ pbm_jobs = ProconBypassMan::HttpClient.new(path: path, server_pool: server_pool).get
6
+ if pbm_jobs.nil? || pbm_jobs.size.zero?
7
+ # ProconBypassMan.logger.debug "remote pbm_jobsはありませんでした"
8
+ return
9
+ else
10
+ pbm_job_hash = pbm_jobs.first
11
+ begin
12
+ pbm_job_object = ProconBypassMan::RemotePbmActionObject.new(action: pbm_job_hash["action"],
13
+ status: pbm_job_hash["status"],
14
+ uuid: pbm_job_hash["uuid"],
15
+ created_at: pbm_job_hash["created_at"],
16
+ job_args: pbm_job_hash["args"])
17
+ pbm_job_object.validate!
18
+ ProconBypassMan::RunRemotePbmActionDispatchCommand.execute(action: pbm_job_object.action, uuid: pbm_job_object.uuid, job_args: pbm_job_object.job_args)
19
+ rescue ProconBypassMan::RemotePbmActionObject::ValidationError => e
20
+ ProconBypassMan::SendErrorCommand.execute(error: e)
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.path
26
+ device_id = ProconBypassMan.device_id
27
+ "/api/devices/#{device_id}/pbm_jobs"
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ class ProconBypassMan::ReportBootJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ retry_on_connection_error: true,
10
+ ).post(body: body, event_type: :boot)
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::ReportErrorJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :error)
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class ProconBypassMan::ReportEventBaseJob < ProconBypassMan::BaseJob
2
+ def self.path
3
+ "/api/events".freeze
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :load_config)
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasInternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :internal)
10
+ end
11
+
12
+ def self.path
13
+ "/api/pressed_buttons"
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :reload_config)
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class ProconBypassMan::SyncDeviceStatsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [Symbol] status
5
+ def self.perform(status)
6
+ ProconBypassMan::SendDeviceStatsHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(status: status, pbm_session_id: ProconBypassMan.session_id)
10
+ end
11
+
12
+ def self.path
13
+ device_id = ProconBypassMan.device_id
14
+ "/api/devices/#{ProconBypassMan.device_id}/device_statuses"
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require "procon_bypass_man/background/jobs/concerns/has_internal_api_setting"
2
+ require "procon_bypass_man/background/jobs/concerns/has_external_api_setting"
3
+ require "procon_bypass_man/background/jobs/concerns/job_runnable"
4
+ require "procon_bypass_man/background/job_runner"
5
+ require "procon_bypass_man/background/job_performer"
6
+ require "procon_bypass_man/background/jobs/base_job"
7
+ require "procon_bypass_man/background/jobs/report_event_base_job"
8
+ require "procon_bypass_man/background/jobs/report_boot_job"
9
+ require "procon_bypass_man/background/jobs/report_reload_config_job"
10
+ require "procon_bypass_man/background/jobs/report_load_config_job"
11
+ require "procon_bypass_man/background/jobs/report_error_job"
12
+ require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
13
+ require "procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job"
14
+ require "procon_bypass_man/background/jobs/sync_device_stats_job"
@@ -8,13 +8,19 @@ class ProconBypassMan::BootMessage
8
8
  @table[:pid_path] = ProconBypassMan.pid_path
9
9
  @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
10
10
  @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
11
+ @table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
12
+ @table[:session_id] = ProconBypassMan.session_id
13
+ @table[:device_id] = ProconBypassMan.device_id
11
14
 
12
- build_version = `git rev-parse --short HEAD`.chomp
13
- if build_version.empty?
14
- @table[:build_version] = 'release version'
15
- else
16
- @table[:build_version] = build_version
17
- end
15
+ # 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
16
+ # build_version = `git rev-parse --short HEAD`.chomp
17
+ # if build_version.empty?
18
+ # @table[:build_version] = 'release version'
19
+ # else
20
+ # @table[:build_version] = build_version
21
+ # end
22
+
23
+ # build version: #{@table[:build_version]}
18
24
  end
19
25
 
20
26
  # @return [String]
@@ -22,13 +28,15 @@ class ProconBypassMan::BootMessage
22
28
  booted_message = <<~EOF
23
29
  ----
24
30
  RUBY_VERSION: #{@table[:ruby_version]}
25
- ProconBypassMan: #{@table[:pbm_version]}
31
+ ProconBypassMan::VERSION: #{@table[:pbm_version]}
26
32
  pid: #{@table[:pid]}
27
33
  root: #{@table[:root_path]}
28
34
  pid_path: #{@table[:pid_path]}
29
35
  setting_path: #{@table[:setting_path]}
30
36
  uptime from boot: #{@table[:uptime_from_boot]} sec
31
- build version: #{@table[:build_version]}
37
+ use_pbmenv: #{@table[:use_pbmenv]}
38
+ session_id: #{ProconBypassMan.session_id}
39
+ device_id: #{ProconBypassMan.device_id}
32
40
  ----
33
41
  EOF
34
42
  end
@@ -20,21 +20,26 @@ module ProconBypassMan
20
20
  if_pressed = [button]
21
21
  when Symbol, String
22
22
  if_pressed = [if_pressed]
23
- when Array, FalseClass
24
- # sono mama
23
+ when Array
24
+ # if_pressed = if_pressed
25
+ when FalseClass, NilClass
26
+ # no-op
25
27
  else
26
28
  raise "not support class"
27
29
  end
30
+
28
31
  hash = { if_pressed: if_pressed }
29
- if force_neutral
30
- case force_neutral
31
- when TrueClass, FalseClass
32
- raise "ボタンを渡してください"
33
- when Symbol, String
34
- hash[:force_neutral] = [force_neutral]
35
- when Array
36
- hash[:force_neutral] = force_neutral
37
- end
32
+ case force_neutral
33
+ when TrueClass
34
+ raise "ボタンを渡してください"
35
+ when Symbol, String
36
+ hash[:force_neutral] = [force_neutral]
37
+ when Array
38
+ hash[:force_neutral] = force_neutral
39
+ when FalseClass, NilClass
40
+ # no-op
41
+ else
42
+ raise "not support value"
38
43
  end
39
44
 
40
45
  if flip_interval
@@ -63,7 +68,7 @@ module ProconBypassMan
63
68
 
64
69
  def remap(button, to: )
65
70
  case to
66
- when TrueClass, FalseClass
71
+ when TrueClass, FalseClass, NilClass
67
72
  raise "ボタンを渡してください"
68
73
  when Symbol, String
69
74
  self.remaps[button] = { to: [to] }
@@ -77,27 +82,27 @@ module ProconBypassMan
77
82
  hash = { cap: cap }
78
83
 
79
84
  case if_pressed
80
- when TrueClass
81
- raise "not support class"
85
+ when TrueClass, FalseClass
86
+ raise "ボタンを渡してください"
82
87
  when Symbol, String
83
88
  if_pressed = [if_pressed]
84
- when Array, FalseClass
85
- # sono mama
86
- when NilClass
87
- if_pressed = nil
89
+ when Array, NilClass
90
+ # no-op
88
91
  else
89
- raise "not support if_pressed"
92
+ raise "not support value"
90
93
  end
91
94
 
92
- if force_neutral
93
- case force_neutral
94
- when TrueClass, FalseClass
95
- raise "ボタンを渡してください"
96
- when Symbol, String
97
- hash[:force_neutral] = [force_neutral]
98
- when Array
99
- hash[:force_neutral] = force_neutral
100
- end
95
+ case force_neutral
96
+ when TrueClass
97
+ raise "ボタンを渡してください"
98
+ when Symbol, String
99
+ hash[:force_neutral] = [force_neutral]
100
+ when Array
101
+ hash[:force_neutral] = force_neutral
102
+ when FalseClass, NilClass
103
+ # no-op
104
+ else
105
+ raise "not support value"
101
106
  end
102
107
 
103
108
  left_analog_stick_caps[if_pressed] = hash
@@ -114,7 +119,7 @@ module ProconBypassMan
114
119
  when Array
115
120
  button.each { |b| disables << b }
116
121
  else
117
- raise "unknown"
122
+ raise "not support value"
118
123
  end
119
124
  end
120
125
 
@@ -4,10 +4,10 @@ module ProconBypassMan
4
4
  require 'digest/md5'
5
5
 
6
6
  def self.load(setting_path: )
7
- ProconBypassMan::ButtonsSettingConfiguration.switch_new_context(:validation) do |validation_instance|
7
+ ProconBypassMan::ButtonsSettingConfiguration.switch_new_context(:validation) do |new_instance|
8
8
  yaml = YAML.load_file(setting_path) or raise "読み込みに失敗しました"
9
- validation_instance.instance_eval(yaml["setting"])
10
- validator = Validator.new(validation_instance)
9
+ new_instance.instance_eval(yaml["setting"])
10
+ validator = Validator.new(new_instance)
11
11
  if validator.valid?
12
12
  next
13
13
  else
@@ -19,11 +19,12 @@ module ProconBypassMan
19
19
  raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです"
20
20
  end
21
21
 
22
- yaml = YAML.load_file(setting_path)
23
22
  ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path = setting_path
24
23
  ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
25
24
  ProconBypassMan.reset!
26
25
 
26
+ yaml = YAML.load_file(setting_path)
27
+ ProconBypassMan.config.raw_setting = yaml.dup
27
28
  case yaml["version"]
28
29
  when 1.0, nil
29
30
  ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(yaml["setting"])