Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: chrome/browser/extensions/api/braille_display_private/brlapi_connection.cc

Issue 2401393003: Add multiline braille support. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio n.h" 5 #include "chrome/browser/extensions/api/braille_display_private/brlapi_connectio n.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/free_deleter.h" 10 #include "base/memory/free_deleter.h"
(...skipping 25 matching lines...) Expand all
36 explicit BrlapiConnectionImpl(LibBrlapiLoader* loader) : 36 explicit BrlapiConnectionImpl(LibBrlapiLoader* loader) :
37 libbrlapi_loader_(loader) {} 37 libbrlapi_loader_(loader) {}
38 38
39 ~BrlapiConnectionImpl() override { Disconnect(); } 39 ~BrlapiConnectionImpl() override { Disconnect(); }
40 40
41 ConnectResult Connect(const OnDataReadyCallback& on_data_ready) override; 41 ConnectResult Connect(const OnDataReadyCallback& on_data_ready) override;
42 void Disconnect() override; 42 void Disconnect() override;
43 bool Connected() override { return handle_ != nullptr; } 43 bool Connected() override { return handle_ != nullptr; }
44 brlapi_error_t* BrlapiError() override; 44 brlapi_error_t* BrlapiError() override;
45 std::string BrlapiStrError() override; 45 std::string BrlapiStrError() override;
46 bool GetDisplaySize(size_t* size) override; 46 bool GetDisplaySize(unsigned int* rows, unsigned int* columns) override;
47 bool WriteDots(const unsigned char* cells) override; 47 bool WriteDots(const std::vector<std::vector<unsigned char>> cells) override;
48 int ReadKey(brlapi_keyCode_t* keyCode) override; 48 int ReadKey(brlapi_keyCode_t* keyCode) override;
49 49
50 // MessageLoopForIO::Watcher 50 // MessageLoopForIO::Watcher
51 void OnFileCanReadWithoutBlocking(int fd) override { on_data_ready_.Run(); } 51 void OnFileCanReadWithoutBlocking(int fd) override { on_data_ready_.Run(); }
52 52
53 void OnFileCanWriteWithoutBlocking(int fd) override {} 53 void OnFileCanWriteWithoutBlocking(int fd) override {}
54 54
55 private: 55 private:
56 bool CheckConnected(); 56 bool CheckConnected();
57 ConnectResult ConnectResultForError(); 57 ConnectResult ConnectResultForError();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 path[pathElements++] = kDefaultTtyChromeOS; 94 path[pathElements++] = kDefaultTtyChromeOS;
95 #endif 95 #endif
96 if (pathElements == 0 && getenv("WINDOWPATH") == NULL) 96 if (pathElements == 0 && getenv("WINDOWPATH") == NULL)
97 path[pathElements++] = kDefaultTtyLinux; 97 path[pathElements++] = kDefaultTtyLinux;
98 if (libbrlapi_loader_->brlapi__enterTtyModeWithPath( 98 if (libbrlapi_loader_->brlapi__enterTtyModeWithPath(
99 handle_.get(), path, pathElements, NULL) < 0) { 99 handle_.get(), path, pathElements, NULL) < 0) {
100 LOG(ERROR) << "brlapi: couldn't enter tty mode: " << BrlapiStrError(); 100 LOG(ERROR) << "brlapi: couldn't enter tty mode: " << BrlapiStrError();
101 Disconnect(); 101 Disconnect();
102 return CONNECT_ERROR_RETRY; 102 return CONNECT_ERROR_RETRY;
103 } 103 }
104 unsigned int rows, columns;
104 105
105 size_t size; 106 if (!GetDisplaySize(&rows, &columns)) {
106 if (!GetDisplaySize(&size)) {
107 // Error already logged. 107 // Error already logged.
108 Disconnect(); 108 Disconnect();
109 return CONNECT_ERROR_RETRY; 109 return CONNECT_ERROR_RETRY;
110 } 110 }
111 111
112 // A display size of 0 means no display connected. We can't reliably 112 // A display size of 0 means no display connected. We can't reliably
113 // detect when a display gets connected, so fail and let the caller 113 // detect when a display gets connected, so fail and let the caller
114 // retry connecting. 114 // retry connecting.
115 if (size == 0) { 115 if (rows * columns == 0) {
116 VLOG(1) << "No braille display connected"; 116 VLOG(1) << "No braille display connected";
117 Disconnect(); 117 Disconnect();
118 return CONNECT_ERROR_RETRY; 118 return CONNECT_ERROR_RETRY;
119 } 119 }
120 120
121 const brlapi_keyCode_t extraKeys[] = { 121 const brlapi_keyCode_t extraKeys[] = {
122 BRLAPI_KEY_TYPE_CMD | BRLAPI_KEY_CMD_OFFLINE, 122 BRLAPI_KEY_TYPE_CMD | BRLAPI_KEY_CMD_OFFLINE,
123 // brltty 5.1 converts dot input to Unicode characters unless we 123 // brltty 5.1 converts dot input to Unicode characters unless we
124 // explicitly accept this command. 124 // explicitly accept this command.
125 BRLAPI_KEY_TYPE_CMD | BRLAPI_KEY_CMD_PASSDOTS, 125 BRLAPI_KEY_TYPE_CMD | BRLAPI_KEY_CMD_PASSDOTS,
(...skipping 29 matching lines...) Expand all
155 } 155 }
156 156
157 brlapi_error_t* BrlapiConnectionImpl::BrlapiError() { 157 brlapi_error_t* BrlapiConnectionImpl::BrlapiError() {
158 return libbrlapi_loader_->brlapi_error_location(); 158 return libbrlapi_loader_->brlapi_error_location();
159 } 159 }
160 160
161 std::string BrlapiConnectionImpl::BrlapiStrError() { 161 std::string BrlapiConnectionImpl::BrlapiStrError() {
162 return libbrlapi_loader_->brlapi_strerror(BrlapiError()); 162 return libbrlapi_loader_->brlapi_strerror(BrlapiError());
163 } 163 }
164 164
165 bool BrlapiConnectionImpl::GetDisplaySize(size_t* size) { 165 bool BrlapiConnectionImpl::GetDisplaySize(unsigned int* rows,
166 unsigned int* columns) {
166 if (!CheckConnected()) { 167 if (!CheckConnected()) {
167 return false; 168 return false;
168 } 169 }
169 unsigned int columns, rows;
170 if (libbrlapi_loader_->brlapi__getDisplaySize( 170 if (libbrlapi_loader_->brlapi__getDisplaySize(
171 handle_.get(), &columns, &rows) < 0) { 171 handle_.get(), columns, rows) < 0) {
172 LOG(ERROR) << "Couldn't get braille display size " << BrlapiStrError(); 172 LOG(ERROR) << "Couldn't get braille display size " << BrlapiStrError();
173 return false; 173 return false;
174 } 174 }
175 *size = columns * rows;
176 return true; 175 return true;
177 } 176 }
178 177
179 bool BrlapiConnectionImpl::WriteDots(const unsigned char* cells) { 178 bool BrlapiConnectionImpl::WriteDots(
179 const std::vector<std::vector<unsigned char>> cells) {
dmazzoni 2016/10/11 17:15:39 This should be indented 4 spaces
ultimatedbz 2016/10/16 01:12:39 Done.
180 // Cells is a 2D vector, but for now, we are just displaying the first row.
180 if (!CheckConnected()) 181 if (!CheckConnected())
181 return false; 182 return false;
182 if (libbrlapi_loader_->brlapi__writeDots(handle_.get(), cells) < 0) { 183 if (libbrlapi_loader_->brlapi__writeDots(handle_.get(), &cells[0][0]) < 0) {
dmazzoni 2016/10/11 17:15:39 I could be wrong but I think it just wants a singl
ultimatedbz 2016/10/16 01:12:39 Done.
183 VLOG(1) << "Couldn't write to brlapi: " << BrlapiStrError(); 184 VLOG(1) << "Couldn't write to brlapi: " << BrlapiStrError();
184 return false; 185 return false;
185 } 186 }
186 return true; 187 return true;
187 } 188 }
188 189
189 int BrlapiConnectionImpl::ReadKey(brlapi_keyCode_t* key_code) { 190 int BrlapiConnectionImpl::ReadKey(brlapi_keyCode_t* key_code) {
190 if (!CheckConnected()) 191 if (!CheckConnected())
191 return -1; 192 return -1;
192 return libbrlapi_loader_->brlapi__readKey( 193 return libbrlapi_loader_->brlapi__readKey(
(...skipping 17 matching lines...) Expand all
210 if (error->brlerrno == BRLAPI_ERROR_LIBCERR 211 if (error->brlerrno == BRLAPI_ERROR_LIBCERR
211 && error->libcerrno == ENOENT) { 212 && error->libcerrno == ENOENT) {
212 return CONNECT_ERROR_NO_RETRY; 213 return CONNECT_ERROR_NO_RETRY;
213 } 214 }
214 return CONNECT_ERROR_RETRY; 215 return CONNECT_ERROR_RETRY;
215 } 216 }
216 217
217 } // namespace braille_display_private 218 } // namespace braille_display_private
218 } // namespace api 219 } // namespace api
219 } // namespace extensions 220 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698