Class: Flic::Client
- Inherits:
-
Object
- Object
- Flic::Client
- 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
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #enter_main_loop ⇒ Object
- #handle_next_event ⇒ Object
-
#initialize(host = 'localhost', port = 5551) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #shutdown ⇒ Object
- #shutdown? ⇒ Boolean
Methods included from Features::ConnectionChannel
#add_connection_channel, #connection_channels, #remove_connection_channel
Methods included from Features::ForceDisconnect
Methods included from Features::GetButtonUuid
Methods included from Features::GetInfo
Methods included from Features::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.
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
39 40 41 |
# File 'lib/flic/client.rb', line 39 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
39 40 41 |
# File 'lib/flic/client.rb', line 39 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
39 40 41 |
# File 'lib/flic/client.rb', line 39 def port @port end |
#socket ⇒ Object (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_loop ⇒ Object
74 75 76 |
# File 'lib/flic/client.rb', line 74 def enter_main_loop loop { handle_next_event } end |
#handle_next_event ⇒ Object
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:: shutdown raise Shutdown, 'The connection has been closed' end end end |
#shutdown ⇒ Object
57 58 59 60 |
# File 'lib/flic/client.rb', line 57 def shutdown socket.close @is_shutdown = true end |
#shutdown? ⇒ Boolean
53 54 55 |
# File 'lib/flic/client.rb', line 53 def shutdown? @is_shutdown end |