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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_connection_posix.cc

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix weird Windows build error. Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698