Class: Orchestrator::Device::Manager

Inherits:
Core::ModuleManager show all
Defined in:
lib/orchestrator/device/manager.rb

Instance Attribute Summary collapse

Attributes inherited from Core::ModuleManager

#current_user, #instance, #logger, #settings, #stattrak, #status, #thread

Instance Method Summary collapse

Methods inherited from Core::ModuleManager

#add_subscription, #define_setting, #get_scheduler, #get_system, #inspect, #reloaded, #setting, #subscribe, #trak, #unsubscribe

Constructor Details

#initialize(*args) ⇒ Manager

Returns a new instance of Manager.



4
5
6
7
8
9
10
# File 'lib/orchestrator/device/manager.rb', line 4

def initialize(*args)
    super(*args)

    # Do we want to start here?
    # Should be ok.
    @thread.next_tick method(:start)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/orchestrator/device/manager.rb', line 12

def connection
  @connection
end

#processorObject (readonly)

Returns the value of attribute processor.



12
13
14
# File 'lib/orchestrator/device/manager.rb', line 12

def processor
  @processor
end

Instance Method Details

#notify_connectedObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/orchestrator/device/manager.rb', line 41

def notify_connected
    if @instance.respond_to? :connected, true
        begin
            @instance.__send__(:connected)
        rescue => e
            @logger.print_error(e, 'error in module connected callback')
        end
    end

    update_connected_status(true)
end

#notify_disconnectedObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/orchestrator/device/manager.rb', line 53

def notify_disconnected
    if @instance.respond_to? :disconnected, true
        begin
            @instance.__send__(:disconnected)
        rescue => e
            @logger.print_error(e, 'error in module disconnected callback')
        end
    end

    update_connected_status(false)
end

#notify_received(data, resolve, command = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/orchestrator/device/manager.rb', line 65

def notify_received(data, resolve, command = nil)
    begin
        blk = command.nil? ? nil : command[:on_receive]
        if blk.respond_to? :call
            blk.call(data, resolve, command)
        elsif @instance.respond_to? :received, true
            @instance.__send__(:received, data, resolve, command)
        else
            @logger.warn('no received function provided')
            :abort
        end
    rescue => e
        @logger.print_error(e, 'error in received callback')
        return :abort
    end
end

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/orchestrator/device/manager.rb', line 14

def start
    return true unless @processor.nil?
    @processor = Processor.new(self)

    super # Calls on load (allows setting of tls certs)

    # Load UV-Rays abstraction here
    @connection = if @settings.udp
        UdpConnection.new(self, @processor)
    elsif @settings.makebreak
        ::UV.connect(@settings.ip, @settings.port, MakebreakConnection, self, @processor, @settings.tls)
    else
        ::UV.connect(@settings.ip, @settings.port, TcpConnection, self, @processor, @settings.tls)
    end

    @processor.transport = @connection
    true # for REST API
end

#stopObject



33
34
35
36
37
38
39
# File 'lib/orchestrator/device/manager.rb', line 33

def stop
    super
    @processor.terminate unless @processor.nil?
    @processor = nil
    @connection.terminate unless @connection.nil?
    @connection = nil
end