Class: Cosmos::StreamInterface
- Defined in:
- lib/cosmos/interfaces/stream_interface.rb
Overview
Stream interfaces use stream protocols to interface with the target. This class simply passes through each method to identically named methods in the stream protocol class. This class is an abstract class and should not be used directly. It should be subclassed and the connect method implemented.
Direct Known Subclasses
Constant Summary
Constants included from Extract
Extract::SCANNING_REGULAR_EXPRESSION
Instance Attribute Summary
Attributes inherited from Interface
#auto_reconnect, #connect_on_startup, #disable_disconnect, #interfaces, #name, #num_clients, #options, #packet_log_writer_pairs, #raw_logger_pair, #read_count, #read_queue_size, #reconnect_delay, #routers, #target_names, #thread, #write_count, #write_queue_size
Instance Method Summary collapse
-
#bytes_read ⇒ Integer
The number of bytes read by the stream protocol.
-
#bytes_read=(bytes_read) ⇒ Integer
Sets the number of bytes read by the stream protocol.
-
#bytes_written ⇒ Integer
The number of bytes written to the stream protocol.
-
#bytes_written=(bytes_written) ⇒ Integer
Sets the number of bytes written to the stream protocol.
-
#connected? ⇒ Boolean
Whether the stream protocol is connected to the target.
-
#disconnect ⇒ Object
Disconnect the stream protocol from the target.
-
#initialize(stream_protocol_type, *stream_protocol_args) ⇒ StreamInterface
constructor
A new instance of StreamInterface.
-
#post_read_data(packet_data) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the StreamProtocol when processing the data in the Stream.
-
#post_read_packet(packet) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the StreamProtocol when processing the data in the Stream.
-
#pre_write_packet(packet) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the StreamProtocol when processing the data in the Stream.
-
#read ⇒ Object
Read a packet from the stream protocol.
-
#write(packet) ⇒ Object
Write a packet to the stream protocol.
-
#write_raw(data) ⇒ Object
Write a raw binary string to the stream protocol.
Methods inherited from Interface
#connect, #copy_to, #post_identify_packet, #read_allowed?, #set_option, #start_raw_logging, #stop_raw_logging, #write_allowed?, #write_raw_allowed?
Methods included from Api
#cmd, #cmd_no_checks, #cmd_no_hazardous_check, #cmd_no_range_check, #cmd_raw, #cmd_raw_no_checks, #cmd_raw_no_hazardous_check, #cmd_raw_no_range_check, #connect_interface, #connect_router, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_limits, #enable_limits_group, #get_cmd_hazardous, #get_cmd_list, #get_cmd_log_filename, #get_cmd_param_list, #get_cmd_time, #get_cmd_value, #get_interface_names, #get_limits, #get_limits_event, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_out_of_limits, #get_overall_limits_state, #get_packet_data, #get_router_names, #get_server_message_log_filename, #get_stale, #get_target_list, #get_tlm_details, #get_tlm_item_list, #get_tlm_list, #get_tlm_log_filename, #get_tlm_packet, #get_tlm_values, #interface_state, #limits_enabled?, #map_target_to_interface, #router_state, #send_raw, #set_limits, #set_limits_set, #set_tlm, #set_tlm_raw, #start_cmd_log, #start_logging, #start_new_server_message_log, #start_raw_logging_interface, #start_raw_logging_router, #start_tlm_log, #stop_cmd_log, #stop_logging, #stop_raw_logging_interface, #stop_raw_logging_router, #stop_tlm_log, #subscribe_limits_events, #subscribe_packet_data, #tlm, #tlm_formatted, #tlm_raw, #tlm_variable, #tlm_with_units, #unsubscribe_limits_events, #unsubscribe_packet_data
Constructor Details
#initialize(stream_protocol_type, *stream_protocol_args) ⇒ StreamInterface
Returns a new instance of StreamInterface.
33 34 35 36 37 38 39 40 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 33 def initialize(stream_protocol_type, *stream_protocol_args) super() stream_protocol_class = stream_protocol_type.to_s.capitalize << 'StreamProtocol' klass = Cosmos.require_class(stream_protocol_class.class_name_to_filename) @stream_protocol = klass.new(*stream_protocol_args) @stream_protocol.interface = self end |
Instance Method Details
#bytes_read ⇒ Integer
Returns The number of bytes read by the stream protocol.
98 99 100 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 98 def bytes_read @stream_protocol.bytes_read end |
#bytes_read=(bytes_read) ⇒ Integer
Returns Sets the number of bytes read by the stream protocol.
103 104 105 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 103 def bytes_read=(bytes_read) @stream_protocol.bytes_read = bytes_read end |
#bytes_written ⇒ Integer
Returns The number of bytes written to the stream protocol.
108 109 110 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 108 def bytes_written @stream_protocol.bytes_written end |
#bytes_written=(bytes_written) ⇒ Integer
Returns Sets the number of bytes written to the stream protocol.
113 114 115 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 113 def bytes_written=(bytes_written) @stream_protocol.bytes_written = bytes_written end |
#connected? ⇒ Boolean
Returns Whether the stream protocol is connected to the target.
45 46 47 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 45 def connected? @stream_protocol.connected? end |
#disconnect ⇒ Object
Disconnect the stream protocol from the target
50 51 52 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 50 def disconnect @stream_protocol.disconnect end |
#post_read_data(packet_data) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the Cosmos::StreamProtocol when processing the data in the Cosmos::Stream.
Subclasses of Cosmos::StreamProtocol can implement the same method. However, if the callback method is implemented in the interface then the subclass method is not called.
Thus if you are implementing an Interface that uses a Cosmos::StreamProtocol and choose to implement this method, you must be aware of any processing that the Cosmos::StreamProtocol does in the same method and re-implement it (or call @stream_protocol.post_read_data(packet_data), etc) in yours.
|
# File 'lib/cosmos/interfaces/stream_interface.rb', line 117
|
#post_read_packet(packet) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the Cosmos::StreamProtocol when processing the data in the Cosmos::Stream.
Subclasses of Cosmos::StreamProtocol can implement the same method. However, if the callback method is implemented in the interface then the subclass method is not called.
Thus if you are implementing an Interface that uses a Cosmos::StreamProtocol and choose to implement this method, you must be aware of any processing that the Cosmos::StreamProtocol does in the same method and re-implement it (or call @stream_protocol.post_read_data(packet_data), etc) in yours.
|
# File 'lib/cosmos/interfaces/stream_interface.rb', line 117
|
#pre_write_packet(packet) ⇒ Object
These methods do not exist in StreamInterface but can be implemented by subclasses and will be called by the Cosmos::StreamProtocol when processing the data in the Cosmos::Stream.
Subclasses of Cosmos::StreamProtocol can implement the same method. However, if the callback method is implemented in the interface then the subclass method is not called.
Thus if you are implementing an Interface that uses a Cosmos::StreamProtocol and choose to implement this method, you must be aware of any processing that the Cosmos::StreamProtocol does in the same method and re-implement it (or call @stream_protocol.post_read_data(packet_data), etc) in yours.
|
# File 'lib/cosmos/interfaces/stream_interface.rb', line 117
|
#read ⇒ Object
Read a packet from the stream protocol
55 56 57 58 59 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 55 def read packet = @stream_protocol.read @read_count += 1 if packet packet end |
#write(packet) ⇒ Object
Write a packet to the stream protocol
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 64 def write(packet) if connected?() begin @stream_protocol.write(packet) @write_count += 1 rescue Exception => err Logger.instance.error("Error writing to interface : #{@name}") disconnect() raise err end else raise "Interface not connected for write : #{@name}" end end |
#write_raw(data) ⇒ Object
Write a raw binary string to the stream protocol
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cosmos/interfaces/stream_interface.rb', line 82 def write_raw(data) if connected?() begin @stream_protocol.write_raw(data) @write_count += 1 rescue Exception => err Logger.instance.error("Error writing raw data to interface : #{@name}") disconnect() raise err end else raise "Interface not connected for write_raw : #{@name}" end end |