Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / device / serial / serial_connection.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_SERIAL_SERIAL_CONNECTION_H_
6 #define DEVICE_SERIAL_SERIAL_CONNECTION_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "device/serial/serial.mojom.h"
11 #include "mojo/public/cpp/bindings/interface_impl.h"
12
13 namespace device {
14
15 class DataSinkReceiver;
16 class DataSourceSender;
17 class ReadOnlyBuffer;
18 class SerialIoHandler;
19 class WritableBuffer;
20
21 class SerialConnection : public mojo::InterfaceImpl<serial::Connection> {
22  public:
23   SerialConnection(scoped_refptr<SerialIoHandler> io_handler,
24                    mojo::InterfaceRequest<serial::DataSink> sink,
25                    mojo::InterfaceRequest<serial::DataSource> source);
26   virtual ~SerialConnection();
27
28   // mojo::InterfaceImpl<serial::Connection> overrides.
29   virtual void GetInfo(
30       const mojo::Callback<void(serial::ConnectionInfoPtr)>& callback) OVERRIDE;
31   virtual void SetOptions(serial::ConnectionOptionsPtr options,
32                           const mojo::Callback<void(bool)>& callback) OVERRIDE;
33   virtual void SetControlSignals(
34       serial::HostControlSignalsPtr signals,
35       const mojo::Callback<void(bool)>& callback) OVERRIDE;
36   virtual void GetControlSignals(const mojo::Callback<
37       void(serial::DeviceControlSignalsPtr)>& callback) OVERRIDE;
38   virtual void Flush(const mojo::Callback<void(bool)>& callback) OVERRIDE;
39
40  private:
41   void OnSendPipeReady(scoped_ptr<ReadOnlyBuffer> buffer);
42   void OnSendCancelled(int32_t error);
43   void OnReceivePipeReady(scoped_ptr<WritableBuffer> buffer);
44
45   scoped_refptr<SerialIoHandler> io_handler_;
46   scoped_refptr<DataSinkReceiver> receiver_;
47   scoped_refptr<DataSourceSender> sender_;
48
49   DISALLOW_COPY_AND_ASSIGN(SerialConnection);
50 };
51
52 }  // namespace device
53
54 #endif  // DEVICE_SERIAL_SERIAL_CONNECTION_H_