Class: WSDiscovery::Searcher
- Inherits:
-
MulticastConnection
- Object
- EventMachine::Connection
- MulticastConnection
- WSDiscovery::Searcher
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/ws_discovery/searcher.rb
Constant Summary
Constants included from NetworkConstants
NetworkConstants::MULTICAST_IP, NetworkConstants::MULTICAST_PORT, NetworkConstants::TTL
Instance Attribute Summary collapse
-
#discovery_responses ⇒ EventMachine::Channel
readonly
Provides subscribers with responses from their search request.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Searcher
constructor
A new instance of Searcher.
-
#parse(data) ⇒ WSDiscovery::Response
Converts the headers to a set of key-value pairs.
-
#post_init ⇒ Object
Sends the probe that was built during init.
-
#probe(options = {}) ⇒ String
Probe for target services supporting WS-Discovery.
-
#receive_data(response) ⇒ Object
This is the callback called by EventMachine when it receives data on the socket that’s been opened for this connection.
Constructor Details
Instance Attribute Details
#discovery_responses ⇒ EventMachine::Channel (readonly)
Returns Provides subscribers with responses from their search request.
11 12 13 |
# File 'lib/ws_discovery/searcher.rb', line 11 def discovery_responses @discovery_responses end |
Instance Method Details
#parse(data) ⇒ WSDiscovery::Response
Converts the headers to a set of key-value pairs.
47 48 49 |
# File 'lib/ws_discovery/searcher.rb', line 47 def parse(data) WSDiscovery::Response.new(data) end |
#post_init ⇒ Object
Sends the probe that was built during init. Logs what was sent if the send was successful.
53 54 55 56 57 |
# File 'lib/ws_discovery/searcher.rb', line 53 def post_init if send_datagram(@search, MULTICAST_IP, MULTICAST_PORT) > 0 logger.info("Sent datagram search:\n#{@search}") end end |
#probe(options = {}) ⇒ String
Probe for target services supporting WS-Discovery.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ws_discovery/searcher.rb', line 68 def probe(={}) namespaces = { 'xmlns:a' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing', 'xmlns:d' => 'http://schemas.xmlsoap.org/ws/2005/04/discovery', 'xmlns:s' => 'http://www.w3.org/2003/05/soap-envelope' } namespaces.merge! [:env_namespaces] if [:env_namespaces] Builder::XmlMarkup.new.s(:Envelope, namespaces) do |xml| xml.s(:Header) do |xml| xml.a(:Action, 'http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe') xml.a(:MessageID, "uuid:#{UUID.generate}") xml.a(:To, 'urn:schemas-xmlsoap-org:ws:2005:04:discovery') end xml.s(:Body) do |xml| xml.d(:Probe) do xml.d(:Types, [:type_attributes], [:types]) xml.d(:Scopes, [:scope_attributes], [:scopes]) end end end end |
#receive_data(response) ⇒ Object
This is the callback called by EventMachine when it receives data on the socket that’s been opened for this connection. In this case, the method parses the probe matches into WSDiscovery::Responses and adds them to the appropriate EventMachine::Channel (provided as accessor methods). This effectively means that in each Channel, you get a WSDiscovery::Response for each response that comes in on the socket.
36 37 38 39 40 41 |
# File 'lib/ws_discovery/searcher.rb', line 36 def receive_data(response) ip, port = peer_info logger.info "<#{self.class}> Response from #{ip}:#{port}:\n#{response}\n" parsed_response = parse(response) @discovery_responses << parsed_response end |