1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Merge branch 'boostless' of github.com:wjwwood/serial into boostless

Conflicts:
	include/serial/serial_listener.h
	src/impl/unix.cc
This commit is contained in:
John Harrison 2012-01-15 02:09:24 -06:00
commit 66036f21c2
3 changed files with 53 additions and 28 deletions

View File

@ -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) set(serial_FOUND TRUE)

View File

@ -90,6 +90,30 @@ typedef boost::function<void(const std::string&)> DataCallback;
*/ */
typedef boost::function<bool(const std::string&)> ComparatorType; typedef boost::function<bool(const std::string&)> ComparatorType;
/*!
* This function type describes the prototype for the tokenizer callback.
*
* The function should take a std::string reference and tokenize it into a
* several TokenPtr's and store them in the given std::vector<TokenPtr>
* reference. There are some default ones or the user can create their own.
*
* The last element in the std::vector of TokenPtr's should always be
* either an empty string ("") or the last partial message. The last element
* in the std::vector will be put back into the data buffer so that if it is
* incomplete it can be completed when more data is read.
*
* Example: A delimeter tokenizer with a delimeter of "\r". The result would
* be: "msg1\rmsg2\r" -> ["msg1", "msg2", ""] for two complete messages, or:
* "msg1\rpartial_msg2" -> ["msg1","partial_msg2"] for one complete message
* and one partial message.
*
* \see SerialListener::setTokenizer, serial::delimeter_tokenizer,
* serial::TokenPtr
*/
typedef boost::function<void(const std::string&, std::vector<TokenPtr>&)>
TokenizerType;
#if 0
/*! /*!
* This function type describes the prototype for the logging callbacks. * This function type describes the prototype for the logging callbacks.
* *
@ -103,6 +127,7 @@ typedef boost::function<bool(const std::string&)> ComparatorType;
* SerialListener::setWarningHandler * SerialListener::setWarningHandler
*/ */
typedef boost::function<void(const std::string&)> LoggingCallback; typedef boost::function<void(const std::string&)> LoggingCallback;
#endif
/*! /*!
* This function type describes the prototype for the exception callback. * This function type describes the prototype for the exception callback.
@ -115,29 +140,6 @@ typedef boost::function<void(const std::string&)> LoggingCallback;
*/ */
typedef boost::function<void(const std::exception&)> ExceptionCallback; typedef boost::function<void(const std::exception&)> ExceptionCallback;
/*!
* This function type describes the prototype for the tokenizer callback.
*
* The function should take a std::string reference and tokenize it into a
* several TokenPtr's and store them in the given std::vector<TokenPtr>
* reference. There are some default ones or the user can create their own.
*
* The last element in the std::vector of TokenPtr's should always be
* either an empty string ("") or the last partial message. The last element
* in the std::vector will be put back into the data buffer so that if it is
* incomplete it can be completed when more data is read.
*
* Example: A delimeter tokenizer with a delimeter of "\r". The result would
* be: "msg1\rmsg2\r" -> ["msg1", "msg2", ""] for two complete messages, or:
* "msg1\rpartial_msg2" -> ["msg1","partial_msg2"] for one complete message
* and one partial message.
*
* \see SerialListener::setTokenizer, serial::delimeter_tokenizer,
* serial::TokenPtr
*/
typedef boost::function<void(const std::string&, std::vector<TokenPtr>&)>
TokenizerType;
/*! /*!
* Represents a filter which new data is passed through. * Represents a filter which new data is passed through.
* *
@ -472,6 +474,7 @@ public:
/***** Hooks and Handlers ******/ /***** Hooks and Handlers ******/
#if 0
/*! /*!
* Sets the handler to be called when a lines is not caught by a filter. * Sets the handler to be called when a lines is not caught by a filter.
* *
@ -579,6 +582,23 @@ public:
setWarningHandler (LoggingCallback warning_handler) { setWarningHandler (LoggingCallback warning_handler) {
this->warn = 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 ******/ /***** Static Functions ******/
@ -772,10 +792,12 @@ private:
// Tokenizer // Tokenizer
TokenizerType tokenize; TokenizerType tokenize;
#if 0
// Logging handlers // Logging handlers
LoggingCallback warn; LoggingCallback warn;
LoggingCallback info; LoggingCallback info;
LoggingCallback debug; LoggingCallback debug;
#endif
// Exception handler // Exception handler
ExceptionCallback handle_exc; ExceptionCallback handle_exc;

View File

@ -4,6 +4,7 @@
/***** Inline Functions *****/ /***** Inline Functions *****/
#if 0
inline void defaultWarningCallback(const std::string& msg) { inline void defaultWarningCallback(const std::string& msg) {
std::cout << "SerialListener Warning: " << msg << std::endl; std::cout << "SerialListener Warning: " << msg << std::endl;
} }
@ -15,6 +16,7 @@ inline void defaultDebugCallback(const std::string& msg) {
inline void defaultInfoCallback(const std::string& msg) { inline void defaultInfoCallback(const std::string& msg) {
std::cout << "SerialListener Info: " << msg << std::endl; std::cout << "SerialListener Info: " << msg << std::endl;
} }
#endif
inline void defaultExceptionCallback(const std::exception &error) { inline void defaultExceptionCallback(const std::exception &error) {
std::cerr << "SerialListener Unhandled Exception: " << error.what(); std::cerr << "SerialListener Unhandled Exception: " << error.what();
@ -38,9 +40,11 @@ SerialListener::default_handler(const std::string &token) {
SerialListener::SerialListener() : listening(false), chunk_size_(5) { SerialListener::SerialListener() : listening(false), chunk_size_(5) {
// Set default callbacks // Set default callbacks
this->handle_exc = defaultExceptionCallback; this->handle_exc = defaultExceptionCallback;
#if 0
this->info = defaultInfoCallback; this->info = defaultInfoCallback;
this->debug = defaultDebugCallback; this->debug = defaultDebugCallback;
this->warn = defaultWarningCallback; this->warn = defaultWarningCallback;
#endif
// Default handler stuff // Default handler stuff
this->_default_handler = NULL; this->_default_handler = NULL;
@ -112,9 +116,6 @@ SerialListener::stopListening() {
this->data_buffer = ""; this->data_buffer = "";
this->serial_port_ = NULL; this->serial_port_ = NULL;
// Delete all the filters
this->removeAllFilters();
} }
size_t size_t