[DEV] separate buffer class ==> done
This commit is contained in:
parent
df3d8ec285
commit
39ee4f0343
@ -40,6 +40,7 @@ def create(target, module_name):
|
|||||||
'zeus/BufferParameter.cpp',
|
'zeus/BufferParameter.cpp',
|
||||||
'zeus/BufferCall.cpp',
|
'zeus/BufferCall.cpp',
|
||||||
'zeus/BufferAnswer.cpp',
|
'zeus/BufferAnswer.cpp',
|
||||||
|
'zeus/BufferData.cpp',
|
||||||
'zeus/BufferEvent.cpp',
|
'zeus/BufferEvent.cpp',
|
||||||
'zeus/BufferFlow.cpp',
|
'zeus/BufferFlow.cpp',
|
||||||
'zeus/BufferParameter_addParameter.cpp',
|
'zeus/BufferParameter_addParameter.cpp',
|
||||||
@ -64,6 +65,7 @@ def create(target, module_name):
|
|||||||
'zeus/BufferParameter.h',
|
'zeus/BufferParameter.h',
|
||||||
'zeus/BufferCall.h',
|
'zeus/BufferCall.h',
|
||||||
'zeus/BufferAnswer.h',
|
'zeus/BufferAnswer.h',
|
||||||
|
'zeus/BufferData.h',
|
||||||
'zeus/BufferEvent.h',
|
'zeus/BufferEvent.h',
|
||||||
'zeus/BufferFlow.h',
|
'zeus/BufferFlow.h',
|
||||||
'zeus/ParamType.h',
|
'zeus/ParamType.h',
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <zeus/ParamType.h>
|
#include <zeus/ParamType.h>
|
||||||
#include <zeus/File.h>
|
#include <zeus/File.h>
|
||||||
#include <zeus/Buffer.h>
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/BufferCall.h>
|
||||||
#include <ememory/memory.h>
|
#include <ememory/memory.h>
|
||||||
|
|
||||||
|
|
||||||
|
367
zeus/Buffer.cpp
367
zeus/Buffer.cpp
@ -10,6 +10,11 @@
|
|||||||
#include <etk/stdTools.h>
|
#include <etk/stdTools.h>
|
||||||
#include <zeus/AbstractFunction.h>
|
#include <zeus/AbstractFunction.h>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <zeus/BufferAnswer.h>
|
||||||
|
#include <zeus/BufferCall.h>
|
||||||
|
#include <zeus/BufferData.h>
|
||||||
|
#include <zeus/BufferFlow.h>
|
||||||
|
#include <zeus/BufferEvent.h>
|
||||||
|
|
||||||
namespace etk {
|
namespace etk {
|
||||||
template<> std::string to_string<enum zeus::Buffer::typeMessage>(const enum zeus::Buffer::typeMessage& _value) {
|
template<> std::string to_string<enum zeus::Buffer::typeMessage>(const enum zeus::Buffer::typeMessage& _value) {
|
||||||
@ -127,41 +132,6 @@ void zeus::Buffer::generateDisplay(std::ostream& _os) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void zeus::BufferCall::generateDisplay(std::ostream& _os) const {
|
|
||||||
zeus::Buffer::generateDisplay(_os);
|
|
||||||
_os << " '" + m_callName + "'";
|
|
||||||
_os << " nbParam=" + etk::to_string(getNumberParameter());
|
|
||||||
if (getNumberParameter() != 0) {
|
|
||||||
_os << " paramType(";
|
|
||||||
for (int32_t iii=0; iii<getNumberParameter(); ++iii) {
|
|
||||||
if (iii != 0) {
|
|
||||||
_os << ",";
|
|
||||||
}
|
|
||||||
_os << getParameterType(iii).getName();
|
|
||||||
}
|
|
||||||
_os << ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferAnswer::generateDisplay(std::ostream& _os) const {
|
|
||||||
zeus::Buffer::generateDisplay(_os);
|
|
||||||
if (getNumberParameter() != 0) {
|
|
||||||
_os << " '" + simpleStringParam(0) + "'";
|
|
||||||
}
|
|
||||||
if (m_errorType.size() != 0) {
|
|
||||||
_os << " Error='" + m_errorType + "'";
|
|
||||||
}if (m_errorHelp.size() != 0) {
|
|
||||||
_os << " Help='" + m_errorHelp + "'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferData::generateDisplay(std::ostream& _os) const {
|
|
||||||
zeus::Buffer::generateDisplay(_os);
|
|
||||||
_os << " paramId=" << etk::to_string(m_parameterId);
|
|
||||||
_os << " part=" << etk::to_string(m_partId);
|
|
||||||
_os << " nbData=" << etk::to_string(m_data.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t zeus::Buffer::getTransactionId() const {
|
uint32_t zeus::Buffer::getTransactionId() const {
|
||||||
return m_header.transactionID;
|
return m_header.transactionID;
|
||||||
}
|
}
|
||||||
@ -194,312 +164,6 @@ enum zeus::Buffer::typeMessage zeus::Buffer::getType() const {
|
|||||||
return zeus::Buffer::typeMessage::unknow;
|
return zeus::Buffer::typeMessage::unknow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// -- Multiple parameter
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
bool zeus::BufferParameter::writeOn(enet::WebSocket& _interface) {
|
|
||||||
uint8_t* data = nullptr;
|
|
||||||
uint32_t dataSize = 0;
|
|
||||||
uint16_t nbParameters = m_parameter.size();
|
|
||||||
size_t size = _interface.writeData((uint8_t*)&nbParameters, sizeof(uint16_t));
|
|
||||||
for (auto &it : m_parameter) {
|
|
||||||
uint32_t paramSize = it.second.size();
|
|
||||||
size = _interface.writeData((uint8_t*)¶mSize, sizeof(uint32_t));
|
|
||||||
size += _interface.writeData(&it.second[0], it.second.size() * sizeof(uint8_t));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferParameter::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
|
||||||
m_parameter.clear();
|
|
||||||
uint16_t nbParameters = 0;
|
|
||||||
if (_lenght < sizeof(uint16_t)) {
|
|
||||||
ZEUS_ERROR("wrong size of the buffer ==> missing parameter count");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint32_t offset = 0;
|
|
||||||
memcpy(&nbParameters, &_buffer[offset], sizeof(uint16_t));
|
|
||||||
offset += sizeof(uint16_t);
|
|
||||||
m_parameter.resize(nbParameters, std::make_pair(-1, std::vector<uint8_t>()));
|
|
||||||
// Load all Parameters
|
|
||||||
nbParameters = 0;
|
|
||||||
while ( nbParameters < m_parameter.size()
|
|
||||||
&& offset < _lenght) {
|
|
||||||
// parameters is contituated with size + data assiciated
|
|
||||||
uint32_t sizeParam;
|
|
||||||
memcpy(&sizeParam, &_buffer[offset], sizeof(uint32_t));
|
|
||||||
offset += sizeof(uint32_t);
|
|
||||||
if (offset+sizeParam > _lenght) {
|
|
||||||
ZEUS_ERROR("Wrong parameter size : " << sizeParam << " / availlable=" << _lenght-offset);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::vector<uint8_t> data;
|
|
||||||
data.resize(sizeParam);
|
|
||||||
memcpy(&data[0], &_buffer[offset], data.size() * sizeof(uint8_t));
|
|
||||||
offset += data.size() * sizeof(uint8_t);
|
|
||||||
m_parameter[nbParameters].second = data;
|
|
||||||
nbParameters++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
|
|
||||||
if (m_parameter.size() <= _id) {
|
|
||||||
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
|
||||||
return createType<void>();
|
|
||||||
}
|
|
||||||
if (m_parameter[_id].second.size() < 2) {
|
|
||||||
ZEUS_ERROR("try to get type with no ID value Type (not enouth data)");
|
|
||||||
return createType<void>();
|
|
||||||
}
|
|
||||||
uint16_t typeId = (uint16_t(m_parameter[_id].second[0]) << 8) + uint16_t(m_parameter[_id].second[1]);
|
|
||||||
if (typeId == createType<void>().getId()) { m_parameter[_id].first = 2; return createType<void>(); }
|
|
||||||
if (typeId == createType<bool>().getId()) { m_parameter[_id].first = 2; return createType<bool>(); }
|
|
||||||
if (typeId == createType<float>().getId()) { m_parameter[_id].first = 2; return createType<float>(); }
|
|
||||||
if (typeId == createType<double>().getId()) { m_parameter[_id].first = 2; return createType<double>(); }
|
|
||||||
if (typeId == createType<int64_t>().getId()) { m_parameter[_id].first = 2; return createType<int64_t>(); }
|
|
||||||
if (typeId == createType<int32_t>().getId()) { m_parameter[_id].first = 2; return createType<int32_t>(); }
|
|
||||||
if (typeId == createType<int16_t>().getId()) { m_parameter[_id].first = 2; return createType<int16_t>(); }
|
|
||||||
if (typeId == createType<int8_t>().getId()) { m_parameter[_id].first = 2; return createType<int8_t>(); }
|
|
||||||
if (typeId == createType<uint64_t>().getId()) { m_parameter[_id].first = 2; return createType<uint64_t>(); }
|
|
||||||
if (typeId == createType<uint32_t>().getId()) { m_parameter[_id].first = 2; return createType<uint32_t>(); }
|
|
||||||
if (typeId == createType<uint16_t>().getId()) { m_parameter[_id].first = 2; return createType<uint16_t>(); }
|
|
||||||
if (typeId == createType<uint8_t>().getId()) { m_parameter[_id].first = 2; return createType<uint8_t>(); }
|
|
||||||
if (typeId == createType<std::string>().getId()) { m_parameter[_id].first = 2; return createType<std::string>(); }
|
|
||||||
if (typeId == createType<std::vector<void>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<void>>(); }
|
|
||||||
if (typeId == createType<std::vector<bool>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<bool>>(); }
|
|
||||||
if (typeId == createType<std::vector<float>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<float>>(); }
|
|
||||||
if (typeId == createType<std::vector<double>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<double>>(); }
|
|
||||||
if (typeId == createType<std::vector<int64_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int64_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<int32_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int32_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<int16_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int16_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<int8_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int8_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<uint64_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint64_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<uint32_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint32_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<uint16_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint16_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<uint8_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint8_t>>(); }
|
|
||||||
if (typeId == createType<std::vector<std::string>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<std::string>>(); }
|
|
||||||
if (typeId == createType<zeus::File>().getId()) { m_parameter[_id].first = 2; return createType<zeus::File>(); }
|
|
||||||
if (typeId == paramTypeRaw) {
|
|
||||||
m_parameter[_id].first = sizeof(uint16_t);
|
|
||||||
return zeus::ParamType("raw", paramTypeRaw);
|
|
||||||
}
|
|
||||||
if (typeId == paramTypeObject) {
|
|
||||||
std::string type = reinterpret_cast<const char*>(&m_parameter[_id].second[2]);
|
|
||||||
m_parameter[_id].first = type.size() + sizeof(uint16_t);
|
|
||||||
// TODO : Check error of \0 ==> limit at 256 char ...
|
|
||||||
return zeus::ParamType(type, paramTypeObject);
|
|
||||||
}
|
|
||||||
ZEUS_ERROR("Can not get type of parameter ... ");
|
|
||||||
return createType<void>();
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t* zeus::BufferParameter::getParameterPointer(int32_t _id) const {
|
|
||||||
const uint8_t* out = nullptr;
|
|
||||||
if (m_parameter.size() <= _id) {
|
|
||||||
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
if (m_parameter[_id].first <= -1) {
|
|
||||||
getParameterType(_id); // this function initialize this parameter if needed ...
|
|
||||||
}
|
|
||||||
out = reinterpret_cast<const uint8_t*>(&m_parameter[_id].second[m_parameter[_id].first]);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t zeus::BufferParameter::getParameterSize(int32_t _id) const {
|
|
||||||
int32_t out = 0;
|
|
||||||
if (m_parameter.size() <= _id) {
|
|
||||||
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (m_parameter[_id].first <= -1) {
|
|
||||||
getParameterType(_id); // this function initialize this parameter if needed ...
|
|
||||||
}
|
|
||||||
return m_parameter[_id].second.size() - m_parameter[_id].first;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t zeus::BufferParameter::getNumberParameter() const {
|
|
||||||
return m_parameter.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string zeus::BufferParameter::simpleStringParam(uint32_t _id) const {
|
|
||||||
zeus::ParamType paramType = getParameterType(_id);
|
|
||||||
if (paramType.isVector() == false) {
|
|
||||||
if (paramType.isNumber() == true) {
|
|
||||||
return etk::to_string(getParameter<int64_t>(_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (paramType == createType<bool>()) {
|
|
||||||
return etk::to_string(getParameter<bool>(_id));
|
|
||||||
}
|
|
||||||
if (paramType == createType<std::string>()) {
|
|
||||||
return "{" + getParameter<std::string>(_id) + "}";
|
|
||||||
}
|
|
||||||
if (paramType == createType<std::vector<std::string>>()) {
|
|
||||||
return "[" + etk::to_string(getParameter<std::vector<std::string>>(_id)) + "]";
|
|
||||||
}
|
|
||||||
return paramType.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferParameter::parameterAppendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
|
||||||
// At this point we just add data at the parameter value:
|
|
||||||
uint16_t parameterID = _obj->getParameterId();
|
|
||||||
|
|
||||||
if (_obj->getData().size() == 0) {
|
|
||||||
// no data (normal case)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// now, we will add datas:
|
|
||||||
if (parameterID >= m_parameter.size()) {
|
|
||||||
ZEUS_ERROR("Try to add data on an unexisting parameter...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int32_t offset = m_parameter[parameterID].second.size();
|
|
||||||
m_parameter[parameterID].second.resize(offset + _obj->getData().size());
|
|
||||||
memcpy(&m_parameter[parameterID].second[offset], &_obj->getData()[0], _obj->getData().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// -- Call
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const std::string& zeus::BufferCall::getCall() const {
|
|
||||||
return m_callName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferCall::setCall(const std::string& _value) {
|
|
||||||
m_callName = _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zeus::BufferCall::writeOn(enet::WebSocket& _interface) {
|
|
||||||
zeus::Buffer::writeOn(_interface);
|
|
||||||
_interface.writeData((uint8_t*)m_callName.c_str(), m_callName.size() + 1);
|
|
||||||
return BufferParameter::writeOn(_interface);
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferCall::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
|
||||||
// First element iw the call name, after, this is the parameters...
|
|
||||||
// parse the string: (call name)
|
|
||||||
uint32_t pos = 0;
|
|
||||||
m_callName.clear();
|
|
||||||
while( pos < _lenght
|
|
||||||
&& (char)_buffer[pos] != '\0') {
|
|
||||||
m_callName += _buffer[pos];
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
// parse parameters:
|
|
||||||
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferCall::appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
|
||||||
parameterAppendBufferData(_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// -- Answer
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool zeus::BufferAnswer::hasError() {
|
|
||||||
return m_errorType.size() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& zeus::BufferAnswer::getError() {
|
|
||||||
return m_errorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& zeus::BufferAnswer::getErrorHelp() {
|
|
||||||
return m_errorHelp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferAnswer::addError(const std::string& _value, const std::string& _comment) {
|
|
||||||
m_errorType = _value;
|
|
||||||
m_errorHelp = _comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zeus::BufferAnswer::writeOn(enet::WebSocket& _interface) {
|
|
||||||
zeus::Buffer::writeOn(_interface);
|
|
||||||
_interface.writeData((uint8_t*)m_errorType.c_str(), m_errorType.size() + 1);
|
|
||||||
if (m_errorType.size() != 0) {
|
|
||||||
_interface.writeData((uint8_t*)m_errorHelp.c_str(), m_errorHelp.size() + 1);
|
|
||||||
}
|
|
||||||
return BufferParameter::writeOn(_interface);
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferAnswer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
|
||||||
// First element iw the call name, after, this is the parameters...
|
|
||||||
// parse the string: (call name)
|
|
||||||
uint32_t pos = 0;
|
|
||||||
m_errorType.clear();
|
|
||||||
m_errorHelp.clear();
|
|
||||||
while( pos < _lenght
|
|
||||||
&& _buffer[pos] != '\0') {
|
|
||||||
m_errorType += _buffer[pos];
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
if (m_errorType.size() != 0) {
|
|
||||||
while( pos < _lenght
|
|
||||||
&& _buffer[pos] != '\0') {
|
|
||||||
m_errorHelp += _buffer[pos];
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
// parse parameters:
|
|
||||||
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferAnswer::appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
|
||||||
parameterAppendBufferData(_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// -- Data
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void zeus::BufferData::addData(uint16_t _parameterId, void* _data, uint32_t _size) {
|
|
||||||
m_parameterId = _parameterId;
|
|
||||||
m_data.resize(_size);
|
|
||||||
memcpy(&m_data[0], _data, _size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// note limited 15 bits
|
|
||||||
uint32_t zeus::BufferData::getPartId() const {
|
|
||||||
return m_partId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferData::setPartId(uint32_t _value) {
|
|
||||||
if (_value == 0) {
|
|
||||||
ZEUS_ERROR("Part ID must be != of 0");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_partId = _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zeus::BufferData::writeOn(enet::WebSocket& _interface) {
|
|
||||||
zeus::Buffer::writeOn(_interface);
|
|
||||||
_interface.writeData((uint8_t*)&m_partId, sizeof(uint32_t));
|
|
||||||
_interface.writeData((uint8_t*)&m_parameterId, sizeof(uint16_t));
|
|
||||||
_interface.writeData((uint8_t*)&m_data[0], m_data.size());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zeus::BufferData::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
|
||||||
// First element iw the call name, after, this is the parameters...
|
|
||||||
// parse the string: (call name)
|
|
||||||
uint32_t pos = 0;
|
|
||||||
m_partId = 0;
|
|
||||||
m_parameterId = 0;
|
|
||||||
memcpy(reinterpret_cast<char*>(&m_partId), &_buffer[pos], sizeof(uint32_t));
|
|
||||||
pos += sizeof(uint32_t);
|
|
||||||
memcpy(reinterpret_cast<char*>(&m_parameterId), &_buffer[pos], sizeof(uint16_t));
|
|
||||||
pos += sizeof(uint16_t);
|
|
||||||
m_data.resize(_lenght - pos);
|
|
||||||
memcpy(&m_data[0], &_buffer[pos], m_data.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
// -- Factory
|
// -- Factory
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
@ -564,24 +228,3 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ememory::SharedPtr<zeus::BufferCall> zeus::BufferCall::create() {
|
|
||||||
return ememory::SharedPtr<zeus::BufferCall>(new zeus::BufferCall);
|
|
||||||
}
|
|
||||||
|
|
||||||
ememory::SharedPtr<zeus::BufferAnswer> zeus::BufferAnswer::create() {
|
|
||||||
return ememory::SharedPtr<zeus::BufferAnswer>(new zeus::BufferAnswer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ememory::SharedPtr<zeus::BufferData> zeus::BufferData::create() {
|
|
||||||
return ememory::SharedPtr<zeus::BufferData>(new zeus::BufferData);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
ememory::SharedPtr<zeus::BufferEvent> zeus::BufferEvent::create() {
|
|
||||||
return ememory::SharedPtr<zeus::BufferEvent>(new zeus::BufferEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
ememory::SharedPtr<zeus::BufferFlow> zeus::BufferFlow::create() {
|
|
||||||
return ememory::SharedPtr<zeus::BufferFlow>(new zeus::BufferFlow);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
283
zeus/Buffer.h
283
zeus/Buffer.h
@ -36,7 +36,8 @@ namespace zeus {
|
|||||||
uint32_t clientID; // same as sevice ID
|
uint32_t clientID; // same as sevice ID
|
||||||
uint8_t flags; // List of flags & type message:
|
uint8_t flags; // List of flags & type message:
|
||||||
// - 0-2: Type of the message
|
// - 0-2: Type of the message
|
||||||
// - 3-6: Reserved
|
// - 3-5: Reserved
|
||||||
|
// - 6: message data is zipped
|
||||||
// - 7: message finished
|
// - 7: message finished
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
@ -233,286 +234,6 @@ namespace zeus {
|
|||||||
virtual bool writeOn(enet::WebSocket& _interface);
|
virtual bool writeOn(enet::WebSocket& _interface);
|
||||||
virtual void generateDisplay(std::ostream& _os) const ;
|
virtual void generateDisplay(std::ostream& _os) const ;
|
||||||
};
|
};
|
||||||
class BufferParameter:
|
|
||||||
public Buffer {
|
|
||||||
protected:
|
|
||||||
mutable std::vector<std::pair<int32_t,std::vector<uint8_t>>> m_parameter; //!< list of the parameter (offset of start data and buffer of data (subprotocol...)
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Template to get a parameter with a specific type
|
|
||||||
* @param[in] _id Number of the parameter
|
|
||||||
* @return Converted type of the parameter (or empty value)
|
|
||||||
*/
|
|
||||||
template<class ZEUS_TYPE_DATA>
|
|
||||||
ZEUS_TYPE_DATA getParameter(int32_t _id) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the type of a parameter.
|
|
||||||
* @param[in] _id Number of the parameter
|
|
||||||
* @return type of the parameter
|
|
||||||
*/
|
|
||||||
zeus::ParamType getParameterType(int32_t _id) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the start pointer of the parameter
|
|
||||||
* @param[in] _id Number of the parameter
|
|
||||||
* @return pointer of the parameter or nullptr
|
|
||||||
*/
|
|
||||||
const uint8_t* getParameterPointer(int32_t _id) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the size of the parameter availlable in the parameter pointer
|
|
||||||
* @param[in] _id Number of the parameter
|
|
||||||
* @return size of the parameter buffer
|
|
||||||
*/
|
|
||||||
uint32_t getParameterSize(int32_t _id) const;
|
|
||||||
/**
|
|
||||||
* @brief Get the number of parameter availlable
|
|
||||||
* @return number of parameter
|
|
||||||
*/
|
|
||||||
uint16_t getNumberParameter() const;
|
|
||||||
/**
|
|
||||||
* @brief Add an empty vector with no type
|
|
||||||
*/
|
|
||||||
void addParameterEmptyVector();
|
|
||||||
/**
|
|
||||||
* @brief Add parameter (or not.. this is the end of an auto resursive add parameter)
|
|
||||||
*/
|
|
||||||
void addParameter();
|
|
||||||
/**
|
|
||||||
* @brief Convert the parameter in a simple human readable string
|
|
||||||
* @param[in] _id Number of the parameter
|
|
||||||
* @return readable string
|
|
||||||
*/
|
|
||||||
std::string simpleStringParam(uint32_t _id) const;
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
bool writeOn(enet::WebSocket& _interface) override;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* @brief Add a parameter at a specific position
|
|
||||||
* @param[in] _paramId Id of the parameter (needed for the multiple packet sending)
|
|
||||||
* @param[in] _value Value to add in parameter
|
|
||||||
*/
|
|
||||||
template<class ZEUS_TYPE_DATA>
|
|
||||||
void addParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
|
|
||||||
public:
|
|
||||||
template<class ZEUS_TYPE_DATA>
|
|
||||||
void addParameter(const ZEUS_TYPE_DATA& _value) {
|
|
||||||
addParameter(m_parameter.size(), _value);
|
|
||||||
}
|
|
||||||
void parameterAppendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj);
|
|
||||||
};
|
|
||||||
class BufferCall :
|
|
||||||
public BufferParameter {
|
|
||||||
friend class zeus::Buffer;
|
|
||||||
protected:
|
|
||||||
std::string m_callName;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferCall::create
|
|
||||||
*/
|
|
||||||
BufferCall() {
|
|
||||||
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::call);
|
|
||||||
};
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
|
||||||
bool writeOn(enet::WebSocket& _interface) override;
|
|
||||||
void generateDisplay(std::ostream& _os) const override;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Create a shared pointer on the BufferCall
|
|
||||||
* @return Allocated Buffer.
|
|
||||||
*/
|
|
||||||
static ememory::SharedPtr<zeus::BufferCall> create();
|
|
||||||
public:
|
|
||||||
enum zeus::Buffer::typeMessage getType() const override {
|
|
||||||
return zeus::Buffer::typeMessage::call;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief get the call value of the buffer
|
|
||||||
* @return string of the function to call
|
|
||||||
*/
|
|
||||||
const std::string& getCall() const;
|
|
||||||
/**
|
|
||||||
* @brief Set the call value of the buffer
|
|
||||||
* @param[in] _value Function to call
|
|
||||||
*/
|
|
||||||
void setCall(const std::string& _value);
|
|
||||||
|
|
||||||
};
|
|
||||||
class BufferAnswer :
|
|
||||||
public BufferParameter {
|
|
||||||
friend class zeus::Buffer;
|
|
||||||
protected:
|
|
||||||
std::string m_errorType;
|
|
||||||
std::string m_errorHelp;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferAnswer::create
|
|
||||||
*/
|
|
||||||
BufferAnswer() {
|
|
||||||
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::answer);
|
|
||||||
};
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
|
||||||
bool writeOn(enet::WebSocket& _interface) override;
|
|
||||||
void generateDisplay(std::ostream& _os) const override;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Create a shared pointer on the BufferAnswer
|
|
||||||
* @return Allocated Buffer.
|
|
||||||
*/
|
|
||||||
static ememory::SharedPtr<zeus::BufferAnswer> create();
|
|
||||||
public:
|
|
||||||
enum zeus::Buffer::typeMessage getType() const override {
|
|
||||||
return zeus::Buffer::typeMessage::answer;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief set the answer of the call
|
|
||||||
* @param[in] _value Value to add
|
|
||||||
*/
|
|
||||||
template<class ZEUS_TYPE_DATA>
|
|
||||||
void addAnswer(const ZEUS_TYPE_DATA& _value) {
|
|
||||||
addParameter(_value);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief get the answer value
|
|
||||||
* @param[in] Data of the answer
|
|
||||||
*/
|
|
||||||
// TODO : Do it better check error ... ==> can be good ...
|
|
||||||
template<class ZEUS_TYPE_DATA>
|
|
||||||
ZEUS_TYPE_DATA getAnswer() const {
|
|
||||||
return getParameter<ZEUS_TYPE_DATA>(0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Ann an error on the message answer
|
|
||||||
* @param[in] _value error value (simple string with no space with all capital letter separaete with '_'
|
|
||||||
* @param[in] _comment Human readable help to understand the error
|
|
||||||
*/
|
|
||||||
void addError(const std::string& _value, const std::string& _comment);
|
|
||||||
/**
|
|
||||||
* @brief Check if the answer have an error
|
|
||||||
* @return status of the error.
|
|
||||||
*/
|
|
||||||
bool hasError();
|
|
||||||
/**
|
|
||||||
* @brief get the error value (if exist)
|
|
||||||
* @return string of the error
|
|
||||||
*/
|
|
||||||
const std::string& getError();
|
|
||||||
/**
|
|
||||||
* @brief get the error help (if exist)
|
|
||||||
* @return string of the error help
|
|
||||||
*/
|
|
||||||
const std::string& getErrorHelp();
|
|
||||||
};
|
|
||||||
class BufferData:
|
|
||||||
public Buffer {
|
|
||||||
friend class zeus::Buffer;
|
|
||||||
protected:
|
|
||||||
uint32_t m_partId;
|
|
||||||
uint16_t m_parameterId;
|
|
||||||
std::vector<uint8_t> m_data;
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferData::create
|
|
||||||
*/
|
|
||||||
BufferData():
|
|
||||||
m_partId(0) {
|
|
||||||
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::data);
|
|
||||||
};
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
// TODO :... void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
|
||||||
bool writeOn(enet::WebSocket& _interface) override;
|
|
||||||
void generateDisplay(std::ostream& _os) const override;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief Create a shared pointer on the BufferData
|
|
||||||
* @return Allocated Buffer.
|
|
||||||
*/
|
|
||||||
static ememory::SharedPtr<zeus::BufferData> create();
|
|
||||||
public:
|
|
||||||
enum zeus::Buffer::typeMessage getType() const override {
|
|
||||||
return zeus::Buffer::typeMessage::data;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Get the parameter Id of the buffer
|
|
||||||
* @return Part Identifier
|
|
||||||
*/
|
|
||||||
uint16_t getParameterId() const {
|
|
||||||
return m_parameterId;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Get the part Id of the buffer
|
|
||||||
* @return Part Identifier
|
|
||||||
*/
|
|
||||||
uint32_t getPartId() const;
|
|
||||||
/**
|
|
||||||
* @brief Set the part Id of the buffer
|
|
||||||
* @param[in] _value New Part ID
|
|
||||||
*/
|
|
||||||
void setPartId(uint32_t _value);
|
|
||||||
/**
|
|
||||||
* @brief add a raw data on the buffer
|
|
||||||
* @param[in] _parameterId Parameter id of the destination of the data
|
|
||||||
* @param[in] _data Pointer on the data
|
|
||||||
* @param[in] _size size of the data to add
|
|
||||||
*/
|
|
||||||
void addData(uint16_t _parameterId, void* _data, uint32_t _size);
|
|
||||||
/**
|
|
||||||
* @brief Get data reference
|
|
||||||
*/
|
|
||||||
const std::vector<uint8_t>& getData() const {
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
class BufferEvent :
|
|
||||||
public BufferParameter {
|
|
||||||
friend class zeus::Buffer;
|
|
||||||
protected:
|
|
||||||
/ **
|
|
||||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferEvent::create
|
|
||||||
* /
|
|
||||||
BufferEvent() {
|
|
||||||
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::event);
|
|
||||||
};
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
|
||||||
public:
|
|
||||||
/ **
|
|
||||||
* @brief Create a shared pointer on the BufferEvent
|
|
||||||
* @return Allocated Buffer.
|
|
||||||
* /
|
|
||||||
static ememory::SharedPtr<zeus::BufferEvent> create();
|
|
||||||
public:
|
|
||||||
enum zeus::Buffer::typeMessage getType() const override {
|
|
||||||
return zeus::Buffer::typeMessage::event;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
class BufferFlow:
|
|
||||||
public Buffer {
|
|
||||||
friend class zeus::Buffer;
|
|
||||||
protected:
|
|
||||||
/ **
|
|
||||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferFlow::create
|
|
||||||
* /
|
|
||||||
BufferFlow() {
|
|
||||||
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::flow);
|
|
||||||
};
|
|
||||||
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
|
||||||
public:
|
|
||||||
/ **
|
|
||||||
* @brief Create a shared pointer on the BufferFlow
|
|
||||||
* @return Allocated Buffer.
|
|
||||||
* /
|
|
||||||
static ememory::SharedPtr<zeus::BufferFlow> create();
|
|
||||||
public:
|
|
||||||
enum zeus::Buffer::typeMessage getType() const override {
|
|
||||||
return zeus::Buffer::typeMessage::flow;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* @brief generate a display of the typemessage
|
* @brief generate a display of the typemessage
|
||||||
* @param[in] _os stream to add data
|
* @param[in] _os stream to add data
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferAnswer.h>
|
||||||
|
|
||||||
|
void zeus::BufferAnswer::generateDisplay(std::ostream& _os) const {
|
||||||
|
zeus::Buffer::generateDisplay(_os);
|
||||||
|
if (getNumberParameter() != 0) {
|
||||||
|
_os << " '" + simpleStringParam(0) + "'";
|
||||||
|
}
|
||||||
|
if (m_errorType.size() != 0) {
|
||||||
|
_os << " Error='" + m_errorType + "'";
|
||||||
|
}if (m_errorHelp.size() != 0) {
|
||||||
|
_os << " Help='" + m_errorHelp + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool zeus::BufferAnswer::hasError() {
|
||||||
|
return m_errorType.size() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& zeus::BufferAnswer::getError() {
|
||||||
|
return m_errorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& zeus::BufferAnswer::getErrorHelp() {
|
||||||
|
return m_errorHelp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferAnswer::addError(const std::string& _value, const std::string& _comment) {
|
||||||
|
m_errorType = _value;
|
||||||
|
m_errorHelp = _comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool zeus::BufferAnswer::writeOn(enet::WebSocket& _interface) {
|
||||||
|
zeus::Buffer::writeOn(_interface);
|
||||||
|
_interface.writeData((uint8_t*)m_errorType.c_str(), m_errorType.size() + 1);
|
||||||
|
if (m_errorType.size() != 0) {
|
||||||
|
_interface.writeData((uint8_t*)m_errorHelp.c_str(), m_errorHelp.size() + 1);
|
||||||
|
}
|
||||||
|
return BufferParameter::writeOn(_interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferAnswer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
||||||
|
// First element iw the call name, after, this is the parameters...
|
||||||
|
// parse the string: (call name)
|
||||||
|
uint32_t pos = 0;
|
||||||
|
m_errorType.clear();
|
||||||
|
m_errorHelp.clear();
|
||||||
|
while( pos < _lenght
|
||||||
|
&& _buffer[pos] != '\0') {
|
||||||
|
m_errorType += _buffer[pos];
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
if (m_errorType.size() != 0) {
|
||||||
|
while( pos < _lenght
|
||||||
|
&& _buffer[pos] != '\0') {
|
||||||
|
m_errorHelp += _buffer[pos];
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
// parse parameters:
|
||||||
|
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferAnswer::appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
||||||
|
parameterAppendBufferData(_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// -- Factory
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ememory::SharedPtr<zeus::BufferAnswer> zeus::BufferAnswer::create() {
|
||||||
|
return ememory::SharedPtr<zeus::BufferAnswer>(new zeus::BufferAnswer);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <zeus/BufferParameter.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
class BufferAnswer :
|
||||||
|
public BufferParameter {
|
||||||
|
friend class zeus::Buffer;
|
||||||
|
protected:
|
||||||
|
std::string m_errorType;
|
||||||
|
std::string m_errorHelp;
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferAnswer::create
|
||||||
|
*/
|
||||||
|
BufferAnswer() {
|
||||||
|
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::answer);
|
||||||
|
};
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
||||||
|
bool writeOn(enet::WebSocket& _interface) override;
|
||||||
|
void generateDisplay(std::ostream& _os) const override;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create a shared pointer on the BufferAnswer
|
||||||
|
* @return Allocated Buffer.
|
||||||
|
*/
|
||||||
|
static ememory::SharedPtr<zeus::BufferAnswer> create();
|
||||||
|
public:
|
||||||
|
enum zeus::Buffer::typeMessage getType() const override {
|
||||||
|
return zeus::Buffer::typeMessage::answer;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief set the answer of the call
|
||||||
|
* @param[in] _value Value to add
|
||||||
|
*/
|
||||||
|
template<class ZEUS_TYPE_DATA>
|
||||||
|
void addAnswer(const ZEUS_TYPE_DATA& _value) {
|
||||||
|
addParameter(_value);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief get the answer value
|
||||||
|
* @param[in] Data of the answer
|
||||||
|
*/
|
||||||
|
// TODO : Do it better check error ... ==> can be good ...
|
||||||
|
template<class ZEUS_TYPE_DATA>
|
||||||
|
ZEUS_TYPE_DATA getAnswer() const {
|
||||||
|
return getParameter<ZEUS_TYPE_DATA>(0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Ann an error on the message answer
|
||||||
|
* @param[in] _value error value (simple string with no space with all capital letter separaete with '_'
|
||||||
|
* @param[in] _comment Human readable help to understand the error
|
||||||
|
*/
|
||||||
|
void addError(const std::string& _value, const std::string& _comment);
|
||||||
|
/**
|
||||||
|
* @brief Check if the answer have an error
|
||||||
|
* @return status of the error.
|
||||||
|
*/
|
||||||
|
bool hasError();
|
||||||
|
/**
|
||||||
|
* @brief get the error value (if exist)
|
||||||
|
* @return string of the error
|
||||||
|
*/
|
||||||
|
const std::string& getError();
|
||||||
|
/**
|
||||||
|
* @brief get the error help (if exist)
|
||||||
|
* @return string of the error help
|
||||||
|
*/
|
||||||
|
const std::string& getErrorHelp();
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferCall.h>
|
||||||
|
|
||||||
|
void zeus::BufferCall::generateDisplay(std::ostream& _os) const {
|
||||||
|
zeus::Buffer::generateDisplay(_os);
|
||||||
|
_os << " '" + m_callName + "'";
|
||||||
|
_os << " nbParam=" + etk::to_string(getNumberParameter());
|
||||||
|
if (getNumberParameter() != 0) {
|
||||||
|
_os << " paramType(";
|
||||||
|
for (int32_t iii=0; iii<getNumberParameter(); ++iii) {
|
||||||
|
if (iii != 0) {
|
||||||
|
_os << ",";
|
||||||
|
}
|
||||||
|
_os << getParameterType(iii).getName();
|
||||||
|
}
|
||||||
|
_os << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& zeus::BufferCall::getCall() const {
|
||||||
|
return m_callName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferCall::setCall(const std::string& _value) {
|
||||||
|
m_callName = _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool zeus::BufferCall::writeOn(enet::WebSocket& _interface) {
|
||||||
|
zeus::Buffer::writeOn(_interface);
|
||||||
|
_interface.writeData((uint8_t*)m_callName.c_str(), m_callName.size() + 1);
|
||||||
|
return BufferParameter::writeOn(_interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferCall::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
||||||
|
// First element iw the call name, after, this is the parameters...
|
||||||
|
// parse the string: (call name)
|
||||||
|
uint32_t pos = 0;
|
||||||
|
m_callName.clear();
|
||||||
|
while( pos < _lenght
|
||||||
|
&& (char)_buffer[pos] != '\0') {
|
||||||
|
m_callName += _buffer[pos];
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
// parse parameters:
|
||||||
|
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferCall::appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
||||||
|
parameterAppendBufferData(_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// -- Factory
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
ememory::SharedPtr<zeus::BufferCall> zeus::BufferCall::create() {
|
||||||
|
return ememory::SharedPtr<zeus::BufferCall>(new zeus::BufferCall);
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <zeus/BufferParameter.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
class BufferCall :
|
||||||
|
public BufferParameter {
|
||||||
|
friend class zeus::Buffer;
|
||||||
|
protected:
|
||||||
|
std::string m_callName;
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferCall::create
|
||||||
|
*/
|
||||||
|
BufferCall() {
|
||||||
|
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::call);
|
||||||
|
};
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
||||||
|
bool writeOn(enet::WebSocket& _interface) override;
|
||||||
|
void generateDisplay(std::ostream& _os) const override;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create a shared pointer on the BufferCall
|
||||||
|
* @return Allocated Buffer.
|
||||||
|
*/
|
||||||
|
static ememory::SharedPtr<zeus::BufferCall> create();
|
||||||
|
public:
|
||||||
|
enum zeus::Buffer::typeMessage getType() const override {
|
||||||
|
return zeus::Buffer::typeMessage::call;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief get the call value of the buffer
|
||||||
|
* @return string of the function to call
|
||||||
|
*/
|
||||||
|
const std::string& getCall() const;
|
||||||
|
/**
|
||||||
|
* @brief Set the call value of the buffer
|
||||||
|
* @param[in] _value Function to call
|
||||||
|
*/
|
||||||
|
void setCall(const std::string& _value);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferData.h>
|
||||||
|
|
||||||
|
void zeus::BufferData::generateDisplay(std::ostream& _os) const {
|
||||||
|
zeus::Buffer::generateDisplay(_os);
|
||||||
|
_os << " paramId=" << etk::to_string(m_parameterId);
|
||||||
|
_os << " part=" << etk::to_string(m_partId);
|
||||||
|
_os << " nbData=" << etk::to_string(m_data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferData::addData(uint16_t _parameterId, void* _data, uint32_t _size) {
|
||||||
|
m_parameterId = _parameterId;
|
||||||
|
m_data.resize(_size);
|
||||||
|
memcpy(&m_data[0], _data, _size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// note limited 15 bits
|
||||||
|
uint32_t zeus::BufferData::getPartId() const {
|
||||||
|
return m_partId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferData::setPartId(uint32_t _value) {
|
||||||
|
if (_value == 0) {
|
||||||
|
ZEUS_ERROR("Part ID must be != of 0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_partId = _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool zeus::BufferData::writeOn(enet::WebSocket& _interface) {
|
||||||
|
zeus::Buffer::writeOn(_interface);
|
||||||
|
_interface.writeData((uint8_t*)&m_partId, sizeof(uint32_t));
|
||||||
|
_interface.writeData((uint8_t*)&m_parameterId, sizeof(uint16_t));
|
||||||
|
_interface.writeData((uint8_t*)&m_data[0], m_data.size());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferData::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
||||||
|
// First element iw the call name, after, this is the parameters...
|
||||||
|
// parse the string: (call name)
|
||||||
|
uint32_t pos = 0;
|
||||||
|
m_partId = 0;
|
||||||
|
m_parameterId = 0;
|
||||||
|
memcpy(reinterpret_cast<char*>(&m_partId), &_buffer[pos], sizeof(uint32_t));
|
||||||
|
pos += sizeof(uint32_t);
|
||||||
|
memcpy(reinterpret_cast<char*>(&m_parameterId), &_buffer[pos], sizeof(uint16_t));
|
||||||
|
pos += sizeof(uint16_t);
|
||||||
|
m_data.resize(_lenght - pos);
|
||||||
|
memcpy(&m_data[0], &_buffer[pos], m_data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// -- Factory
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ememory::SharedPtr<zeus::BufferData> zeus::BufferData::create() {
|
||||||
|
return ememory::SharedPtr<zeus::BufferData>(new zeus::BufferData);
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
class BufferData:
|
||||||
|
public Buffer {
|
||||||
|
friend class zeus::Buffer;
|
||||||
|
protected:
|
||||||
|
uint32_t m_partId;
|
||||||
|
uint16_t m_parameterId;
|
||||||
|
std::vector<uint8_t> m_data;
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferData::create
|
||||||
|
*/
|
||||||
|
BufferData():
|
||||||
|
m_partId(0) {
|
||||||
|
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::data);
|
||||||
|
};
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
// TODO :... void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
||||||
|
bool writeOn(enet::WebSocket& _interface) override;
|
||||||
|
void generateDisplay(std::ostream& _os) const override;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create a shared pointer on the BufferData
|
||||||
|
* @return Allocated Buffer.
|
||||||
|
*/
|
||||||
|
static ememory::SharedPtr<zeus::BufferData> create();
|
||||||
|
public:
|
||||||
|
enum zeus::Buffer::typeMessage getType() const override {
|
||||||
|
return zeus::Buffer::typeMessage::data;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Get the parameter Id of the buffer
|
||||||
|
* @return Part Identifier
|
||||||
|
*/
|
||||||
|
uint16_t getParameterId() const {
|
||||||
|
return m_parameterId;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Get the part Id of the buffer
|
||||||
|
* @return Part Identifier
|
||||||
|
*/
|
||||||
|
uint32_t getPartId() const;
|
||||||
|
/**
|
||||||
|
* @brief Set the part Id of the buffer
|
||||||
|
* @param[in] _value New Part ID
|
||||||
|
*/
|
||||||
|
void setPartId(uint32_t _value);
|
||||||
|
/**
|
||||||
|
* @brief add a raw data on the buffer
|
||||||
|
* @param[in] _parameterId Parameter id of the destination of the data
|
||||||
|
* @param[in] _data Pointer on the data
|
||||||
|
* @param[in] _size size of the data to add
|
||||||
|
*/
|
||||||
|
void addData(uint16_t _parameterId, void* _data, uint32_t _size);
|
||||||
|
/**
|
||||||
|
* @brief Get data reference
|
||||||
|
*/
|
||||||
|
const std::vector<uint8_t>& getData() const {
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferEvent.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// -- Factory
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ememory::SharedPtr<zeus::BufferEvent> zeus::BufferEvent::create() {
|
||||||
|
return ememory::SharedPtr<zeus::BufferEvent>(new zeus::BufferEvent);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
/*
|
||||||
|
class BufferEvent :
|
||||||
|
public BufferParameter {
|
||||||
|
friend class zeus::Buffer;
|
||||||
|
protected:
|
||||||
|
/ **
|
||||||
|
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferEvent::create
|
||||||
|
* /
|
||||||
|
BufferEvent() {
|
||||||
|
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::event);
|
||||||
|
};
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
void appendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) override;
|
||||||
|
public:
|
||||||
|
/ **
|
||||||
|
* @brief Create a shared pointer on the BufferEvent
|
||||||
|
* @return Allocated Buffer.
|
||||||
|
* /
|
||||||
|
static ememory::SharedPtr<zeus::BufferEvent> create();
|
||||||
|
public:
|
||||||
|
enum zeus::Buffer::typeMessage getType() const override {
|
||||||
|
return zeus::Buffer::typeMessage::event;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferFlow.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
// -- Factory
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ememory::SharedPtr<zeus::BufferFlow> zeus::BufferFlow::create() {
|
||||||
|
return ememory::SharedPtr<zeus::BufferFlow>(new zeus::BufferFlow);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,38 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
/*
|
||||||
|
class BufferFlow:
|
||||||
|
public Buffer {
|
||||||
|
friend class zeus::Buffer;
|
||||||
|
protected:
|
||||||
|
/ **
|
||||||
|
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferFlow::create
|
||||||
|
* /
|
||||||
|
BufferFlow() {
|
||||||
|
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::flow);
|
||||||
|
};
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
public:
|
||||||
|
/ **
|
||||||
|
* @brief Create a shared pointer on the BufferFlow
|
||||||
|
* @return Allocated Buffer.
|
||||||
|
* /
|
||||||
|
static ememory::SharedPtr<zeus::BufferFlow> create();
|
||||||
|
public:
|
||||||
|
enum zeus::Buffer::typeMessage getType() const override {
|
||||||
|
return zeus::Buffer::typeMessage::flow;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
}
|
@ -0,0 +1,175 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/BufferData.h>
|
||||||
|
#include <zeus/debug.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
#include <etk/stdTools.h>
|
||||||
|
#include <zeus/BufferParameter.h>
|
||||||
|
#include <zeus/File.h>
|
||||||
|
|
||||||
|
bool zeus::BufferParameter::writeOn(enet::WebSocket& _interface) {
|
||||||
|
uint8_t* data = nullptr;
|
||||||
|
uint32_t dataSize = 0;
|
||||||
|
uint16_t nbParameters = m_parameter.size();
|
||||||
|
size_t size = _interface.writeData((uint8_t*)&nbParameters, sizeof(uint16_t));
|
||||||
|
for (auto &it : m_parameter) {
|
||||||
|
uint32_t paramSize = it.second.size();
|
||||||
|
size = _interface.writeData((uint8_t*)¶mSize, sizeof(uint32_t));
|
||||||
|
size += _interface.writeData(&it.second[0], it.second.size() * sizeof(uint8_t));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferParameter::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
|
||||||
|
m_parameter.clear();
|
||||||
|
uint16_t nbParameters = 0;
|
||||||
|
if (_lenght < sizeof(uint16_t)) {
|
||||||
|
ZEUS_ERROR("wrong size of the buffer ==> missing parameter count");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t offset = 0;
|
||||||
|
memcpy(&nbParameters, &_buffer[offset], sizeof(uint16_t));
|
||||||
|
offset += sizeof(uint16_t);
|
||||||
|
m_parameter.resize(nbParameters, std::make_pair(-1, std::vector<uint8_t>()));
|
||||||
|
// Load all Parameters
|
||||||
|
nbParameters = 0;
|
||||||
|
while ( nbParameters < m_parameter.size()
|
||||||
|
&& offset < _lenght) {
|
||||||
|
// parameters is contituated with size + data assiciated
|
||||||
|
uint32_t sizeParam;
|
||||||
|
memcpy(&sizeParam, &_buffer[offset], sizeof(uint32_t));
|
||||||
|
offset += sizeof(uint32_t);
|
||||||
|
if (offset+sizeParam > _lenght) {
|
||||||
|
ZEUS_ERROR("Wrong parameter size : " << sizeParam << " / availlable=" << _lenght-offset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
data.resize(sizeParam);
|
||||||
|
memcpy(&data[0], &_buffer[offset], data.size() * sizeof(uint8_t));
|
||||||
|
offset += data.size() * sizeof(uint8_t);
|
||||||
|
m_parameter[nbParameters].second = data;
|
||||||
|
nbParameters++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
|
||||||
|
if (m_parameter.size() <= _id) {
|
||||||
|
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
||||||
|
return createType<void>();
|
||||||
|
}
|
||||||
|
if (m_parameter[_id].second.size() < 2) {
|
||||||
|
ZEUS_ERROR("try to get type with no ID value Type (not enouth data)");
|
||||||
|
return createType<void>();
|
||||||
|
}
|
||||||
|
uint16_t typeId = (uint16_t(m_parameter[_id].second[0]) << 8) + uint16_t(m_parameter[_id].second[1]);
|
||||||
|
if (typeId == createType<void>().getId()) { m_parameter[_id].first = 2; return createType<void>(); }
|
||||||
|
if (typeId == createType<bool>().getId()) { m_parameter[_id].first = 2; return createType<bool>(); }
|
||||||
|
if (typeId == createType<float>().getId()) { m_parameter[_id].first = 2; return createType<float>(); }
|
||||||
|
if (typeId == createType<double>().getId()) { m_parameter[_id].first = 2; return createType<double>(); }
|
||||||
|
if (typeId == createType<int64_t>().getId()) { m_parameter[_id].first = 2; return createType<int64_t>(); }
|
||||||
|
if (typeId == createType<int32_t>().getId()) { m_parameter[_id].first = 2; return createType<int32_t>(); }
|
||||||
|
if (typeId == createType<int16_t>().getId()) { m_parameter[_id].first = 2; return createType<int16_t>(); }
|
||||||
|
if (typeId == createType<int8_t>().getId()) { m_parameter[_id].first = 2; return createType<int8_t>(); }
|
||||||
|
if (typeId == createType<uint64_t>().getId()) { m_parameter[_id].first = 2; return createType<uint64_t>(); }
|
||||||
|
if (typeId == createType<uint32_t>().getId()) { m_parameter[_id].first = 2; return createType<uint32_t>(); }
|
||||||
|
if (typeId == createType<uint16_t>().getId()) { m_parameter[_id].first = 2; return createType<uint16_t>(); }
|
||||||
|
if (typeId == createType<uint8_t>().getId()) { m_parameter[_id].first = 2; return createType<uint8_t>(); }
|
||||||
|
if (typeId == createType<std::string>().getId()) { m_parameter[_id].first = 2; return createType<std::string>(); }
|
||||||
|
if (typeId == createType<std::vector<void>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<void>>(); }
|
||||||
|
if (typeId == createType<std::vector<bool>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<bool>>(); }
|
||||||
|
if (typeId == createType<std::vector<float>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<float>>(); }
|
||||||
|
if (typeId == createType<std::vector<double>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<double>>(); }
|
||||||
|
if (typeId == createType<std::vector<int64_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int64_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<int32_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int32_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<int16_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int16_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<int8_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<int8_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<uint64_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint64_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<uint32_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint32_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<uint16_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint16_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<uint8_t>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<uint8_t>>(); }
|
||||||
|
if (typeId == createType<std::vector<std::string>>().getId()) { m_parameter[_id].first = 2; return createType<std::vector<std::string>>(); }
|
||||||
|
if (typeId == createType<zeus::File>().getId()) { m_parameter[_id].first = 2; return createType<zeus::File>(); }
|
||||||
|
if (typeId == paramTypeRaw) {
|
||||||
|
m_parameter[_id].first = sizeof(uint16_t);
|
||||||
|
return zeus::ParamType("raw", paramTypeRaw);
|
||||||
|
}
|
||||||
|
if (typeId == paramTypeObject) {
|
||||||
|
std::string type = reinterpret_cast<const char*>(&m_parameter[_id].second[2]);
|
||||||
|
m_parameter[_id].first = type.size() + sizeof(uint16_t);
|
||||||
|
// TODO : Check error of \0 ==> limit at 256 char ...
|
||||||
|
return zeus::ParamType(type, paramTypeObject);
|
||||||
|
}
|
||||||
|
ZEUS_ERROR("Can not get type of parameter ... ");
|
||||||
|
return createType<void>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* zeus::BufferParameter::getParameterPointer(int32_t _id) const {
|
||||||
|
const uint8_t* out = nullptr;
|
||||||
|
if (m_parameter.size() <= _id) {
|
||||||
|
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
if (m_parameter[_id].first <= -1) {
|
||||||
|
getParameterType(_id); // this function initialize this parameter if needed ...
|
||||||
|
}
|
||||||
|
out = reinterpret_cast<const uint8_t*>(&m_parameter[_id].second[m_parameter[_id].first]);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t zeus::BufferParameter::getParameterSize(int32_t _id) const {
|
||||||
|
int32_t out = 0;
|
||||||
|
if (m_parameter.size() <= _id) {
|
||||||
|
ZEUS_ERROR("out of range Id for parameter ... " << _id << " have " << m_parameter.size());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (m_parameter[_id].first <= -1) {
|
||||||
|
getParameterType(_id); // this function initialize this parameter if needed ...
|
||||||
|
}
|
||||||
|
return m_parameter[_id].second.size() - m_parameter[_id].first;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t zeus::BufferParameter::getNumberParameter() const {
|
||||||
|
return m_parameter.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string zeus::BufferParameter::simpleStringParam(uint32_t _id) const {
|
||||||
|
zeus::ParamType paramType = getParameterType(_id);
|
||||||
|
if (paramType.isVector() == false) {
|
||||||
|
if (paramType.isNumber() == true) {
|
||||||
|
return etk::to_string(getParameter<int64_t>(_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (paramType == createType<bool>()) {
|
||||||
|
return etk::to_string(getParameter<bool>(_id));
|
||||||
|
}
|
||||||
|
if (paramType == createType<std::string>()) {
|
||||||
|
return "{" + getParameter<std::string>(_id) + "}";
|
||||||
|
}
|
||||||
|
if (paramType == createType<std::vector<std::string>>()) {
|
||||||
|
return "[" + etk::to_string(getParameter<std::vector<std::string>>(_id)) + "]";
|
||||||
|
}
|
||||||
|
return paramType.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
void zeus::BufferParameter::parameterAppendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj) {
|
||||||
|
// At this point we just add data at the parameter value:
|
||||||
|
uint16_t parameterID = _obj->getParameterId();
|
||||||
|
|
||||||
|
if (_obj->getData().size() == 0) {
|
||||||
|
// no data (normal case)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// now, we will add datas:
|
||||||
|
if (parameterID >= m_parameter.size()) {
|
||||||
|
ZEUS_ERROR("Try to add data on an unexisting parameter...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int32_t offset = m_parameter[parameterID].second.size();
|
||||||
|
m_parameter[parameterID].second.resize(offset + _obj->getData().size());
|
||||||
|
memcpy(&m_parameter[parameterID].second[offset], &_obj->getData()[0], _obj->getData().size());
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <etk/types.h>
|
||||||
|
#include <enet/WebSocket.h>
|
||||||
|
#include <zeus/ParamType.h>
|
||||||
|
|
||||||
|
namespace zeus {
|
||||||
|
|
||||||
|
class BufferParameter:
|
||||||
|
public Buffer {
|
||||||
|
protected:
|
||||||
|
mutable std::vector<std::pair<int32_t,std::vector<uint8_t>>> m_parameter; //!< list of the parameter (offset of start data and buffer of data (subprotocol...)
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Template to get a parameter with a specific type
|
||||||
|
* @param[in] _id Number of the parameter
|
||||||
|
* @return Converted type of the parameter (or empty value)
|
||||||
|
*/
|
||||||
|
template<class ZEUS_TYPE_DATA>
|
||||||
|
ZEUS_TYPE_DATA getParameter(int32_t _id) const;
|
||||||
|
/**
|
||||||
|
* @brief Get the type of a parameter.
|
||||||
|
* @param[in] _id Number of the parameter
|
||||||
|
* @return type of the parameter
|
||||||
|
*/
|
||||||
|
zeus::ParamType getParameterType(int32_t _id) const;
|
||||||
|
/**
|
||||||
|
* @brief Get the start pointer of the parameter
|
||||||
|
* @param[in] _id Number of the parameter
|
||||||
|
* @return pointer of the parameter or nullptr
|
||||||
|
*/
|
||||||
|
const uint8_t* getParameterPointer(int32_t _id) const;
|
||||||
|
/**
|
||||||
|
* @brief Get the size of the parameter availlable in the parameter pointer
|
||||||
|
* @param[in] _id Number of the parameter
|
||||||
|
* @return size of the parameter buffer
|
||||||
|
*/
|
||||||
|
uint32_t getParameterSize(int32_t _id) const;
|
||||||
|
/**
|
||||||
|
* @brief Get the number of parameter availlable
|
||||||
|
* @return number of parameter
|
||||||
|
*/
|
||||||
|
uint16_t getNumberParameter() const;
|
||||||
|
/**
|
||||||
|
* @brief Add an empty vector with no type
|
||||||
|
*/
|
||||||
|
void addParameterEmptyVector();
|
||||||
|
/**
|
||||||
|
* @brief Add parameter (or not.. this is the end of an auto resursive add parameter)
|
||||||
|
*/
|
||||||
|
void addParameter();
|
||||||
|
/**
|
||||||
|
* @brief Convert the parameter in a simple human readable string
|
||||||
|
* @param[in] _id Number of the parameter
|
||||||
|
* @return readable string
|
||||||
|
*/
|
||||||
|
std::string simpleStringParam(uint32_t _id) const;
|
||||||
|
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
|
||||||
|
bool writeOn(enet::WebSocket& _interface) override;
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief Add a parameter at a specific position
|
||||||
|
* @param[in] _paramId Id of the parameter (needed for the multiple packet sending)
|
||||||
|
* @param[in] _value Value to add in parameter
|
||||||
|
*/
|
||||||
|
template<class ZEUS_TYPE_DATA>
|
||||||
|
void addParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
|
||||||
|
public:
|
||||||
|
template<class ZEUS_TYPE_DATA>
|
||||||
|
void addParameter(const ZEUS_TYPE_DATA& _value) {
|
||||||
|
addParameter(m_parameter.size(), _value);
|
||||||
|
}
|
||||||
|
void parameterAppendBufferData(const ememory::SharedPtr<zeus::BufferData>& _obj);
|
||||||
|
};
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
#include <zeus/Buffer.h>
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/BufferData.h>
|
||||||
#include <zeus/debug.h>
|
#include <zeus/debug.h>
|
||||||
#include <zeus/ParamType.h>
|
#include <zeus/ParamType.h>
|
||||||
#include <etk/stdTools.h>
|
#include <etk/stdTools.h>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* @license APACHE v2.0 (see license file)
|
* @license APACHE v2.0 (see license file)
|
||||||
*/
|
*/
|
||||||
#include <zeus/Future.h>
|
#include <zeus/Future.h>
|
||||||
|
#include <zeus/BufferAnswer.h>
|
||||||
#include <zeus/debug.h>
|
#include <zeus/debug.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <zeus/File.h>
|
#include <zeus/File.h>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* @license APACHE v2.0 (see license file)
|
* @license APACHE v2.0 (see license file)
|
||||||
*/
|
*/
|
||||||
#include <zeus/FutureBase.h>
|
#include <zeus/FutureBase.h>
|
||||||
|
#include <zeus/BufferAnswer.h>
|
||||||
#include <zeus/debug.h>
|
#include <zeus/debug.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <zeus/debug.h>
|
#include <zeus/debug.h>
|
||||||
#include <ethread/tools.h>
|
#include <ethread/tools.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <zeus/BufferData.h>
|
||||||
|
|
||||||
|
|
||||||
ememory::SharedPtr<zeus::BufferCall> zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) {
|
ememory::SharedPtr<zeus::BufferCall> zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <zeus/Buffer.h>
|
#include <zeus/Buffer.h>
|
||||||
|
#include <zeus/BufferAnswer.h>
|
||||||
#include <enet/WebSocket.h>
|
#include <enet/WebSocket.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user