summaryrefslogtreecommitdiff
path: root/lib/net/ssh/multi/pending_connection.rb
blob: fcebcbaa9da17603eb8e6aa13b8b81fbb3a6547b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'net/ssh/multi/channel_proxy'

module Net; module SSH; module Multi
  class PendingConnection
    class ChannelOpenRecording #:nodoc:
      attr_reader :type, :extras, :channel

      def initialize(type, extras, channel)
        @type, @extras, @channel = type, extras, channel
      end

      def replay_on(session)
        real_channel = session.open_channel(type, *extras, &channel.on_confirm)
        channel.delegate_to(real_channel)
      end
    end

    class SendGlobalRequestRecording #:nodoc:
      attr_reader :type, :extra, :callback

      def initialize(type, extra, callback)
        @type, @extra, @callback = type, extra, callback
      end

      def replay_on(session)
        session.send_global_request(type, *extra, &callback)
      end
    end

    attr_reader :server

    def initialize(server)
      @server = server
      @recordings = []
    end

    def replace_with(session)
      @recordings.each { |recording| recording.replay_on(session) }
      @server.replace_session(session)
    end

    def open_channel(type="session", *extras, &on_confirm)
      channel = ChannelProxy.new(&on_confirm)
      @recordings << ChannelOpenRecording.new(type, extras, channel)
      return channel
    end

    def send_global_request(type, *extra, &callback)
      @recordings << SendGlobalRequestRecording.new(type, extra, callback)
      self
    end

    def busy?(include_invisible=false)
      true
    end

    def close
      self
    end

    def channels
      []
    end

    def preprocess
      true
    end

    def postprocess(readers, writers)
      true
    end

    def listeners
      {}
    end
  end
end; end; end