Sha256: 960edd333131147ca2a818d4110ae230b7d4cfd5f0938c2afebec5057de7ca61

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

# encoding: ascii-8bit

# Copyright 2017 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos/interfaces/interface'

module Cosmos
  # Base class for interfaces that act read and write from a stream
  class StreamInterface < Interface
    attr_accessor :stream

    def initialize(protocol_type = nil, protocol_args = [])
      super()
      @protocol_type = ConfigParser::handle_nil(protocol_type)
      @protocol_args = protocol_args
      if @protocol_type
        protocol_class_name = protocol_type.to_s.capitalize << 'Protocol'
        klass = Cosmos.require_class(protocol_class_name.class_name_to_filename)
        add_protocol(klass, protocol_args, :READ_WRITE)
      end
    end

    def connect
      super()
      @stream.connect if @stream
    end

    def connected?
      if @stream
        @stream.connected?
      else
        false
      end
    end

    def disconnect
      @stream.disconnect if @stream
      super()
    end

    def read_interface
      begin
        data = @stream.read
      rescue Timeout::Error
        Logger.instance.error "Timeout waiting for data to be read"
        data = nil
      end
      return nil if data.nil? or data.length <= 0
      read_interface_base(data)
      data
    end

    def write_interface(data)
      write_interface_base(data)
      @stream.write(data)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cosmos-4.1.1-java lib/cosmos/interfaces/stream_interface.rb
cosmos-4.1.1 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.1.0-java lib/cosmos/interfaces/stream_interface.rb
cosmos-4.1.0 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.3-java lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.3-universal-java-1.8 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.3 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.2-universal-java-1.8 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.2 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.1-universal-java-1.8 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.1 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.0-universal-java-1.8 lib/cosmos/interfaces/stream_interface.rb
cosmos-4.0.0 lib/cosmos/interfaces/stream_interface.rb