Class: SystemBrowser::Client
- Inherits:
-
Object
- Object
- SystemBrowser::Client
- Defined in:
- lib/system_browser/client.rb
Constant Summary collapse
- PID_COMMAND =
The command that the client sends to the server at the session initialisation.
'set-window-pid'
- CLIENT_NAME =
The name of the executable of the client application.
'system_browser'
- ClientNotFoundError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
- #session ⇒ SystemBrowser::Session writeonly
Instance Method Summary collapse
-
#close ⇒ void
Destroys the window by sending the SIGINT signal (the window has its own handlers to destroy itself, so it’s not our job).
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#start ⇒ Integer
Spawns a new process in a new process group.
-
#window_pid=(window_pid) ⇒ Integer
The process ID of the client process (window).
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
18 19 20 |
# File 'lib/system_browser/client.rb', line 18 def initialize @init_pid = nil end |
Instance Attribute Details
#session=(value) ⇒ SystemBrowser::Session (writeonly)
14 15 16 |
# File 'lib/system_browser/client.rb', line 14 def session=(value) @session = value end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Destroys the window by sending the SIGINT signal (the window has its own handlers to destroy itself, so it’s not our job). Does not wait for anything.
59 60 61 62 63 |
# File 'lib/system_browser/client.rb', line 59 def close SLogger.debug("[client] interrupting window (#{@window_pid})...") Process.kill(:INT, @window_pid) end |
#start ⇒ Integer
@init_pid and @window_pid are two different processes. The
Spawns a new process in a new process group. I really wanted to find the way to spawn the process in the same group. However, when I do that, I cannot send any signals to the window anymore (the app crashes, because the ruby process exits).
client uses @init_id to bootstrap itself and @window_pid is the process that can be used to send signals to the client.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/system_browser/client.rb', line 34 def start executable = self.client_executable unless system("which #{executable} > /dev/null 2>&1") fail ClientNotFoundError, "executable '#{executable}' is not on your $PATH" end @init_pid = spawn(executable, pgroup: true) Process.wait(@init_pid) @init_pid end |
#window_pid=(window_pid) ⇒ Integer
Returns the process ID of the client process (window).
49 50 51 52 |
# File 'lib/system_browser/client.rb', line 49 def window_pid=(window_pid) SLogger.debug("[client] setting window pid (#{window_pid})") @window_pid = window_pid end |