1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "library_loaders/libbrlapi.h"
13 namespace extensions
{
15 namespace braille_display_private
{
17 // A connection to the brlapi server. See brlapi.h for more information
18 // about the semantics of the methods in this class.
19 class BrlapiConnection
{
21 typedef base::Closure OnDataReadyCallback
;
25 CONNECT_ERROR_NO_RETRY
,
29 static scoped_ptr
<BrlapiConnection
> Create(LibBrlapiLoader
* loader
);
31 virtual ~BrlapiConnection();
33 virtual ConnectResult
Connect(const OnDataReadyCallback
& onDataReady
) = 0;
35 virtual void Disconnect() = 0;
37 virtual bool Connected() = 0;
39 // Gets the last brlapi error on this thread.
40 // This works ismilar to errno in C. There's one thread-local error
41 // value, meaning that this method should be called after any
42 // other method of this class that can return an error without calling
43 // another method in between. This class is not thread safe.
44 virtual brlapi_error_t
* BrlapiError() = 0;
46 // Gets a description of the last brlapi error for this thread, useful
48 virtual std::string
BrlapiStrError() = 0;
50 // Gets the total size of the display, which may be 0 if no display is
51 // present, returning true on success. Note that this is cached in the
52 // brlapi client so it is cheap.
53 virtual bool GetDisplaySize(size_t* size
) = 0;
55 // Sends the specified cells to the display. The array size must
56 // be equal to what GetDisplaySize() last returned for this connection.
57 virtual bool WriteDots(const unsigned char* cells
) = 0;
59 // Reads the next keyboard command, returning true on success.
60 // Returns < 0 on error, 0 if no more keys are pending and > 0
61 // on success, in which case keyCode will be set to the key command
63 virtual int ReadKey(brlapi_keyCode_t
* keyCode
) = 0;
67 DISALLOW_COPY_AND_ASSIGN(BrlapiConnection
);
70 } // namespace braille_display_private
72 } // namespace extensions
74 #endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_