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. 4 5#ifndef CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_ 6#define CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_ 7 8#include "base/basictypes.h" 9#include "base/callback_forward.h" 10#include "base/memory/scoped_ptr.h" 11#include "library_loaders/libbrlapi.h" 12 13namespace extensions { 14namespace api { 15namespace braille_display_private { 16 17// A connection to the brlapi server. See brlapi.h for more information 18// about the semantics of the methods in this class. 19class BrlapiConnection { 20 public: 21 typedef base::Closure OnDataReadyCallback; 22 23 enum ConnectResult { 24 CONNECT_ERROR_RETRY, 25 CONNECT_ERROR_NO_RETRY, 26 CONNECT_SUCCESS, 27 }; 28 29 static scoped_ptr<BrlapiConnection> Create(LibBrlapiLoader* loader); 30 31 virtual ~BrlapiConnection(); 32 33 virtual ConnectResult Connect(const OnDataReadyCallback& onDataReady) = 0; 34 35 virtual void Disconnect() = 0; 36 37 virtual bool Connected() = 0; 38 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; 45 46 // Gets a description of the last brlapi error for this thread, useful 47 // for logging. 48 virtual std::string BrlapiStrError() = 0; 49 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; 54 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; 58 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; 64 65 protected: 66 BrlapiConnection(); 67 DISALLOW_COPY_AND_ASSIGN(BrlapiConnection); 68}; 69 70} // namespace braille_display_private 71} // namespace api 72} // namespace extensions 73 74#endif // CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRLAPI_CONNECTION_H_ 75