]> git.tdb.fi Git - libs/core.git/blob - source/io/serial.h
Add move semantics to Variant
[libs/core.git] / source / io / serial.h
1 #ifndef MSP_IO_SERIAL_H_
2 #define MSP_IO_SERIAL_H_
3
4 #include <msp/core/mspcore_api.h>
5 #include "eventobject.h"
6 #include "eventreader.h"
7 #include "handle.h"
8
9 namespace Msp {
10 namespace IO {
11
12 class MSPCORE_API Serial: public EventObject
13 {
14 public:
15         enum Parity
16         {
17                 NONE,
18                 EVEN,
19                 ODD
20         };
21
22 private:
23         struct DeviceState;
24
25         Handle handle;
26         EventReader reader;
27
28 public:
29         Serial(const std::string &);
30 private:
31         void platform_init(const std::string &);
32 public:
33         ~Serial() override;
34
35 private:
36         void close();
37
38 public:
39         void set_block(bool) override;
40         void set_inherit(bool) override;
41
42         void set_baud_rate(unsigned);
43         void set_data_bits(unsigned);
44         void set_parity(Parity);
45         void set_stop_bits(unsigned);
46         void set_parameters(const std::string &);
47
48 private:
49         std::size_t do_write(const char *, std::size_t) override;
50         std::size_t do_read(char *, std::size_t) override;
51
52 public:
53         const Handle &get_handle(Mode) override;
54         const Handle &get_event_handle() override { return reader.get_event(); }
55 };
56
57 } // namespace IO
58 } // namespace Msp
59
60 #endif