Class: RobotLab::Discovery::Advertiser
- Inherits:
-
Object
- Object
- RobotLab::Discovery::Advertiser
- Defined in:
- lib/robot_lab/discovery/advertiser.rb
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(name:, port:, path:, hostname: Socket.gethostname, capabilities: []) ⇒ Advertiser
constructor
A new instance of Advertiser.
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(name:, port:, path:, hostname: Socket.gethostname, capabilities: []) ⇒ Advertiser
Returns a new instance of Advertiser.
11 12 13 14 15 16 17 18 19 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 11 def initialize(name:, port:, path:, hostname: Socket.gethostname, capabilities: []) @name = name @port = port @path = path @hostname = hostname @capabilities = Array(capabilities).map(&:to_s) @service = nil @thread = nil end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
9 10 11 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 9 def capabilities @capabilities end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 9 def hostname @hostname end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 9 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 9 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 9 def port @port end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 21 def start @service = ZeroConf::Service.new( SERVICE_TYPE, @port, @hostname, instance_name: @name, text: TxtRecord.encode(path: @path, capabilities: @capabilities), subtypes: @capabilities.map { |c| "_#{RobotLab::Discovery.dns_label(c)}" } ) @thread = Thread.new { @service.start } self end |
#started? ⇒ Boolean
42 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 42 def started? = @thread&.alive? || false |
#stop ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/robot_lab/discovery/advertiser.rb', line 34 def stop @service&.stop @thread&.join @service = nil @thread = nil self end |