OLD | NEW |
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // In canonical mode, each read only gets a single line. | 140 // In canonical mode, each read only gets a single line. |
141 if (icanon_ && data[i] == kNL) { | 141 if (icanon_ && data[i] == kNL) { |
142 data_size = i + 1; | 142 data_size = i + 1; |
143 data.resize(data_size); | 143 data.resize(data_size); |
144 break; | 144 break; |
145 } | 145 } |
146 } | 146 } |
147 send_data_queue_.erase(send_data_queue_.begin(), | 147 send_data_queue_.erase(send_data_queue_.begin(), |
148 send_data_queue_.begin() + data_size); | 148 send_data_queue_.begin() + data_size); |
149 | 149 |
150 pending_read.callback.Run(mojo::files::ERROR_OK, data.Pass()); | 150 pending_read.callback.Run(mojo::files::Error::OK, data.Pass()); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 void MotermDriver::FlushInputLine() { | 154 void MotermDriver::FlushInputLine() { |
155 for (size_t i = 0; i < input_line_queue_.size(); i++) | 155 for (size_t i = 0; i < input_line_queue_.size(); i++) |
156 send_data_queue_.push_back(input_line_queue_[i]); | 156 send_data_queue_.push_back(input_line_queue_[i]); |
157 input_line_queue_.clear(); | 157 input_line_queue_.clear(); |
158 CompletePendingReads(); | 158 CompletePendingReads(); |
159 } | 159 } |
160 | 160 |
(...skipping 15 matching lines...) Expand all Loading... |
176 // TODO(vtl): It seems extremely unlikely that we'd overlow a |uint32_t| here | 176 // TODO(vtl): It seems extremely unlikely that we'd overlow a |uint32_t| here |
177 // (but it's theoretically possible). But perhaps we should handle it more | 177 // (but it's theoretically possible). But perhaps we should handle it more |
178 // gracefully if it ever comes up. | 178 // gracefully if it ever comes up. |
179 CHECK_LE(translated_bytes.size(), std::numeric_limits<uint32_t>::max()); | 179 CHECK_LE(translated_bytes.size(), std::numeric_limits<uint32_t>::max()); |
180 client_->OnDataReceived(translated_bytes.data(), | 180 client_->OnDataReceived(translated_bytes.data(), |
181 static_cast<uint32_t>(translated_bytes.size())); | 181 static_cast<uint32_t>(translated_bytes.size())); |
182 } | 182 } |
183 | 183 |
184 void MotermDriver::Close(const CloseCallback& callback) { | 184 void MotermDriver::Close(const CloseCallback& callback) { |
185 if (is_closed_) { | 185 if (is_closed_) { |
186 callback.Run(mojo::files::ERROR_CLOSED); | 186 callback.Run(mojo::files::Error::CLOSED); |
187 return; | 187 return; |
188 } | 188 } |
189 | 189 |
190 // TODO(vtl): Call pending read callbacks? | 190 // TODO(vtl): Call pending read callbacks? |
191 | 191 |
192 is_closed_ = true; | 192 is_closed_ = true; |
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, mojo::Array<uint8_t>()); |
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, mojo::Array<uint8_t>()); |
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, mojo::Array<uint8_t>()); |
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, |
225 const WriteCallback& callback) { | 225 const WriteCallback& callback) { |
226 DCHECK(!bytes_to_write.is_null()); | 226 DCHECK(!bytes_to_write.is_null()); |
227 | 227 |
228 if (is_closed_) { | 228 if (is_closed_) { |
229 callback.Run(mojo::files::ERROR_CLOSED, 0); | 229 callback.Run(mojo::files::Error::CLOSED, 0); |
230 return; | 230 return; |
231 } | 231 } |
232 | 232 |
233 if (offset != 0 || whence != mojo::files::WHENCE_FROM_CURRENT) { | 233 if (offset != 0 || whence != mojo::files::Whence::FROM_CURRENT) { |
234 // TODO(vtl): Is this the "right" behavior? | 234 // TODO(vtl): Is this the "right" behavior? |
235 callback.Run(mojo::files::ERROR_INVALID_ARGUMENT, 0); | 235 callback.Run(mojo::files::Error::INVALID_ARGUMENT, 0); |
236 return; | 236 return; |
237 } | 237 } |
238 | 238 |
239 if (!bytes_to_write.size()) { | 239 if (!bytes_to_write.size()) { |
240 callback.Run(mojo::files::ERROR_OK, 0); | 240 callback.Run(mojo::files::Error::OK, 0); |
241 return; | 241 return; |
242 } | 242 } |
243 | 243 |
244 HandleOutput(&bytes_to_write.front(), bytes_to_write.size()); | 244 HandleOutput(&bytes_to_write.front(), bytes_to_write.size()); |
245 | 245 |
246 // TODO(vtl): Is this OK if the client detached (and we're destroyed?). | 246 // TODO(vtl): Is this OK if the client detached (and we're destroyed?). |
247 callback.Run(mojo::files::ERROR_OK, | 247 callback.Run(mojo::files::Error::OK, |
248 static_cast<uint32_t>(bytes_to_write.size())); | 248 static_cast<uint32_t>(bytes_to_write.size())); |
249 } | 249 } |
250 | 250 |
251 void MotermDriver::ReadToStream(mojo::ScopedDataPipeProducerHandle source, | 251 void MotermDriver::ReadToStream(mojo::ScopedDataPipeProducerHandle source, |
252 int64_t offset, | 252 int64_t offset, |
253 mojo::files::Whence whence, | 253 mojo::files::Whence whence, |
254 int64_t num_bytes_to_read, | 254 int64_t num_bytes_to_read, |
255 const ReadToStreamCallback& callback) { | 255 const ReadToStreamCallback& callback) { |
256 if (is_closed_) { | 256 if (is_closed_) { |
257 callback.Run(mojo::files::ERROR_CLOSED); | 257 callback.Run(mojo::files::Error::CLOSED); |
258 return; | 258 return; |
259 } | 259 } |
260 | 260 |
261 // TODO(vtl) | 261 // TODO(vtl) |
262 NOTIMPLEMENTED(); | 262 NOTIMPLEMENTED(); |
263 callback.Run(mojo::files::ERROR_UNIMPLEMENTED); | 263 callback.Run(mojo::files::Error::UNIMPLEMENTED); |
264 } | 264 } |
265 | 265 |
266 void MotermDriver::WriteFromStream(mojo::ScopedDataPipeConsumerHandle sink, | 266 void MotermDriver::WriteFromStream(mojo::ScopedDataPipeConsumerHandle sink, |
267 int64_t offset, | 267 int64_t offset, |
268 mojo::files::Whence whence, | 268 mojo::files::Whence whence, |
269 const WriteFromStreamCallback& callback) { | 269 const WriteFromStreamCallback& callback) { |
270 if (is_closed_) { | 270 if (is_closed_) { |
271 callback.Run(mojo::files::ERROR_CLOSED); | 271 callback.Run(mojo::files::Error::CLOSED); |
272 return; | 272 return; |
273 } | 273 } |
274 | 274 |
275 // TODO(vtl) | 275 // TODO(vtl) |
276 NOTIMPLEMENTED(); | 276 NOTIMPLEMENTED(); |
277 callback.Run(mojo::files::ERROR_UNIMPLEMENTED); | 277 callback.Run(mojo::files::Error::UNIMPLEMENTED); |
278 } | 278 } |
279 | 279 |
280 void MotermDriver::Tell(const TellCallback& callback) { | 280 void MotermDriver::Tell(const TellCallback& callback) { |
281 if (is_closed_) { | 281 if (is_closed_) { |
282 callback.Run(mojo::files::ERROR_CLOSED, 0); | 282 callback.Run(mojo::files::Error::CLOSED, 0); |
283 return; | 283 return; |
284 } | 284 } |
285 | 285 |
286 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 286 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
287 // unsupported/EINVAL is better.) | 287 // unsupported/EINVAL is better.) |
288 callback.Run(mojo::files::ERROR_UNAVAILABLE, 0); | 288 callback.Run(mojo::files::Error::UNAVAILABLE, 0); |
289 } | 289 } |
290 | 290 |
291 void MotermDriver::Seek(int64_t offset, | 291 void MotermDriver::Seek(int64_t offset, |
292 mojo::files::Whence whence, | 292 mojo::files::Whence whence, |
293 const SeekCallback& callback) { | 293 const SeekCallback& callback) { |
294 if (is_closed_) { | 294 if (is_closed_) { |
295 callback.Run(mojo::files::ERROR_CLOSED, 0); | 295 callback.Run(mojo::files::Error::CLOSED, 0); |
296 return; | 296 return; |
297 } | 297 } |
298 | 298 |
299 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 299 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
300 // unsupported/EINVAL is better.) | 300 // unsupported/EINVAL is better.) |
301 callback.Run(mojo::files::ERROR_UNAVAILABLE, 0); | 301 callback.Run(mojo::files::Error::UNAVAILABLE, 0); |
302 } | 302 } |
303 | 303 |
304 void MotermDriver::Stat(const StatCallback& callback) { | 304 void MotermDriver::Stat(const StatCallback& callback) { |
305 if (is_closed_) { | 305 if (is_closed_) { |
306 callback.Run(mojo::files::ERROR_CLOSED, nullptr); | 306 callback.Run(mojo::files::Error::CLOSED, nullptr); |
307 return; | 307 return; |
308 } | 308 } |
309 | 309 |
310 // TODO(vtl) | 310 // TODO(vtl) |
311 NOTIMPLEMENTED(); | 311 NOTIMPLEMENTED(); |
312 callback.Run(mojo::files::ERROR_UNIMPLEMENTED, nullptr); | 312 callback.Run(mojo::files::Error::UNIMPLEMENTED, nullptr); |
313 } | 313 } |
314 | 314 |
315 void MotermDriver::Truncate(int64_t size, const TruncateCallback& callback) { | 315 void MotermDriver::Truncate(int64_t size, const TruncateCallback& callback) { |
316 if (is_closed_) { | 316 if (is_closed_) { |
317 callback.Run(mojo::files::ERROR_CLOSED); | 317 callback.Run(mojo::files::Error::CLOSED); |
318 return; | 318 return; |
319 } | 319 } |
320 | 320 |
321 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 321 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
322 // unsupported/EINVAL is better.) | 322 // unsupported/EINVAL is better.) |
323 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 323 callback.Run(mojo::files::Error::UNAVAILABLE); |
324 } | 324 } |
325 | 325 |
326 void MotermDriver::Touch(mojo::files::TimespecOrNowPtr atime, | 326 void MotermDriver::Touch(mojo::files::TimespecOrNowPtr atime, |
327 mojo::files::TimespecOrNowPtr mtime, | 327 mojo::files::TimespecOrNowPtr mtime, |
328 const TouchCallback& callback) { | 328 const TouchCallback& callback) { |
329 if (is_closed_) { | 329 if (is_closed_) { |
330 callback.Run(mojo::files::ERROR_CLOSED); | 330 callback.Run(mojo::files::Error::CLOSED); |
331 return; | 331 return; |
332 } | 332 } |
333 | 333 |
334 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 334 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
335 // unsupported/EINVAL is better.) | 335 // unsupported/EINVAL is better.) |
336 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 336 callback.Run(mojo::files::Error::UNAVAILABLE); |
337 } | 337 } |
338 | 338 |
339 void MotermDriver::Dup(mojo::InterfaceRequest<mojo::files::File> file, | 339 void MotermDriver::Dup(mojo::InterfaceRequest<mojo::files::File> file, |
340 const DupCallback& callback) { | 340 const DupCallback& callback) { |
341 if (is_closed_) { | 341 if (is_closed_) { |
342 callback.Run(mojo::files::ERROR_CLOSED); | 342 callback.Run(mojo::files::Error::CLOSED); |
343 return; | 343 return; |
344 } | 344 } |
345 | 345 |
346 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 346 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
347 // unsupported/EINVAL is better.) | 347 // unsupported/EINVAL is better.) |
348 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 348 callback.Run(mojo::files::Error::UNAVAILABLE); |
349 } | 349 } |
350 | 350 |
351 void MotermDriver::Reopen(mojo::InterfaceRequest<mojo::files::File> file, | 351 void MotermDriver::Reopen(mojo::InterfaceRequest<mojo::files::File> file, |
352 uint32_t open_flags, | 352 uint32_t open_flags, |
353 const ReopenCallback& callback) { | 353 const ReopenCallback& callback) { |
354 if (is_closed_) { | 354 if (is_closed_) { |
355 callback.Run(mojo::files::ERROR_CLOSED); | 355 callback.Run(mojo::files::Error::CLOSED); |
356 return; | 356 return; |
357 } | 357 } |
358 | 358 |
359 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe | 359 // TODO(vtl): Is this what we want? (Also is "unavailable" right? Maybe |
360 // unsupported/EINVAL is better.) | 360 // unsupported/EINVAL is better.) |
361 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 361 callback.Run(mojo::files::Error::UNAVAILABLE); |
362 } | 362 } |
363 | 363 |
364 void MotermDriver::AsBuffer(const AsBufferCallback& callback) { | 364 void MotermDriver::AsBuffer(const AsBufferCallback& callback) { |
365 if (is_closed_) { | 365 if (is_closed_) { |
366 callback.Run(mojo::files::ERROR_CLOSED, mojo::ScopedSharedBufferHandle()); | 366 callback.Run(mojo::files::Error::CLOSED, mojo::ScopedSharedBufferHandle()); |
367 return; | 367 return; |
368 } | 368 } |
369 | 369 |
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, mojo::Array<uint32_t>()); |
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, mojo::Array<uint32_t>()); |
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, mojo::Array<uint32_t>()); |
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, mojo::Array<uint32_t>()); |
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, mojo::Array<uint32_t>()); |
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, mojo::Array<uint32_t>()); |
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()), |
447 mojo::Array<uint32_t>()); | 447 mojo::Array<uint32_t>()); |
448 } | 448 } |
449 | 449 |
450 mojo::files::Error MotermDriver::IoctlSetSettingsHelper( | 450 mojo::files::Error MotermDriver::IoctlSetSettingsHelper( |
451 mojo::Array<uint32_t> in_values) { | 451 mojo::Array<uint32_t> in_values) { |
452 // Note: "termios" offsets (and sizes) are increased by 1, to accomodate the | 452 // Note: "termios" offsets (and sizes) are increased by 1, to accomodate the |
453 // subrequest at index 0. | 453 // subrequest at index 0. |
454 | 454 |
455 // The "cc" values are optional. | 455 // The "cc" values are optional. |
456 if (in_values.size() < 1 + kBaseFieldCount) | 456 if (in_values.size() < 1 + kBaseFieldCount) |
457 return mojo::files::ERROR_INVALID_ARGUMENT; | 457 return mojo::files::Error::INVALID_ARGUMENT; |
458 | 458 |
459 // TODO(vtl): Add support for various things. Also, some values can't be | 459 // TODO(vtl): Add support for various things. Also, some values can't be |
460 // changed. | 460 // changed. |
461 | 461 |
462 // iflag: | 462 // iflag: |
463 icrnl_ = !!(in_values[1 + kIFlagIdx] & | 463 icrnl_ = !!(in_values[1 + kIFlagIdx] & |
464 mojo::files::kIoctlTerminalTermiosIFlagICRNL); | 464 mojo::files::kIoctlTerminalTermiosIFlagICRNL); |
465 | 465 |
466 // oflag: | 466 // oflag: |
467 onlcr_ = !!(in_values[1 + kOFlagIdx] & | 467 onlcr_ = !!(in_values[1 + kOFlagIdx] & |
468 mojo::files::kIoctlTerminalTermiosOFlagONLCR); | 468 mojo::files::kIoctlTerminalTermiosOFlagONLCR); |
469 | 469 |
470 // lflag: | 470 // lflag: |
471 icanon_ = !!(in_values[1 + kLFlagIdx] & | 471 icanon_ = !!(in_values[1 + kLFlagIdx] & |
472 mojo::files::kIoctlTerminalTermiosLFlagICANON); | 472 mojo::files::kIoctlTerminalTermiosLFlagICANON); |
473 | 473 |
474 // TODO(vtl): Check that ispeed and ospeed are not set? | 474 // TODO(vtl): Check that ispeed and ospeed are not set? |
475 | 475 |
476 // cc: | 476 // cc: |
477 if (1 + kVEraseIdx < in_values.size()) { | 477 if (1 + kVEraseIdx < in_values.size()) { |
478 uint32_t value = in_values[1 + kVEraseIdx]; | 478 uint32_t value = in_values[1 + kVEraseIdx]; |
479 if (value > std::numeric_limits<uint8_t>::max()) | 479 if (value > std::numeric_limits<uint8_t>::max()) |
480 return mojo::files::ERROR_INVALID_ARGUMENT; | 480 return mojo::files::Error::INVALID_ARGUMENT; |
481 verase_ = static_cast<uint8_t>(value); | 481 verase_ = static_cast<uint8_t>(value); |
482 } | 482 } |
483 if (1 + kVEOFIdx < in_values.size()) { | 483 if (1 + kVEOFIdx < in_values.size()) { |
484 uint32_t value = in_values[1 + kVEOFIdx]; | 484 uint32_t value = in_values[1 + kVEOFIdx]; |
485 if (value > std::numeric_limits<uint8_t>::max()) | 485 if (value > std::numeric_limits<uint8_t>::max()) |
486 return mojo::files::ERROR_INVALID_ARGUMENT; | 486 return mojo::files::Error::INVALID_ARGUMENT; |
487 veof_ = static_cast<uint8_t>(value); | 487 veof_ = static_cast<uint8_t>(value); |
488 } | 488 } |
489 | 489 |
490 return mojo::files::ERROR_OK; | 490 return mojo::files::Error::OK; |
491 } | 491 } |
OLD | NEW |