Class: CZTop::Beacon
Overview
Used for LAN discovery and presence.
This is implemented using an Actor.
Constant Summary collapse
- ZBEACON_FPTR =
function pointer to the zbeacon() function
::CZMQ::FFI.ffi_libraries.each do |dl| fptr = dl.find_function("zbeacon") break fptr if fptr end
- MAX_BEACON_DATA =
Returns maximum length of data to #publish.
255
Instance Attribute Summary collapse
-
#actor ⇒ Actor
readonly
The actor behind this Beacon.
Instance Method Summary collapse
-
#configure(port) ⇒ String
Run the beacon on the specified UDP port.
-
#initialize ⇒ Beacon
constructor
Initialize new Beacon.
-
#listen ⇒ void
Just like #subscribe, but subscribe to all peer beacons.
-
#publish(data, interval) ⇒ void
Start broadcasting a beacon.
-
#receive ⇒ Message
Receive next beacon from a peer.
-
#silence ⇒ void
Stop broadcasting the beacon.
-
#subscribe(filter) ⇒ void
Start listening to beacons from peers.
-
#terminate ⇒ void
Terminates the beacon.
-
#unsubscribe ⇒ void
Stop listening to other peers.
-
#verbose! ⇒ void
Enable verbose logging of commands and activity.
Constructor Details
#initialize ⇒ Beacon
Initialize new Beacon.
18 19 20 |
# File 'lib/cztop/beacon.rb', line 18 def initialize @actor = Actor.new(ZBEACON_FPTR) end |
Instance Attribute Details
#actor ⇒ Actor (readonly)
Returns the actor behind this Beacon.
23 24 25 |
# File 'lib/cztop/beacon.rb', line 23 def actor @actor end |
Instance Method Details
#configure(port) ⇒ String
Run the beacon on the specified UDP port.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cztop/beacon.rb', line 45 def configure(port) @actor.send_picture("si", :string, "CONFIGURE", :int, port) ptr = Zstr.recv(@actor) # NULL if context terminated or interrupted HasFFIDelegate.raise_zmq_err if ptr.null? hostname = ptr.read_string return hostname unless hostname.empty? raise NotImplementedError, "system doesn't support UDP broadcasts" end |
#listen ⇒ void
This method returns an undefined value.
Just like #subscribe, but subscribe to all peer beacons.
88 89 90 91 |
# File 'lib/cztop/beacon.rb', line 88 def listen @actor.send_picture("sb", :string, "SUBSCRIBE", :string, nil, :int, 0) end |
#publish(data, interval) ⇒ void
This method returns an undefined value.
Start broadcasting a beacon.
66 67 68 69 70 |
# File 'lib/cztop/beacon.rb', line 66 def publish(data, interval) raise ArgumentError, "data too long" if data.bytesize > MAX_BEACON_DATA @actor.send_picture("sbi", :string, "PUBLISH", :string, data, :int, data.bytesize, :int, interval) end |
#receive ⇒ Message
Receive next beacon from a peer.
101 102 103 |
# File 'lib/cztop/beacon.rb', line 101 def receive @actor.receive end |
#silence ⇒ void
This method returns an undefined value.
Stop broadcasting the beacon.
74 75 76 |
# File 'lib/cztop/beacon.rb', line 74 def silence @actor << "SILENCE" end |
#subscribe(filter) ⇒ void
This method returns an undefined value.
Start listening to beacons from peers.
81 82 83 84 |
# File 'lib/cztop/beacon.rb', line 81 def subscribe(filter) @actor.send_picture("sb", :string, "SUBSCRIBE", :string, filter, :int, filter.bytesize) end |
#terminate ⇒ void
This method returns an undefined value.
Terminates the beacon.
27 28 29 |
# File 'lib/cztop/beacon.rb', line 27 def terminate @actor.terminate end |
#unsubscribe ⇒ void
This method returns an undefined value.
Stop listening to other peers.
95 96 97 |
# File 'lib/cztop/beacon.rb', line 95 def unsubscribe @actor << "UNSUBSCRIBE" end |
#verbose! ⇒ void
This method returns an undefined value.
Enable verbose logging of commands and activity.
33 34 35 |
# File 'lib/cztop/beacon.rb', line 33 def verbose! @actor << "VERBOSE" end |