All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Types | Private Member Functions | Private Attributes
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:
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

std::string header
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.

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

Constructor.

Returns:

Definition at line 81 of file mjpeg_server.cpp.

Destructor - Cleans up.

Definition at line 91 of file mjpeg_server.cpp.


Member Function Documentation

Closes all client threads.

Definition at line 932 of file mjpeg_server.cpp.

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 672 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:
base64encoded data
Returns:
plain decoded data

Definition at line 226 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:
URIstring
Returns:
a map of parameter/value pairs

Definition at line 370 of file mjpeg_server.cpp.

Runs whenever a new goal is sent to the move_base.

Parameters:
goalThe goal to pursue
feedbackFeedback 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 802 of file mjpeg_server.cpp.

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 150 of file mjpeg_server.cpp.

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

Definition at line 387 of file mjpeg_server.cpp.

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

Convert a hexadecimal ASCII character to integer.

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

Definition at line 269 of file mjpeg_server.cpp.

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

Definition at line 95 of file mjpeg_server.cpp.

Initializes the iobuffer structure properly.

Parameters:
Pointerto already allocated iobuffer

Definition at line 135 of file mjpeg_server.cpp.

Initializes the request structure properly.

Parameters:
Pointerto already allocated req

Definition at line 141 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:
inputimage
outputimage

Definition at line 401 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 208 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 157 of file mjpeg_server.cpp.

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

Send an error message.

Parameters:
fildescriptorfd to send the answer to
errornumber
errormessage

Definition at line 323 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:
fildescriptorfd to send the answer to
parameterstring

Definition at line 563 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:
fildescriptorfd to send the answer to
parameterstring

Definition at line 415 of file mjpeg_server.cpp.

Starts the server and spins.

Definition at line 939 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:
stringto split
Returns:
vector of tokens

Definition at line 105 of file mjpeg_server.cpp.

Stops the server.

Definition at line 947 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
defaultreturn value
Returns:
corresponding value, default_value in case of error

Definition at line 123 of file mjpeg_server.cpp.

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

Replaces XX with the character code it represents, URI.

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

Definition at line 283 of file mjpeg_server.cpp.


Member Data Documentation

std::string mjpeg_server::MJPEGServer::header [private]

Definition at line 147 of file mjpeg_server.h.

Definition at line 294 of file mjpeg_server.h.

Definition at line 296 of file mjpeg_server.h.

Definition at line 295 of file mjpeg_server.h.

Definition at line 285 of file mjpeg_server.h.

Definition at line 284 of file mjpeg_server.h.

Definition at line 286 of file mjpeg_server.h.

Definition at line 288 of file mjpeg_server.h.

Definition at line 289 of file mjpeg_server.h.

Definition at line 291 of file mjpeg_server.h.

Definition at line 292 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 Friends Defines


mjpeg_server
Author(s): Maintained by Benjamin Pitzer
autogenerated on Thu May 2 2013 11:28:51