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

Side by Side Diff: device/serial/data_receiver.h

Issue 437933002: Add data pipe wrappers to be used to implement serial receive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serial-buffer
Patch Set: address comments Created 6 years, 4 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
OLDNEW
(Empty)
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_DATA_RECEIVER_H_
6 #define DEVICE_SERIAL_DATA_RECEIVER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "device/serial/buffer.h"
12 #include "device/serial/data_stream.mojom.h"
13 #include "mojo/public/cpp/system/data_pipe.h"
14
15 namespace device {
16
17 class AsyncWaiter;
18
19 // A DataReceiver receives data from a DataSource.
20 class DataReceiver : public base::RefCounted<DataReceiver>,
21 public serial::DataSourceClient,
22 public mojo::ErrorHandler {
23 public:
24 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback;
25 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback;
26
27 // Constructs a DataReceiver to receive data from |source|, using a data
28 // pipe with a buffer size of |buffer_size|, with connection errors reported
29 // as |fatal_error_value|.
30 DataReceiver(mojo::InterfacePtr<serial::DataSource> source,
31 uint32_t buffer_size,
32 int32_t fatal_error_value);
33
34 // Begins a receive operation. If this returns true, exactly one of |callback|
35 // and |error_callback| will eventually be called. If there is already a
36 // receive in progress, |callback| or |error_callback| is invalid or there has
37 // been a connection error, this will have no effect and return false.
38 bool Receive(const ReceiveDataCallback& callback,
39 const ReceiveErrorCallback& error_callback);
40
41 private:
42 class PendingReceive;
43 struct PendingError;
44 friend class base::RefCounted<DataReceiver>;
45
46 virtual ~DataReceiver();
47
48 // serial::DataSourceClient override.
49 virtual void OnError(uint32_t bytes_since_last_error, int32_t error) OVERRIDE;
50
51 // mojo::ErrorHandler override.
52 virtual void OnConnectionError() OVERRIDE;
53
54 void Done(uint32_t bytes_consumed);
raymes 2014/08/06 05:46:43 Please add comments for each of these methods and
Sam McNally 2014/08/06 08:28:14 Done.
55 void OnDoneWaiting(MojoResult result);
56
57 void ReceiveInternal();
58
59 bool CheckBytesReceived(uint32_t num_bytes);
60
61 void ShutDown();
62
63 mojo::InterfacePtr<serial::DataSource> source_;
64 const int32_t fatal_error_value_;
65 mojo::ScopedDataPipeConsumerHandle handle_;
66 uint32_t bytes_received_;
67 bool shut_down_;
68 scoped_ptr<AsyncWaiter> waiter_;
69 scoped_ptr<PendingReceive> receive_;
70 scoped_ptr<PendingError> error_;
71 base::WeakPtrFactory<DataReceiver> weak_factory_;
72
73 DISALLOW_COPY_AND_ASSIGN(DataReceiver);
74 };
75
76 } // namespace device
77
78 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698