Class: Flic::Client

Inherits:
Object
  • Object
show all
Extended by:
Callbacks
Includes:
Features::ConnectionChannel, Features::ForceDisconnect, Features::GetButtonUuid, Features::GetInfo, Features::Ping, Features::Scan, Features::ScanWizard
Defined in:
lib/flic/client.rb,
lib/flic/client/scanner.rb,
lib/flic/client/features.rb,
lib/flic/client/scan_wizard.rb,
lib/flic/client/server_info.rb,
lib/flic/client/features/ping.rb,
lib/flic/client/features/scan.rb,
lib/flic/client/features/get_info.rb,
lib/flic/client/connection_channel.rb,
lib/flic/client/features/scan_wizard.rb,
lib/flic/client/features/get_button_uuid.rb,
lib/flic/client/features/force_disconnect.rb,
lib/flic/client/features/connection_channel.rb

Defined Under Namespace

Modules: Features Classes: ConnectionChannel, Error, ScanWizard, Scanner, ServerInfo, Shutdown

Constant Summary

Constants included from Callbacks

Flic::Callbacks::SEMAPHORE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Features::ConnectionChannel

#add_connection_channel, #connection_channels, #remove_connection_channel

Methods included from Features::ForceDisconnect

#force_disconnect

Methods included from Features::GetButtonUuid

#get_button_uuid

Methods included from Features::GetInfo

#get_info

Methods included from Features::Ping

#ping

Methods included from Features::Scan

#add_scanner, #remove_scanner, #scanners

Methods included from Features::ScanWizard

#add_scan_wizard, #remove_scan_wizard, #scan_wizards

Constructor Details

#initialize(host = 'localhost', port = 5551) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

  • _self (Flic::Client)

    the object that the method was called on



44
45
46
47
48
49
50
51
# File 'lib/flic/client.rb', line 44

def initialize(host = 'localhost', port = 5551)
  @host, @port = host, port
  @handle_next_event_semaphore = Mutex.new
  @socket = TCPSocket.new(host, port)
  @connection = Protocol::Connection.new(socket)
  @is_shutdown = false
  yield self if block_given?
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



39
40
41
# File 'lib/flic/client.rb', line 39

def connection
  @connection
end

#hostObject (readonly)

Returns the value of attribute host.



39
40
41
# File 'lib/flic/client.rb', line 39

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



39
40
41
# File 'lib/flic/client.rb', line 39

def port
  @port
end

#socketObject (readonly)

Returns the value of attribute socket.



39
40
41
# File 'lib/flic/client.rb', line 39

def socket
  @socket
end

Class Method Details

.open(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/flic/client.rb', line 28

def open(*args)
  client = new(*args)

  begin
    yield client
  ensure
    client.shutdown
  end
end

Instance Method Details

#enter_main_loopObject



74
75
76
# File 'lib/flic/client.rb', line 74

def enter_main_loop
  loop { handle_next_event }
end

#handle_next_eventObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/flic/client.rb', line 62

def handle_next_event
  @handle_next_event_semaphore.synchronize do
    begin
      handle_event connection.recv_event
    rescue Protocol::Connection::UnderlyingSocketClosedError
      shutdown

      raise Shutdown, 'The connection has been closed'
    end
  end
end

#shutdownObject



57
58
59
60
# File 'lib/flic/client.rb', line 57

def shutdown
  socket.close
  @is_shutdown = true
end

#shutdown?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/flic/client.rb', line 53

def shutdown?
  @is_shutdown
end