| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/serial/serial_connection.h" | 5 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
| 6 | 6 |
| 7 #include <errno.h> | |
| 8 #include <fcntl.h> | |
| 9 #include <stdio.h> | |
| 10 #include <string> | |
| 11 #include <termios.h> | |
| 12 #include <unistd.h> | |
| 13 | |
| 14 #include "base/file_path.h" | |
| 15 #include "base/file_util.h" | |
| 16 #include "base/string_util.h" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 namespace extensions { | 7 namespace extensions { |
| 22 | 8 |
| 23 SerialConnection::SerialConnection(const std::string& port, | 9 bool SerialConnection::PostOpen() { |
| 24 APIResourceEventNotifier* event_notifier) | 10 return true; |
| 25 : APIResource(APIResource::SerialConnectionResource, event_notifier), | |
| 26 port_(port), fd_(0) { | |
| 27 } | |
| 28 | |
| 29 SerialConnection::~SerialConnection() { | |
| 30 } | |
| 31 | |
| 32 bool SerialConnection::Open() { | |
| 33 fd_ = open(port_.c_str(), O_RDWR | O_NOCTTY | O_NDELAY); | |
| 34 return (fd_ > 0); | |
| 35 } | |
| 36 | |
| 37 void SerialConnection::Close() { | |
| 38 if (fd_ > 0) { | |
| 39 close(fd_); | |
| 40 fd_ = 0; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 int SerialConnection::Read(uint8* byte) { | |
| 45 return read(fd_, byte, 1); | |
| 46 } | |
| 47 | |
| 48 int SerialConnection::Write(scoped_refptr<net::IOBuffer> io_buffer, | |
| 49 int byte_count) { | |
| 50 return write(fd_, io_buffer.get(), byte_count); | |
| 51 } | 11 } |
| 52 | 12 |
| 53 } // namespace extensions | 13 } // namespace extensions |
| OLD | NEW |