Class: SystemBrowser::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/system_browser/session.rb

Overview

This class glues Server and Client providing the support for interaction between them.

Constant Summary collapse

@@running_session =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, client) ⇒ Session

Returns a new instance of Session.



24
25
26
27
28
29
30
31
32
# File 'lib/system_browser/session.rb', line 24

def initialize(server, client)
  @server = server
  @client = client
  [@server, @client].each { |o| o.session = self }

  @previous_sigint_callback = nil

  self.register_sigint_hook
end

Instance Attribute Details

#connectionTCPSocket

Returns the connection between the server and the client.

Returns:

  • (TCPSocket)

    the connection between the server and the client



22
23
24
# File 'lib/system_browser/session.rb', line 22

def connection
  @connection
end

Class Method Details

.initObject

Initialises a new session.



10
11
12
13
14
15
16
17
18
19
# File 'lib/system_browser/session.rb', line 10

def self.init
  if @@running_session
    SLogger.debug("can't init a new session! Kill the old one first")
    return
  else
    @@running_session = true
  end

  self.new(Server.new, Client.new).init
end

Instance Method Details

#destroyObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/system_browser/session.rb', line 45

def destroy
  self.restore_previous_sigint

  @client.close
  @server.shutdown

  @@running_session = false

  SLogger.debug('[SESSION] the session was destroyed')
end

#initvoid

This method returns an undefined value.

Runs SystemBrowser::Server in background. Invokes Client and suspends the calling thread for the duration of the client.



38
39
40
41
42
43
# File 'lib/system_browser/session.rb', line 38

def init
  Thread.new { @server.start }
  Thread.new { @client.start }.join

  true
end

#send(response) ⇒ void

This method returns an undefined value.

Sends a response to the client.

Parameters:



67
68
69
# File 'lib/system_browser/session.rb', line 67

def send(response)
  self.connection.puts(response.to_json)
end

#set_client_pid(pid) ⇒ Object

Sets the client’s window pid (real pid).



58
59
60
# File 'lib/system_browser/session.rb', line 58

def set_client_pid(pid)
  @client.window_pid = pid
end