Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / braille_display_private / brlapi_connection.h
blob044e6f5dcd3614fb71ef0c128ca8257f2df33342
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 {
14 namespace api {
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 {
20 public:
21 typedef base::Closure OnDataReadyCallback;
23 enum ConnectResult {
24 CONNECT_ERROR_RETRY,
25 CONNECT_ERROR_NO_RETRY,
26 CONNECT_SUCCESS,
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
47 // for logging.
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
62 // value.
63 virtual int ReadKey(brlapi_keyCode_t* keyCode) = 0;
65 protected:
66 BrlapiConnection();
67 DISALLOW_COPY_AND_ASSIGN(BrlapiConnection);
70 } // namespace braille_display_private
71 } // namespace api
72 } // namespace extensions
74 #endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_