blob: c828cfca2fe0aef2fe481ddb822ce24640ad927f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_
#define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_
#include <set>
#include <string>
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
#include "chrome/browser/extensions/api/api_resource.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/io_buffer.h"
using content::BrowserThread;
namespace extensions {
extern const char kSerialConnectionNotFoundError[];
class ApiResourceEventNotifier;
// Encapsulates an open serial port. Platform-specific implementations are in
// _win and _posix versions of the the .cc file.
class SerialConnection : public ApiResource {
public:
SerialConnection(const std::string& port,
int bitrate,
const std::string& owner_extension_id,
ApiResourceEventNotifier* event_notifier);
virtual ~SerialConnection();
virtual bool Open();
virtual void Close();
virtual void Flush();
virtual int Read(scoped_refptr<net::IOBufferWithSize> io_buffer);
virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count);
struct ControlSignals {
// Sent from workstation to device. The should_set_ values indicate whether
// SetControlSignals should change the given signal (true) or else leave it
// as-is (false).
bool should_set_dtr;
bool dtr;
bool should_set_rts;
bool rts;
// Received by workstation from device. DCD (Data Carrier Detect) is
// equivalent to RLSD (Receive Line Signal Detect) on some platforms.
bool dcd;
bool cts;
};
virtual bool GetControlSignals(ControlSignals &control_signals);
virtual bool SetControlSignals(const ControlSignals &control_signals);
protected:
// Do platform-specific work after a successful Open().
bool PostOpen();
private:
std::string port_;
int bitrate_;
base::PlatformFile file_;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_CONNECTION_H_
|