Class: Cosmos::BackgroundTask

Inherits:
Object
  • Object
show all
Includes:
Api
Defined in:
lib/cosmos/tools/cmd_tlm_server/background_task.rb

Overview

Handles a user supplied thread to run in the background of the Command and Telemetry Server

Direct Known Subclasses

LimitsGroupsBackgroundTask

Constant Summary collapse

@@count =

Returns The number of background tasks created.

Returns:

  • (Integer)

    The number of background tasks created

0

Constants included from ApiShared

ApiShared::DEFAULT_TLM_POLLING_RATE

Constants included from Extract

Extract::SCANNING_REGULAR_EXPRESSION

Instance Attribute Summary collapse

Instance Method Summary collapse

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, #cmd_tlm_clear_counters, #cmd_tlm_reload, #connect_interface, #connect_router, #disable_limits, #disable_limits_group, #disconnect_interface, #disconnect_router, #enable_limits, #enable_limits_group, #get_all_cmd_info, #get_all_interface_info, #get_all_packet_logger_info, #get_all_router_info, #get_all_target_info, #get_all_tlm_info, #get_background_tasks, #get_cmd_buffer, #get_cmd_cnt, #get_cmd_hazardous, #get_cmd_list, #get_cmd_log_filename, #get_cmd_param_list, #get_cmd_time, #get_cmd_value, #get_interface_info, #get_interface_names, #get_interface_targets, #get_limits, #get_limits_event, #get_limits_groups, #get_limits_set, #get_limits_sets, #get_out_of_limits, #get_output_logs_filenames, #get_overall_limits_state, #get_packet, #get_packet_data, #get_packet_logger_info, #get_packet_loggers, #get_router_info, #get_router_names, #get_saved_config, #get_screen_definition, #get_screen_list, #get_server_message, #get_server_message_log_filename, #get_server_status, #get_stale, #get_target_ignored_items, #get_target_ignored_parameters, #get_target_info, #get_target_list, #get_tlm_buffer, #get_tlm_cnt, #get_tlm_details, #get_tlm_item_list, #get_tlm_list, #get_tlm_log_filename, #get_tlm_packet, #get_tlm_values, #inject_tlm, #interface_state, #limits_enabled?, #map_target_to_interface, #normalize_tlm, #override_tlm, #override_tlm_raw, #replay_move_end, #replay_move_index, #replay_move_start, #replay_play, #replay_reverse_play, #replay_select_file, #replay_set_playback_delay, #replay_status, #replay_step_back, #replay_step_forward, #replay_stop, #router_state, #send_raw, #set_limits, #set_limits_set, #set_tlm, #set_tlm_raw, #start_background_task, #start_cmd_log, #start_logging, #start_new_server_message_log, #start_raw_logging_interface, #start_raw_logging_router, #start_tlm_log, #stop_background_task, #stop_cmd_log, #stop_logging, #stop_raw_logging_interface, #stop_raw_logging_router, #stop_tlm_log, #subscribe_limits_events, #subscribe_packet_data, #subscribe_server_messages, #tlm, #tlm_formatted, #tlm_raw, #tlm_variable, #tlm_with_units, #unsubscribe_limits_events, #unsubscribe_packet_data, #unsubscribe_server_messages

Constructor Details

#initializeBackgroundTask

Constructor



32
33
34
35
36
37
38
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 32

def initialize
  @@count += 1
  @name = "Background Task #{@@count}"
  @thread = nil
  @status = ''
  @stopped = false
end

Instance Attribute Details

#nameString

Returns Name of the background task.

Returns:

  • (String)

    Name of the background task



23
24
25
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 23

def name
  @name
end

#statusString

Returns Status message to display in the CTS.

Returns:

  • (String)

    Status message to display in the CTS



27
28
29
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 27

def status
  @status
end

#stoppedBoolean

Returns Whether the task is initially stopped when the CTS starts.

Returns:

  • (Boolean)

    Whether the task is initially stopped when the CTS starts



29
30
31
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 29

def stopped
  @stopped
end

#threadThread

Returns Ruby thread running the task.

Returns:

  • (Thread)

    Ruby thread running the task



25
26
27
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 25

def thread
  @thread
end

Instance Method Details

#callObject

Subclasses should override the call method which is called once by the Command and Telemetry Server. Thus subclasses should add their own loop and sleep statements if they expect to run continuously.



43
44
45
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 43

def call
  raise "call method must be defined by subclass"
end

#stopObject

The Command and Telemetry Server calls the stop method before killing the Thread which is running the background tasks. This method should be overriden by subclasses to do whatever shutdown is necessary.



50
51
52
# File 'lib/cosmos/tools/cmd_tlm_server/background_task.rb', line 50

def stop
  # Nothing to do by default
end