From d85465dd66a6fc80a9fb7868d1193a86abfe5b7c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 13 Jun 2011 17:42:49 +0300 Subject: [PATCH] Use EventReader in Serial as well --- source/io/serial.cpp | 14 +++----------- source/io/serial.h | 4 +++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/source/io/serial.cpp b/source/io/serial.cpp index 74af366..5d335b6 100644 --- a/source/io/serial.cpp +++ b/source/io/serial.cpp @@ -149,7 +149,8 @@ void set_stop_bits(DeviceState &state, unsigned bits) namespace Msp { namespace IO { -Serial::Serial(const string &descr) +Serial::Serial(const string &descr): + reader(handle, 1024) { string::size_type comma = descr.find(','); string port = descr.substr(0, comma); @@ -291,16 +292,7 @@ unsigned Serial::do_read(char *buf, unsigned size) if(size==0) return 0; - return sys_read(handle, buf, size); -} - -const Handle &Serial::get_event_handle() -{ -#ifdef WIN32 - throw logic_error("Serial port events not supported on win32 yet"); -#else - return handle; -#endif + return reader.read(buf, size); } } // namespace IO diff --git a/source/io/serial.h b/source/io/serial.h index 98b1667..39ca27a 100644 --- a/source/io/serial.h +++ b/source/io/serial.h @@ -2,6 +2,7 @@ #define MSP_IO_SERIAL_H_ #include "eventobject.h" +#include "eventreader.h" #include "handle.h" namespace Msp { @@ -19,6 +20,7 @@ public: private: Handle handle; + EventReader reader; public: Serial(const std::string &); @@ -41,7 +43,7 @@ private: virtual unsigned do_read(char *, unsigned); public: - virtual const Handle &get_event_handle(); + virtual const Handle &get_event_handle() { return reader.get_event(); } }; } // namespace IO -- 2.43.0