Visual Servoing Platform  version 3.4.0
vpRequest Class Referenceabstract

#include <vpRequest.h>

Public Member Functions

 vpRequest ()
 
virtual ~vpRequest ()
 
void addParameter (char *params)
 
void addParameter (std::string &params)
 
void addParameter (std::vector< std::string > &listOfparams)
 
template<typename T >
void addParameterObject (T *params, const int &sizeOfObject=sizeof(T))
 
virtual void decode ()=0
 
void clear ()
 
virtual void encode ()=0
 
std::string & operator[] (const unsigned int &i)
 
const std::string & operator[] (const unsigned int &i) const
 
std::string getId ()
 
void setId (const char *id)
 
unsigned int size ()
 

Protected Attributes

std::string request_id
 
std::vector< std::string > listOfParams
 

Detailed Description

This the request that will transit on the network.

Exemple request decoding an image on a specific form. First parameter : Height of the image. Second parameter : Width of the image. Thirs parameter : Bitmap of the image (not compress).

Here is the header of the vpRequestImage class.

#ifndef vpRequestImage_H
#define vpRequestImage_H
#include <visp3/core/vpImage.h>
#include <visp3/core/vpRequest.h>
class vpRequestImage : public vpRequest
{
private:
public:
vpRequestImage();
vpRequestImage(vpImage<unsigned char> *);
virtual ~vpRequestImage();
virtual void encode();
virtual void decode();
};
#endif

Here is the definition of the vpRequestImage class.

#include <vpRequestImage.h>
vpRequestImage::vpRequestImage(){
request_id = "image";
}
vpRequestImage::vpRequestImage(vpImage<unsigned char> *Im){
request_id = "image";
I = Im;
}
vpRequestImage::~vpRequestImage(){}
void vpRequestImage::encode(){
clear();
unsigned int h = I->getHeight();
unsigned int w = I->getWidth();
addParameterObject(I->bitmap,h*w*sizeof(unsigned char));
}
void vpRequestImage::decode(){
if(listOfParams.size() == 3){
unsigned int w, h;
memcpy((void*)&h, (void*)listOfParams[0].c_str(), sizeof(unsigned int));
memcpy((void*)&w, (void*)listOfParams[1].c_str(), sizeof(unsigned int));
I->resize(h,w);
memcpy((void*)I->bitmap,(void*)listOfParams[2].c_str(),w*h*sizeof(unsigned char));
}
}
See also
vpClient
vpServer
vpNetwork

Definition at line 131 of file vpRequest.h.

Constructor & Destructor Documentation

vpRequest::vpRequest ( )

Definition at line 41 of file vpRequest.cpp.

vpRequest::~vpRequest ( )
virtual

Definition at line 43 of file vpRequest.cpp.

Member Function Documentation

void vpRequest::addParameter ( char *  params)

Add a message as parameter of the request.

See also
vpNetwork::addParameterObject()
Parameters
params: Array of characters representing the message to add.

Definition at line 52 of file vpRequest.cpp.

References listOfParams.

void vpRequest::addParameter ( std::string &  params)

Add a message as parameter of the request.

See also
vpNetwork::addParameterObject()
Parameters
params: std::string representing the message to add.

Definition at line 65 of file vpRequest.cpp.

References listOfParams.

void vpRequest::addParameter ( std::vector< std::string > &  listOfparams)

Add messages as parameters of the request. Each message corresponds to one parameter.

See also
vpNetwork::addParameterObject()
Parameters
listOfparams: Array of std::string representing the messages to add.

Definition at line 75 of file vpRequest.cpp.

template<typename T >
void vpRequest::addParameterObject ( T *  params,
const int &  sizeOfObject = sizeof(T) 
)

Add an object as parameter of the request.

Warning
Only simple object can be sent unless you know its size. Sending object containing pointers, virtual methods, etc, won't probably work. Unless the size is well defined...
See also
vpRequest::addParameter()
Parameters
params: Object to add.
sizeOfObject: Size of the object.

Definition at line 221 of file vpRequest.h.

void vpRequest::clear ( )
inline

Clear the parameters of the request.

Definition at line 156 of file vpRequest.h.

virtual void vpRequest::decode ( )
pure virtual

Decode the parameters of the request (Funtion that has to be redifined).

See also
vpRequest::encode()
virtual void vpRequest::encode ( )
pure virtual

Encode the parameters of the request (Funtion that has to be redifined).

See also
vpRequest::decode()

Referenced by vpNetwork::sendAndEncodeRequest(), and vpNetwork::sendAndEncodeRequestTo().

std::string vpRequest::getId ( )
inline

Get the ID of the request.

See also
vpRequest::setId()
Returns
ID of the request.

Definition at line 186 of file vpRequest.h.

Referenced by vpNetwork::addDecodingRequest(), and vpNetwork::sendRequestTo().

std::string& vpRequest::operator[] ( const unsigned int &  i)
inline

Accessor on the parameters.

Returns
Parameter at the index i.

Definition at line 170 of file vpRequest.h.

const std::string& vpRequest::operator[] ( const unsigned int &  i) const
inline

Accessor on the parameters (const).

Returns
Parameter at the index i (const).

Definition at line 177 of file vpRequest.h.

void vpRequest::setId ( const char *  id)
inline

Change the ID of the request.

See also
vpRequest::getId()
Parameters
id: new ID.

Definition at line 195 of file vpRequest.h.

unsigned int vpRequest::size ( )
inline

Get the number of parameters.

Returns
Number of parameters.

Definition at line 202 of file vpRequest.h.

Referenced by vpNetwork::sendRequestTo().

Member Data Documentation

std::vector<std::string> vpRequest::listOfParams
protected

Definition at line 135 of file vpRequest.h.

Referenced by addParameter().

std::string vpRequest::request_id
protected

Definition at line 134 of file vpRequest.h.