Sha256: 160fea8b7b5fe0490ed5b3ae517a4a86e00f8e6bd333d35207fdf17ddba826d0

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require_relative './input'

module Fusuma
  module Plugin
    module Inputs
      # libinput commands wrapper
      class TimerInput < Input
        DEFAULT_INTERVAL = 0.3
        def config_param_types
          {
            interval: [Float]
          }
        end

        attr_reader :pid

        def io
          @io ||= begin
            reader, writer = create_io
            @pid = start(reader, writer)

            reader
          end
        end

        def start(reader, writer)
          pid = fork do
            timer_loop(reader, writer)
          end
          Process.detach(pid)
          writer.close
          pid
        end

        def timer_loop(reader, writer)
          reader.close
          begin
            loop do
              sleep interval
              writer.puts 'timer'
            end
          rescue Errno::EPIPE
            exit 0
          rescue StandardError => e
            MultiLogger.error e
          end
        end

        private

        def create_io
          IO.pipe
        end

        def interval
          config_params(:interval) || DEFAULT_INTERVAL
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fusuma-2.4.1 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.4.0 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.3.0 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.2.0 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.1.0 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.5 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.4 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.3 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.2 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.1 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.0 lib/fusuma/plugin/inputs/timer_input.rb
fusuma-2.0.0.pre2 lib/fusuma/plugin/inputs/timer_input.rb