Method: Roby::Distributed::Peer#initialize

Defined in:
lib/roby/distributed/peer.rb

#initialize(connection_space, socket, remote_name, remote_id, remote_state, &block) ⇒ Peer

Creates a Peer object for the peer connected at socket. This peer is to be managed by connection_space If a block is given, it is called in the control thread when the connection is finalized



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/roby/distributed/peer.rb', line 282

def initialize(connection_space, socket, remote_name, remote_id, remote_state, &block)
    # Initialize the remote name with the socket parameters. It will be set to 
    # the real name during the connection process
    @remote_name = remote_name
    @remote_id   = remote_id
    @peer_info   = socket.peer_info

    super() if defined? super

    @connection_space = connection_space
    @local_server = PeerServer.new(self)
    @proxies    = Hash.new
    @removing_proxies = Hash.new { |h, k| h[k] = Array.new }
    @mutex    = Mutex.new
    @triggers     = Hash.new
    @socket       = socket
    @stats        = ComStats.new 0, 0
    @dead   = false
    @disabled_rx  = 0
    @disabled_tx  = 0
    connection_space.pending_sockets << [socket, self]

    @connection_state = :connected
    @send_queue       = Queue.new
    @completion_queue = Queue.new
    @current_cycle    = Array.new

    Roby::Distributed.peers[remote_id]   = self
    local_server.state_update remote_state

    @task = ConnectionTask.new :peer => self
    Roby::Control.once do
  connection_space.plan.permanent(task)
  task.start!
  task.emit(:ready)
    end

    @send_thread      = Thread.new(&method(:communication_loop))
end