Class: Tochka::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/tochka/agent.rb

Constant Summary collapse

SOCKPATH =
"/var/run/captured.sock"
CMD_GET_STATUS =
"get_status"
CMD_START_CAPTURE =
"start_capture"
CMD_STOP_CAPTURE =
"stop_capture"
STATE_INIT =
"init"
STATE_RUNNING =
"running"
STATE_STOP =
"stop"
STATE_UNKNOWN =
"unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tochka/agent.rb', line 19

def initialize
  @state = STATE_INIT
  @file_name = "<None>"
  @file_size = 0
  @duration = 0
  @current_channel = 0
  @channel_walk = 0
  @frame_count = 0
  @utilization = 0
  @utilization_channel = 0
end

Instance Attribute Details

#channel_walkObject (readonly)

Returns the value of attribute channel_walk.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def channel_walk
  @channel_walk
end

#current_channelObject (readonly)

Returns the value of attribute current_channel.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def current_channel
  @current_channel
end

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def duration
  @duration
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def file_name
  @file_name
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def file_size
  @file_size
end

#frame_countObject (readonly)

Returns the value of attribute frame_count.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def frame_count
  @frame_count
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def state
  @state
end

#utilizationObject (readonly)

Returns the value of attribute utilization.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def utilization
  @utilization
end

#utilization_channelObject (readonly)

Returns the value of attribute utilization_channel.



7
8
9
# File 'lib/tochka/agent.rb', line 7

def utilization_channel
  @utilization_channel
end

Instance Method Details

#get_statusObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tochka/agent.rb', line 31

def get_status
  resp = do_rpc(get_msg(CMD_GET_STATUS))
  if resp["state"] != nil
    update_state(resp)
    return resp
  end

  # not responded?
  @state = STATE_UNKNOWN
  return {}
rescue => e
  $log.err("agent detected unknown error in get_status (#{e})")
  return {}
end

#start_captureObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tochka/agent.rb', line 46

def start_capture
  $log.info("requesting start_capture")
  resp = do_rpc(get_msg(CMD_START_CAPTURE))
  resp = get_status()
  if resp["state"] == STATE_RUNNING
    update_state(resp)
    return true
  end

  # not responded or failed
  @state = STATE_UNKNOWN
  return false
rescue => e
  $log.err("agent detected unknown error in start_capture (#{e})")
  return false
end

#stop_captureObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tochka/agent.rb', line 63

def stop_capture
  $log.info("requesting stop_capture")
  resp = do_rpc(get_msg(CMD_STOP_CAPTURE))
  resp = get_status()
  if resp["state"] == STATE_STOP
    update_state(resp)
    return true
  end

  return false
rescue => e
  $log.err("agent detected unknown error in stop_capture (#{e})")
  return false
end