Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpRequest.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Network Request.
32 */
33
34#ifndef vpRequest_H
35#define vpRequest_H
36
37#include <visp3/core/vpConfig.h>
38#include <visp3/core/vpDebug.h>
39#include <visp3/core/vpException.h>
40#include <visp3/core/vpImageException.h>
41
42#include <string.h>
43#include <vector>
44
126class VISP_EXPORT vpRequest
127{
128protected:
129 std::string request_id;
130 std::vector<std::string> listOfParams;
131
132public:
133 vpRequest();
134 virtual ~vpRequest();
135
136 void addParameter(char *params);
137 void addParameter(std::string &params);
138 void addParameter(std::vector<std::string> &listOfparams);
139 template <typename T> void addParameterObject(T *params, const int &sizeOfObject = sizeof(T));
140
146 virtual void decode() = 0;
147
151 void clear() { listOfParams.clear(); }
152
158 virtual void encode() = 0;
159
165 inline std::string &operator[](const unsigned int &i) { return listOfParams[i]; }
166
172 inline const std::string &operator[](const unsigned int &i) const { return listOfParams[i]; }
173
181 std::string getId() { return request_id; }
182
190 void setId(const char *id) { request_id = id; }
191
197 unsigned int size() { return (unsigned int)listOfParams.size(); }
198};
199
200//######## Definition of Template Functions ########
201//# #
202//##################################################
203
216template <typename T> void vpRequest::addParameterObject(T *params, const int &sizeOfObject)
217{
218 if (sizeOfObject != 0) {
219 char *tempS = new char[sizeOfObject];
220 memcpy((void *)tempS, (void *)params, sizeOfObject);
221 std::string returnVal(tempS, (size_t)sizeOfObject);
222
223 listOfParams.push_back(returnVal);
224
225 delete[] tempS;
226 }
227}
228
229#endif
This the request that will transit on the network.
Definition vpRequest.h:127
void clear()
Definition vpRequest.h:151
std::string & operator[](const unsigned int &i)
Definition vpRequest.h:165
void setId(const char *id)
Definition vpRequest.h:190
std::string request_id
Definition vpRequest.h:129
virtual void decode()=0
unsigned int size()
Definition vpRequest.h:197
virtual void encode()=0
std::vector< std::string > listOfParams
Definition vpRequest.h:130
std::string getId()
Definition vpRequest.h:181
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition vpRequest.h:216
const std::string & operator[](const unsigned int &i) const
Definition vpRequest.h:172