mjpeg_server::MJPEGServer Class Reference

#include <mjpeg_server.h>

List of all members.

Public Member Functions

void cleanUp ()
 Closes all client threads.
void client (int fd)
 Client thread function Serve a connected TCP-client. This thread function is called for each connect of a HTTP client like a webbrowser. It determines if it is a valid HTTP request and dispatches between the different response options.
void execute ()
 Runs whenever a new goal is sent to the move_base.
 MJPEGServer (ros::NodeHandle &node)
 Constructor.
void spin ()
 Starts the server and spins.
void stop ()
 Stops the server.
virtual ~MJPEGServer ()
 Destructor - Cleans up.

Private Types

typedef std::map< std::string,
ImageBuffer * > 
ImageBufferMap
typedef std::map< std::string,
image_transport::Subscriber > 
ImageSubscriberMap
typedef std::map< std::string,
std::string > 
ParameterMap

Private Member Functions

void decodeBase64 (char *data)
 Decodes the data and stores the result to the same buffer. The buffer will be large enough, because base64 requires more space then plain text.
void decodeParameter (const std::string &parameter, ParameterMap &parameter_map)
 Decodes URI parameters in form of ?parameter=value.
void freeRequest (request *req)
 If strings were assigned to the different members free them. This will fail if strings are static, so always use strdup().
ImageBuffergetImageBuffer (const std::string &topic)
int hexCharToInt (char in)
 Convert a hexadecimal ASCII character to integer.
void imageCallback (const sensor_msgs::ImageConstPtr &msg, const std::string &topic)
void initIOBuffer (iobuffer *iobuf)
 Initializes the iobuffer structure properly.
void initRequest (request *req)
 Initializes the request structure properly.
void invertImage (const cv::Mat &input, cv::Mat &output)
 Rotate input image by 180 degrees.
int readLineWithTimeout (int fd, iobuffer *iobuf, char *buffer, size_t len, int timeout)
 Read a single line from the provided fildescriptor. This funtion will return under two conditions:

  • line end was reached
  • timeout occured.

int readWithTimeout (int fd, iobuffer *iobuf, char *buffer, size_t len, int timeout)
 read with timeout, implemented without using signals tries to read len bytes and returns if enough bytes were read or the timeout was triggered. In case of timeout the return value may differ from the requested bytes "len".
void sendError (int fd, int which, const char *message)
 Send an error message.
void sendSnapshot (int fd, const char *parameter)
 Send a complete HTTP response and a single JPG-frame.
void sendStream (int fd, const char *parameter)
 Send a complete HTTP response and a stream of JPG-frames.
void splitString (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiter=" ")
 Split string into a list of tokens.
int stringToInt (const std::string &str, const int default_value=0)
 Convert a string to an integer.
int unescape (char *string)
 Replaces XX with the character code it represents, URI.

Private Attributes

ImageBufferMap image_buffers_
boost::mutex image_maps_mutex_
ImageSubscriberMap image_subscribers_
image_transport::ImageTransport image_transport_
ros::NodeHandle node_
int port_
int sd [MAX_NUM_SOCKETS]
int sd_len
bool stop_requested_
char * www_folder_

Detailed Description

Definition at line 97 of file mjpeg_server.h.


Member Typedef Documentation

typedef std::map<std::string, ImageBuffer*> mjpeg_server::MJPEGServer::ImageBufferMap [private]

Definition at line 143 of file mjpeg_server.h.

typedef std::map<std::string, image_transport::Subscriber> mjpeg_server::MJPEGServer::ImageSubscriberMap [private]

Definition at line 144 of file mjpeg_server.h.

typedef std::map<std::string, std::string> mjpeg_server::MJPEGServer::ParameterMap [private]

Definition at line 145 of file mjpeg_server.h.


Constructor & Destructor Documentation

mjpeg_server::MJPEGServer::MJPEGServer ( ros::NodeHandle &  node  ) 

Constructor.

Returns:

Definition at line 92 of file mjpeg_server.cpp.

mjpeg_server::MJPEGServer::~MJPEGServer (  )  [virtual]

Destructor - Cleans up.

Definition at line 99 of file mjpeg_server.cpp.


Member Function Documentation

void mjpeg_server::MJPEGServer::cleanUp (  ) 

Closes all client threads.

Definition at line 922 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::client ( int  fd  ) 

Client thread function Serve a connected TCP-client. This thread function is called for each connect of a HTTP client like a webbrowser. It determines if it is a valid HTTP request and dispatches between the different response options.

Definition at line 662 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::decodeBase64 ( char *  data  )  [private]

Decodes the data and stores the result to the same buffer. The buffer will be large enough, because base64 requires more space then plain text.

Parameters:
base64 encoded data
Returns:
plain decoded data

Definition at line 233 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::decodeParameter ( const std::string &  parameter,
ParameterMap parameter_map 
) [private]

Decodes URI parameters in form of ?parameter=value.

Parameters:
URI string
Returns:
a map of parameter/value pairs

Definition at line 371 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::execute (  ) 

Runs whenever a new goal is sent to the move_base.

Parameters:
goal The goal to pursue
feedback Feedback that the action gives to a higher-level monitor, in this case, the position of the robot
Returns:
The result of the execution, ie: Success, Preempted, Aborted, etc.

Definition at line 792 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::freeRequest ( request req  )  [private]

If strings were assigned to the different members free them. This will fail if strings are static, so always use strdup().

Parameters:
req,: pointer to request structure

Definition at line 158 of file mjpeg_server.cpp.

ImageBuffer * mjpeg_server::MJPEGServer::getImageBuffer ( const std::string &  topic  )  [private]

Definition at line 388 of file mjpeg_server.cpp.

int mjpeg_server::MJPEGServer::hexCharToInt ( char  in  )  [private]

Convert a hexadecimal ASCII character to integer.

Parameters:
ASCII character
Returns:
corresponding value between 0 and 15, or -1 in case of error

Definition at line 270 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::imageCallback ( const sensor_msgs::ImageConstPtr &  msg,
const std::string &  topic 
) [private]

Definition at line 103 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::initIOBuffer ( iobuffer iobuf  )  [private]

Initializes the iobuffer structure properly.

Parameters:
Pointer to already allocated iobuffer

Definition at line 143 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::initRequest ( request req  )  [private]

Initializes the request structure properly.

Parameters:
Pointer to already allocated req

Definition at line 149 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::invertImage ( const cv::Mat &  input,
cv::Mat &  output 
) [private]

Rotate input image by 180 degrees.

Parameters:
input image
output image

Definition at line 402 of file mjpeg_server.cpp.

int mjpeg_server::MJPEGServer::readLineWithTimeout ( int  fd,
iobuffer iobuf,
char *  buffer,
size_t  len,
int  timeout 
) [private]

Read a single line from the provided fildescriptor. This funtion will return under two conditions:

  • line end was reached
  • timeout occured.

Parameters:
fd.....,: fildescriptor to read from
iobuf..,: iobuffer that allows to use this functions from multiple threads because the complete context is the iobuffer.
buffer.,: The buffer to store values at, will be set to zero before storing values.
len....,: the length of buffer
timeout,: seconds to wait for an answer
Returns:
buffer.: will become filled with bytes read
iobuf..: May get altered to save the context for future calls.
func().: bytes copied to buffer or -1 in case of error

Definition at line 215 of file mjpeg_server.cpp.

int mjpeg_server::MJPEGServer::readWithTimeout ( int  fd,
iobuffer iobuf,
char *  buffer,
size_t  len,
int  timeout 
) [private]

read with timeout, implemented without using signals tries to read len bytes and returns if enough bytes were read or the timeout was triggered. In case of timeout the return value may differ from the requested bytes "len".

Parameters:
fd.....,: fildescriptor to read from
iobuf..,: iobuffer that allows to use this functions from multiple threads because the complete context is the iobuffer.
buffer.,: The buffer to store values at, will be set to zero before storing values.
len....,: the length of buffer
timeout,: seconds to wait for an answer
Returns:
buffer.: will become filled with bytes read
iobuf..: May get altered to save the context for future calls.
func().: bytes copied to buffer or -1 in case of error

Definition at line 165 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::sendError ( int  fd,
int  which,
const char *  message 
) [private]

Send an error message.

Parameters:
fildescriptor fd to send the answer to
error number
error message

Definition at line 324 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::sendSnapshot ( int  fd,
const char *  parameter 
) [private]

Send a complete HTTP response and a single JPG-frame.

Parameters:
fildescriptor fd to send the answer to
parameter string

Definition at line 555 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::sendStream ( int  fd,
const char *  parameter 
) [private]

Send a complete HTTP response and a stream of JPG-frames.

Parameters:
fildescriptor fd to send the answer to
parameter string

Definition at line 416 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::spin (  ) 

Starts the server and spins.

Definition at line 929 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::splitString ( const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiter = " " 
) [private]

Split string into a list of tokens.

Parameters:
string to split
Returns:
vector of tokens

Definition at line 113 of file mjpeg_server.cpp.

void mjpeg_server::MJPEGServer::stop (  ) 

Stops the server.

Definition at line 937 of file mjpeg_server.cpp.

int mjpeg_server::MJPEGServer::stringToInt ( const std::string &  str,
const int  default_value = 0 
) [private]

Convert a string to an integer.

Parameters:
string 
default return value
Returns:
corresponding value, default_value in case of error

Definition at line 131 of file mjpeg_server.cpp.

int mjpeg_server::MJPEGServer::unescape ( char *  string  )  [private]

Replaces XX with the character code it represents, URI.

Parameters:
string to unescape
Returns:
0 if everything is ok, -1 in case of error

Definition at line 284 of file mjpeg_server.cpp.


Member Data Documentation

Definition at line 292 of file mjpeg_server.h.

Definition at line 294 of file mjpeg_server.h.

Definition at line 293 of file mjpeg_server.h.

image_transport::ImageTransport mjpeg_server::MJPEGServer::image_transport_ [private]

Definition at line 283 of file mjpeg_server.h.

ros::NodeHandle mjpeg_server::MJPEGServer::node_ [private]

Definition at line 282 of file mjpeg_server.h.

Definition at line 284 of file mjpeg_server.h.

int mjpeg_server::MJPEGServer::sd[MAX_NUM_SOCKETS] [private]

Definition at line 286 of file mjpeg_server.h.

Definition at line 287 of file mjpeg_server.h.

Definition at line 289 of file mjpeg_server.h.

Definition at line 290 of file mjpeg_server.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


mjpeg_server
Author(s): Benjamin Pitzer
autogenerated on Fri Jan 11 10:04:00 2013