Visual Servoing Platform  version 3.2.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 130 of file vpRequest.h.

Constructor & Destructor Documentation

◆ vpRequest()

vpRequest::vpRequest ( )

Definition at line 40 of file vpRequest.cpp.

◆ ~vpRequest()

vpRequest::~vpRequest ( )
virtual

Definition at line 42 of file vpRequest.cpp.

Member Function Documentation

◆ addParameter() [1/3]

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 51 of file vpRequest.cpp.

◆ addParameter() [2/3]

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 64 of file vpRequest.cpp.

◆ addParameter() [3/3]

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 74 of file vpRequest.cpp.

◆ addParameterObject()

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 220 of file vpRequest.h.

◆ clear()

void vpRequest::clear ( )
inline

Clear the parameters of the request.

Definition at line 155 of file vpRequest.h.

◆ decode()

virtual void vpRequest::decode ( )
pure virtual

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

See also
vpRequest::encode()

◆ encode()

virtual void vpRequest::encode ( )
pure virtual

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

See also
vpRequest::decode()

◆ getId()

std::string vpRequest::getId ( )
inline

Get the ID of the request.

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

Definition at line 185 of file vpRequest.h.

◆ operator[]() [1/2]

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

Accessor on the parameters.

Returns
Parameter at the index i.

Definition at line 169 of file vpRequest.h.

◆ operator[]() [2/2]

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 176 of file vpRequest.h.

◆ setId()

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

Change the ID of the request.

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

Definition at line 194 of file vpRequest.h.

◆ size()

unsigned int vpRequest::size ( )
inline

Get the number of parameters.

Returns
Number of parameters.

Definition at line 201 of file vpRequest.h.

Member Data Documentation

◆ listOfParams

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

Definition at line 134 of file vpRequest.h.

◆ request_id

std::string vpRequest::request_id
protected

Definition at line 133 of file vpRequest.h.

vpRequest::clear
void clear()
Definition: vpRequest.h:155
vpRequest::addParameterObject
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:220
vpRequest::encode
virtual void encode()=0
vpRequest
This the request that will transit on the network.
Definition: vpRequest.h:130
vpRequest::request_id
std::string request_id
Definition: vpRequest.h:133
vpImage::bitmap
Type * bitmap
points toward the bitmap
Definition: vpImage.h:132
vpImage::getHeight
unsigned int getHeight() const
Definition: vpImage.h:177
vpRequest::listOfParams
std::vector< std::string > listOfParams
Definition: vpRequest.h:134
vpImage< unsigned char >
vpImage::resize
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:865
vpRequest::decode
virtual void decode()=0
vpImage::getWidth
unsigned int getWidth() const
Definition: vpImage.h:238