Visual Servoing Platform  version 3.6.1 under development (2024-04-18)
vpRequest Class Referenceabstract

#include <visp3/core/vpRequest.h>

Public Member Functions

 vpRequest ()
 
virtual ~vpRequest ()
 
void addParameter (const char *params)
 
void addParameter (const std::string &params)
 
void addParameter (const 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 () const
 
void setId (const char *id)
 
unsigned int size () const
 

Protected Attributes

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

Detailed Description

This the request that will transit on the network.

Example 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
This the request that will transit on the network.
Definition: vpRequest.h:127
virtual void decode()=0
virtual void encode()=0

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));
}
}
unsigned int getWidth() const
Definition: vpImage.h:245
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:783
Type * bitmap
points toward the bitmap
Definition: vpImage.h:139
unsigned int getHeight() const
Definition: vpImage.h:184
void clear()
Definition: vpRequest.h:151
std::string request_id
Definition: vpRequest.h:129
std::vector< std::string > listOfParams
Definition: vpRequest.h:130
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:216
See also
vpClient
vpServer
vpNetwork

Definition at line 126 of file vpRequest.h.

Constructor & Destructor Documentation

◆ vpRequest()

vpRequest::vpRequest ( )

Definition at line 41 of file vpRequest.cpp.

◆ ~vpRequest()

vpRequest::~vpRequest ( )
virtual

Definition at line 43 of file vpRequest.cpp.

Member Function Documentation

◆ addParameter() [1/3]

void vpRequest::addParameter ( const 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.

◆ addParameter() [2/3]

void vpRequest::addParameter ( const 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.

◆ addParameter() [3/3]

void vpRequest::addParameter ( const 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.

References listOfParams.

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

References listOfParams.

◆ clear()

void vpRequest::clear ( )
inline

Clear the parameters of the request.

Definition at line 151 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()

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

◆ getId()

std::string vpRequest::getId ( ) const
inline

Get the ID of the request.

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

Definition at line 181 of file vpRequest.h.

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

◆ 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 165 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 172 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 190 of file vpRequest.h.

◆ size()

unsigned int vpRequest::size ( ) const
inline

Get the number of parameters.

Returns
Number of parameters.

Definition at line 197 of file vpRequest.h.

Referenced by vpNetwork::sendRequestTo().

Member Data Documentation

◆ listOfParams

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

Definition at line 130 of file vpRequest.h.

Referenced by addParameter(), and addParameterObject().

◆ request_id

std::string vpRequest::request_id
protected

Definition at line 129 of file vpRequest.h.