Lely core libraries 2.3.4
serial.hpp
Go to the documentation of this file.
1
22#ifndef LELY_IO_SERIAL_HPP_
23#define LELY_IO_SERIAL_HPP_
24
25#ifndef __cplusplus
26#error "include <lely/io/serial.h> for the C interface"
27#endif
28
29#include <lely/io/io.hpp>
30#include <lely/io/serial.h>
31
32#include <utility>
33
34namespace lely {
35
37class IOSerial : public IOHandle {
38 public:
39 IOSerial(const char* path, io_attr_t* attr = 0)
40 : IOHandle(io_open_serial(path, attr)) {
41 if (!operator bool()) throw_or_abort(bad_init());
42 }
43
44 IOSerial(const IOSerial& serial) noexcept : IOHandle(serial) {}
45
46 IOSerial(IOSerial&& serial) noexcept
47 : IOHandle(::std::forward<IOSerial>(serial)) {}
48
50 operator=(const IOSerial& serial) noexcept {
51 IOHandle::operator=(serial);
52 return *this;
53 }
54
56 operator=(IOSerial&& serial) noexcept {
57 IOHandle::operator=(::std::forward<IOSerial>(serial));
58 return *this;
59 }
60
61 int
62 purge(int flags) noexcept {
63 return io_purge(*this, flags);
64 }
65
66 int
67 getAttr(io_attr_t& attr) noexcept {
68 return io_serial_get_attr(*this, &attr);
69 }
70
71 int
72 setAttr(const io_attr_t& attr) noexcept {
73 return io_serial_set_attr(*this, &attr);
74 }
75};
76
77} // namespace lely
78
79#endif // !LELY_IO_SERIAL_HPP_
An I/O device handle.
Definition: io.hpp:35
A serial I/O device handle.
Definition: serial.hpp:37
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
Definition: c_type.hpp:38
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
Definition: exception.hpp:38
This header file is part of the I/O library; it contains the C++ interface of the I/O device handle.
This header file is part of the I/O library; it contains the serial I/O declarations.
int io_serial_set_attr(io_handle_t handle, const io_attr_t *attr)
Sets the attributes of a serial I/O device to those in *attr.
Definition: serial.c:242
io_handle_t io_open_serial(const char *path, io_attr_t *attr)
Opens a serial I/O device.
Definition: serial.c:51
int io_purge(io_handle_t handle, int flags)
Purges the receive and/or transmit buffers of a serial I/O device.
Definition: serial.c:197
int io_serial_get_attr(io_handle_t handle, io_attr_t *attr)
Retrieves the current attributes of a serial I/O device and stores them in *attr.
Definition: serial.c:216
An opaque serial I/O device attributes type.
Definition: attr.h:34