From 8b21709a014aaa56f221c339d7011be6473b41d8 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 4 Jul 2016 21:13:20 +0200 Subject: [PATCH] [DEV] correct rework of buffer interface to manage more type of messages ... --- test/client/appl/main.cpp | 10 +- tools/system-gateway/appl/ClientInterface.cpp | 21 +- .../system-gateway/appl/ServiceInterface.cpp | 7 +- zeus/AbstractFunction.h | 2 +- zeus/AbstractFunctionTypeClass.h | 6 +- zeus/AbstractFunctionTypeDirect.h | 6 +- zeus/Buffer.cpp | 628 +++++++++++------- zeus/Buffer.h | 341 +++++++--- zeus/Buffer_addParameter.cpp | 64 +- zeus/Buffer_getParameter.cpp | 200 +++--- zeus/Client.cpp | 2 +- zeus/Client.h | 4 +- zeus/Future.cpp | 50 +- zeus/FutureBase.cpp | 22 +- zeus/Service.cpp | 40 +- zeus/ServiceRemote.h | 4 +- zeus/WebServer.cpp | 26 +- zeus/WebServer.h | 51 +- 18 files changed, 885 insertions(+), 599 deletions(-) diff --git a/test/client/appl/main.cpp b/test/client/appl/main.cpp index c841a1d..8086006 100644 --- a/test/client/appl/main.cpp +++ b/test/client/appl/main.cpp @@ -37,20 +37,20 @@ int main(int _argc, const char *_argv[]) { APPL_INFO("=================================="); if (false) { - bool ret = client1.connect("test1~atria-soft.com", "clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968"); + bool ret = client1.connect("test1~atria-soft.com", "clientTest1~atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968"); if (ret == false) { - APPL_ERROR(" ==> NOT Connected with 'clientTest1#atria-soft.com'"); + APPL_ERROR(" ==> NOT Connected to 'test1~atria-soft.com' with 'clientTest1~atria-soft.com'"); return -1; } else { - APPL_INFO(" ==> Connected with 'clientTest1#atria-soft.com'"); + APPL_INFO(" ==> Connected with 'clientTest1~atria-soft.com'"); } } else if (true) { bool ret = client1.connect("test1~atria-soft.com", "coucou"); if (ret == false) { - APPL_ERROR(" ==> NOT Authentify with 'test1#atria-soft.com'"); + APPL_ERROR(" ==> NOT Authentify with 'test1~atria-soft.com'"); return -1; } else { - APPL_INFO(" ==> Authentify with 'test1#atria-soft.com'"); + APPL_INFO(" ==> Authentify with 'test1~atria-soft.com'"); } } else { bool ret = client1.connect("test1~atria-soft.com"); diff --git a/tools/system-gateway/appl/ClientInterface.cpp b/tools/system-gateway/appl/ClientInterface.cpp index f66ec9e..24b0d48 100644 --- a/tools/system-gateway/appl/ClientInterface.cpp +++ b/tools/system-gateway/appl/ClientInterface.cpp @@ -109,7 +109,8 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& answerProtocolError(transactionId, "missing parameter: 'call' / wrong type 'call'"); return; } - std::string callFunction = _value->getCall(); + ememory::SharedPtr callObj = std::static_pointer_cast(_value); + std::string callFunction = callObj->getCall(); switch (m_state) { case appl::ClientInterface::state::disconnect: case appl::ClientInterface::state::unconnect: @@ -125,7 +126,7 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& return; } if (callFunction == "connectToUser") { - m_userConnectionName = _value->getParameter(0); + m_userConnectionName = callObj->getParameter(0); if (m_userConnectionName == "") { answerProtocolError(transactionId, "Call connectToUser with no parameter 'user'"); } else { @@ -158,8 +159,8 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& return; } if (callFunction == "identify") { - std::string clientName = _value->getParameter(0); - std::string clientTocken = _value->getParameter(1); + std::string clientName = callObj->getParameter(0); + std::string clientTocken = callObj->getParameter(1); if (m_userService == nullptr) { answerProtocolError(transactionId, "gateWay internal error 3"); return; @@ -180,7 +181,7 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& m_clientName = clientName; } if (callFunction == "auth") { - std::string password = _value->getParameter(0); + std::string password = callObj->getParameter(0); zeus::Future fut = m_userService->m_interfaceClient.callClient(m_uid2, "checkAuth", password); fut.wait(); // TODO: Set timeout ... if (fut.hasError() == true) { @@ -235,7 +236,7 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& break; case appl::ClientInterface::state::clientIdentify: { - uint32_t serviceId = _value->getServiceId(); + uint32_t serviceId = callObj->getServiceId(); if (serviceId == 0) { // This is 2 default service for the cient interface that manage the authorisation of view: if (callFunction == "getServiceCount") { @@ -249,7 +250,7 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& } if (callFunction == "link") { // first param: - std::string serviceName = _value->getParameter(0); + std::string serviceName = callObj->getParameter(0); // Check if service already link: auto it = m_listConnectedService.begin(); while (it != m_listConnectedService.end()) { @@ -290,7 +291,7 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& } if (callFunction == "unlink") { // first param: the service we want to unconnect ... - int64_t localServiceID = _value->getParameter(0)-1; + int64_t localServiceID = callObj->getParameter(0)-1; // Check if service already link: if (localServiceID >= m_listConnectedService.size()) { m_interfaceClient.answerError(transactionId, "NOT-CONNECTED-SERVICE"); @@ -332,10 +333,10 @@ void appl::ClientInterface::onClientData(const ememory::SharedPtr& return true; } ZEUS_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId); - ZEUS_DEBUG(" msg=" << *tmpp); + ZEUS_DEBUG(" msg=" << tmpp); tmpp->setTransactionId(transactionId); tmpp->setServiceId(serviceId+1); - ZEUS_DEBUG("transmit=" << *tmpp); + ZEUS_DEBUG("transmit=" << tmpp); m_interfaceClient.writeBinary(tmpp); // multiple send element ... return tmpp->getPartFinish(); diff --git a/tools/system-gateway/appl/ServiceInterface.cpp b/tools/system-gateway/appl/ServiceInterface.cpp index fc06091..4c21a63 100644 --- a/tools/system-gateway/appl/ServiceInterface.cpp +++ b/tools/system-gateway/appl/ServiceInterface.cpp @@ -75,14 +75,15 @@ void appl::ServiceInterface::onServiceData(const ememory::SharedPtrgetType() == zeus::Buffer::typeMessage::call) { - std::string callFunction = _value->getCall(); + ememory::SharedPtr callObj = std::static_pointer_cast(_value); + std::string callFunction = callObj->getCall(); if (callFunction == "connect-service") { if (m_name != "") { - ZEUS_WARNING("Service interface ==> try change the servie name after init: '" << _value->getParameter(0)); + ZEUS_WARNING("Service interface ==> try change the servie name after init: '" << callObj->getParameter(0)); m_interfaceClient.answerValue(transactionId, false); return; } - m_name = _value->getParameter(0); + m_name = callObj->getParameter(0); m_interfaceClient.setInterfaceName("srv-" + m_name); m_interfaceClient.answerValue(transactionId, true); return; diff --git a/zeus/AbstractFunction.h b/zeus/AbstractFunction.h index 4367b1c..e0f02b1 100644 --- a/zeus/AbstractFunction.h +++ b/zeus/AbstractFunction.h @@ -124,7 +124,7 @@ namespace zeus { * @param[in] _class Pointer on the object that might be call (note: brut cast) */ virtual void execute(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, void* _class=nullptr) = 0; }; } diff --git a/zeus/AbstractFunctionTypeClass.h b/zeus/AbstractFunctionTypeClass.h index c05cda7..7288264 100644 --- a/zeus/AbstractFunctionTypeClass.h +++ b/zeus/AbstractFunctionTypeClass.h @@ -21,7 +21,7 @@ namespace zeus { */ template void executeClassCall(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, ZEUS_CLASS_TYPE* _pointer, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) { if (_obj == nullptr) { @@ -54,7 +54,7 @@ namespace zeus { */ template void executeClassCall(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, ZEUS_CLASS_TYPE* _pointer, void (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) { if (_obj == nullptr) { @@ -108,7 +108,7 @@ namespace zeus { return out; } void execute(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, void* _class) override { if (_obj == nullptr) { return; diff --git a/zeus/AbstractFunctionTypeDirect.h b/zeus/AbstractFunctionTypeDirect.h index 2430283..06c037f 100644 --- a/zeus/AbstractFunctionTypeDirect.h +++ b/zeus/AbstractFunctionTypeDirect.h @@ -17,7 +17,7 @@ namespace zeus { */ template void executeCall(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, ZEUS_RETURN (*_func)(ZEUS_TYPES...)) { if (_obj == nullptr) { return; @@ -46,7 +46,7 @@ namespace zeus { */ template void executeCall(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, void (*_func)(ZEUS_TYPES...)) { if (_obj == nullptr) { return; @@ -99,7 +99,7 @@ namespace zeus { return out; } void execute(const ememory::SharedPtr& _interfaceClient, - const ememory::SharedPtr& _obj, + const ememory::SharedPtr& _obj, void* _class) override { if (_obj == nullptr) { return; diff --git a/zeus/Buffer.cpp b/zeus/Buffer.cpp index c2633da..6998556 100644 --- a/zeus/Buffer.cpp +++ b/zeus/Buffer.cpp @@ -53,11 +53,11 @@ zeus::Buffer::Buffer() { clear(); } -ememory::SharedPtr zeus::Buffer::create() { - return ememory::SharedPtr(new zeus::Buffer); +void zeus::Buffer::appendBufferData(const ememory::SharedPtr& _obj) { + ZEUS_ERROR("Can not append datas ... Not managed"); } -void zeus::Buffer::appendBufferData(const ememory::SharedPtr& _obj) { +void zeus::Buffer::appendBuffer(const ememory::SharedPtr& _obj) { if (_obj == nullptr) { return; } @@ -69,161 +69,99 @@ void zeus::Buffer::appendBufferData(const ememory::SharedPtr& _obj return; } setPartFinish(_obj->getPartFinish()); - if (_obj->m_parameter.size() <= 1) { - // normal end frame with no data ==> no problem ... - return; - } - // At this point we just add data at the parameter value: - //It contain 2 things : - // - param 0 : parameter ID (int16_t) - // - param 1 : Raw data (local direct acces ...) - uint16_t parameterID = _obj->internalGetParameter(0); - - zeus::ParamType type = _obj->internalGetParameterType(1); - const uint8_t* pointer = _obj->internalGetParameterPointer(1); - uint32_t dataSize = _obj->internalGetParameterSize(1); - if ( type.getId() != zeus::paramTypeRaw - || pointer == nullptr) { - ZEUS_ERROR("Can not get parameter Raw ==> stop add"); - return; - } - if (dataSize == 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 + dataSize); - memcpy(&m_parameter[parameterID].second[offset], pointer, dataSize); + appendBufferData(std::static_pointer_cast(_obj)); } - -void zeus::Buffer::internalComposeWith(const uint8_t* _buffer, uint32_t _lenght) { - clear(); - if (_lenght < sizeof(headerBin)) { - ZEUS_ERROR("wrong size of the buffer"); - return; - } - uint32_t offset = 0; - memcpy(reinterpret_cast(&m_header), &_buffer[offset], sizeof(headerBin)); - offset += sizeof(headerBin); - m_parameter.clear(); - m_parameter.resize(m_header.numberOfParameter, std::make_pair(-1, std::vector())); - // Load all Parameters - int32_t nbParameters = 0; - while ( nbParameters < m_header.numberOfParameter - && 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 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++; - } +size_t zeus::Buffer::getSize() { + return sizeof(headerBin); } bool zeus::Buffer::writeOn(enet::WebSocket& _interface) { - m_header.numberOfParameter = m_parameter.size(); - uint64_t size = sizeof(headerBin); - for (auto &it : m_parameter) { - size += sizeof(uint32_t); // parameter size - size += it.second.size(); - } + uint64_t size = getSize(); if (_interface.writeHeader(size, false) == false) { return false; } - uint8_t* data = nullptr; - uint32_t dataSize = 0; - m_header.numberOfParameter = m_parameter.size(); - size = _interface.writeData((uint8_t*)&m_header, sizeof(headerBin)); - 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::Buffer::composeWith(const std::vector& _buffer) { - internalComposeWith(&_buffer[0], _buffer.size()); + +void zeus::Buffer::composeWith(const uint8_t* _buffer, uint32_t _lenght) { + // impossible case } void zeus::Buffer::clear() { - m_parameter.clear(); m_header.transactionID = 1; m_header.clientID = 0; - m_header.partID = 0x8000; - m_header.typeMessage = 1; - m_header.numberOfParameter = 1; + m_header.flags = ZEUS_BUFFER_FLAG_FINISH; } -std::ostream& zeus::operator <<(std::ostream& _os, const zeus::Buffer& _obj) { +std::ostream& zeus::operator <<(std::ostream& _os, zeus::Buffer* _obj) { _os << "zeus::Buffer: "; - //out += " v=" + etk::to_string(m_header.versionProtocol); // se it in the websocket - _os << " id=" << etk::to_string(_obj.getTransactionId()); - _os << " cId=" << etk::to_string(_obj.getClientId()); - if ( _obj.getPartFinish() == false - || _obj.getPartId() != 0) { - _os << " part=" << etk::to_string(_obj.getPartId()); - if (_obj.getPartFinish() == true) { - _os << "/finish"; - } + if (_obj == nullptr) { + _os << "nullptr"; + } else { + _obj->generateDisplay(_os); } - enum zeus::Buffer::typeMessage type = _obj.getType(); + return _os; +} +void zeus::Buffer::generateDisplay(std::ostream& _os) const { + //out += " v=" + etk::to_string(m_header.versionProtocol); // se it in the websocket + _os << " id=" << etk::to_string(getTransactionId()); + _os << " cId=" << etk::to_string(getClientId()); + if (getPartFinish() == true) { + _os << "finish"; + } + enum zeus::Buffer::typeMessage type = getType(); switch (type) { case zeus::Buffer::typeMessage::unknow: _os << " -UNKNOW-"; break; case zeus::Buffer::typeMessage::call: - _os << " nbParam=" + etk::to_string(_obj.getNumberParameter()); - _os << " -CALL-:'" + _obj.getCall() + "'"; + _os << " -CALL-"; break; case zeus::Buffer::typeMessage::answer: - _os << " -ANSWER-:"; - if (_obj.m_parameter.size() == 1) { - _os << "Value:" + _obj.simpleStringParam(0); - } else if (_obj.m_parameter.size() == 2) { - _os << "Error"; - _os << "Error:" + _obj.simpleStringParam(0); - } else if (_obj.m_parameter.size() == 3) { - _os << "Value:" + _obj.simpleStringParam(0); - _os << "+Error:" + _obj.simpleStringParam(1); - } else { - _os << "???"; - } + _os << " -ANSWER-"; break; case zeus::Buffer::typeMessage::event: _os << " -EVENT-"; - break; case zeus::Buffer::typeMessage::data: _os << " -DATA-"; - break; } - if (_obj.getNumberParameter() != 0) { +} + +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<_obj.getNumberParameter(); ++iii) { + for (int32_t iii=0; iii 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())); + // 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 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(); @@ -335,139 +306,308 @@ zeus::ParamType zeus::Buffer::internalGetParameterType(int32_t _id) const { ZEUS_ERROR("Can not get type of parameter ... "); return createType(); } -zeus::ParamType zeus::Buffer::getParameterType(int32_t _id) const { - return internalGetParameterType(_id + 1); -} -const uint8_t* zeus::Buffer::internalGetParameterPointer(int32_t _id) const { +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) { - internalGetParameterType(_id); // this function initialize this parameter if needed ... + getParameterType(_id); // this function initialize this parameter if needed ... } out = reinterpret_cast(&m_parameter[_id].second[m_parameter[_id].first]); return out; } -const uint8_t* zeus::Buffer::getParameterPointer(int32_t _id) const { - return internalGetParameterPointer(_id + 1); -} - -uint32_t zeus::Buffer::internalGetParameterSize(int32_t _id) const { +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) { - internalGetParameterType(_id); // this function initialize this parameter if needed ... + getParameterType(_id); // this function initialize this parameter if needed ... } return m_parameter[_id].second.size() - m_parameter[_id].first; } -void zeus::Buffer::addData(uint16_t _parameterId, void* _data, uint32_t _size) { - m_parameter.clear(); - addParameter(_parameterId); - std::vector data; - // set parameter type in case of wrong interpretation - zeus::addTypeRaw(data); - int32_t offset = data.size(); - data.resize(offset + _size); - memcpy(&data[offset], _data, _size); - m_parameter.push_back(std::make_pair(2,data)); +uint16_t zeus::BufferParameter::getNumberParameter() const { + return m_parameter.size(); } -uint32_t zeus::Buffer::getParameterSize(int32_t _id) const { - return internalGetParameterSize(_id + 1); -} - - -void zeus::Buffer::addError(const std::string& _value, const std::string& _comment) { - addParameter(_value); - addParameter(_comment); -} - -std::string zeus::Buffer::getCall() const { - std::string out; - switch(getType()) { - case zeus::Buffer::typeMessage::call: - return internalGetParameter(0); - break; - case zeus::Buffer::typeMessage::answer: - ZEUS_WARNING("get 'call' with an input type: 'answer'"); - break; - default: - ZEUS_WARNING("get 'call' with an input type: '" << getType() << "'"); - break; - } - return ""; -} - -void zeus::Buffer::setCall(std::string _value) { - if (m_parameter.size() != 0) { - ZEUS_ERROR("Clear Buffer of parameter ==> set the call type in first ..."); - m_parameter.clear(); - } - addParameter(_value); -} - - -bool zeus::Buffer::hasError() { - if (getType() != zeus::Buffer::typeMessage::answer) { - return false; - } - if (m_parameter.size() == 2) { - return true; - } else if (m_parameter.size() == 3) { - return true; - } - return false; -} - -std::string zeus::Buffer::getError() { - if (getType() != zeus::Buffer::typeMessage::answer) { - return ""; - } - if (m_parameter.size() == 2) { - return getParameter(0); - } else if (m_parameter.size() == 3) { - return getParameter(1); - } - return ""; -} - -std::string zeus::Buffer::getErrorHelp() { - if (getType() != zeus::Buffer::typeMessage::answer) { - return ""; - } - if (m_parameter.size() == 2) { - return getParameter(1); - } else if (m_parameter.size() == 3) { - return getParameter(2); - } - return ""; -} - - -std::string zeus::Buffer::simpleStringParam(uint32_t _id) const { - zeus::ParamType paramType = internalGetParameterType(_id); +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(internalGetParameter(_id)); + return etk::to_string(getParameter(_id)); } } if (paramType == createType()) { - return etk::to_string(internalGetParameter(_id)); + return etk::to_string(getParameter(_id)); } if (paramType == createType()) { - return "{" + internalGetParameter(_id) + "}"; + return "{" + getParameter(_id) + "}"; } if (paramType == createType>()) { - return "[" + etk::to_string(internalGetParameter>(_id)) + "]"; + return "[" + etk::to_string(getParameter>(_id)) + "]"; } return paramType.getName(); } +void zeus::BufferParameter::parameterAppendBufferData(const ememory::SharedPtr& _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; +} + +size_t zeus::BufferCall::getSize() { + // name + \0 + parameters ... + return m_callName.size()+1 + parameterGetSize(); +} + +bool zeus::BufferCall::writeOn(enet::WebSocket& _interface) { + _interface.writeData((uint8_t*)m_callName.c_str(), m_callName.size() + 1); + return parameterWriteOn(_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 + && _buffer[pos] != '\0') { + m_callName += _buffer[pos]; + pos++; + } + // parse parameters: + parameterComposeWith(&_buffer[pos], _lenght-pos); +} + +void zeus::BufferCall::appendBufferData(const ememory::SharedPtr& _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; +} + +size_t zeus::BufferAnswer::getSize() { + // name + \0 + parameters ... + size_t size = m_errorType.size()+1 + parameterGetSize(); + if (m_errorType.size() != 0) { + size += m_errorHelp.size() + 1; + } + return size; +} + +bool zeus::BufferAnswer::writeOn(enet::WebSocket& _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 parameterWriteOn(_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++; + } + if (m_errorType.size() != 0) { + while( pos < _lenght + && _buffer[pos] != '\0') { + m_errorHelp += _buffer[pos]; + pos++; + } + } + // parse parameters: + parameterComposeWith(&_buffer[pos], _lenght-pos); +} + +void zeus::BufferAnswer::appendBufferData(const ememory::SharedPtr& _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; +} + +size_t zeus::BufferData::getSize() { + // name + \0 + parameters ... + return sizeof(uint32_t) + sizeof(uint16_t) + m_data.size(); +} + +bool zeus::BufferData::writeOn(enet::WebSocket& _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(&m_partId), &_buffer[pos], sizeof(uint32_t)); + pos += sizeof(uint32_t); + memcpy(reinterpret_cast(&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::Buffer::create() { + return ememory::SharedPtr(new zeus::Buffer); +} + +ememory::SharedPtr zeus::Buffer::create(const std::vector& _buffer) { + headerBin header; + if (_buffer.size() < sizeof(headerBin)) { + ZEUS_ERROR("wrong size of the buffer"); + return nullptr; + } + memcpy(reinterpret_cast(&header), &_buffer[0], sizeof(headerBin)); + enum zeus::Buffer::typeMessage type = getTypeType(uint16_t(header.flags & 0x07)); + switch (type) { + case zeus::Buffer::typeMessage::unknow: + return nullptr; + case zeus::Buffer::typeMessage::call: { + ememory::SharedPtr value = zeus::BufferCall::create(); + if (value == nullptr) { + return nullptr; + } + value->setTransactionId(header.transactionID); + value->setClientId(header.clientID); + value->setClientId((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); + value->composeWith(&_buffer[sizeof(headerBin)], + _buffer.size() - sizeof(headerBin)); + return value; + } + break; + case zeus::Buffer::typeMessage::answer: { + ememory::SharedPtr value = zeus::BufferAnswer::create(); + if (value == nullptr) { + return nullptr; + } + value->setTransactionId(header.transactionID); + value->setClientId(header.clientID); + value->setClientId((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); + value->composeWith(&_buffer[sizeof(headerBin)], + _buffer.size() - sizeof(headerBin)); + return value; + } + break; + case zeus::Buffer::typeMessage::data: { + ememory::SharedPtr value = zeus::BufferData::create(); + if (value == nullptr) { + return nullptr; + } + value->setTransactionId(header.transactionID); + value->setClientId(header.clientID); + value->setClientId((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0); + value->composeWith(&_buffer[sizeof(headerBin)], + _buffer.size() - sizeof(headerBin)); + return value; + } + break; + case zeus::Buffer::typeMessage::event: + + break; + } + return nullptr; +} + +ememory::SharedPtr zeus::BufferCall::create() { + return ememory::SharedPtr(new zeus::BufferCall); +} + +ememory::SharedPtr zeus::BufferAnswer::create() { + return ememory::SharedPtr(new zeus::BufferAnswer); +} + +ememory::SharedPtr zeus::BufferData::create() { + return ememory::SharedPtr(new zeus::BufferData); +} +/* +ememory::SharedPtr zeus::BufferEvent::create() { + return ememory::SharedPtr(new zeus::BufferEvent); +} + +ememory::SharedPtr zeus::BufferFlow::create() { + return ememory::SharedPtr(new zeus::BufferFlow); +} +*/ + diff --git a/zeus/Buffer.h b/zeus/Buffer.h index 6b7fa37..afd3164 100644 --- a/zeus/Buffer.h +++ b/zeus/Buffer.h @@ -17,8 +17,10 @@ namespace zeus { namespace zeus { + class BufferData; //U32 message lenght #pragma pack(push,1) + /* struct headerBin { //uint16_t versionProtocol; // protocol Version (might be 1) uint32_t transactionID; @@ -27,6 +29,16 @@ namespace zeus { uint16_t typeMessage; //TypeMessgae (1:call, 2:Answer, 4:event) uint16_t numberOfParameter; }; + */ + struct headerBin { + //uint16_t versionProtocol; // protocol Version (might be 1) + uint32_t transactionID; + uint32_t clientID; // same as sevice ID + uint8_t flags; // List of flags & type message: + // - 0-2: Type of the message + // - 3-6: Reserved + // - 7: message finished + }; #pragma pack(pop) /* // not needed ==> can be deduced with parameter number ... U16 Offset String call Name (start of the buffer) end with \0 @@ -89,25 +101,36 @@ namespace zeus { - vector:string - obj:file */ + #define ZEUS_BUFFER_FLAG_FINISH (0x80) + #define ZEUS_BUFFER_FLAG_TYPE_MESSAGE (0x07) /** * @brief Protocol buffer to transmit datas */ class Buffer { - friend std::ostream& operator<<(std::ostream&, const zeus::Buffer&); + friend std::ostream& operator<<(std::ostream&, zeus::Buffer*); protected: /** * @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Buffer::create */ Buffer(); public: + /** + * Virtualize the buffer class + */ + virtual ~Buffer() = default; /** * @brief Create a shared pointer on the buffer * @return Allocated Buffer. */ static ememory::SharedPtr create(); + /** + * @brief Create a shared pointer on the buffer + * @param[in] _buffer Buffer on the data + * @return Allocated Buffer. + */ + static ememory::SharedPtr create(const std::vector& _buffer); protected: headerBin m_header; //!< header of the protocol - mutable std::vector>> m_parameter; //!< list of the parameter (offset of start data and buffer of data (subprotocol...) std::vector m_multipleSend; //!< Async element to send data on the webinterface when too big ... public: /** @@ -128,20 +151,16 @@ namespace zeus { * @brief When multiple frame buffer, they need to concatenate the data... call this function with the new data to append it ... * @param[in] _obj Buffer to add */ - void appendBufferData(const ememory::SharedPtr& _obj); + void appendBuffer(const ememory::SharedPtr& _obj); + virtual void appendBufferData(const ememory::SharedPtr& _obj); protected: /** * @brief When receive new data form websocket, it might be added by this input (set all the frame ...) * @param[in] _buffer Pointer on the data to add. * @param[in] _lenght number of octet to add. */ - void internalComposeWith(const uint8_t* _buffer, uint32_t _lenght); + virtual void composeWith(const uint8_t* _buffer, uint32_t _lenght); public: - /** - * @brief When receive new data form websocket, it might be added by this input. - * @param[in] _buffer Buffer on the data - */ - void composeWith(const std::vector& _buffer); /** * @brief Chear the buffer */ @@ -180,16 +199,6 @@ namespace zeus { void setServiceId(uint32_t _value) { setClientId(_value); } - /** - * @brief Get the part Id of the buffer - * @return Part Identifier - */ - uint16_t getPartId() const; - /** - * @brief Set the part Id of the buffer - * @param[in] _value New Part ID - */ - void setPartId(uint16_t _value); /** * @brief Check if it is the last packet of the buffer * @return If "true" The Buffer wait no more datas @@ -214,63 +223,29 @@ namespace zeus { * @brief Get the type of the buffer * @return the current type of the buffer */ - enum typeMessage getType() const; + virtual enum typeMessage getType() const; + public: /** - * @brief Set the type of the buffer - * @param[in] _value New type of the buffer + * @brief Write the buffer on a specific interface + * @param[in] _interface socket to write data + * @return true of no error appear */ - void setType(enum typeMessage _value); + virtual bool writeOn(enet::WebSocket& _interface); + virtual size_t getSize(); + virtual void generateDisplay(std::ostream& _os) const ; + }; + class BufferParameter: + public Buffer { protected: + mutable std::vector>> 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 - ZEUS_TYPE_DATA internalGetParameter(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 internalGetParameterType(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* internalGetParameterPointer(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 internalGetParameterSize(int32_t _id) const; - /** - * @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; - // =============================================== - // == Section call - // =============================================== - public: - /** - * @brief get the call value of the buffer - * @return string of the function to call - */ - std::string getCall() const; - /** - * @brief Set the call value of the buffer - * @param[in] _value Function to call - */ - void setCall(std::string _value); - /** - * @brief Get the number of parameter availlable - * @return number of parameter - */ - uint16_t getNumberParameter() const; + ZEUS_TYPE_DATA getParameter(int32_t _id) const; /** * @brief Get the type of a parameter. * @param[in] _id Number of the parameter @@ -289,24 +264,11 @@ namespace zeus { * @return size of the parameter buffer */ uint32_t getParameterSize(int32_t _id) const; - - 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 + * @brief Get the number of parameter availlable + * @return number of parameter */ - template - void internalAddParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value); - public: - /** - * @brief Add a parameter on the call function - * @param[in] _value Value to add in parameter - */ - template - void addParameter(const ZEUS_TYPE_DATA& _value) { - internalAddParameter(m_parameter.size(), _value); - } + uint16_t getNumberParameter() const; /** * @brief Add an empty vector with no type */ @@ -316,18 +278,101 @@ namespace zeus { */ void addParameter(); /** - * @brief Template to get a parameter with a specific type + * @brief Convert the parameter in a simple human readable string * @param[in] _id Number of the parameter - * @return Converted type of the parameter (or empty value) + * @return readable string + */ + std::string simpleStringParam(uint32_t _id) const; + /** + * @brief When receive new data form websocket, it might be added by this input (set all the frame ...) + * @param[in] _buffer Pointer on the data to add. + * @param[in] _lenght number of octet to add. + */ + void parameterComposeWith(const uint8_t* _buffer, uint32_t _lenght); + bool parameterWriteOn(enet::WebSocket& _interface); + size_t parameterGetSize(); + 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 - ZEUS_TYPE_DATA getParameter(int32_t _id) const { - return internalGetParameter(_id+1); - } - // =============================================== - // == Section Answer - // =============================================== + void addParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value); public: + template + void addParameter(const ZEUS_TYPE_DATA& _value) { + addParameter(m_parameter.size(), _value); + } + void parameterAppendBufferData(const ememory::SharedPtr& _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& _obj) override; + bool writeOn(enet::WebSocket& _interface) override; + size_t getSize() override; + void generateDisplay(std::ostream& _os) const override; + public: + /** + * @brief Create a shared pointer on the BufferCall + * @return Allocated Buffer. + */ + static ememory::SharedPtr 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& _obj) override; + bool writeOn(enet::WebSocket& _interface) override; + size_t getSize() override; + void generateDisplay(std::ostream& _os) const override; + public: + /** + * @brief Create a shared pointer on the BufferAnswer + * @return Allocated Buffer. + */ + static ememory::SharedPtr 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 @@ -343,7 +388,7 @@ namespace zeus { // TODO : Do it better check error ... ==> can be good ... template ZEUS_TYPE_DATA getAnswer() const { - return internalGetParameter(0); + return getParameter(0); } /** * @brief Ann an error on the message answer @@ -360,14 +405,60 @@ namespace zeus { * @brief get the error value (if exist) * @return string of the error */ - std::string getError(); + const std::string& getError(); /** * @brief get the error help (if exist) * @return string of the error help */ - std::string getErrorHelp(); - + const std::string& getErrorHelp(); + }; + class BufferData: + public Buffer { + friend class zeus::Buffer; + protected: + uint32_t m_partId; + uint16_t m_parameterId; + std::vector 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& _obj) override; + bool writeOn(enet::WebSocket& _interface) override; + size_t getSize() override; + void generateDisplay(std::ostream& _os) const override; public: + /** + * @brief Create a shared pointer on the BufferData + * @return Allocated Buffer. + */ + static ememory::SharedPtr 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 @@ -376,12 +467,62 @@ namespace zeus { */ void addData(uint16_t _parameterId, void* _data, uint32_t _size); /** - * @brief Write the buffer on a specific interface - * @param[in] _interface socket to write data - * @return true of no error appear + * @brief Get data reference */ - bool writeOn(enet::WebSocket& _interface); + const std::vector& 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& _obj) override; + public: + / ** + * @brief Create a shared pointer on the BufferEvent + * @return Allocated Buffer. + * / + static ememory::SharedPtr 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 create(); + public: + enum zeus::Buffer::typeMessage getType() const override { + return zeus::Buffer::typeMessage::flow; + } + + }; + */ /** * @brief generate a display of the typemessage * @param[in] _os stream to add data @@ -395,7 +536,7 @@ namespace zeus { * @value[in] _obj Buffer to display * @return a reference of the stream */ - std::ostream& operator <<(std::ostream& _os, const zeus::Buffer& _obj); + std::ostream& operator <<(std::ostream& _os, zeus::Buffer* _obj); // internal: /** diff --git a/zeus/Buffer_addParameter.cpp b/zeus/Buffer_addParameter.cpp index e1fc783..3bd3c0b 100644 --- a/zeus/Buffer_addParameter.cpp +++ b/zeus/Buffer_addParameter.cpp @@ -35,12 +35,12 @@ void zeus::addTypeRaw(std::vector& _data) { } -void zeus::Buffer::addParameter() { +void zeus::BufferParameter::addParameter() { std::vector data; addType(data, createType()); m_parameter.push_back(std::make_pair(2,data)); } -void zeus::Buffer::addParameterEmptyVector() { +void zeus::BufferParameter::addParameterEmptyVector() { // special case of json change mode std::vector data; addType(data, createType>()); @@ -48,7 +48,7 @@ void zeus::Buffer::addParameterEmptyVector() { } namespace zeus { template<> - void Buffer::internalAddParameter(uint16_t _paramId, const std::string& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const std::string& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -57,7 +57,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // count all datas: @@ -80,7 +80,7 @@ namespace zeus { } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -99,7 +99,7 @@ namespace zeus { } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -109,7 +109,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -119,7 +119,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -129,7 +129,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -139,7 +139,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -149,7 +149,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -159,7 +159,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -169,7 +169,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -180,7 +180,7 @@ namespace zeus { } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -191,7 +191,7 @@ namespace zeus { } template<> - void Buffer::internalAddParameter>(uint16_t _paramId, const std::vector& _value) { + void BufferParameter::addParameter>(uint16_t _paramId, const std::vector& _value) { std::vector data; addType(data, createType>()); // add size: @@ -202,21 +202,21 @@ namespace zeus { } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const int8_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const int8_t& _value) { std::vector data; addType(data, createType()); data.push_back(uint8_t(_value)); m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const uint8_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const uint8_t& _value) { std::vector data; addType(data, createType()); data.push_back(_value); m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const int16_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const int16_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -225,7 +225,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const uint16_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const uint16_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -234,7 +234,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const int32_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const int32_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -243,7 +243,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const uint32_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const uint32_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -252,7 +252,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const int64_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const int64_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -261,7 +261,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const uint64_t& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const uint64_t& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -270,7 +270,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const float& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const float& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -279,7 +279,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const double& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const double& _value) { std::vector data; addType(data, createType()); int32_t currentOffset = data.size(); @@ -288,7 +288,7 @@ namespace zeus { m_parameter.push_back(std::make_pair(2,data)); } template<> - void Buffer::internalAddParameter(uint16_t _paramId, const bool& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const bool& _value) { std::vector data; addType(data, createType()); if (_value == true) { @@ -321,10 +321,9 @@ namespace zeus { uint32_t _clientId, uint32_t _transactionId, uint32_t _partId) { - ememory::SharedPtr answer = zeus::Buffer::create(); + ememory::SharedPtr answer = zeus::BufferData::create(); answer->setTransactionId(_transactionId); answer->setClientId(_clientId); - answer->setType(zeus::Buffer::typeMessage::data); answer->setPartId(_partId); answer->setPartFinish(false); int32_t tmpSize = ZEUS_MINIMUM_SIZE_MULTIPLE; @@ -342,7 +341,7 @@ namespace zeus { } }; template<> - void Buffer::internalAddParameter(uint16_t _paramId, const zeus::File& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const zeus::File& _value) { std::vector data; addType(data, createType()); // set mine type in string: @@ -393,10 +392,9 @@ namespace zeus { if (m_node.fileIsOpen() == false) { m_node.fileOpenRead(); } - ememory::SharedPtr answer = zeus::Buffer::create(); + ememory::SharedPtr answer = zeus::BufferData::create(); answer->setTransactionId(_transactionId); answer->setClientId(_clientId); - answer->setType(zeus::Buffer::typeMessage::data); answer->setPartId(_partId); answer->setPartFinish(false); int32_t tmpSize = ZEUS_MINIMUM_SIZE_MULTIPLE; @@ -417,7 +415,7 @@ namespace zeus { }; template<> - void Buffer::internalAddParameter(uint16_t _paramId, const zeus::FileServer& _value) { + void BufferParameter::addParameter(uint16_t _paramId, const zeus::FileServer& _value) { etk::FSNode node(_value.getFileName()); node.fileOpenRead(); std::string extention = std::string(_value.getFileName().begin()+_value.getFileName().size() -3, _value.getFileName().end()); @@ -430,7 +428,7 @@ namespace zeus { node.fileRead(&fileData[0], 1, size); } zeus::File tmpFile(zeus::getMineType(extention), fileData, size); - internalAddParameter(_paramId, tmpFile); + addParameter(_paramId, tmpFile); node.fileClose(); if (size >= ZEUS_MINIMUM_SIZE_MULTIPLE) { m_multipleSend.push_back(zeus::SendFile(_value.getFileName(), _paramId, size)); diff --git a/zeus/Buffer_getParameter.cpp b/zeus/Buffer_getParameter.cpp index fbe4032..9e4afb1 100644 --- a/zeus/Buffer_getParameter.cpp +++ b/zeus/Buffer_getParameter.cpp @@ -12,10 +12,10 @@ #include namespace zeus { template<> - bool Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + bool BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); if (createType() != type) { return 0; } @@ -29,11 +29,11 @@ namespace zeus { } template<> - std::string Buffer::internalGetParameter(int32_t _id) const { + std::string BufferParameter::getParameter(int32_t _id) const { std::string out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); out.resize(dataSize, 0); memcpy(&out[0], pointer, out.size()); return out; @@ -41,10 +41,10 @@ namespace zeus { template<> - uint8_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + uint8_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -81,10 +81,10 @@ namespace zeus { return 0; } template<> - uint16_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + uint16_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -122,10 +122,10 @@ namespace zeus { } template<> - uint32_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + uint32_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -163,10 +163,10 @@ namespace zeus { } template<> - uint64_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + uint64_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -204,10 +204,10 @@ namespace zeus { } template<> - int8_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + int8_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -245,10 +245,10 @@ namespace zeus { } template<> - int16_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + int16_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -286,10 +286,10 @@ namespace zeus { } template<> - int32_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + int32_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -327,10 +327,10 @@ namespace zeus { } template<> - int64_t Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + int64_t BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -368,10 +368,10 @@ namespace zeus { } template<> - float Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + float BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -408,10 +408,10 @@ namespace zeus { return 0.0f; } template<> - double Buffer::internalGetParameter(int32_t _id) const { - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + double BufferParameter::getParameter(int32_t _id) const { + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { const uint8_t* tmp = reinterpret_cast(pointer); @@ -472,11 +472,11 @@ namespace zeus { template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -562,11 +562,11 @@ namespace zeus { return out; } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -653,11 +653,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -744,11 +744,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -835,11 +835,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -926,11 +926,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1017,11 +1017,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1108,11 +1108,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1199,11 +1199,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1290,11 +1290,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1381,11 +1381,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (type == createType>()) { return out; @@ -1403,11 +1403,11 @@ namespace zeus { } template<> - std::vector Buffer::internalGetParameter>(int32_t _id) const { + std::vector BufferParameter::getParameter>(int32_t _id) const { std::vector out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); if (type == createType>()) { return out; } else if (createType>() == type) { @@ -1428,11 +1428,11 @@ namespace zeus { } template<> - zeus::File Buffer::internalGetParameter(int32_t _id) const { + zeus::File BufferParameter::getParameter(int32_t _id) const { zeus::File out; - zeus::ParamType type = internalGetParameterType(_id); - const uint8_t* pointer = internalGetParameterPointer(_id); - uint32_t dataSize = internalGetParameterSize(_id); + zeus::ParamType type = getParameterType(_id); + const uint8_t* pointer = getParameterPointer(_id); + uint32_t dataSize = getParameterSize(_id); // TODO : Check size ... if (createType() == type) { // get mine type in string: diff --git a/zeus/Client.cpp b/zeus/Client.cpp index 407f85a..b0b9848 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -24,7 +24,7 @@ void zeus::Client::onClientData(const ememory::SharedPtr& _value) if (_value == nullptr) { return; } - ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << *_value); + ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value); } zeus::ServiceRemote zeus::Client::getService(const std::string& _name) { diff --git a/zeus/Client.h b/zeus/Client.h index e24a07f..13a6b64 100644 --- a/zeus/Client.h +++ b/zeus/Client.h @@ -104,7 +104,7 @@ namespace zeus { template zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { if (m_interfaceClient == nullptr) { - ememory::SharedPtr ret = zeus::Buffer::create(); + ememory::SharedPtr ret = zeus::BufferAnswer::create(); ret->addError("NULLPTR", "call " + _functionName + " with no interface open"); return zeus::FutureBase(0, ret); } @@ -120,7 +120,7 @@ namespace zeus { template zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { if (m_interfaceClient == nullptr) { - ememory::SharedPtr ret = zeus::Buffer::create(); + ememory::SharedPtr ret = zeus::BufferAnswer::create(); ret->addError("NULLPTR", "call " + _functionName + " with no interface open"); return zeus::FutureBase(0, ret, _callback); } diff --git a/zeus/Future.cpp b/zeus/Future.cpp index 8555279..eeccb83 100644 --- a/zeus/Future.cpp +++ b/zeus/Future.cpp @@ -19,7 +19,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return false; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> int64_t zeus::Future::get() { @@ -31,7 +31,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> int32_t zeus::Future::get() { @@ -43,7 +43,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> int16_t zeus::Future::get() { @@ -55,7 +55,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> int8_t zeus::Future::get() { @@ -67,7 +67,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> uint64_t zeus::Future::get() { @@ -79,7 +79,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> uint32_t zeus::Future::get() { @@ -91,7 +91,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> uint16_t zeus::Future::get() { @@ -103,7 +103,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> uint8_t zeus::Future::get() { @@ -115,7 +115,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> double zeus::Future::get() { @@ -127,7 +127,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0.0; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> float zeus::Future::get() { @@ -139,7 +139,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return 0.0f; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> std::string zeus::Future::get() { @@ -151,7 +151,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return ""; } - return m_data->m_returnData->getAnswer(); + return static_cast(m_data->m_returnData.get())->getAnswer(); } template<> std::vector zeus::Future>::get() { @@ -164,7 +164,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -178,7 +178,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -192,7 +192,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -206,7 +206,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -220,7 +220,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -234,7 +234,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -248,7 +248,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -262,7 +262,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -276,7 +276,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -290,7 +290,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -304,7 +304,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -318,7 +318,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer>(); + out = static_cast(m_data->m_returnData.get())->getAnswer>(); return out; } template<> @@ -332,7 +332,7 @@ namespace zeus { ZEUS_WARNING("No Return value ..."); return out; } - out = m_data->m_returnData->getAnswer(); + out = static_cast(m_data->m_returnData.get())->getAnswer(); return out; } } diff --git a/zeus/FutureBase.cpp b/zeus/FutureBase.cpp index a12eec2..fafb368 100644 --- a/zeus/FutureBase.cpp +++ b/zeus/FutureBase.cpp @@ -82,7 +82,7 @@ bool zeus::FutureBase::appendData(const ememory::SharedPtr& _value } if (_value->getType() == zeus::Buffer::typeMessage::data) { if (m_data->m_returnData != nullptr) { - m_data->m_returnData->appendBufferData(_value); + m_data->m_returnData->appendBuffer(_value); } } else { m_data->m_returnData = _value; @@ -120,10 +120,14 @@ uint32_t zeus::FutureBase::getClientId() const { } bool zeus::FutureBase::hasError() const { - if (m_data == nullptr) { + if ( m_data == nullptr + || m_data->m_returnData == nullptr) { return true; } - return m_data->m_returnData->hasError(); + if (m_data->m_returnData->getType() == zeus::Buffer::typeMessage::answer) { + return true; + } + return static_cast(m_data->m_returnData.get())->hasError(); } std::string zeus::FutureBase::getErrorType() const { @@ -131,15 +135,21 @@ std::string zeus::FutureBase::getErrorType() const { || m_data->m_returnData == nullptr) { return "NULL_PTR"; } - return m_data->m_returnData->getError(); + if (m_data->m_returnData->getType() == zeus::Buffer::typeMessage::answer) { + return "NOT_ANSWER_MESSAGE"; + } + return static_cast(m_data->m_returnData.get())->getError(); } std::string zeus::FutureBase::getErrorHelp() const { if ( m_data == nullptr || m_data->m_returnData == nullptr) { - return "Thsi is a nullptr future"; + return "This is a nullptr future"; } - return m_data->m_returnData->getErrorHelp(); + if (m_data->m_returnData->getType() == zeus::Buffer::typeMessage::answer) { + return "This answer is not a anwser type"; + } + return static_cast(m_data->m_returnData.get())->getErrorHelp(); } bool zeus::FutureBase::isValid() const { diff --git a/zeus/Service.cpp b/zeus/Service.cpp index 21a26d5..6fd5e94 100644 --- a/zeus/Service.cpp +++ b/zeus/Service.cpp @@ -133,26 +133,28 @@ void zeus::Service::callBinary(const ememory::SharedPtr& _obj) { ZEUS_ERROR("Local Answer: '...'"); return; } - //if (_obj.getType() == zeus::Buffer::typeMessage::event) { - uint32_t clientId = _obj->getClientId(); - std::string callFunction = _obj->getCall(); - if (callFunction[0] == '_') { - if (callFunction == "_new") { - std::string userName = _obj->getParameter(0); - std::string clientName = _obj->getParameter(1); - std::vector clientGroup = _obj->getParameter>(2); - clientConnect(clientId, userName, clientName, clientGroup); - } else if (callFunction == "_delete") { - clientDisconnect(clientId); + if (_obj->getType() == zeus::Buffer::typeMessage::call) { + ememory::SharedPtr callObj = std::static_pointer_cast(_obj); + uint32_t clientId = callObj->getClientId(); + std::string callFunction = callObj->getCall(); + if (callFunction[0] == '_') { + if (callFunction == "_new") { + std::string userName = callObj->getParameter(0); + std::string clientName = callObj->getParameter(1); + std::vector clientGroup = callObj->getParameter>(2); + clientConnect(clientId, userName, clientName, clientGroup); + } else if (callFunction == "_delete") { + clientDisconnect(clientId); + } + m_interfaceClient->answerValue(callObj->getTransactionId(), true, clientId); + return; + } else if (isFunctionAuthorized(clientId, callFunction) == true) { + callBinary2(callFunction, callObj); + return; + } else { + m_interfaceClient->answerError(callObj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId); + return; } - m_interfaceClient->answerValue(_obj->getTransactionId(), true, clientId); - return; - } else if (isFunctionAuthorized(clientId, callFunction) == true) { - callBinary2(callFunction, _obj); - return; - } else { - m_interfaceClient->answerError(_obj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId); - return; } } diff --git a/zeus/ServiceRemote.h b/zeus/ServiceRemote.h index e0da4cf..717beed 100644 --- a/zeus/ServiceRemote.h +++ b/zeus/ServiceRemote.h @@ -53,7 +53,7 @@ namespace zeus { template zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { if (m_interfaceClient == nullptr) { - ememory::SharedPtr ret = zeus::Buffer::create(); + ememory::SharedPtr ret = zeus::BufferAnswer::create(); if (ret != nullptr) { ret->addError("NULLPTR", "call " + _functionName + " with no interface open"); } @@ -69,7 +69,7 @@ namespace zeus { template zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { if (m_interfaceClient == nullptr) { - ememory::SharedPtr ret = zeus::Buffer::create(); + ememory::SharedPtr ret = zeus::BufferAnswer::create(); if (ret != nullptr) { ret->addError("NULLPTR", "call " + _functionName + " with no interface open"); } diff --git a/zeus/WebServer.cpp b/zeus/WebServer.cpp index cbd0695..4392fc6 100644 --- a/zeus/WebServer.cpp +++ b/zeus/WebServer.cpp @@ -9,8 +9,8 @@ #include -ememory::SharedPtr zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) { - ememory::SharedPtr obj = zeus::Buffer::create(); +ememory::SharedPtr zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) { + ememory::SharedPtr obj = zeus::BufferCall::create(); if (obj == nullptr) { return nullptr; } @@ -20,7 +20,7 @@ ememory::SharedPtr zeus::createBaseCall(uint64_t _transactionId, c return obj; } -void zeus::createParam(int32_t _paramId, const ememory::SharedPtr& _obj) { +void zeus::createParam(int32_t _paramId, const ememory::SharedPtr& _obj) { // Finish recursive parse ... } @@ -135,11 +135,10 @@ class SendAsyncBinary { m_partId++; } if (m_async.size() == 0) { - ememory::SharedPtr obj = zeus::Buffer::create(); + ememory::SharedPtr obj = zeus::BufferData::create(); if (obj == nullptr) { return true; } - obj->setType(zeus::Buffer::typeMessage::data); obj->setServiceId(m_serviceId); obj->setTransactionId(m_transactionId); obj->setPartId(m_partId); @@ -182,13 +181,12 @@ bool zeus::WebServer::onReceiveUri(const std::string& _uri, const std::vector& _frame, bool _isBinary) { - ememory::SharedPtr dataRaw = zeus::Buffer::create(); if (_isBinary == true) { ZEUS_ERROR("Receive non binary frame ..."); disconnect(true); return; } - dataRaw->composeWith(_frame); + ememory::SharedPtr dataRaw = zeus::Buffer::create(_frame); newBuffer(dataRaw); } @@ -197,7 +195,7 @@ void zeus::WebServer::ping() { } void zeus::WebServer::newBuffer(const ememory::SharedPtr& _buffer) { - ZEUS_VERBOSE("Receive :" << *_buffer); + ZEUS_VERBOSE("Receive :" << _buffer); zeus::FutureBase future; uint64_t tid = _buffer->getTransactionId(); if (tid == 0) { @@ -306,8 +304,7 @@ zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId, ZEUS_VERBOSE("Send [START] "); if (isActive() == false) { ZEUS_ERROR("Send [STOP] ==> not connected (no TCP)"); - ememory::SharedPtr obj = zeus::Buffer::create(); - obj->setType(zeus::Buffer::typeMessage::answer); + ememory::SharedPtr obj = zeus::BufferAnswer::create(); obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)"); return zeus::FutureBase(_transactionId, obj, _callback); } @@ -330,8 +327,7 @@ zeus::FutureBase zeus::WebServer::callForward(uint32_t _clientId, //ret.setSynchronous(); if (isActive() == false) { - ememory::SharedPtr obj = zeus::Buffer::create(); - obj->setType(zeus::Buffer::typeMessage::answer); + ememory::SharedPtr obj = zeus::BufferAnswer::create(); obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)"); return zeus::FutureBase(0, obj, _callback); } @@ -371,11 +367,10 @@ void zeus::WebServer::callForwardMultiple(uint32_t _clientId, } void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId) { - ememory::SharedPtr answer = zeus::Buffer::create(); + ememory::SharedPtr answer = zeus::BufferAnswer::create(); if (answer == nullptr) { return; } - answer->setType(zeus::Buffer::typeMessage::answer); answer->setTransactionId(_clientTransactionId); answer->setClientId(_clientId); answer->addError(_errorValue, _errorHelp); @@ -384,11 +379,10 @@ void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::stri void zeus::WebServer::answerVoid(uint64_t _clientTransactionId, uint32_t _clientId) { - ememory::SharedPtr answer = zeus::Buffer::create(); + ememory::SharedPtr answer = zeus::BufferAnswer::create(); if (answer == nullptr) { return; } - answer->setType(zeus::Buffer::typeMessage::answer); answer->setTransactionId(_clientTransactionId); answer->setClientId(_clientId); answer->addParameter(); diff --git a/zeus/WebServer.h b/zeus/WebServer.h index c1b2e76..ac884a1 100644 --- a/zeus/WebServer.h +++ b/zeus/WebServer.h @@ -17,14 +17,14 @@ namespace zeus { * @param[in] * @return */ - ememory::SharedPtr createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0); + ememory::SharedPtr createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0); /** * @brief * @param[in] * @return */ void createParam(int32_t _paramId, - const ememory::SharedPtr& _obj); + const ememory::SharedPtr& _obj); /** * @brief @@ -33,9 +33,9 @@ namespace zeus { */ template void createParam(int32_t _paramId, - const ememory::SharedPtr& _obj, - const ZEUS_TYPE& _param, - _ARGS&&... _args) { + const ememory::SharedPtr& _obj, + const ZEUS_TYPE& _param, + _ARGS&&... _args) { _obj->addParameter(_param); _paramId++; createParam(_paramId, _obj, std::forward<_ARGS>(_args)...); @@ -48,9 +48,9 @@ namespace zeus { // convert const char in std::string ... template void createParam(int32_t _paramId, - const ememory::SharedPtr& _obj, - const char* _param, - _ARGS&&... _args) { + const ememory::SharedPtr& _obj, + const char* _param, + _ARGS&&... _args) { createParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...); } @@ -60,8 +60,8 @@ namespace zeus { * @return */ template - ememory::SharedPtr createCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) { - ememory::SharedPtr callElem = createBaseCall(_transactionId, _functionName); + ememory::SharedPtr createCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) { + ememory::SharedPtr callElem = createBaseCall(_transactionId, _functionName); if (callElem == nullptr) { return nullptr; } @@ -74,8 +74,8 @@ namespace zeus { * @return */ template - ememory::SharedPtr createCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) { - ememory::SharedPtr callElem = createBaseCall(_transactionId, _functionName, _serviceName); + ememory::SharedPtr createCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) { + ememory::SharedPtr callElem = createBaseCall(_transactionId, _functionName, _serviceName); if (callElem == nullptr) { return nullptr; } @@ -245,7 +245,7 @@ namespace zeus { template zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...); + ememory::SharedPtr callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem); } /** @@ -256,7 +256,7 @@ namespace zeus { template zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...); + ememory::SharedPtr callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem, _callback); } public: // section call with service ID / Client ID @@ -269,7 +269,7 @@ namespace zeus { template zeus::FutureBase callService(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args) { uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); + ememory::SharedPtr callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem); } /** @@ -280,7 +280,7 @@ namespace zeus { template zeus::FutureBase callServiceAction(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); + ememory::SharedPtr callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem, _callback); } /** @@ -290,8 +290,8 @@ namespace zeus { */ template zeus::FutureBase callClient(uint32_t _clientId, - const std::string& _functionName, - _ARGS&&... _args) { + const std::string& _functionName, + _ARGS&&... _args) { return callService(_clientId, _functionName, _args...); } /** @@ -301,9 +301,9 @@ namespace zeus { */ template zeus::FutureBase callClientAction(uint32_t _clientId, - const std::string& _functionName, - _ARGS&&... _args, - zeus::FutureData::ObserverFinish _callback) { + const std::string& _functionName, + _ARGS&&... _args, + zeus::FutureData::ObserverFinish _callback) { return callServiceAction(_clientId, _functionName, _args..., _callback); } /** @@ -312,9 +312,9 @@ namespace zeus { * @return */ zeus::FutureBase callForward(uint32_t _clientId, - const ememory::SharedPtr& _Buffer, - uint64_t _singleReferenceId, - zeus::FutureData::ObserverFinish _callback); + const ememory::SharedPtr& _Buffer, + uint64_t _singleReferenceId, + zeus::FutureData::ObserverFinish _callback); /** * @brief * @param[in] @@ -338,8 +338,7 @@ namespace zeus { */ template void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0) { - ememory::SharedPtr answer = zeus::Buffer::create(); - answer->setType(zeus::Buffer::typeMessage::answer); + ememory::SharedPtr answer = zeus::BufferAnswer::create(); answer->setTransactionId(_clientTransactionId); answer->setClientId(_clientId); answer->addAnswer(_value);