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

Side by Side Diff: apps/moterm/moterm_driver.cc

Issue 1459033002: Replace (most) occurrences of mojo::Array<T>() with nullptr. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/versioning_test_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "apps/moterm/moterm_driver.h" 5 #include "apps/moterm/moterm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 callback.Run(mojo::files::Error::OK); 193 callback.Run(mojo::files::Error::OK);
194 194
195 client_->OnClosed(); 195 client_->OnClosed();
196 } 196 }
197 197
198 void MotermDriver::Read(uint32_t num_bytes_to_read, 198 void MotermDriver::Read(uint32_t num_bytes_to_read,
199 int64_t offset, 199 int64_t offset,
200 mojo::files::Whence whence, 200 mojo::files::Whence whence,
201 const ReadCallback& callback) { 201 const ReadCallback& callback) {
202 if (is_closed_) { 202 if (is_closed_) {
203 callback.Run(mojo::files::Error::CLOSED, mojo::Array<uint8_t>()); 203 callback.Run(mojo::files::Error::CLOSED, nullptr);
204 return; 204 return;
205 } 205 }
206 206
207 if (offset != 0 || whence != mojo::files::Whence::FROM_CURRENT) { 207 if (offset != 0 || whence != mojo::files::Whence::FROM_CURRENT) {
208 // TODO(vtl): Is this the "right" behavior? 208 // TODO(vtl): Is this the "right" behavior?
209 callback.Run(mojo::files::Error::INVALID_ARGUMENT, mojo::Array<uint8_t>()); 209 callback.Run(mojo::files::Error::INVALID_ARGUMENT, nullptr);
210 return; 210 return;
211 } 211 }
212 212
213 if (!num_bytes_to_read) { 213 if (!num_bytes_to_read) {
214 callback.Run(mojo::files::Error::OK, mojo::Array<uint8_t>()); 214 callback.Run(mojo::files::Error::OK, nullptr);
215 return; 215 return;
216 } 216 }
217 217
218 pending_read_queue_.push_back(PendingRead(num_bytes_to_read, callback)); 218 pending_read_queue_.push_back(PendingRead(num_bytes_to_read, callback));
219 CompletePendingReads(); 219 CompletePendingReads();
220 } 220 }
221 221
222 void MotermDriver::Write(mojo::Array<uint8_t> bytes_to_write, 222 void MotermDriver::Write(mojo::Array<uint8_t> bytes_to_write,
223 int64_t offset, 223 int64_t offset,
224 mojo::files::Whence whence, 224 mojo::files::Whence whence,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe 370 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe
371 // unsupported/EINVAL is better.) 371 // unsupported/EINVAL is better.)
372 callback.Run(mojo::files::Error::UNAVAILABLE, 372 callback.Run(mojo::files::Error::UNAVAILABLE,
373 mojo::ScopedSharedBufferHandle()); 373 mojo::ScopedSharedBufferHandle());
374 } 374 }
375 375
376 void MotermDriver::Ioctl(uint32_t request, 376 void MotermDriver::Ioctl(uint32_t request,
377 mojo::Array<uint32_t> in_values, 377 mojo::Array<uint32_t> in_values,
378 const IoctlCallback& callback) { 378 const IoctlCallback& callback) {
379 if (is_closed_) { 379 if (is_closed_) {
380 callback.Run(mojo::files::Error::CLOSED, mojo::Array<uint32_t>()); 380 callback.Run(mojo::files::Error::CLOSED, nullptr);
381 return; 381 return;
382 } 382 }
383 383
384 if (request != mojo::files::kIoctlTerminal) { 384 if (request != mojo::files::kIoctlTerminal) {
385 callback.Run(mojo::files::Error::UNIMPLEMENTED, mojo::Array<uint32_t>()); 385 callback.Run(mojo::files::Error::UNIMPLEMENTED, nullptr);
386 return; 386 return;
387 } 387 }
388 388
389 // "Is TTY?" Yes. 389 // "Is TTY?" Yes.
390 if (!in_values || !in_values.size()) { 390 if (!in_values || !in_values.size()) {
391 callback.Run(mojo::files::Error::OK, mojo::Array<uint32_t>()); 391 callback.Run(mojo::files::Error::OK, nullptr);
392 return; 392 return;
393 } 393 }
394 394
395 switch (in_values[0]) { 395 switch (in_values[0]) {
396 case mojo::files::kIoctlTerminalGetSettings: 396 case mojo::files::kIoctlTerminalGetSettings:
397 IoctlGetSettings(in_values.Pass(), callback); 397 IoctlGetSettings(in_values.Pass(), callback);
398 return; 398 return;
399 case mojo::files::kIoctlTerminalSetSettings: 399 case mojo::files::kIoctlTerminalSetSettings:
400 IoctlSetSettings(in_values.Pass(), callback); 400 IoctlSetSettings(in_values.Pass(), callback);
401 return; 401 return;
402 case mojo::files::kIoctlTerminalGetWindowSize: 402 case mojo::files::kIoctlTerminalGetWindowSize:
403 case mojo::files::kIoctlTerminalSetWindowSize: 403 case mojo::files::kIoctlTerminalSetWindowSize:
404 NOTIMPLEMENTED(); 404 NOTIMPLEMENTED();
405 callback.Run(mojo::files::Error::UNIMPLEMENTED, mojo::Array<uint32_t>()); 405 callback.Run(mojo::files::Error::UNIMPLEMENTED, nullptr);
406 return; 406 return;
407 default: 407 default:
408 callback.Run(mojo::files::Error::UNIMPLEMENTED, mojo::Array<uint32_t>()); 408 callback.Run(mojo::files::Error::UNIMPLEMENTED, nullptr);
409 return; 409 return;
410 } 410 }
411 } 411 }
412 412
413 void MotermDriver::IoctlGetSettings(mojo::Array<uint32_t> in_values, 413 void MotermDriver::IoctlGetSettings(mojo::Array<uint32_t> in_values,
414 const IoctlCallback& callback) { 414 const IoctlCallback& callback) {
415 if (in_values.size() != 1u) { 415 if (in_values.size() != 1u) {
416 callback.Run(mojo::files::Error::INVALID_ARGUMENT, mojo::Array<uint32_t>()); 416 callback.Run(mojo::files::Error::INVALID_ARGUMENT, nullptr);
417 return; 417 return;
418 } 418 }
419 419
420 auto out_values = mojo::Array<uint32_t>::New(kTotalFieldCount); 420 auto out_values = mojo::Array<uint32_t>::New(kTotalFieldCount);
421 421
422 // TODO(vtl): Add support for various things. Also, some values should be 422 // TODO(vtl): Add support for various things. Also, some values should be
423 // hard-coded. 423 // hard-coded.
424 424
425 // iflag: 425 // iflag:
426 if (icrnl_) 426 if (icrnl_)
427 out_values[kIFlagIdx] |= mojo::files::kIoctlTerminalTermiosIFlagICRNL; 427 out_values[kIFlagIdx] |= mojo::files::kIoctlTerminalTermiosIFlagICRNL;
428 428
429 // oflag: 429 // oflag:
430 if (onlcr_) 430 if (onlcr_)
431 out_values[kOFlagIdx] |= mojo::files::kIoctlTerminalTermiosOFlagONLCR; 431 out_values[kOFlagIdx] |= mojo::files::kIoctlTerminalTermiosOFlagONLCR;
432 432
433 // lflag: 433 // lflag:
434 if (icanon_) 434 if (icanon_)
435 out_values[kLFlagIdx] |= mojo::files::kIoctlTerminalTermiosLFlagICANON; 435 out_values[kLFlagIdx] |= mojo::files::kIoctlTerminalTermiosLFlagICANON;
436 436
437 // cc: 437 // cc:
438 out_values[kVEraseIdx] = verase_; 438 out_values[kVEraseIdx] = verase_;
439 out_values[kVEOFIdx] = veof_; 439 out_values[kVEOFIdx] = veof_;
440 440
441 callback.Run(mojo::files::Error::OK, out_values.Pass()); 441 callback.Run(mojo::files::Error::OK, out_values.Pass());
442 } 442 }
443 443
444 void MotermDriver::IoctlSetSettings(mojo::Array<uint32_t> in_values, 444 void MotermDriver::IoctlSetSettings(mojo::Array<uint32_t> in_values,
445 const IoctlCallback& callback) { 445 const IoctlCallback& callback) {
446 callback.Run(IoctlSetSettingsHelper(in_values.Pass()), 446 callback.Run(IoctlSetSettingsHelper(in_values.Pass()), nullptr);
447 mojo::Array<uint32_t>());
448 } 447 }
449 448
450 mojo::files::Error MotermDriver::IoctlSetSettingsHelper( 449 mojo::files::Error MotermDriver::IoctlSetSettingsHelper(
451 mojo::Array<uint32_t> in_values) { 450 mojo::Array<uint32_t> in_values) {
452 // Note: "termios" offsets (and sizes) are increased by 1, to accomodate the 451 // Note: "termios" offsets (and sizes) are increased by 1, to accomodate the
453 // subrequest at index 0. 452 // subrequest at index 0.
454 453
455 // The "cc" values are optional. 454 // The "cc" values are optional.
456 if (in_values.size() < 1 + kBaseFieldCount) 455 if (in_values.size() < 1 + kBaseFieldCount)
457 return mojo::files::Error::INVALID_ARGUMENT; 456 return mojo::files::Error::INVALID_ARGUMENT;
(...skipping 24 matching lines...) Expand all
482 } 481 }
483 if (1 + kVEOFIdx < in_values.size()) { 482 if (1 + kVEOFIdx < in_values.size()) {
484 uint32_t value = in_values[1 + kVEOFIdx]; 483 uint32_t value = in_values[1 + kVEOFIdx];
485 if (value > std::numeric_limits<uint8_t>::max()) 484 if (value > std::numeric_limits<uint8_t>::max())
486 return mojo::files::Error::INVALID_ARGUMENT; 485 return mojo::files::Error::INVALID_ARGUMENT;
487 veof_ = static_cast<uint8_t>(value); 486 veof_ = static_cast<uint8_t>(value);
488 } 487 }
489 488
490 return mojo::files::Error::OK; 489 return mojo::files::Error::OK;
491 } 490 }
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/versioning_test_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698