Visual Servoing Platform  version 3.6.1 under development (2024-11-12)
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:128
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:242
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:542
Type * bitmap
points toward the bitmap
Definition: vpImage.h:135
unsigned int getHeight() const
Definition: vpImage.h:181
void clear()
Definition: vpRequest.h:152
std::string request_id
Definition: vpRequest.h:130
std::vector< std::string > listOfParams
Definition: vpRequest.h:131
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:217
See also
vpClient
vpServer
vpNetwork

Definition at line 127 of file vpRequest.h.

Constructor & Destructor Documentation

◆ vpRequest()

BEGIN_VISP_NAMESPACE vpRequest::vpRequest ( )

Definition at line 42 of file vpRequest.cpp.

◆ ~vpRequest()

vpRequest::~vpRequest ( )
virtual

Definition at line 44 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 53 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 66 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 76 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 217 of file vpRequest.h.

References listOfParams.

◆ clear()

void vpRequest::clear ( )
inline

Clear the parameters of the request.

Definition at line 152 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 182 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 166 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 173 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 191 of file vpRequest.h.

◆ size()

unsigned int vpRequest::size ( ) const
inline

Get the number of parameters.

Returns
Number of parameters.

Definition at line 198 of file vpRequest.h.

Referenced by vpNetwork::sendRequestTo().

Member Data Documentation

◆ listOfParams

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

Definition at line 131 of file vpRequest.h.

Referenced by addParameter(), and addParameterObject().

◆ request_id

std::string vpRequest::request_id
protected

Definition at line 130 of file vpRequest.h.