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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a0674ff73c1ac25e311e304e7a3736e3feadb9f8d1221453202abbce8e00372
4
- data.tar.gz: 29e63c8ee818a1ca3fe62de9152779cdbea38167db19824e0f402145dec36c04
3
+ metadata.gz: 346ad7fa333241bf5464ac38fce07caec0e0a021def6e2d456b7dc49a1f70b0a
4
+ data.tar.gz: 5f9f6d94706fd00c9ecc738f9626c5a2e6418039997f487f856d2298a6a9df1c
5
5
  SHA512:
6
- metadata.gz: 2bbbce43d9ed8495f513b5cbd9688f0187f3fd64cdd932730c3938ba8d5e43d4c8e3b15118082742bb1692d95aa66537ccc501930cd778144d7639460d98c32e
7
- data.tar.gz: 2a2276871754b37296e2dff2c4b0d3f1cc3822ecb4b5c55e61c2eba4996951072af69e990742463fa282cf57a5f956439a70304402cc4a208be8cd1a43309bb1
6
+ metadata.gz: 792586a96060eb9adb8e7c0cf31bd56663da6343fa753709158890d47aed1025e87f24f670d176dea543d71cf6de2c6e8bb200b3bf109981f99e0f73b8eaa932
7
+ data.tar.gz: 8e82db2b88efb8d5752797eab1e203379d30edf6e71fcda3ff35bdba8e46e27923e5da313442be366c50e6c38b8a0583296a36e94c35f078d648fb18f59c2a0d
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,4 +1,16 @@
1
- ## [0.1.10] - 202
1
+ ## [0.1.14] - 2021-12-02
2
+ - 外部サーバからOSの再起動やprocon_bypass_manのバージョンアップができるようになりました
3
+
4
+ ## [0.1.13] - 2021-11-24
5
+ - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
6
+
7
+ ## [0.1.12] - 2021-11-18
8
+ - 起動ログなどを設定した外部サーバに送信できるようにしました
9
+
10
+ ## [0.1.11] - 2021-11-05
11
+ - PBM-WEB(>= 0.1.3)でボタンの入力を見るためのスレッドが動くようになりました
12
+
13
+ ## [0.1.10] - 2021-10-28
2
14
  - ボタンを無効化するdisableを設定できるようになりました
3
15
  - pvmenvで生成する初期ファイルにprocon_bypass_man-webを同梱しました
4
16
  - PBM自体の設定の構文を変更しました
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.10)
4
+ procon_bypass_man (0.1.14)
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.5)
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,20 +92,21 @@ 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
99
101
  arm64-darwin-20
102
+ arm64-darwin-21
100
103
  armv7l-linux
101
104
  x86_64-linux
102
105
 
103
106
  DEPENDENCIES
104
107
  procon_bypass_man!
105
108
  pry
106
- rake (~> 13.0)
109
+ rake
107
110
  rbs
108
111
  rspec
109
112
  rubocop
@@ -113,4 +116,4 @@ DEPENDENCIES
113
116
  webrick
114
117
 
115
118
  BUNDLED WITH
116
- 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,26 +61,28 @@ 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
- * `bundle exec bin/report_receive_server.rb`
74
- * `bin/console`
75
- * `ProconBypassMan.api_server = "http://localhost:4567"`
76
- * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
73
+ * `bundle exec bin/dev_api_server.rb`
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)`
77
76
 
78
77
  ### リリース手順
79
78
  * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
79
+ * CHANGELOG.md に日付を書く
80
80
  * be rake release
81
81
 
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
data/bin/console CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "bundler/setup"
5
5
  require "procon_bypass_man"
6
+ require "pry"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
8
9
  # with your gem easier. You can also use a different console, if you like.
@@ -12,4 +13,7 @@ require "procon_bypass_man"
12
13
  # Pry.start
13
14
 
14
15
  require "irb"
16
+
17
+ ProconBypassMan.config.logger = Logger.new($stdout)
18
+
15
19
  IRB.start(__FILE__)
@@ -4,8 +4,15 @@ 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 ''
11
11
  end
12
+
13
+ post '/api/pressed_buttons' do
14
+ r = JSON.parse(request.body.read)
15
+ puts r
16
+ status 200
17
+ body ''
18
+ end
@@ -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
@@ -0,0 +1,45 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ class JobRunner
4
+ MAX_QUEUE_SIZE = 100
5
+
6
+ def self.start!
7
+ new.start!
8
+ end
9
+
10
+ # for test
11
+ def stop!
12
+ return unless defined?(@thread)
13
+ @thread.kill
14
+ end
15
+
16
+ def start!
17
+ return if defined?(@thread)
18
+ @thread = Thread.new do
19
+ while(item = self.class.queue.pop)
20
+ begin
21
+ JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
22
+ sleep(1)
23
+ rescue => e
24
+ ProconBypassMan.logger.error(e)
25
+ end
26
+ end
27
+ end
28
+ self
29
+ end
30
+
31
+ def self.queue
32
+ @@queue ||= Queue.new
33
+ end
34
+
35
+ def self.push(hash)
36
+ if queue.size > MAX_QUEUE_SIZE
37
+ ProconBypassMan.logger.error('Over queue size cap!!')
38
+ return
39
+ end
40
+
41
+ queue.push(hash)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -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"])