From dc53f3d1329ddbbf777a9ba573797dc270fecc75 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Fri, 13 Jan 2012 15:39:17 -0600 Subject: [PATCH 1/4] Fixing a warning. --- src/impl/unix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/unix.cc b/src/impl/unix.cc index f583eb4..77ca79c 100644 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -226,7 +226,7 @@ Serial::SerialImpl::read (size_t size) { fd_set readfds; memset(buf, 0, (size + 1) * sizeof(*buf)); ssize_t bytes_read = 0; - while (bytes_read < size) { + while (bytes_read < (ssize_t)size) { if (timeout_ != -1) { FD_ZERO(&readfds); FD_SET(fd_, &readfds); From 4afa6e2e7ce0c943a9e9903202b1f9644100d79f Mon Sep 17 00:00:00 2001 From: William Woodall Date: Sat, 14 Jan 2012 20:52:50 -0600 Subject: [PATCH 2/4] Fixing Findserial.cmake and updating serial_listener.h to remove unused functions. --- Findserial.cmake | 6 ++- include/serial/serial_listener.h | 70 ++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Findserial.cmake b/Findserial.cmake index 26877ab..cb839a6 100644 --- a/Findserial.cmake +++ b/Findserial.cmake @@ -1,6 +1,8 @@ -find_path(serial_INCLUDE_DIRS serial.h serial_listener.h /usr/include/serial "$ENV{NAMER_ROOT}") +find_path(serial_INCLUDE_DIRS serial.h serial_listener.h /usr/include/serial + /usr/local/include/serial "$ENV{NAMER_ROOT}") -find_library(serial_LIBRARIES serial /usr/lib "$ENV{NAMER_ROOT}") +find_library(serial_LIBRARIES serial /usr/lib /usr/local/lib + "$ENV{NAMER_ROOT}") set(serial_FOUND TRUE) diff --git a/include/serial/serial_listener.h b/include/serial/serial_listener.h index 0aebffa..318ab6f 100644 --- a/include/serial/serial_listener.h +++ b/include/serial/serial_listener.h @@ -90,31 +90,6 @@ typedef boost::function DataCallback; */ typedef boost::function ComparatorType; -/*! - * This function type describes the prototype for the logging callbacks. - * - * The function takes a std::string reference and returns nothing. It is - * called from the library when a logging message occurs. This - * allows the library user to hook into this and integrate it with their own - * logging system. It can be set with any of the setHandler - * functions. - * - * \see SerialListener::setInfoHandler, SerialListener::setDebugHandler, - * SerialListener::setWarningHandler - */ -typedef boost::function LoggingCallback; - -/*! - * This function type describes the prototype for the exception callback. - * - * The function takes a std::exception reference and returns nothing. It is - * called from the library when an exception occurs in a library thread. - * This exposes these exceptions to the user so they can to error handling. - * - * \see SerialListener::setExceptionHandler - */ -typedef boost::function ExceptionCallback; - /*! * This function type describes the prototype for the tokenizer callback. * @@ -138,6 +113,33 @@ typedef boost::function ExceptionCallback; typedef boost::function&)> TokenizerType; +#if 0 +/*! + * This function type describes the prototype for the logging callbacks. + * + * The function takes a std::string reference and returns nothing. It is + * called from the library when a logging message occurs. This + * allows the library user to hook into this and integrate it with their own + * logging system. It can be set with any of the setHandler + * functions. + * + * \see SerialListener::setInfoHandler, SerialListener::setDebugHandler, + * SerialListener::setWarningHandler + */ +typedef boost::function LoggingCallback; +#endif + +/*! + * This function type describes the prototype for the exception callback. + * + * The function takes a std::exception reference and returns nothing. It is + * called from the library when an exception occurs in a library thread. + * This exposes these exceptions to the user so they can to error handling. + * + * \see SerialListener::setExceptionHandler + */ +typedef boost::function ExceptionCallback; + /*! * Represents a filter which new data is passed through. * @@ -472,6 +474,7 @@ public: /***** Hooks and Handlers ******/ +#if 0 /*! * Sets the handler to be called when a lines is not caught by a filter. * @@ -579,6 +582,23 @@ public: setWarningHandler (LoggingCallback warning_handler) { this->warn = warning_handler; } +#endif + +/*! + * Sets the function to be called when an exception occurs internally. + * + * This allows you to hook into the exceptions that occur in threads inside + * the serial listener library. + * + * \param exception_handler A function pointer to the callback to handle new + * interal exceptions. + * + * \see serial::ExceptionCallback + */ +void +setWarningHandler (ExceptionCallback exception_handler) { + this->handle_exc = exception_handler; +} /***** Static Functions ******/ From ae3e4a1f51def531fbf4dc595e69f30c026c6b95 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Sat, 14 Jan 2012 21:01:55 -0600 Subject: [PATCH 3/4] Fixing compile errors with serial listener. --- include/serial/serial_listener.h | 2 ++ src/serial_listener.cc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/serial/serial_listener.h b/include/serial/serial_listener.h index 318ab6f..ba274aa 100644 --- a/include/serial/serial_listener.h +++ b/include/serial/serial_listener.h @@ -792,10 +792,12 @@ private: // Tokenizer TokenizerType tokenize; +#if 0 // Logging handlers LoggingCallback warn; LoggingCallback info; LoggingCallback debug; +#endif // Exception handler ExceptionCallback handle_exc; diff --git a/src/serial_listener.cc b/src/serial_listener.cc index 85055db..84adc87 100644 --- a/src/serial_listener.cc +++ b/src/serial_listener.cc @@ -2,6 +2,7 @@ /***** Inline Functions *****/ +#if 0 inline void defaultWarningCallback(const std::string& msg) { std::cout << "SerialListener Warning: " << msg << std::endl; } @@ -13,6 +14,7 @@ inline void defaultDebugCallback(const std::string& msg) { inline void defaultInfoCallback(const std::string& msg) { std::cout << "SerialListener Info: " << msg << std::endl; } +#endif inline void defaultExceptionCallback(const std::exception &error) { std::cerr << "SerialListener Unhandled Exception: " << error.what(); @@ -36,9 +38,11 @@ SerialListener::default_handler(const std::string &token) { SerialListener::SerialListener() : listening(false), chunk_size_(5) { // Set default callbacks this->handle_exc = defaultExceptionCallback; +#if 0 this->info = defaultInfoCallback; this->debug = defaultDebugCallback; this->warn = defaultWarningCallback; +#endif // Default handler stuff this->_default_handler = NULL; From 5ec0707418dce5f0d47316bc79f9913bdd33ecbf Mon Sep 17 00:00:00 2001 From: William Woodall Date: Sat, 14 Jan 2012 21:24:48 -0600 Subject: [PATCH 4/4] Changed the stopListening function, now it no longer removes filters, just stops listening and cleans the data buffer of partial messages. --- src/serial_listener.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/serial_listener.cc b/src/serial_listener.cc index 84adc87..599ee88 100644 --- a/src/serial_listener.cc +++ b/src/serial_listener.cc @@ -114,9 +114,6 @@ SerialListener::stopListening() { this->data_buffer = ""; this->serial_port_ = NULL; - - // Delete all the filters - this->removeAllFilters(); } size_t