Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRequest Class Referenceabstract

#include <vpRequest.h>

Public Member Functions

 vpRequest ()
 vpRequest (const vpRequest &req)
virtual ~vpRequest ()
vpRequestoperator= (const vpRequest &req)
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
Definition of the vpImage class member functions.
Definition vpImage.h:131
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:544
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
unsigned int getHeight() const
Definition vpImage.h:181
void clear()
Definition vpRequest.h:163
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:228
See also
vpClient
vpServer
vpNetwork

Definition at line 127 of file vpRequest.h.

Constructor & Destructor Documentation

◆ vpRequest() [1/2]

BEGIN_VISP_NAMESPACE vpRequest::vpRequest ( )

Definition at line 37 of file vpRequest.cpp.

References listOfParams, and request_id.

Referenced by operator=(), and vpRequest().

◆ vpRequest() [2/2]

vpRequest::vpRequest ( const vpRequest & req)
inline

Definition at line 135 of file vpRequest.h.

References vpRequest().

◆ ~vpRequest()

virtual vpRequest::~vpRequest ( )
inlinevirtual

Definition at line 139 of file vpRequest.h.

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 46 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 59 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 69 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 228 of file vpRequest.h.

References listOfParams.

◆ clear()

void vpRequest::clear ( )
inline

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

References request_id.

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

◆ operator=()

vpRequest & vpRequest::operator= ( const vpRequest & req)
inline

Definition at line 141 of file vpRequest.h.

References listOfParams, request_id, and vpRequest().

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

References listOfParams.

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

References listOfParams.

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

References request_id.

◆ size()

unsigned int vpRequest::size ( ) const
inline

Get the number of parameters.

Returns
Number of parameters.

Definition at line 209 of file vpRequest.h.

References listOfParams.

Referenced by vpNetwork::sendRequestTo().

Member Data Documentation

◆ listOfParams

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

◆ request_id

std::string vpRequest::request_id
protected

Definition at line 130 of file vpRequest.h.

Referenced by getId(), operator=(), setId(), and vpRequest().