Class: Libuv::Loop

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrator/status.rb,
lib/orchestrator/datagram_server.rb

Instance Method Summary collapse

Instance Method Details

#observerObject



259
260
261
262
# File 'lib/orchestrator/status.rb', line 259

def observer
    @observer ||= ::Orchestrator::Status.new(@loop)
    @observer
end

#udp_broadcast(data, port = 9, ip = '<broadcast>') ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/orchestrator/datagram_server.rb', line 85

def udp_broadcast(data, port = 9, ip = '<broadcast>')
    if @udp_broadcast
        @udp_broadcast.send(ip, port, data)
    else
        CRITICAL.synchronize {
            return @udp_broadcast.send(ip, port, data) if @udp_broadcast
            
            port = Rails.configuration.orchestrator.broadcast_port || 0

            if port == 0
                @udp_broadcast = ::UV.open_datagram_socket(::Orchestrator::UdpBroadcast)
            elsif defined? @@udp_broadcast
                @udp_broadcast = @@udp_broadcast
            else # define a class variable at the specified port
                @udp_broadcast = ::UV.open_datagram_socket(::Orchestrator::UdpBroadcast, '0.0.0.0', port)
                @@udp_broadcast = @udp_broadcast
            end

            @udp_broadcast.send(ip, port, data)
        }
    end
end

#udp_serviceObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/orchestrator/datagram_server.rb', line 64

def udp_service
    if @udp_service
        @udp_service
    else
        CRITICAL.synchronize {
            return @udp_service if @udp_service

            port = Rails.configuration.orchestrator.datagram_port || 0

            if port == 0
                @udp_service = ::UV.open_datagram_socket(::Orchestrator::UdpService)
            elsif defined? @@udp_service
                @udp_service = @@udp_service
            else # define a class variable at the specified port
                @udp_service = ::UV.open_datagram_socket(::Orchestrator::UdpService, '0.0.0.0', port)
                @@udp_service = @udp_service
            end
        }
    end
end

#wake_device(mac, ip = '<broadcast>') ⇒ Object



108
109
110
111
112
# File 'lib/orchestrator/datagram_server.rb', line 108

def wake_device(mac, ip = '<broadcast>')
    mac = mac.gsub(/(0x|[^0-9A-Fa-f])*/, "").scan(/.{2}/).pack("H*H*H*H*H*H*")
    magicpacket = (0xff.chr) * 6 + mac * 16
    udp_broadcast(magicpacket, 9, ip)
end