Class: Idb::PBWatcherThread

Inherits:
Qt::Object
  • Object
show all
Defined in:
lib/gui/pb_watcher_thread.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PBWatcherThread

Returns a new instance of PBWatcherThread.



5
6
7
8
# File 'lib/gui/pb_watcher_thread.rb', line 5

def initialize *args
  super *args
  $terminate_pbwatcher_thread = false
end

Instance Method Details

#start_pbwatcher_thread(pbs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gui/pb_watcher_thread.rb', line 16

def start_pbwatcher_thread pbs
  @pbwatcher_thread = Thread.new do
    channel = $device.ssh.open_channel do |ch|
      ch.request_pty do |ch, success|
      cmd = "/var/root/pbwatcher 1 #{pbs}"
      $log.info "Executing pbwatcher: #{cmd}"
      ch.exec cmd do |ch, success|
        $log.error "could not execute command" unless success

        # "on_data" is called when the process writes something to stdout
        ch.on_data do |c, data|
          emit new_entry(data)
        end

         # "on_extended_data" is called when the process writes something to stderr
         ch.on_extended_data do |c, type, data|
           emit new_entry(data)
         end

         ch.on_close { |ch|
           $log.info "pbwatcher terminated"
         }
      end
        end
    end

    loop do
      #TODO mutex to protect device?
      #even better: make one central thread that calls process.
      # and all functions using it call it to ensure its running. or auto start it.
      sleep 0.5
      $device.ssh.process
      #$device.ssh.process 0
      if $terminate_pbwatcher_thread
        $log.info "Terminating pbwatcher"
        channel.close
        break
      end
    end
    $log.info "Terminating thread"
  end


end

#stopObject



11
12
13
# File 'lib/gui/pb_watcher_thread.rb', line 11

def stop
  $terminate_pbwatcher_thread = true
end