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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procon_bypass_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: extension for Nintendo Switch Pro Controller
14
14
  email:
@@ -38,37 +38,50 @@ files:
38
38
  - docs/setup_raspi.mitamae.rb
39
39
  - docs/setup_raspi_by_mitamae.md
40
40
  - lib/procon_bypass_man.rb
41
- - lib/procon_bypass_man/background/report_thread.rb
41
+ - lib/procon_bypass_man/background.rb
42
+ - lib/procon_bypass_man/background/has_server_pool.rb
43
+ - lib/procon_bypass_man/background/http_client.rb
44
+ - lib/procon_bypass_man/background/job_performer.rb
45
+ - lib/procon_bypass_man/background/job_runnable.rb
46
+ - lib/procon_bypass_man/background/job_runner.rb
47
+ - lib/procon_bypass_man/background/jobs/base_job.rb
48
+ - lib/procon_bypass_man/background/jobs/report_boot_job.rb
49
+ - lib/procon_bypass_man/background/jobs/report_error_job.rb
50
+ - lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb
51
+ - lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb
52
+ - lib/procon_bypass_man/background/jobs/report_reload_config_job.rb
42
53
  - lib/procon_bypass_man/boot_message.rb
43
54
  - lib/procon_bypass_man/buttons_setting_configuration.rb
55
+ - lib/procon_bypass_man/buttons_setting_configuration/layer.rb
56
+ - lib/procon_bypass_man/buttons_setting_configuration/loader.rb
57
+ - lib/procon_bypass_man/buttons_setting_configuration/validator.rb
44
58
  - lib/procon_bypass_man/bypass.rb
45
59
  - lib/procon_bypass_man/bypass/usb_hid_logger.rb
46
60
  - lib/procon_bypass_man/callbacks.rb
61
+ - lib/procon_bypass_man/commands.rb
62
+ - lib/procon_bypass_man/commands/connect_device_command.rb
63
+ - lib/procon_bypass_man/commands/print_boot_message_command.rb
64
+ - lib/procon_bypass_man/commands/send_error_command.rb
65
+ - lib/procon_bypass_man/commands/send_reload_config_event_command.rb
66
+ - lib/procon_bypass_man/commands/write_device_id_command.rb
67
+ - lib/procon_bypass_man/commands/write_session_id_command.rb
47
68
  - lib/procon_bypass_man/configuration.rb
48
- - lib/procon_bypass_man/configuration/layer.rb
49
- - lib/procon_bypass_man/configuration/loader.rb
50
- - lib/procon_bypass_man/configuration/validator.rb
51
69
  - lib/procon_bypass_man/device_connector.rb
52
70
  - lib/procon_bypass_man/io_monitor.rb
53
71
  - lib/procon_bypass_man/on_memory_cache.rb
54
- - lib/procon_bypass_man/outbound/base.rb
55
- - lib/procon_bypass_man/outbound/error_reporter.rb
56
- - lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb
57
- - lib/procon_bypass_man/outbound/reporter.rb
58
72
  - lib/procon_bypass_man/processor.rb
59
73
  - lib/procon_bypass_man/procon.rb
60
74
  - lib/procon_bypass_man/procon/analog_stick.rb
61
75
  - lib/procon_bypass_man/procon/analog_stick_cap.rb
62
76
  - lib/procon_bypass_man/procon/button_collection.rb
63
- - lib/procon_bypass_man/procon/data.rb
77
+ - lib/procon_bypass_man/procon/consts.rb
64
78
  - lib/procon_bypass_man/procon/flip_cache.rb
65
- - lib/procon_bypass_man/procon/layer_changeable.rb
79
+ - lib/procon_bypass_man/procon/layer_changer.rb
66
80
  - lib/procon_bypass_man/procon/macro_registry.rb
67
81
  - lib/procon_bypass_man/procon/mode_registry.rb
68
82
  - lib/procon_bypass_man/procon/press_button_aware.rb
69
- - lib/procon_bypass_man/procon/pressed_button_helper.rb
70
83
  - lib/procon_bypass_man/procon/user_operation.rb
71
- - lib/procon_bypass_man/readonly_procon.rb
84
+ - lib/procon_bypass_man/procon_reader.rb
72
85
  - lib/procon_bypass_man/runner.rb
73
86
  - lib/procon_bypass_man/timer.rb
74
87
  - lib/procon_bypass_man/uptime.rb
@@ -1,53 +0,0 @@
1
- module ProconBypassMan
2
- module Outbound
3
- class Base
4
- class Client
5
- class Result < Struct.new(:stats); end
6
-
7
- def initialize(path: , server: )
8
- @path = path
9
- if server.is_a?(Array)
10
- # TODO エラーが起きたらローテーションする
11
- @server = server.first
12
- else
13
- @server = server
14
- end
15
- @hostname = `hostname`.chomp
16
- end
17
-
18
- def post(body: )
19
- # TODO ここでvalidationする
20
- if @server.nil?
21
- ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
22
- return Result.new(false)
23
- end
24
-
25
- unless body.is_a?(Hash)
26
- body = { value: body }
27
- end
28
-
29
- uri = URI.parse("#{@server}#{@path}")
30
- http = Net::HTTP.new(uri.host, uri.port)
31
- http.use_ssl = uri.scheme === "https"
32
- params = { hostname: @hostname }.merge(body)
33
- response = http.post(
34
- uri.path,
35
- params.to_json,
36
- { "Content-Type" => "application/json" },
37
- )
38
- case response.code
39
- when /^200/
40
- return Result.new(true)
41
- else
42
- ProconBypassMan.logger.error("200以外(#{response.code})が帰ってきました. #{response.body}")
43
- return Result.new(false)
44
- end
45
- rescue => e
46
- puts e
47
- ProconBypassMan.logger.error("erro: #{e}")
48
- Result.new(false)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,13 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::ErrorReporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/error_reports"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.api_server,
10
- ).post(body: body.full_message)
11
- end
12
- end
13
-
@@ -1,13 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::PressedButtonsReporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/pressed_buttons"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.internal_api_servers,
10
- ).post(body: body)
11
- end
12
- end
13
-
@@ -1,12 +0,0 @@
1
- require "procon_bypass_man/outbound/base"
2
-
3
- class ProconBypassMan::Reporter < ProconBypassMan::Outbound::Base
4
- PATH = "/api/reports"
5
-
6
- def self.report(body: )
7
- Client.new(
8
- path: PATH,
9
- server: ProconBypassMan.config.api_server,
10
- ).post(body: body)
11
- end
12
- end
@@ -1,28 +0,0 @@
1
- module ProconBypassMan::Procon::LayerChangeable
2
- def next_layer_key
3
- case
4
- when pressed_up?
5
- :up
6
- when pressed_right?
7
- :right
8
- when pressed_left?
9
- :left
10
- when pressed_down?
11
- :down
12
- else
13
- ProconBypassMan.logger.warn("next_layer_key is unknown")
14
- :up
15
- end
16
- end
17
-
18
- def change_layer?
19
- if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
20
- raise "prefix_keysが未設定です"
21
- end
22
- ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed_button?(b) }.all?
23
- end
24
-
25
- def pressed_next_layer?
26
- change_layer? && (pressed_up? || pressed_right? || pressed_left? || pressed_down?)
27
- end
28
- end
@@ -1,15 +0,0 @@
1
- module ProconBypassMan::Procon::PressedButtonHelper
2
- module Dynamic
3
- @@compiled = false
4
- def compile_if_not_compile_yet!
5
- unless @@compiled
6
- ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
7
- define_method "pressed_#{button}?" do
8
- pressed_button?(button)
9
- end
10
- end
11
- end
12
- @@compiled = true
13
- end
14
- end
15
- end