ROSaic
Public Types | Public Member Functions | Private Attributes
io_comm_mosaic::CallbackHandler< T > Class Template Reference

Abstract class representing a generic callback handler, includes high-level functionality such as wait. More...

#include <callbackhandlers.hpp>

Inheritance diagram for io_comm_mosaic::CallbackHandler< T >:
Inheritance graph
[legend]
Collaboration diagram for io_comm_mosaic::CallbackHandler< T >:
Collaboration graph
[legend]

Public Types

typedef boost::function< void(const T &)> Callback
 

Public Member Functions

 CallbackHandler (const Callback &func=Callback())
 
virtual const T & Get ()
 
void Handle (mosaicMessage &mMessage, std::string message_key)
 
- Public Member Functions inherited from io_comm_mosaic::AbstractCallbackHandler
bool Wait (const boost::posix_time::time_duration &timeout)
 

Private Attributes

Callback func_
 
message_
 

Additional Inherited Members

- Protected Attributes inherited from io_comm_mosaic::AbstractCallbackHandler
boost::mutex mutex_
 
boost::condition_variable condition_
 

Detailed Description

template<typename T>
class io_comm_mosaic::CallbackHandler< T >

Abstract class representing a generic callback handler, includes high-level functionality such as wait.

Derived class operating on a ROS message level.

Definition at line 133 of file callbackhandlers.hpp.

Member Typedef Documentation

◆ Callback

template<typename T>
typedef boost::function<void(const T&)> io_comm_mosaic::CallbackHandler< T >::Callback

Definition at line 136 of file callbackhandlers.hpp.

Constructor & Destructor Documentation

◆ CallbackHandler()

template<typename T>
io_comm_mosaic::CallbackHandler< T >::CallbackHandler ( const Callback func = Callback())
inline

Definition at line 138 of file callbackhandlers.hpp.

Member Function Documentation

◆ Get()

template<typename T>
virtual const T& io_comm_mosaic::CallbackHandler< T >::Get ( )
inlinevirtual

Definition at line 140 of file callbackhandlers.hpp.

◆ Handle()

template<typename T>
void io_comm_mosaic::CallbackHandler< T >::Handle ( mosaicMessage mMessage,
std::string  message_key 
)
inlinevirtual

Implements io_comm_mosaic::AbstractCallbackHandler.

Definition at line 142 of file callbackhandlers.hpp.

References io_comm_mosaic::AbstractCallbackHandler::condition_, io_comm_mosaic::mosaicMessage::MessageID(), io_comm_mosaic::AbstractCallbackHandler::mutex_, and io_comm_mosaic::mosaicMessage::Read().

143  {
144  boost::mutex::scoped_lock lock(mutex_);
145  try
146  {
147  if (!mMessage.Read<T>(message_, message_key))
148  {
149  std::ostringstream ss;
150  ss << "Read unsuccessful: mosaic decoder error for message with ID (empty field if non-determinable)" << mMessage.MessageID() << ". Reason unknown.";
151  throw std::runtime_error(ss.str());
152  ROS_INFO("%s", ss.str().c_str());
153  return;
154  }
155  } catch (std::runtime_error& e)
156  {
157  std::ostringstream ss;
158  ss << "Read unsuccessful: mosaic decoder error for message with ID " << mMessage.MessageID() << ".\nReason: " << e.what();
159  throw std::runtime_error(ss.str());
160  ROS_INFO("%s", ss.str().c_str());
161  return;
162  }
163 
164  condition_.notify_all();
165  if (func_) func_(message_);
166  }
Here is the call graph for this function:

Field Documentation

◆ func_

template<typename T>
Callback io_comm_mosaic::CallbackHandler< T >::func_
private

Definition at line 169 of file callbackhandlers.hpp.

◆ message_

template<typename T>
T io_comm_mosaic::CallbackHandler< T >::message_
private

Definition at line 170 of file callbackhandlers.hpp.


The documentation for this class was generated from the following file: