Class: SystemBrowser::Session
- Inherits:
-
Object
- Object
- SystemBrowser::Session
- Defined in:
- lib/system_browser/session.rb
Overview
Constant Summary collapse
- @@running_session =
false
Instance Attribute Summary collapse
-
#connection ⇒ TCPSocket
The connection between the server and the client.
Class Method Summary collapse
-
.init ⇒ Object
Initialises a new session.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#init ⇒ void
Runs Server in background.
-
#initialize(server, client) ⇒ Session
constructor
A new instance of Session.
-
#send(response) ⇒ void
Sends a response to the client.
-
#set_client_pid(pid) ⇒ Object
Sets the client’s window pid (real pid).
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
#connection ⇒ TCPSocket
Returns 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
.init ⇒ Object
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
#destroy ⇒ Object
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 |
#init ⇒ void
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.
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 |