-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathio_base.hpp
More file actions
54 lines (41 loc) · 1.56 KB
/
io_base.hpp
File metadata and controls
54 lines (41 loc) · 1.56 KB
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
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Dimitry Ishenko
// Contact: dimitry (dot) ishenko (at) (gee) mail (dot) com
//
// Distributed under the GNU GPL license. See the LICENSE.md file for details.
////////////////////////////////////////////////////////////////////////////////
#ifndef FIRMATA_IO_BASE_HPP
#define FIRMATA_IO_BASE_HPP
////////////////////////////////////////////////////////////////////////////////
#include "firmata/call_chain.hpp"
#include "firmata/types.hpp"
#include <functional>
#include <utility>
////////////////////////////////////////////////////////////////////////////////
namespace firmata
{
////////////////////////////////////////////////////////////////////////////////
// Firmata protocol I/O base class
//
class io_base
{
public:
////////////////////
// write message
virtual void write(msg_id, const payload& = { }) = 0;
using read_call = call<void(msg_id, const payload&)>;
// install read callback
virtual cid on_read(read_call fn) { return chain_.insert(std::move(fn)); }
// remove read callback
virtual bool remove_call(cid id) { return chain_.erase(id); }
using condition = std::function<bool()>;
// block until condition or timeout
virtual bool wait_until(const condition&, const msec&) = 0;
protected:
////////////////////
call_chain<read_call> chain_;
};
////////////////////////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////
#endif