Class: VLC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/vlc-client/server.rb

Overview

Manages a local VLC server in a child process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost', port = 9595, headless = false) ⇒ Server

Creates a VLC server lifecycle manager



15
16
17
18
19
# File 'lib/vlc-client/server.rb', line 15

def initialize(host = 'localhost', port = 9595, headless = false)
  @host, @port, @headless = host, port, headless
  @pid = NullObject.new
  @deamon = false
end

Instance Attribute Details

#headlessObject Also known as: headless?

Returns the value of attribute headless.



4
5
6
# File 'lib/vlc-client/server.rb', line 4

def headless
  @headless
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/vlc-client/server.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/vlc-client/server.rb', line 4

def port
  @port
end

Instance Method Details

#daemonizeInteger

Start a VLC instance as a system deamon

See Also:



62
63
64
# File 'lib/vlc-client/server.rb', line 62

def daemonize
  start(true)
end

#daemonized?Boolean

Queries if VLC is running in daemonized mode

See Also:



70
71
72
# File 'lib/vlc-client/server.rb', line 70

def daemonized?
  @deamon == true
end

#running?Boolean Also known as: started?

Queries if VLC is running



25
26
27
# File 'lib/vlc-client/server.rb', line 25

def running?
  not @pid.nil?
end

#start(detached = false) ⇒ Integer

Starts a VLC instance in a subprocess

See Also:



48
49
50
51
52
53
54
# File 'lib/vlc-client/server.rb', line 48

def start(detached = false)
  return @pid if running?

  detached ? @deamon = true : setup_traps

  @pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
end

#stopInteger

Starts a VLC instance in a subprocess



79
80
81
82
83
84
85
86
87
# File 'lib/vlc-client/server.rb', line 79

def stop
  return nil if stopped?

  Process.kill('SIGTERM', pid = @pid)
  @pid = NullObject.new
  @deamon = false

  pid
end

#stopped?Boolean

Queries if VLC is stopped



35
36
37
# File 'lib/vlc-client/server.rb', line 35

def stopped?
  not running?
end