procon_bypass_man 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +2 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +2 -8
  7. data/lib/procon_bypass_man/analog_stick_position.rb +2 -8
  8. data/lib/procon_bypass_man/boot_message.rb +1 -1
  9. data/lib/procon_bypass_man/buttons_setting_configuration.rb +100 -0
  10. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +20 -0
  11. data/lib/procon_bypass_man/bypass.rb +57 -38
  12. data/lib/procon_bypass_man/callbacks.rb +70 -0
  13. data/lib/procon_bypass_man/configuration/layer.rb +18 -2
  14. data/lib/procon_bypass_man/configuration/loader.rb +8 -8
  15. data/lib/procon_bypass_man/configuration/validator.rb +1 -1
  16. data/lib/procon_bypass_man/configuration.rb +67 -77
  17. data/lib/procon_bypass_man/outbound/base.rb +40 -0
  18. data/lib/procon_bypass_man/outbound/error_reporter.rb +13 -0
  19. data/lib/procon_bypass_man/outbound/reporter.rb +12 -0
  20. data/lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb +13 -0
  21. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  22. data/lib/procon_bypass_man/procon/layer_changeable.rb +2 -2
  23. data/lib/procon_bypass_man/procon/macro_registry.rb +2 -2
  24. data/lib/procon_bypass_man/procon/mode_registry.rb +2 -2
  25. data/lib/procon_bypass_man/procon/user_operation.rb +4 -0
  26. data/lib/procon_bypass_man/procon.rb +9 -5
  27. data/lib/procon_bypass_man/runner.rb +1 -1
  28. data/lib/procon_bypass_man/uptime.rb +3 -1
  29. data/lib/procon_bypass_man/version.rb +1 -1
  30. data/lib/procon_bypass_man.rb +20 -73
  31. data/project_template/README.md +1 -1
  32. data/project_template/app.rb +5 -5
  33. data/project_template/systemd_units/pbm_web.service +11 -0
  34. data/project_template/web.rb +16 -0
  35. data/sig/main.rbs +44 -4
  36. metadata +11 -4
  37. data/lib/procon_bypass_man/error_reporter.rb +0 -44
  38. data/lib/procon_bypass_man/reporter.rb +0 -42
@@ -0,0 +1,40 @@
1
+ module ProconBypassMan
2
+ module Outbound
3
+ class Base
4
+ class Client
5
+ def initialize(path: , server: )
6
+ @path = path
7
+ if server.is_a?(Array)
8
+ @server = server.first
9
+ else
10
+ @server = server
11
+ end
12
+ @hostname = `hostname`.chomp
13
+ end
14
+
15
+ def post(body: )
16
+ # TODO ここでvalidationする
17
+ if @server.nil?
18
+ ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
19
+ return
20
+ end
21
+
22
+ uri = URI.parse("#{@server}#{@path}")
23
+ http = Net::HTTP.new(uri.host, uri.port)
24
+ http.use_ssl = uri.scheme === "https"
25
+ response = http.post(
26
+ uri.path,
27
+ { report: body.to_json, hostname: @hostname }.to_json,
28
+ { "Content-Type" => "application/json" },
29
+ )
30
+ unless response.code == /^20/
31
+ ProconBypassMan.logger.error(response.body)
32
+ end
33
+ rescue => e
34
+ puts e
35
+ ProconBypassMan.logger.error(e)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
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.to_json)
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
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.to_json)
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require "procon_bypass_man/outbound/base"
2
+
3
+ class ProconBypassMan::UsbHidDataReporter < ProconBypassMan::Outbound::Base
4
+ PATH = "/api/usb_hid_chunks"
5
+
6
+ def self.report(body: )
7
+ Client.new(
8
+ path: PATH,
9
+ server: ProconBypassMan.config.internal_api_servers,
10
+ ).post(body: body.to_json)
11
+ end
12
+ end
13
+
@@ -22,7 +22,7 @@ class ProconBypassMan::Procon::AnalogStickCap
22
22
  attr_accessor :neutral_position
23
23
 
24
24
  def initialize(binary)
25
- @neutral_position = ProconBypassMan::Configuration.instance.neutral_position
25
+ @neutral_position = ProconBypassMan::ButtonsSettingConfiguration.instance.neutral_position
26
26
  @binary = binary
27
27
 
28
28
  byte6 = binary[6].unpack("H*").first.to_i(16).to_s(2).rjust(8, "0")
@@ -16,10 +16,10 @@ module ProconBypassMan::Procon::LayerChangeable
16
16
  end
17
17
 
18
18
  def change_layer?
19
- if ProconBypassMan::Configuration.instance.prefix_keys.empty?
19
+ if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
20
20
  raise "prefix_keysが未設定です"
21
21
  end
22
- ProconBypassMan::Configuration.instance.prefix_keys.map { |b| pressed_button?(b) }.all?
22
+ ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed_button?(b) }.all?
23
23
  end
24
24
 
25
25
  def pressed_next_layer?
@@ -37,11 +37,11 @@ class ProconBypassMan::Procon::MacroRegistry
37
37
  end
38
38
 
39
39
  def self.reset!
40
- ProconBypassMan::Configuration.instance.macro_plugins = {}
40
+ ProconBypassMan::ButtonsSettingConfiguration.instance.macro_plugins = {}
41
41
  end
42
42
 
43
43
  def self.plugins
44
- ProconBypassMan::Configuration.instance.macro_plugins
44
+ ProconBypassMan::ButtonsSettingConfiguration.instance.macro_plugins
45
45
  end
46
46
 
47
47
  reset!
@@ -35,11 +35,11 @@ class ProconBypassMan::Procon::ModeRegistry
35
35
  end
36
36
 
37
37
  def self.reset!
38
- ProconBypassMan::Configuration.instance.mode_plugins = {}
38
+ ProconBypassMan::ButtonsSettingConfiguration.instance.mode_plugins = {}
39
39
  end
40
40
 
41
41
  def self.plugins
42
- ProconBypassMan::Configuration.instance.mode_plugins
42
+ ProconBypassMan::ButtonsSettingConfiguration.instance.mode_plugins
43
43
  end
44
44
 
45
45
  reset!
@@ -31,6 +31,8 @@ class ProconBypassMan::Procon
31
31
  end
32
32
 
33
33
  def unpress_button(button)
34
+ return if not pressed_button?(button)
35
+
34
36
  byte_position = ButtonCollection.load(button).byte_position
35
37
  value = binary[byte_position].unpack("H*").first.to_i(16) - (2**ButtonCollection.load(button).bit_position)
36
38
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
@@ -41,6 +43,8 @@ class ProconBypassMan::Procon
41
43
  end
42
44
 
43
45
  def press_button(button)
46
+ return if pressed_button?(button)
47
+
44
48
  byte_position = ButtonCollection.load(button).byte_position
45
49
  value = binary[byte_position].unpack("H*").first.to_i(16) + (2**ButtonCollection.load(button).bit_position)
46
50
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
@@ -31,7 +31,7 @@ class ProconBypassMan::Procon
31
31
  def current_layer_key; @@status[:current_layer_key]; end
32
32
 
33
33
  def current_layer
34
- ProconBypassMan::Configuration.instance.layers[current_layer_key]
34
+ ProconBypassMan::ButtonsSettingConfiguration.instance.layers[current_layer_key]
35
35
  end
36
36
 
37
37
  def apply!
@@ -95,10 +95,14 @@ class ProconBypassMan::Procon
95
95
  return user_operation.binary
96
96
  end
97
97
 
98
+ current_layer.disables.each do |button|
99
+ user_operation.unpress_button(button)
100
+ end
101
+
98
102
  current_layer.left_analog_stick_caps.each do |button, options|
99
103
  if button.nil? || button.all? { |b| user_operation.pressed_button?(b) }
100
104
  options[:force_neutral]&.each do |force_neutral_button|
101
- user_operation.pressed_button?(force_neutral_button) && user_operation.unpress_button(force_neutral_button)
105
+ user_operation.unpress_button(force_neutral_button)
102
106
  end
103
107
  user_operation.apply_left_analog_stick_cap(cap: options[:cap])
104
108
  end
@@ -107,7 +111,7 @@ class ProconBypassMan::Procon
107
111
  current_layer.flip_buttons.each do |button, options|
108
112
  # 何もしないで常に連打
109
113
  if !options[:if_pressed] && status[button]
110
- user_operation.press_button(button) unless user_operation.pressed_button?(button)
114
+ user_operation.press_button(button)
111
115
  next
112
116
  end
113
117
 
@@ -118,7 +122,7 @@ class ProconBypassMan::Procon
118
122
  end
119
123
 
120
124
  options[:force_neutral]&.each do |force_neutral_button|
121
- user_operation.pressed_button?(force_neutral_button) && user_operation.unpress_button(force_neutral_button)
125
+ user_operation.unpress_button(force_neutral_button)
122
126
  end
123
127
  end
124
128
  end
@@ -128,7 +132,7 @@ class ProconBypassMan::Procon
128
132
  user_operation.unpress_button(from_button)
129
133
  # TODO 2重でpressしないようにしたい
130
134
  to_buttons[:to].each do |to_button|
131
- user_operation.press_button(to_button) unless user_operation.pressed_button?(to_button)
135
+ user_operation.press_button(to_button)
132
136
  end
133
137
  end
134
138
  end
@@ -35,7 +35,7 @@ class ProconBypassMan::Runner
35
35
  Process.wait
36
36
  ProconBypassMan.logger.info("Reloading config file")
37
37
  begin
38
- ProconBypassMan::Configuration::Loader.reload_setting
38
+ ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
39
39
  puts "設定ファイルの再読み込みができました"
40
40
  rescue ProconBypassMan::CouldNotLoadConfigError
41
41
  ProconBypassMan.logger.error "設定ファイルが不正です。再読み込みができませんでした"
@@ -3,7 +3,9 @@ require "time"
3
3
  module ProconBypassMan
4
4
  class Uptime
5
5
  def self.from_boot
6
- boot_time = Time.parse(`uptime -s`.chomp).to_i
6
+ result = `uptime -s`.chomp
7
+ return -1 if result == '' # darwin系だとsオプションが使えない
8
+ boot_time = result.to_i
7
9
  return Time.now.to_i - boot_time.to_i
8
10
  rescue => e
9
11
  ProconBypassMan.logger.error(e)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProconBypassMan
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.10"
5
5
  end
@@ -1,8 +1,11 @@
1
1
  require "logger"
2
2
  require 'yaml'
3
+ require "json"
4
+ require "net/http"
3
5
  require "fileutils"
4
6
 
5
7
  require_relative "procon_bypass_man/version"
8
+ require_relative "procon_bypass_man/callbacks"
6
9
  require_relative "procon_bypass_man/analog_stick_position"
7
10
  require_relative "procon_bypass_man/timer"
8
11
  require_relative "procon_bypass_man/bypass"
@@ -10,43 +13,42 @@ require_relative "procon_bypass_man/device_connector"
10
13
  require_relative "procon_bypass_man/runner"
11
14
  require_relative "procon_bypass_man/processor"
12
15
  require_relative "procon_bypass_man/configuration"
16
+ require_relative "procon_bypass_man/buttons_setting_configuration"
13
17
  require_relative "procon_bypass_man/procon"
14
18
  require_relative "procon_bypass_man/procon/debug_dumper"
15
19
  require_relative "procon_bypass_man/procon/analog_stick_cap"
16
- require_relative "procon_bypass_man/reporter"
17
- require_relative "procon_bypass_man/error_reporter"
20
+ require_relative "procon_bypass_man/outbound/reporter"
21
+ require_relative "procon_bypass_man/outbound/error_reporter"
22
+ require_relative "procon_bypass_man/outbound/usb_hid_data_reporter"
18
23
  require_relative "procon_bypass_man/on_memory_cache"
19
24
 
20
25
  STDOUT.sync = true
21
26
  Thread.abort_on_exception = true
22
27
 
23
- # new feature from ruby3.0
24
- if GC.respond_to?(:auto_compact)
25
- GC.auto_compact = true
26
- end
27
-
28
28
  module ProconBypassMan
29
+ extend ProconBypassMan::Configuration::ClassAttributes
30
+
29
31
  class ProConRejected < StandardError; end
30
32
  class CouldNotLoadConfigError < StandardError; end
31
33
  class FirstConnectionError < StandardError; end
32
34
  class EternalConnectionError < StandardError; end
33
35
 
34
- def self.configure(setting_path: nil, &block)
36
+ def self.buttons_setting_configure(setting_path: nil, &block)
35
37
  unless setting_path
36
38
  logger.warn "setting_pathが未設定です。設定ファイルのライブリロードが使えません。"
37
39
  end
38
40
 
39
41
  if block_given?
40
- ProconBypassMan::Configuration.instance.instance_eval(&block)
42
+ ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(&block)
41
43
  else
42
- ProconBypassMan::Configuration::Loader.load(setting_path: setting_path)
44
+ ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
43
45
  end
44
46
  end
45
47
 
46
48
  def self.run(setting_path: nil, &block)
47
49
  ProconBypassMan.logger.info "PBMを起動しています"
48
50
  puts "PBMを起動しています"
49
- configure(setting_path: setting_path, &block)
51
+ buttons_setting_configure(setting_path: setting_path, &block)
50
52
  File.write(pid_path, $$)
51
53
  Runner.new.run
52
54
  rescue CouldNotLoadConfigError
@@ -65,76 +67,21 @@ module ProconBypassMan
65
67
  retry
66
68
  end
67
69
 
68
- def self.logger=(logger)
69
- @@logger = logger
70
- end
71
-
72
- # @return [Logger]
73
- def self.logger
74
- if ENV["PBM_ENV"] == 'test'
75
- return Logger.new($stdout)
76
- end
77
-
78
- if defined?(@@logger) && @@logger.is_a?(Logger)
79
- @@logger
80
- else
81
- Logger.new(nil)
82
- end
83
- end
84
-
85
- def self.enable_critical_error_logging!
86
- @@enable_critical_error_logging = true
87
- end
88
-
89
- def self.error_logger
90
- if defined?(@@enable_critical_error_logging)
91
- @@error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
92
- else
93
- Logger.new(nil)
94
- end
70
+ def self.configure(&block)
71
+ @@configuration = ProconBypassMan::Configuration.new
72
+ @@configuration.instance_eval(&block)
73
+ @@configuration
95
74
  end
96
75
 
97
- def self.pid_path
98
- @@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
76
+ def self.config
77
+ @@configuration ||= ProconBypassMan::Configuration.new
99
78
  end
100
79
 
101
80
  def self.reset!
102
81
  ProconBypassMan::Procon::MacroRegistry.reset!
103
82
  ProconBypassMan::Procon::ModeRegistry.reset!
104
83
  ProconBypassMan::Procon.reset!
105
- ProconBypassMan::Configuration.instance.reset!
84
+ ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
106
85
  ProconBypassMan::IOMonitor.reset!
107
86
  end
108
-
109
- def self.root
110
- if defined?(@@root)
111
- @@root
112
- else
113
- File.expand_path('..', __dir__).freeze
114
- end
115
- end
116
-
117
- def self.root=(path)
118
- @@root = path
119
- end
120
-
121
- def self.api_server=(api_server)
122
- @@api_server = api_server
123
- end
124
-
125
- def self.api_server
126
- if defined?(@@api_server)
127
- @@api_server
128
- else
129
- nil
130
- end
131
- end
132
-
133
- def self.cache
134
- @@cache_table ||= ProconBypassMan::OnMemoryCache.new
135
- end
136
-
137
- def self.digest_path
138
- "#{root}/.setting_yaml_digest"
139
- end
140
87
  end
@@ -3,6 +3,7 @@ https://github.com/splaplapla/pbmenv で使っているファイルです
3
3
 
4
4
  ## systemd
5
5
  * sudo ln -s /usr/share/pbm/current/systemd_units/pbm.service /etc/systemd/system/pbm.service
6
+ * sudo ln -s /usr/share/pbm/current/systemd_units/pbm_web.service /etc/systemd/system/pbm_web.service
6
7
  * commands
7
8
  * systemctl daemon-reload
8
9
  * systemctl enable pbm.service
@@ -14,4 +15,3 @@ https://github.com/splaplapla/pbmenv で使っているファイルです
14
15
 
15
16
  ### ログ
16
17
  * journalctl -xe -f
17
-
@@ -9,12 +9,12 @@ gemfile do
9
9
  gem 'procon_bypass_man-splatoon2', github: 'splaplapla/procon_bypass_man-splatoon2', tag: "0.1.1"
10
10
  end
11
11
 
12
- ProconBypassMan.tap do |pbm|
13
- pbm.root = File.expand_path(__dir__)
14
- pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
15
- pbm.logger.level = :debug
12
+ ProconBypassMan.configure do |config|
13
+ config.root = File.expand_path(__dir__)
14
+ config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
15
+ config.logger.level = :debug
16
16
  # pbm.api_server = 'https://...'
17
- pbm.enable_critical_error_logging!
17
+ config.enable_critical_error_logging!
18
18
  end
19
19
 
20
20
  ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=PBM WEB
3
+
4
+ [Service]
5
+ Type=simple
6
+ WorkingDirectory=/home/pi/src/procon_bypass_man_sample
7
+ ExecStart=/bin/bash -c "/home/pi/.rbenv/versions/3.0.1/bin/ruby /usr/share/pbm/current/web.rb"
8
+ Restart=always
9
+
10
+ [Install]
11
+ WantedBy=multi-user.target
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/inline'
4
+
5
+ gemfile do
6
+ source 'https://rubygems.org'
7
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
8
+ gem 'procon_bypass_man-web', '0.1.2'
9
+ end
10
+
11
+ ProconBypassMan::Web.configure do |config|
12
+ config.root = File.expand_path(__dir__)
13
+ config.logger = Logger.new("#{ProconBypassMan::Web.root}/web.log", 1, 1024 * 1024 * 10)
14
+ end
15
+
16
+ ProconBypassMan::Web::Server.start
data/sig/main.rbs CHANGED
@@ -63,7 +63,7 @@ class AnalogStickPosition
63
63
  end
64
64
 
65
65
  module ProconBypassMan
66
- class Configuration
66
+ class ButtonsSettingConfiguration
67
67
  attr_accessor layers: untyped
68
68
 
69
69
  attr_accessor setting_path: untyped
@@ -101,7 +101,7 @@ module ProconBypassMan
101
101
  end
102
102
 
103
103
  module ProconBypassMan
104
- class Configuration
104
+ class ButtonsSettingConfiguration
105
105
  class Layer
106
106
  attr_accessor mode: untyped
107
107
 
@@ -131,7 +131,7 @@ module ProconBypassMan
131
131
  end
132
132
 
133
133
  module ProconBypassMan
134
- class Configuration
134
+ class ButtonsSettingConfiguration
135
135
  module Loader
136
136
  def self.load: (setting_path: untyped setting_path) -> untyped
137
137
 
@@ -141,7 +141,7 @@ module ProconBypassMan
141
141
  end
142
142
 
143
143
  module ProconBypassMan
144
- class Configuration
144
+ class ButtonsSettingConfiguration
145
145
  class Validator
146
146
  def initialize: (untyped config) -> untyped
147
147
 
@@ -167,6 +167,46 @@ module ProconBypassMan
167
167
  end
168
168
  end
169
169
 
170
+ class ProconBypassMan::Configuration
171
+ module ClassAttributes
172
+ def root: () -> untyped
173
+
174
+ def logger: () -> untyped
175
+
176
+ def error_logger: () -> untyped
177
+
178
+ def pid_path: () -> untyped
179
+
180
+ def digest_path: () -> untyped
181
+
182
+ def cache: () -> untyped
183
+
184
+ def config: () -> untyped
185
+ end
186
+
187
+ attr_reader api_server: untyped
188
+
189
+ attr_accessor enable_critical_error_logging: untyped
190
+
191
+ def root=: (untyped path) -> untyped
192
+
193
+ def root: () -> untyped
194
+
195
+ def api_server=: (untyped api_server) -> untyped
196
+
197
+ def logger=: (untyped logger) -> untyped
198
+
199
+ def logger: () -> untyped
200
+
201
+ def error_logger: () -> untyped
202
+
203
+ def digest_path: () -> ::String
204
+
205
+ # @return [String] pbm-webの接続先
206
+ def internal_api_servers: () -> untyped
207
+ end
208
+
209
+
170
210
  class ProconBypassMan::DeviceConnector
171
211
  class BytesMismatchError < StandardError
172
212
  end
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.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-19 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: extension for Nintendo Switch Pro Controller
14
14
  email:
@@ -42,15 +42,21 @@ files:
42
42
  - lib/procon_bypass_man.rb
43
43
  - lib/procon_bypass_man/analog_stick_position.rb
44
44
  - lib/procon_bypass_man/boot_message.rb
45
+ - lib/procon_bypass_man/buttons_setting_configuration.rb
45
46
  - lib/procon_bypass_man/bypass.rb
47
+ - lib/procon_bypass_man/bypass/usb_hid_logger.rb
48
+ - lib/procon_bypass_man/callbacks.rb
46
49
  - lib/procon_bypass_man/configuration.rb
47
50
  - lib/procon_bypass_man/configuration/layer.rb
48
51
  - lib/procon_bypass_man/configuration/loader.rb
49
52
  - lib/procon_bypass_man/configuration/validator.rb
50
53
  - lib/procon_bypass_man/device_connector.rb
51
- - lib/procon_bypass_man/error_reporter.rb
52
54
  - lib/procon_bypass_man/io_monitor.rb
53
55
  - lib/procon_bypass_man/on_memory_cache.rb
56
+ - lib/procon_bypass_man/outbound/base.rb
57
+ - lib/procon_bypass_man/outbound/error_reporter.rb
58
+ - lib/procon_bypass_man/outbound/reporter.rb
59
+ - lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb
54
60
  - lib/procon_bypass_man/processor.rb
55
61
  - lib/procon_bypass_man/procon.rb
56
62
  - lib/procon_bypass_man/procon/analog_stick_cap.rb
@@ -64,7 +70,6 @@ files:
64
70
  - lib/procon_bypass_man/procon/press_button_aware.rb
65
71
  - lib/procon_bypass_man/procon/pressed_button_helper.rb
66
72
  - lib/procon_bypass_man/procon/user_operation.rb
67
- - lib/procon_bypass_man/reporter.rb
68
73
  - lib/procon_bypass_man/runner.rb
69
74
  - lib/procon_bypass_man/timer.rb
70
75
  - lib/procon_bypass_man/uptime.rb
@@ -74,6 +79,8 @@ files:
74
79
  - project_template/app.rb
75
80
  - project_template/setting.yml
76
81
  - project_template/systemd_units/pbm.service
82
+ - project_template/systemd_units/pbm_web.service
83
+ - project_template/web.rb
77
84
  - sig/README.rb
78
85
  - sig/main.rbs
79
86
  homepage: https://github.com/splaplapla/procon_bypass_man
@@ -1,44 +0,0 @@
1
- require "net/http"
2
- require "json"
3
-
4
- class ProconBypassMan::ErrorReporter
5
- PATH = "/api/error_reports" # POST
6
-
7
- class Client
8
- def initialize
9
- @server = ProconBypassMan.api_server
10
- @hostname = `hostname`.chomp
11
- end
12
-
13
- def post(body: )
14
- # TODO ここでvalidationする
15
- if @server.nil?
16
- ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
17
- return
18
- end
19
-
20
- uri = URI.parse("#{@server}#{PATH}")
21
- http = Net::HTTP.new(uri.host, uri.port)
22
- http.use_ssl = uri.scheme === "https"
23
- response = http.post(
24
- uri.path,
25
- { report: body.full_message.to_json, hostname: @hostname }.to_json,
26
- { "Content-Type" => "application/json" },
27
- )
28
- unless response.code == /^20/
29
- ProconBypassMan.logger.error(response.body)
30
- end
31
- rescue => e
32
- puts e
33
- ProconBypassMan.logger.error(e)
34
- end
35
- end
36
-
37
- def self.report(body: )
38
- ProconBypassMan.logger.error(body)
39
- Client.new.post(body: body)
40
- rescue => e
41
- ProconBypassMan.logger.error(e)
42
- end
43
- end
44
-
@@ -1,42 +0,0 @@
1
- require "net/http"
2
- require "json"
3
-
4
- class ProconBypassMan::Reporter
5
- PATH = "/api/reports" # POST
6
-
7
- class Client
8
- def initialize
9
- @server = ProconBypassMan.api_server
10
- @hostname = `hostname`.chomp
11
- end
12
-
13
- def post(body: )
14
- # TODO ここでvalidationする
15
- if @server.nil?
16
- ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
17
- return
18
- end
19
-
20
- uri = URI.parse("#{@server}#{PATH}")
21
- http = Net::HTTP.new(uri.host, uri.port)
22
- http.use_ssl = uri.scheme === "https"
23
- response = http.post(
24
- uri.path,
25
- { report: body.to_json, hostname: @hostname }.to_json,
26
- { "Content-Type" => "application/json" },
27
- )
28
- unless response.code == /^20/
29
- ProconBypassMan.logger.error(response.body)
30
- end
31
- rescue => e
32
- puts e
33
- ProconBypassMan.logger.error(e)
34
- end
35
- end
36
-
37
- def self.report(body: )
38
- Client.new.post(body: body)
39
- rescue => e
40
- ProconBypassMan.logger.error(e)
41
- end
42
- end