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