[DEV] rework source tree

This commit is contained in:
Edouard DUPIN 2016-12-07 22:18:34 +01:00
parent 07dcff3647
commit f1937e97d1
55 changed files with 3250 additions and 3353 deletions

View File

@ -432,15 +432,15 @@ class ServiceDefinition:
out += "#include <" + register_filename + ">\n"
out += "#include <" + register_filename_proxy + ">\n"
out += "#include <etk/types.hpp>\n"
out += "#include <zeus/Buffer.hpp>\n"
out += "#include <zeus/BufferData.hpp>\n"
out += "#include <zeus/message/Message.hpp>\n"
out += "#include <zeus/message/Data.hpp>\n"
out += "#include <zeus/debug.hpp>\n"
out += "#include <zeus/ParamType.hpp>\n"
out += "#include <etk/stdTools.hpp>\n"
out += "#include <zeus/AbstractFunction.hpp>\n"
out += "#include <climits>\n"
out += "#include <etk/os/FSNode.hpp>\n"
out += "#include <zeus/BufferParameter.hpp>\n"
out += "#include <zeus/message/Parameter.hpp>\n"
out += "#include <zeus/WebServer.hpp>\n"
out += "#include <zeus/Object.hpp>\n"
out += "\n"

View File

@ -37,69 +37,90 @@ def configure(target, my_module):
'zeus/debug.cpp'
])
my_module.add_path(".")
# Future and promise interface
my_module.add_src_file([
'zeus/FutureBase.cpp',
'zeus/Future.cpp',
'zeus/Promise.cpp',
])
my_module.add_header_file([
'zeus/Promise.hpp',
'zeus/FutureBase.hpp',
'zeus/Future.hpp',
])
# messaging interface
my_module.add_src_file([
'zeus/message/Message.cpp',
'zeus/message/Parameter.cpp',
'zeus/message/Call.cpp',
'zeus/message/Answer.cpp',
'zeus/message/Data.cpp',
'zeus/message/Event.cpp',
'zeus/message/Flow.cpp',
'zeus/message/Parameter_addParameter.cpp',
'zeus/message/Parameter_getParameter.cpp',
'zeus/message/ParamType.cpp',
'zeus/message/type.cpp',
])
my_module.add_header_file([
'zeus/message/Message.hpp',
'zeus/message/Parameter.hpp',
'zeus/message/Call.hpp',
'zeus/message/Answer.hpp',
'zeus/message/Data.hpp',
'zeus/message/Event.hpp',
'zeus/message/Flow.hpp',
'zeus/message/ParamType.hpp',
'zeus/message/type.hpp',
])
# complexe object interface
my_module.add_src_file([
'zeus/Object.cpp',
'zeus/ObjectIntrospect.cpp',
'zeus/ObjectRemote.cpp',
'zeus/Proxy.cpp',
])
my_module.add_header_file([
'zeus/Object.hpp',
'zeus/ObjectIntrospect.hpp',
'zeus/ObjectRemote.hpp',
'zeus/Proxy.hpp',
])
# other ...
my_module.add_src_file([
'zeus/zeus.cpp',
'zeus/AbstractFunction.cpp',
'zeus/FutureBase.cpp',
'zeus/Future.cpp',
'zeus/Raw.cpp',
'zeus/FileImpl.cpp',
'zeus/Buffer.cpp',
'zeus/BufferParameter.cpp',
'zeus/BufferCall.cpp',
'zeus/BufferCtrl.cpp',
'zeus/BufferAnswer.cpp',
'zeus/BufferData.cpp',
'zeus/BufferEvent.cpp',
'zeus/BufferFlow.cpp',
'zeus/BufferParameter_addParameter.cpp',
'zeus/BufferParameter_getParameter.cpp',
'zeus/ParamType.cpp',
'zeus/Client.cpp',
'zeus/Object.cpp',
'zeus/ObjectRemote.cpp',
'zeus/RemoteProcessCall.cpp',
'zeus/WebServer.cpp',
'zeus/mineType.cpp',
'zeus/BaseProxy.cpp',
'zeus/SystemProxy.cpp',
'zeus/RemoteProperty.cpp',
])
my_module.add_header_file([
'zeus/Raw.hpp',
'zeus/zeus.hpp',
'zeus/AbstractFunction.hpp',
'zeus/AbstractFunctionTypeDirect.hpp',
'zeus/AbstractFunctionTypeClass.hpp',
'zeus/FutureData.hpp',
'zeus/FutureBase.hpp',
'zeus/Future.hpp',
'zeus/Raw.hpp',
'zeus/FileImpl.hpp',
'zeus/Buffer.hpp',
'zeus/BufferParameter.hpp',
'zeus/BufferCall.hpp',
'zeus/BufferCtrl.hpp',
'zeus/BufferAnswer.hpp',
'zeus/BufferData.hpp',
'zeus/BufferEvent.hpp',
'zeus/BufferFlow.hpp',
'zeus/ParamType.hpp',
'zeus/debug.hpp',
'zeus/Client.hpp',
'zeus/Object.hpp',
'zeus/ObjectRemote.hpp',
'zeus/RemoteProcessCall.hpp',
'zeus/WebObj.hpp',
'zeus/WebServer.hpp',
'zeus/mineType.hpp',
'zeus/BaseProxy.hpp',
'zeus/RemoteProperty.hpp',
'zeus/SystemProxy.hpp',
])
# add basic object:
zeus_macro = macro.load_macro('zeus')
zeus_macro.parse_object_idl(my_module, 'zeus/zeus-File.obj.zeus.idl')
my_module.add_src_file([
'zeus/zeus-File.impl.cpp',
])
my_module.add_header_file([
'zeus/zeus-File.impl.hpp',
])
if target.config["compilator"] == "clang":
my_module.add_flag('c++', "-Wno-unsequenced", export=True)

View File

@ -8,7 +8,7 @@
#include <appl/ClientInterface.hpp>
#include <zeus/Future.hpp>
#include <appl/Router.hpp>
#include <zeus/BufferCtrl.hpp>
#include <zeus/message/Ctrl.hpp>
#include <zeus/AbstractFunction.hpp>

View File

@ -5,10 +5,10 @@
*/
#pragma once
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/File.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/BufferCall.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/message/Call.hpp>
#include <ememory/memory.hpp>

View File

@ -1,80 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/BufferParameter.hpp>
namespace zeus {
class WebServer;
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(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::BufferParameter(_iface) {
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(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(ememory::SharedPtr<zeus::WebServer> _iface);
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 ememory::SharedPtr<zeus::WebServer>& _iface, const ZEUS_TYPE_DATA& _value) {
addParameter(_iface, _value);
}
/**
* @brief get the answer value
* @param[in] Data of the answer
*/
template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getAnswer() const {
return getParameter<ZEUS_TYPE_DATA>(m_iface, 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() const;
/**
* @brief get the error value (if exist)
* @return string of the error
*/
const std::string& getError() const;
/**
* @brief get the error help (if exist)
* @return string of the error help
*/
const std::string& getErrorHelp() const;
};
}

View File

@ -1,53 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/BufferParameter.hpp>
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(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::BufferParameter(_iface) {
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(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(ememory::SharedPtr<zeus::WebServer> _iface);
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);
};
}

View File

@ -1,57 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferCtrl.hpp>
void zeus::BufferCtrl::generateDisplay(std::ostream& _os) const {
zeus::Buffer::generateDisplay(_os);
_os << " '" + m_ctrlValue + "'";
}
const std::string& zeus::BufferCtrl::getCtrl() const {
return m_ctrlValue;
}
void zeus::BufferCtrl::setCtrl(const std::string& _value) {
m_ctrlValue = _value;
}
bool zeus::BufferCtrl::writeOn(enet::WebSocket& _interface) {
zeus::Buffer::writeOn(_interface);
_interface.writeData((uint8_t*)m_ctrlValue.c_str(), m_ctrlValue.size() + 1);
return true;
}
void zeus::BufferCtrl::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_ctrlValue.clear();
while( pos < _lenght
&& (char)_buffer[pos] != '\0') {
m_ctrlValue += _buffer[pos];
pos++;
}
pos++;
// TODO : Check if some parameter are present ... ==> must create an error
}
void zeus::BufferCtrl::appendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
ZEUS_ERROR("A ctrl message can not have data ...");
}
// ------------------------------------------------------------------------------------
// -- Factory
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::BufferCtrl> zeus::BufferCtrl::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::BufferCtrl>(new zeus::BufferCtrl(_iface));
}

View File

@ -1,53 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/Buffer.hpp>
namespace zeus {
class BufferCtrl :
public Buffer {
friend class zeus::Buffer;
protected:
std::string m_ctrlValue;
protected:
/**
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::BufferCall::create
*/
BufferCtrl(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::Buffer(_iface) {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::Buffer::typeMessage::ctrl);
};
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
void appendBufferData(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::BufferCtrl> create(ememory::SharedPtr<zeus::WebServer> _iface);
public:
enum zeus::Buffer::typeMessage getType() const override {
return zeus::Buffer::typeMessage::ctrl;
}
/**
* @brief get the call value of the buffer
* @return string of the function to call
*/
const std::string& getCtrl() const;
/**
* @brief Set the call value of the buffer
* @param[in] _value Function to call
*/
void setCtrl(const std::string& _value);
};
}

View File

@ -1,76 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/Buffer.hpp>
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(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::Buffer(_iface),
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(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(ememory::SharedPtr<zeus::WebServer> _iface);
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;
}
};
}

View File

@ -1,40 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
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(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;
}
};
*/
}

View File

@ -1,38 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
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;
}
};
*/
}

View File

@ -1,91 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <ememory/memory.hpp>
namespace zeus {
class WebServer;
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:
BufferParameter(ememory::SharedPtr<zeus::WebServer> _iface);
/**
* @brief Template to get a parameter with a specific type
* @param[in] _id Number of the parameter
* @param[in] _iface IO Web interface
* @return Converted type of the parameter (or empty value)
*/
template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getParameter(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const;
/**
* @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 {
return getParameter<ZEUS_TYPE_DATA>(m_iface, _id);
}
/**
* @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(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
public:
template<class ZEUS_TYPE_DATA>
void addParameter(const ememory::SharedPtr<zeus::WebServer>& _iface, const ZEUS_TYPE_DATA& _value) {
addParameter(_iface, m_parameter.size(), _value);
}
void parameterAppendBufferData(ememory::SharedPtr<zeus::BufferData> _obj);
};
}

View File

@ -1,365 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/BufferData.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/AbstractFunction.hpp>
#include <climits>
#include <etk/os/FSNode.hpp>
#include <zeus/mineType.hpp>
#include <zeus/WebServer.hpp>
void zeus::addType(std::vector<uint8_t>& _data, zeus::ParamType _type) {
_data.push_back(uint8_t(_type.getId()>>8));
_data.push_back(uint8_t(_type.getId()));
}
void zeus::addTypeObject(std::vector<uint8_t>& _data, const std::string _type) {
_data.push_back(uint8_t(zeus::paramTypeObject>>8));
_data.push_back(uint8_t(zeus::paramTypeObject));
for (auto &it : _type) {
_data.push_back(uint8_t(it));
}
_data.push_back(0);
}
void zeus::BufferParameter::addParameter() {
std::vector<uint8_t> data;
addType(data, createType<void>());
m_parameter.push_back(std::make_pair(2,data));
}
void zeus::BufferParameter::addParameterEmptyVector() {
// special case of json change mode
std::vector<uint8_t> data;
addType(data, createType<std::vector<void>>());
m_parameter.push_back(std::make_pair(2,data));
}
namespace zeus {
template<>
void BufferParameter::addParameter<std::string>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::string& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::string>());
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], _value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<std::string>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<std::string>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<std::string>>());
// count all datas:
uint32_t size = 0;
for (auto &it : _value) {
size+=it.size()+1;
}
uint16_t nb = _value.size();
int32_t currentOffset = data.size();
data.resize(data.size()+size+2);
memcpy(&data[currentOffset], &nb, sizeof(uint16_t));
currentOffset += sizeof(uint16_t);
for (auto &it : _value) {
memcpy(&data[currentOffset], &it[0], it.size());
currentOffset += it.size();
data[currentOffset] = '\0';
currentOffset++;
}
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<bool>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<bool>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<bool>>());
// add size:
uint16_t nb = _value.size();
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
for (const auto &it : _value) {
if (it == true) {
data[currentOffset] = 'T';
} else {
data[currentOffset] = 'F';
}
currentOffset++;
}
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<int8_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int8_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int8_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int8_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<int16_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int16_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int16_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int16_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<int32_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int32_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int32_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int32_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<int64_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int64_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int64_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int64_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<uint8_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint8_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint8_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint8_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<uint16_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint16_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint16_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint16_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<uint32_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint32_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint32_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint32_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<uint64_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint64_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint64_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint64_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<float>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<float>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<float>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(float)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<std::vector<double>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<double>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<double>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(double)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<int8_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int8_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int8_t>());
data.push_back(uint8_t(_value));
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<uint8_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint8_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint8_t>());
data.push_back(_value);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<int16_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int16_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int16_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+2);
memcpy(&data[currentOffset], &_value, 2);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<uint16_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint16_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint16_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+2);
memcpy(&data[currentOffset], &_value, 2);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<int32_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int32_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int32_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<uint32_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint32_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint32_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<int64_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int64_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int64_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<uint64_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint64_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint64_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
#if defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs)
template<>
void BufferParameter::addParameter<size_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const size_t& _value) {
addParameter(_paramId, uint64_t(_value));
}
#endif
template<>
void BufferParameter::addParameter<float>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const float& _value) {
std::vector<uint8_t> data;
addType(data, createType<float>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<double>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const double& _value) {
std::vector<uint8_t> data;
addType(data, createType<double>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void BufferParameter::addParameter<bool>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const bool& _value) {
std::vector<uint8_t> data;
addType(data, createType<bool>());
if (_value == true) {
data.push_back('T');
} else {
data.push_back('F');
}
m_parameter.push_back(std::make_pair(2,data));
}
#define ZEUS_MINIMUM_SIZE_MULTIPLE (1024*50)
class SendData {
private:
zeus::Raw m_data;
uint16_t m_parameterId;
int64_t m_size;
uint64_t m_offset;
public:
SendData(const zeus::Raw& _data, uint16_t _parameterId) :
m_data(_data),
m_parameterId(_parameterId),
m_size(_data.size()-1),
m_offset(0) {
}
~SendData() {
}
// TODO : Set it with a sharedPtr instaed of pointer ...
bool operator() (zeus::WebServer* _interface,
uint32_t _source,
uint32_t _destination,
uint32_t _transactionId,
uint32_t _partId) {
ememory::SharedPtr<zeus::BufferData> answer = zeus::BufferData::create(_interface->sharedFromThis());
answer->setTransactionId(_transactionId);
answer->setSource(_source);
answer->setDestination(_destination);
answer->setPartId(_partId);
answer->setPartFinish(false);
int32_t tmpSize = ZEUS_MINIMUM_SIZE_MULTIPLE;
if (m_size < ZEUS_MINIMUM_SIZE_MULTIPLE) {
tmpSize = m_size;
}
answer->addData(m_parameterId, (void *)(&m_data.data()[m_offset]), tmpSize);
m_size -= tmpSize;
m_offset += tmpSize;
_interface->writeBinary(answer);;
if (m_size <= 0) {
return true;
}
return false;
}
};
template<>
void BufferParameter::addParameter<zeus::Raw>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const zeus::Raw& _value) {
std::vector<uint8_t> data;
addType(data, createType<zeus::Raw>());
// set mine type in string:
int32_t currentOffset = data.size();
if (_value.size() != 0) {
if (_value.size() < ZEUS_MINIMUM_SIZE_MULTIPLE) {
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], _value.data(), _value.size());
} else {
m_multipleSend.push_back(zeus::SendData(_value, _paramId));
}
}
m_parameter.push_back(std::make_pair(2,data));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
* @license APACHE v2.0 (see license file)
*/
#include <zeus/Future.hpp>
#include <zeus/BufferAnswer.hpp>
#include <zeus/message/Answer.hpp>
#include <zeus/debug.hpp>
#include <zeus/Raw.hpp>
@ -13,340 +13,340 @@
namespace zeus {
template<>
bool zeus::Future<bool>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return false;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return false;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<bool>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<bool>();
}
template<>
int64_t zeus::Future<int64_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<bool>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<bool>();
}
template<>
int32_t zeus::Future<int32_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<int32_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<int32_t>();
}
template<>
int16_t zeus::Future<int16_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<int16_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<int16_t>();
}
template<>
int8_t zeus::Future<int8_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<int8_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<int8_t>();
}
template<>
uint64_t zeus::Future<uint64_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<int64_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<int64_t>();
}
template<>
uint32_t zeus::Future<uint32_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<uint32_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<uint32_t>();
}
template<>
uint16_t zeus::Future<uint16_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<uint16_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<uint16_t>();
}
template<>
uint8_t zeus::Future<uint8_t>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<uint8_t>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<uint8_t>();
}
template<>
double zeus::Future<double>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0.0;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<double>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<double>();
}
template<>
float zeus::Future<float>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return 0.0f;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return 0.0f;
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<float>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<float>();
}
template<>
std::string zeus::Future<std::string>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return "";
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return "";
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::string>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::string>();
}
template<>
std::vector<int64_t> zeus::Future<std::vector<int64_t>>::get() {
std::vector<int64_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<int64_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<int64_t>>();
return out;
}
template<>
std::vector<int32_t> zeus::Future<std::vector<int32_t>>::get() {
std::vector<int32_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<int32_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<int32_t>>();
return out;
}
template<>
std::vector<int16_t> zeus::Future<std::vector<int16_t>>::get() {
std::vector<int16_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<int16_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<int16_t>>();
return out;
}
template<>
std::vector<int8_t> zeus::Future<std::vector<int8_t>>::get() {
std::vector<int8_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<int8_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<int8_t>>();
return out;
}
template<>
std::vector<uint64_t> zeus::Future<std::vector<uint64_t>>::get() {
std::vector<uint64_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<uint64_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<uint64_t>>();
return out;
}
template<>
std::vector<uint32_t> zeus::Future<std::vector<uint32_t>>::get() {
std::vector<uint32_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<uint32_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<uint32_t>>();
return out;
}
template<>
std::vector<uint16_t> zeus::Future<std::vector<uint16_t>>::get() {
std::vector<uint16_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<uint16_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<uint16_t>>();
return out;
}
template<>
std::vector<uint8_t> zeus::Future<std::vector<uint8_t>>::get() {
std::vector<uint8_t> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<uint8_t>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<uint8_t>>();
return out;
}
template<>
std::vector<double> zeus::Future<std::vector<double>>::get() {
std::vector<double> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<double>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<double>>();
return out;
}
template<>
std::vector<float> zeus::Future<std::vector<float>>::get() {
std::vector<float> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<float>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<float>>();
return out;
}
template<>
std::vector<std::string> zeus::Future<std::vector<std::string>>::get() {
std::vector<std::string> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<std::string>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<std::string>>();
return out;
}
template<>
std::vector<bool> zeus::Future<std::vector<bool>>::get() {
std::vector<bool> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<std::vector<bool>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<std::vector<bool>>();
return out;
}
template<>
zeus::Raw zeus::Future<zeus::Raw>::get() {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return zeus::Raw();
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return zeus::Raw();
}
return static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<zeus::Raw>();
return static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<zeus::Raw>();
}
template<>
ememory::SharedPtr<zeus::ObjectRemoteBase> zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>>::get() {
ememory::SharedPtr<zeus::ObjectRemoteBase> out;
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if ( m_promise == nullptr
|| m_promise->m_message == nullptr) {
return out;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
if (m_promise->m_message->getType() != zeus::message::Message::typeMessage::answer) {
ZEUS_WARNING("No Return value ...");
return out;
}
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<ememory::SharedPtr<zeus::ObjectRemoteBase>>();
out = static_cast<zeus::message::Answer*>(m_promise->m_message.get())->getAnswer<ememory::SharedPtr<zeus::ObjectRemoteBase>>();
return out;
}
}

View File

@ -30,7 +30,7 @@ namespace zeus {
* @return the reference on the local element
*/
zeus::Future<ZEUS_RETURN>& operator= (const zeus::FutureBase& _base) {
m_data = _base.m_data;
m_promise = _base.m_promise;
return *this;
}
/**
@ -46,19 +46,19 @@ namespace zeus {
zeus::FutureBase::wait();
return *this;
}
const Future<ZEUS_RETURN>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) const {
const Future<ZEUS_RETURN>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta);
return *this;
}
Future<ZEUS_RETURN>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) {
Future<ZEUS_RETURN>& waitFor(echrono::Duration _delta = echrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta);
return *this;
}
const Future<ZEUS_RETURN>& waitUntil(std::chrono::steady_clock::time_point _endTime) const {
const Future<ZEUS_RETURN>& waitUntil(echrono::Steady _endTime) const {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
Future<ZEUS_RETURN>& waitUntil(std::chrono::steady_clock::time_point _endTime) {
Future<ZEUS_RETURN>& waitUntil(echrono::Steady _endTime) {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
@ -83,7 +83,7 @@ namespace zeus {
* @return the reference on the local element
*/
zeus::Future<void>& operator= (const zeus::FutureBase& _base) {
m_data = _base.m_data;
m_promise = _base.m_promise;
return *this;
}
const Future<void>& wait() const {
@ -94,19 +94,19 @@ namespace zeus {
zeus::FutureBase::wait();
return *this;
}
const Future<void>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) const {
const Future<void>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta);
return *this;
}
Future<void>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) {
Future<void>& waitFor(echrono::Duration _delta = echrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta);
return *this;
}
const Future<void>& waitUntil(std::chrono::steady_clock::time_point _endTime) const {
const Future<void>& waitUntil(echrono::Steady _endTime) const {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
Future<void>& waitUntil(std::chrono::steady_clock::time_point _endTime) {
Future<void>& waitUntil(echrono::Steady _endTime) {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}

View File

@ -4,236 +4,143 @@
* @license APACHE v2.0 (see license file)
*/
#include <zeus/FutureBase.hpp>
#include <zeus/BufferAnswer.hpp>
#include <zeus/message/Answer.hpp>
#include <zeus/debug.hpp>
zeus::FutureBase::FutureBase(const zeus::FutureBase& _base):
m_data(_base.m_data) {
m_promise(_base.m_promise) {
}
zeus::FutureBase::FutureBase() {
m_data = nullptr;
m_promise = nullptr;
}
zeus::FutureBase::FutureBase(uint32_t _transactionId, uint32_t _source) {
m_data = ememory::makeShared<zeus::FutureData>();
if (m_data == nullptr) {
return;
}
m_data->m_sendTime = std::chrono::steady_clock::now();
m_data->m_transactionId = _transactionId;
m_data->m_source = _source;
m_promise = ememory::makeShared<zeus::Promise>(_transactionId, _source);
}
ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() {
if (m_data == nullptr) {
ememory::SharedPtr<zeus::message::Message> zeus::FutureBase::getRaw() {
if (m_promise == nullptr) {
return nullptr;
}
return m_data->m_returnData;
return m_promise->getRaw();
}
zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, uint32_t _source) {
m_data = ememory::makeShared<zeus::FutureData>();
if (m_data == nullptr) {
return;
}
m_data->m_sendTime = std::chrono::steady_clock::now();
m_data->m_transactionId = _transactionId;
m_data->m_source = _source;
m_data->m_returnData = _returnData;
if (isFinished() == true) {
m_data->m_receiveTime = std::chrono::steady_clock::now();
}
zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::message::Message> _returnData, uint32_t _source) {
m_promise = ememory::makeShared<zeus::Promise>(_transactionId, _returnData, _source);
}
void zeus::FutureBase::andAll(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
void zeus::FutureBase::andAll(zeus::Promise::Observer _callback) {
if (m_promise == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackThen = _callback;
m_data->m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
if (m_data->m_callbackThen != nullptr) {
m_data->m_callbackThen(*this);
}
} else {
if (m_data->m_callbackElse != nullptr) {
m_data->m_callbackElse(*this);
}
}
m_promise->andAll(_callback);
}
void zeus::FutureBase::andThen(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
void zeus::FutureBase::andThen(zeus::Promise::Observer _callback) {
if (m_promise == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackThen = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == true) {
return;
}
if (m_data->m_callbackThen == nullptr) {
return;
}
m_data->m_callbackThen(*this);
m_promise->andThen(_callback);
}
void zeus::FutureBase::andElse(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
void zeus::FutureBase::andElse(zeus::Promise::Observer _callback) {
if (m_promise == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
return;
}
if (m_data->m_callbackElse == nullptr) {
return;
}
m_data->m_callbackElse(*this);
m_promise->andElse(_callback);
}
std::chrono::nanoseconds zeus::FutureBase::getTransmitionTime() const {
if (m_data == nullptr) {
return std::chrono::nanoseconds(0);
echrono::Duration zeus::FutureBase::getTransmitionTime() const {
if (m_promise == nullptr) {
return echrono::nanoseconds(0);
}
if (isFinished() == false) {
return std::chrono::nanoseconds(0);
}
return m_data->m_receiveTime - m_data->m_sendTime;
return m_promise->getTransmitionTime();
}
zeus::FutureBase zeus::FutureBase::operator= (const zeus::FutureBase& _base) {
m_data = _base.m_data;
m_promise = _base.m_promise;
return *this;
}
bool zeus::FutureBase::setBuffer(ememory::SharedPtr<zeus::Buffer> _value) {
if (m_data == nullptr) {
bool zeus::FutureBase::setBuffer(ememory::SharedPtr<zeus::message::Message> _value) {
if (m_promise == nullptr) {
ZEUS_ERROR(" Not a valid future ...");
return true;
}
m_data->m_receiveTime = std::chrono::steady_clock::now();
m_data->m_returnData = _value;
if (m_data->m_returnData == nullptr) {
return true;
}
if (m_data->m_returnData->getPartFinish() == false) {
ZEUS_ERROR("set buffer that is not finished ...");
return false;
}
if (hasError() == false) {
if (m_data->m_callbackThen != nullptr) {
return m_data->m_callbackThen(*this);
}
} else {
if (m_data->m_callbackElse != nullptr) {
return m_data->m_callbackElse(*this);
}
}
return true;
return m_promise->setBuffer(_value);
}
uint32_t zeus::FutureBase::getTransactionId() const {
if (m_data == nullptr) {
if (m_promise == nullptr) {
return 0;
}
return m_data->m_transactionId;
return m_promise->getTransactionId();
}
uint32_t zeus::FutureBase::getSource() const {
if (m_data == nullptr) {
if (m_promise == nullptr) {
return 0;
}
return m_data->m_source;
return m_promise->getSource();
}
bool zeus::FutureBase::hasError() const {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if (m_promise == nullptr) {
return true;
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
return true;
}
return static_cast<const zeus::BufferAnswer*>(m_data->m_returnData.get())->hasError();
return m_promise->hasError();
}
std::string zeus::FutureBase::getErrorType() const {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if (m_promise == nullptr) {
return "NULL_PTR";
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
return "NOT_ANSWER_MESSAGE";
}
return static_cast<const zeus::BufferAnswer*>(m_data->m_returnData.get())->getError();
return m_promise->getErrorType();
}
std::string zeus::FutureBase::getErrorHelp() const {
if ( m_data == nullptr
|| m_data->m_returnData == nullptr) {
if (m_promise == nullptr) {
return "This is a nullptr future";
}
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
return "This answer is not a anwser type";
}
return static_cast<const zeus::BufferAnswer*>(m_data->m_returnData.get())->getErrorHelp();
m_promise->getErrorHelp();
}
bool zeus::FutureBase::isValid() const {
return m_data != nullptr;
return m_promise != nullptr;
}
bool zeus::FutureBase::isFinished() const {
if (m_data == nullptr) {
if (m_promise == nullptr) {
return true;
}
if (m_data->m_returnData == nullptr) {
// in this case, we are waiting for an answer that the first packet is not arrived
return false;
}
return m_data->m_returnData->getPartFinish();
return m_promise->isFinished();
}
const zeus::FutureBase& zeus::FutureBase::wait() const {
while (isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if (m_promise == nullptr) {
return *this;
}
m_promise.waitFor(echrono::seconds(5));
return *this;
}
const zeus::FutureBase& zeus::FutureBase::waitFor(std::chrono::microseconds _delta) const {
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
while ( std::chrono::steady_clock::now() - start < _delta
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(std::chrono::milliseconds(10));
start = std::chrono::steady_clock::now();
const zeus::FutureBase& zeus::FutureBase::waitFor(echrono::Duration _delta) const {
if (m_promise == nullptr) {
return *this;
}
m_promise.waitFor(_delta);
return *this;
}
const zeus::FutureBase& zeus::FutureBase::waitUntil(std::chrono::steady_clock::time_point _endTime) const {
while ( std::chrono::steady_clock::now() < _endTime
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(std::chrono::milliseconds(10));
const zeus::FutureBase& zeus::FutureBase::waitUntil(echrono::Steady _endTime) const {
if (m_promise == nullptr) {
return *this;
}
m_promise.waitUntil(_endTime);
return *this;
}

View File

@ -5,7 +5,7 @@
*/
#pragma once
#include <zeus/FutureData.hpp>
#include <zeus/Promise.hpp>
namespace zeus {
/**
@ -13,7 +13,7 @@ namespace zeus {
*/
class FutureBase {
public:
ememory::SharedPtr<zeus::FutureData> m_data; // Reference on the data
ememory::SharedPtr<zeus::Promise> m_promise; // Reference on the data
public:
/**
* @brief Copy contructor of a FutureBase
@ -37,28 +37,28 @@ namespace zeus {
* @param[in] _returnData Set return value
* @param[in] _source Source that is waiting for answer
*/
FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, uint32_t _source=0);
FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::message::Message> _returnData, uint32_t _source=0);
/**
* @brief Attach callback on all return type of value
* @param[in] _callback Handle on the function to call in all case
*/
void andAll(zeus::FutureData::Observer _callback);
void andAll(zeus::Promise::Observer _callback);
/**
* @brief Attach callback on a specific return action (SUCESS)
* @param[in] _callback Handle on the function to call in case of sucess on the call
*/
void andThen(zeus::FutureData::Observer _callback);
void andThen(zeus::Promise::Observer _callback);
/**
* @brief Attach callback on a specific return action (ERROR)
* @param[in] _callback Handle on the function to call in case of error on the call
*/
void andElse(zeus::FutureData::Observer _callback);
void andElse(zeus::Promise::Observer _callback);
/*
/ **
* @brief Attach callback on a specific return action (ABORT)
* @param[in] _callback Handle on the function to call in case of abort on the call
* /
void andAbort(zeus::FutureData::Observer _callback); // an abort is requested in the actiron ...
void andAbort(zeus::Promise::Observer _callback); // an abort is requested in the actiron ...
*/
/**
* @brief Asignement operator with an other future
@ -71,7 +71,7 @@ namespace zeus {
* @param[in] _returnValue Returned buffer
* @return return true if an error occured
*/
bool setBuffer(ememory::SharedPtr<zeus::Buffer> _returnValue);
bool setBuffer(ememory::SharedPtr<zeus::message::Message> _returnValue);
/**
* @brief Get the transaction Id of the Future
* @return Transaction Id requested or 0
@ -117,23 +117,23 @@ namespace zeus {
* @param[in] _delta delay to wait the data arrive
* @return reference on the current futur
*/
const FutureBase& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) const;
const FutureBase& waitFor(echrono::Duration _delta = echrono::seconds(30)) const;
/**
* @brief Wait the Future receive data
* @param[in] _endTime tiem to wait the data
* @return reference on the current futur
*/
const FutureBase& waitUntil(std::chrono::steady_clock::time_point _endTime) const;
const FutureBase& waitUntil(echrono::Steady _endTime) const;
/**
* @brief Get the Buffer receive
* @return pointer on the receive data
*/
ememory::SharedPtr<zeus::Buffer> getRaw();
ememory::SharedPtr<zeus::message::Message> getRaw();
/**
* @brief Get duration of the current trasaction take
* @return Tile in nanosecond to wait answer
*/
std::chrono::nanoseconds getTransmitionTime() const;
echrono::Duration getTransmitionTime() const;
};
}

View File

@ -1,34 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <functional>
#include <ememory/memory.hpp>
namespace zeus {
class FutureBase;
/**
* @brief Data interface of the future (the future can be copied, but the data need to stay...
*/
class FutureData {
public:
//using ObserverFinish = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer
using Observer = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer
public:
uint32_t m_transactionId; //!< waiting answer data
uint32_t m_source; //!< Source of the message.
ememory::SharedPtr<zeus::Buffer> m_returnData; //!< all buffer concatenate or last buffer if synchronous
Observer m_callbackThen; //!< observer callback When data arrive and NO error appear
Observer m_callbackElse; //!< observer callback When data arrive and AN error appear
//Observer m_callbackAbort; //!< observer callback When Action is abort by user
std::chrono::steady_clock::time_point m_sendTime; //!< time when the future has been sended request
std::chrono::steady_clock::time_point m_receiveTime; //!< time when the future has receve answer
};
}

View File

@ -1,113 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <string>
namespace zeus {
/**
* @brief generisation of type of the type of the parameter
*/
class ParamType {
protected:
const std::string m_typeName; //!< generic type
const uint16_t m_id; //!< simplification ID (if possible)
const bool m_isNumber; //!< if the element is a number (convertion possible)
const bool m_isVector; //!< if the element is a vector (convertion possible)
public:
/**
* @brief contructor onf a generic name parameter
* @param[in] _name Name of the parameter
* @param[in] _id Generic Id of the parameter
* @param[in] _isNumber set true of the type is a number
* @param[in] _isVector set true of the type is a vector element
* @return
*/
ParamType(const char* _name = "", uint16_t _id=0, bool _isNumber=false, bool _isVector=false);
/**
* @copydoc zeus::ParamType::ParamType
*/
ParamType(const std::string& _name, uint16_t _id, bool _isNumber=false, bool _isVector=false);
/**
* @brief Get name of tha parameter
* @return string describing the TYPE
*/
const std::string& getName() const;
/**
* @brief Get generic Id of the type
* @return unsigned int containing the type
*/
uint16_t getId() const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type
* @return true if the 2 object are identical
*/
bool operator == (const ParamType& _obj) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type
* @return true if the 2 object are different
*/
bool operator != (const ParamType& _obj) const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type in strin
* @return true if the 2 object are identical
*/
bool operator == (const std::string& _value) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type in string
* @return true if the 2 object are different
*/
bool operator != (const std::string& _value) const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type enum integer
* @return true if the 2 object are identical
*/
bool operator == (const uint16_t& _value) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type enum integer
* @return true if the 2 object are different
*/
bool operator != (const uint16_t& _value) const;
/**
* @brief Check if the type is a number
* @return return true if the type is a number
*/
bool isNumber() const;
/**
* @brief Check if the type is a vector
* @return return true if the type is a vector
*/
bool isVector() const;
};
extern const uint16_t paramTypeObject; //!< van not automatic create a type with the string named object
/**
* @brief Create human readable stream to debug
* @param[in] _os the stream to inject data
* @param[in] _obj Object to display
* @return The inpout stream
*/
std::ostream& operator <<(std::ostream& _os, const zeus::ParamType& _obj);
/**
* @brief Template to automaticly get the type of an generic std type without create a dynamic element
* @return generic parameter created
*/
template<class ZEUS_TYPE>
const ParamType& createType();
/**
* @brief Check the compatibility of 2 parameter type
* @param[in] _first First parameter to check
* @param[in] _second Second parameter to check
* @return Return true if parameters are compatible (thay can be converted)
*/
bool checkCompatibility(const ParamType& _first, const ParamType& _second);
}

183
zeus/Promise.cpp Normal file
View File

@ -0,0 +1,183 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <zeus/Promise.hpp>
#include <zeus/message/Answer.hpp>
#include <zeus/debug.hpp>
zeus::Promise::Promise(uint32_t _transactionId, uint32_t _source) {
m_sendTime = echrono::Steady::now();
m_transactionId = _transactionId;
m_source = _source;
}
ememory::SharedPtr<zeus::message::Message> zeus::Promise::getRaw() {
return m_message;
}
zeus::Promise::Promise(uint32_t _transactionId, ememory::SharedPtr<zeus::message::Message> _returnData, uint32_t _source) {
m_sendTime = echrono::Steady::now();
m_transactionId = _transactionId;
m_source = _source;
m_message = _returnData;
if (isFinished() == true) {
m_receiveTime = echrono::Steady::now();
}
}
void zeus::Promise::andAll(zeus::Promise::Observer _callback) {
// TODO : Lock ...
m_callbackThen = _callback;
m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
if (m_callbackThen != nullptr) {
m_callbackThen(*this);
}
} else {
if (m_callbackElse != nullptr) {
m_callbackElse(*this);
}
}
}
void zeus::Promise::andThen(zeus::Promise::Observer _callback) {
// TODO : Lock ...
m_callbackThen = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == true) {
return;
}
if (m_callbackThen == nullptr) {
return;
}
m_callbackThen(*this);
}
void zeus::Promise::andElse(zeus::Promise::Observer _callback) {
// TODO : Lock ...
m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
return;
}
if (m_callbackElse == nullptr) {
return;
}
m_callbackElse(*this);
}
echrono::Duration zeus::Promise::getTransmitionTime() const {
if (isFinished() == false) {
return echrono::nanoseconds(0);
}
return m_receiveTime - m_sendTime;
}
bool zeus::Promise::setBuffer(ememory::SharedPtr<zeus::message::Message> _value) {
m_receiveTime = echrono::Steady::now();
m_message = _value;
if (m_message == nullptr) {
return true;
}
if (m_message->getPartFinish() == false) {
ZEUS_ERROR("set buffer that is not finished ...");
return false;
}
if (hasError() == false) {
if (m_callbackThen != nullptr) {
return m_callbackThen(*this);
}
} else {
if (m_callbackElse != nullptr) {
return m_callbackElse(*this);
}
}
return true;
}
uint32_t zeus::Promise::getTransactionId() const {
return m_transactionId;
}
uint32_t zeus::Promise::getSource() const {
return m_source;
}
bool zeus::Promise::hasError() const {
if (m_message == nullptr) {
return true;
}
if (m_message->getType() != zeus::message::Message::typeMessage::answer) {
return true;
}
return static_cast<const zeus::message::Answer*>(m_message.get())->hasError();
}
std::string zeus::Promise::getErrorType() const {
if (m_message == nullptr) {
return "NULL_PTR";
}
if (m_message->getType() != zeus::message::Message::typeMessage::answer) {
return "NOT_ANSWER_MESSAGE";
}
return static_cast<const zeus::message::Answer*>(m_message.get())->getError();
}
std::string zeus::Promise::getErrorHelp() const {
if (m_message == nullptr) {
return "This is a nullptr future";
}
if (m_message->getType() != zeus::message::Message::typeMessage::answer) {
return "This answer is not a anwser type";
}
return static_cast<const zeus::message::Answer*>(m_message.get())->getErrorHelp();
}
bool zeus::Promise::isFinished() const {
if (m_message == nullptr) {
// in this case, we are waiting for an answer that the first packet is not arrived
return false;
}
return m_message->getPartFinish();
}
const zeus::Promise& zeus::Promise::wait() const {
while (isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(echrono::milliseconds(10));
}
return *this;
}
const zeus::Promise& zeus::Promise::waitFor(echrono::Duration _delta) const {
echrono::Steady start = echrono::Steady::now();
while ( echrono::Steady::now() - start < _delta
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(echrono::milliseconds(10));
start = echrono::Steady::now();
}
return *this;
}
const zeus::Promise& zeus::Promise::waitUntil(echrono::Steady _endTime) const {
while ( echrono::Steady::now() < _endTime
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(echrono::milliseconds(10));
}
return *this;
}

133
zeus/Promise.hpp Normal file
View File

@ -0,0 +1,133 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <zeus/message/Message.hpp>
#include <functional>
#include <ememory/memory.hpp>
namespace zeus {
class FutureBase;
/**
* @brief Data interface of the future (the future can be copied, but the data need to stay...
*/
class Promise {
public:
using Observer = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer
private:
uint32_t m_transactionId; //!< waiting answer data
uint32_t m_source; //!< Source of the message.
ememory::SharedPtr<zeus::message::Message> m_message; //!< all buffer concatenate or last buffer if synchronous
Observer m_callbackThen; //!< observer callback When data arrive and NO error appear
Observer m_callbackElse; //!< observer callback When data arrive and AN error appear
//Observer m_callbackAbort; //!< observer callback When Action is abort by user
echrono::Steady m_sendTime; //!< time when the future has been sended request
echrono::Steady m_receiveTime; //!< time when the future has receve answer
public:
/**
* @brief Contructor of the FutureBase with an ofserver
* @param[in] _transactionId Transaction waiting answer
* @param[in] _source Client/sevice Id waiting answer
*/
Promise(uint32_t _transactionId, uint32_t _source=0);
/**
* @brief Contructor of the FutureBase for direct error answer
* @param[in] _transactionId Transaction waiting answer
* @param[in] _isFinished set state finish or not
* @param[in] _returnData Set return value
* @param[in] _source Source that is waiting for answer
*/
Promise(uint32_t _transactionId, ememory::SharedPtr<zeus::message::Message> _returnData, uint32_t _source=0);
/**
* @brief Attach callback on all return type of value
* @param[in] _callback Handle on the function to call in all case
*/
void andAll(zeus::Promise::Observer _callback);
/**
* @brief Attach callback on a specific return action (SUCESS)
* @param[in] _callback Handle on the function to call in case of sucess on the call
*/
void andThen(zeus::Promise::Observer _callback);
/**
* @brief Attach callback on a specific return action (ERROR)
* @param[in] _callback Handle on the function to call in case of error on the call
*/
void andElse(zeus::Promise::Observer _callback);
/*
/ **
* @brief Attach callback on a specific return action (ABORT)
* @param[in] _callback Handle on the function to call in case of abort on the call
* /
void andAbort(zeus::Promise::Observer _callback); // an abort is requested in the actiron ...
*/
/**
* @brief Add data on the call/answer
* @param[in] _returnValue Returned buffer
* @return return true if an error occured
*/
bool setBuffer(ememory::SharedPtr<zeus::message::Message> _returnValue);
/**
* @brief Get the transaction Id of the Future
* @return Transaction Id requested or 0
*/
uint32_t getTransactionId() const;
/**
* @brief Get the client Id of the Future
* @return Client id requested or 0
*/
uint32_t getSource() const;
/**
* @brief check if the answer have an error
* @return return true if an error is registered
*/
bool hasError() const;
/**
* @brief get type of the error
* @return the string of the error type
*/
std::string getErrorType() const;
/**
* @brief get help of the error
* @return the string of the error help
*/
std::string getErrorHelp() const;
/**
* @brief Check if the futur have finish receiving data
* @return status of the fisnish state
*/
bool isFinished() const;
/**
* @brief Wait the Future receive data
* @return reference on the current futur
*/
const FutureBase& wait() const;
/**
* @brief Wait the Future receive data
* @param[in] _delta delay to wait the data arrive
* @return reference on the current futur
*/
const FutureBase& waitFor(echrono::Duration _delta = echrono::seconds(30)) const;
/**
* @brief Wait the Future receive data
* @param[in] _endTime tiem to wait the data
* @return reference on the current futur
*/
const FutureBase& waitUntil(echrono::Steady _endTime) const;
/**
* @brief Get the Buffer receive
* @return pointer on the receive data
*/
ememory::SharedPtr<zeus::message::Message> getRaw();
/**
* @brief Get duration of the current trasaction take
* @return Tile in nanosecond to wait answer
*/
echrono::Duration getTransmitionTime() const;
};
}

View File

@ -4,25 +4,25 @@
* @license APACHE v2.0 (see license file)
*/
#include <zeus/BaseProxy.hpp>
#include <zeus/Proxy.hpp>
#include <zeus/debug.hpp>
const zeus::BaseProxy& zeus::BaseProxy::operator= (const zeus::ObjectRemote& _obj) {
const zeus::Proxy& zeus::Proxy::operator= (const zeus::ObjectRemote& _obj) {
m_obj = _obj;
return *this;
}
zeus::BaseProxy::BaseProxy():
zeus::Proxy::Proxy():
sys(m_obj) {
}
zeus::BaseProxy::BaseProxy(const zeus::ObjectRemote& _obj):
zeus::Proxy::Proxy(const zeus::ObjectRemote& _obj):
m_obj(_obj),
sys(m_obj) {
}
bool zeus::BaseProxy::exist() const {
bool zeus::Proxy::exist() const {
return m_obj.exist();
}

View File

@ -6,22 +6,22 @@
#pragma once
#include <zeus/ObjectRemote.hpp>
#include <zeus/SystemProxy.hpp>
#include <zeus/ObjectIntrospection.hpp>
namespace zeus {
/**
* @brief Proxy base interface
*/
class BaseProxy {
class Proxy {
protected:
zeus::ObjectRemote m_obj; //!< Service instance handle
public:
zeus::SystemProxy sys;
zeus::ObjectIntrospection sys;
public:
const BaseProxy& operator= (const zeus::ObjectRemote& _srv);
BaseProxy();
virtual ~BaseProxy() = default;
BaseProxy(const zeus::ObjectRemote& _srv);
const Proxy& operator= (const zeus::ObjectRemote& _srv);
Proxy();
virtual ~Proxy() = default;
Proxy(const zeus::ObjectRemote& _srv);
bool exist() const;
};
}

View File

View File

View File

@ -7,8 +7,8 @@
#include <zeus/debug.hpp>
#include <ethread/tools.hpp>
#include <zeus/BufferData.hpp>
#include <zeus/BufferCtrl.hpp>
#include <zeus/message/Data.hpp>
#include <zeus/message/Ctrl.hpp>
ememory::SharedPtr<zeus::BufferCall> zeus::createBaseCall(const ememory::SharedPtr<zeus::WebServer>& _iface, uint64_t _transactionId, const uint32_t& _source, const uint32_t& _destination, const std::string& _functionName) {

View File

@ -4,8 +4,8 @@
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <zeus/Buffer.hpp>
#include <zeus/BufferAnswer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/message/Answer.hpp>
#include <enet/WebSocket.hpp>
#include <thread>
#include <ememory/memory.hpp>

View File

@ -4,13 +4,13 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferAnswer.hpp>
#include <zeus/message/Answer.hpp>
void zeus::BufferAnswer::generateDisplay(std::ostream& _os) const {
void zeus::message::Answer::generateDisplay(std::ostream& _os) const {
zeus::Buffer::generateDisplay(_os);
if (getNumberParameter() != 0) {
_os << " '" + simpleStringParam(0) + "'";
@ -22,24 +22,24 @@ void zeus::BufferAnswer::generateDisplay(std::ostream& _os) const {
}
}
bool zeus::BufferAnswer::hasError() const {
bool zeus::message::Answer::hasError() const {
return m_errorType.size() != 0;
}
const std::string& zeus::BufferAnswer::getError() const {
const std::string& zeus::message::Answer::getError() const {
return m_errorType;
}
const std::string& zeus::BufferAnswer::getErrorHelp() const {
const std::string& zeus::message::Answer::getErrorHelp() const {
return m_errorHelp;
}
void zeus::BufferAnswer::addError(const std::string& _value, const std::string& _comment) {
void zeus::message::Answer::addError(const std::string& _value, const std::string& _comment) {
m_errorType = _value;
m_errorHelp = _comment;
}
bool zeus::BufferAnswer::writeOn(enet::WebSocket& _interface) {
bool zeus::message::Answer::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) {
@ -48,7 +48,7 @@ bool zeus::BufferAnswer::writeOn(enet::WebSocket& _interface) {
return BufferParameter::writeOn(_interface);
}
void zeus::BufferAnswer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
void zeus::message::Answer::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;
@ -72,7 +72,7 @@ void zeus::BufferAnswer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
}
void zeus::BufferAnswer::appendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
void zeus::message::Answer::appendBufferData(ememory::SharedPtr<zeus::message::Data> _obj) {
parameterAppendBufferData(_obj);
}
@ -80,7 +80,7 @@ void zeus::BufferAnswer::appendBufferData(ememory::SharedPtr<zeus::BufferData> _
// -- Factory
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::BufferAnswer> zeus::BufferAnswer::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::BufferAnswer>(new zeus::BufferAnswer(_iface));
ememory::SharedPtr<zeus::message::Answer> zeus::message::Answer::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::message::Answer>(new zeus::message::Answer(_iface));
}

82
zeus/message/Answer.hpp Normal file
View File

@ -0,0 +1,82 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/message/Parameter.hpp>
namespace zeus {
class WebServer;
namespace message {
class Answer :
public message::Parameter {
friend class zeus::message::Message;
protected:
std::string m_errorType;
std::string m_errorHelp;
protected:
/**
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Answer::create
*/
Answer(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::message::Parameter(_iface) {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::message::type::answer);
};
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
void appendBufferData(ememory::SharedPtr<zeus::message::Data> _obj) override;
bool writeOn(enet::WebSocket& _interface) override;
void generateDisplay(std::ostream& _os) const override;
public:
/**
* @brief Create a shared pointer on the Answer
* @return Allocated Buffer.
*/
static ememory::SharedPtr<zeus::Answer> create(ememory::SharedPtr<zeus::WebServer> _iface);
public:
enum zeus::message::type getType() const override {
return zeus::message::type::answer;
}
/**
* @brief set the answer of the call
* @param[in] _value Value to add
*/
template<class ZEUS_TYPE_DATA>
void addAnswer(const ememory::SharedPtr<zeus::WebServer>& _iface, const ZEUS_TYPE_DATA& _value) {
addParameter(_iface, _value);
}
/**
* @brief get the answer value
* @param[in] Data of the answer
*/
template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getAnswer() const {
return getParameter<ZEUS_TYPE_DATA>(m_iface, 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() const;
/**
* @brief get the error value (if exist)
* @return string of the error
*/
const std::string& getError() const;
/**
* @brief get the error help (if exist)
* @return string of the error help
*/
const std::string& getErrorHelp() const;
};
}
}

View File

@ -4,13 +4,13 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferCall.hpp>
#include <zeus/message/Call.hpp>
void zeus::BufferCall::generateDisplay(std::ostream& _os) const {
void zeus::message::Call::generateDisplay(std::ostream& _os) const {
zeus::Buffer::generateDisplay(_os);
_os << " '" + m_callName + "'";
_os << " nbParam=" + etk::to_string(getNumberParameter());
@ -26,21 +26,21 @@ void zeus::BufferCall::generateDisplay(std::ostream& _os) const {
}
}
const std::string& zeus::BufferCall::getCall() const {
const std::string& zeus::message::Call::getCall() const {
return m_callName;
}
void zeus::BufferCall::setCall(const std::string& _value) {
void zeus::message::Call::setCall(const std::string& _value) {
m_callName = _value;
}
bool zeus::BufferCall::writeOn(enet::WebSocket& _interface) {
bool zeus::message::Call::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) {
void zeus::message::Call::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;
@ -55,7 +55,7 @@ void zeus::BufferCall::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
BufferParameter::composeWith(&_buffer[pos], _lenght-pos);
}
void zeus::BufferCall::appendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
void zeus::message::Call::appendBufferData(ememory::SharedPtr<zeus::message::Data> _obj) {
parameterAppendBufferData(_obj);
}
@ -64,6 +64,6 @@ void zeus::BufferCall::appendBufferData(ememory::SharedPtr<zeus::BufferData> _ob
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::BufferCall> zeus::BufferCall::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::BufferCall>(new zeus::BufferCall(_iface));
ememory::SharedPtr<zeus::message::Call> zeus::message::Call::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::message::Call>(new zeus::message::Call(_iface));
}

54
zeus/message/Call.hpp Normal file
View File

@ -0,0 +1,54 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/message/Parameter.hpp>
namespace zeus {
namespace message {
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(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::BufferParameter(_iface) {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::message::type::call);
};
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
void appendBufferData(ememory::SharedPtr<zeus::message::Data> _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(ememory::SharedPtr<zeus::WebServer> _iface);
public:
enum zeus::message::type getType() const override {
return zeus::message::type::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);
};
}
}

View File

@ -4,31 +4,31 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferData.hpp>
#include <zeus/message/Data.hpp>
void zeus::BufferData::generateDisplay(std::ostream& _os) const {
void zeus::message::Data::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) {
void zeus::message::Data::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 {
uint32_t zeus::message::Data::getPartId() const {
return m_partId;
}
void zeus::BufferData::setPartId(uint32_t _value) {
void zeus::message::Data::setPartId(uint32_t _value) {
if (_value == 0) {
ZEUS_ERROR("Part ID must be != of 0");
return;
@ -36,7 +36,7 @@ void zeus::BufferData::setPartId(uint32_t _value) {
m_partId = _value;
}
bool zeus::BufferData::writeOn(enet::WebSocket& _interface) {
bool zeus::message::Data::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));
@ -44,7 +44,7 @@ bool zeus::BufferData::writeOn(enet::WebSocket& _interface) {
return true;
}
void zeus::BufferData::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
void zeus::message::Data::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;
@ -62,6 +62,6 @@ void zeus::BufferData::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
// -- Factory
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::BufferData> zeus::BufferData::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::BufferData>(new zeus::BufferData(_iface));
ememory::SharedPtr<zeus::message::Data> zeus::message::Data::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::message::Data>(new zeus::message::Data(_iface));
}

77
zeus/message/Data.hpp Normal file
View File

@ -0,0 +1,77 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/message/Message.hpp>
namespace zeus {
namespace message {
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
*/
Data(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::Message(_iface),
m_partId(0) {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::message::type::data);
};
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
// TODO :... void appendBufferData(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::message::Data> create(ememory::SharedPtr<zeus::WebServer> _iface);
public:
enum zeus::message::type getType() const override {
return zeus::message::type::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;
}
};
}
}

View File

@ -4,11 +4,11 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Buffer.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferEvent.hpp>
#include <zeus/message/Event.hpp>
/*
// ------------------------------------------------------------------------------------

41
zeus/message/Event.hpp Normal file
View File

@ -0,0 +1,41 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
namespace zeus {
namespace message {
/*
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::message::type::event);
};
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
void appendBufferData(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::message::type getType() const override {
return zeus::message::type::event;
}
};
*/
}
}

View File

@ -4,11 +4,11 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferFlow.hpp>
#include <zeus/message/Flow.hpp>
/*
// ------------------------------------------------------------------------------------

39
zeus/message/Flow.hpp Normal file
View File

@ -0,0 +1,39 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
namespace zeus {
namespace message {
/*
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::message::type::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::message::type getType() const override {
return zeus::message::type::flow;
}
};
*/
}
}

View File

@ -4,77 +4,34 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/AbstractFunction.hpp>
#include <climits>
#include <zeus/BufferAnswer.hpp>
#include <zeus/BufferCtrl.hpp>
#include <zeus/BufferCall.hpp>
#include <zeus/BufferData.hpp>
#include <zeus/BufferFlow.hpp>
#include <zeus/BufferEvent.hpp>
#include <zeus/message/Answer.hpp>
#include <zeus/message/Call.hpp>
#include <zeus/message/Data.hpp>
#include <zeus/message/Flow.hpp>
#include <zeus/message/Event.hpp>
#include <zeus/WebServer.hpp>
namespace etk {
template<> std::string to_string<enum zeus::Buffer::typeMessage>(const enum zeus::Buffer::typeMessage& _value) {
switch (_value) {
case zeus::Buffer::typeMessage::unknow:
return "unknow";
case zeus::Buffer::typeMessage::ctrl:
return "ctrl";
case zeus::Buffer::typeMessage::call:
return "call";
case zeus::Buffer::typeMessage::answer:
return "answer";
case zeus::Buffer::typeMessage::event:
return "event";
case zeus::Buffer::typeMessage::data:
return "data";
}
return "???";
}
}
std::ostream& zeus::operator <<(std::ostream& _os, enum zeus::Buffer::typeMessage _value) {
_os << etk::to_string(_value);
return _os;
}
static enum zeus::Buffer::typeMessage getTypeType(uint16_t _value) {
switch (_value) {
case 0:
return zeus::Buffer::typeMessage::unknow;
case 1:
return zeus::Buffer::typeMessage::ctrl;
case 2:
return zeus::Buffer::typeMessage::call;
case 3:
return zeus::Buffer::typeMessage::answer;
case 4:
return zeus::Buffer::typeMessage::data;
case 5:
return zeus::Buffer::typeMessage::event;
}
return zeus::Buffer::typeMessage::unknow;
}
zeus::Buffer::Buffer(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::message::Message(ememory::SharedPtr<zeus::WebServer> _iface):
m_iface(_iface) {
clear();
}
void zeus::Buffer::appendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
void zeus::message::appendBufferData(ememory::SharedPtr<zeus::MessageData> _obj) {
ZEUS_ERROR("Can not append datas ... Not managed");
}
void zeus::Buffer::appendBuffer(ememory::SharedPtr<zeus::Buffer> _obj) {
void zeus::message::appendBuffer(ememory::SharedPtr<zeus::Message> _obj) {
if (_obj == nullptr) {
return;
}
if (_obj->getType() != zeus::Buffer::typeMessage::data) {
if (_obj->getType() != zeus::message::type::data) {
ZEUS_ERROR("try to add data with a wrong buffer: " << _obj->getType() << " ==> set the buffer finish ...");
// close the connection ...
setPartFinish(true);
@ -82,10 +39,10 @@ void zeus::Buffer::appendBuffer(ememory::SharedPtr<zeus::Buffer> _obj) {
return;
}
setPartFinish(_obj->getPartFinish());
appendBufferData(ememory::staticPointerCast<zeus::BufferData>(_obj));
appendBufferData(ememory::staticPointerCast<zeus::MessageData>(_obj));
}
bool zeus::Buffer::writeOn(enet::WebSocket& _interface) {
bool zeus::message::writeOn(enet::WebSocket& _interface) {
if (_interface.configHeader(false) == false) {
return false;
}
@ -94,11 +51,11 @@ bool zeus::Buffer::writeOn(enet::WebSocket& _interface) {
}
void zeus::Buffer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
void zeus::message::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
// impossible case
}
void zeus::Buffer::clear() {
void zeus::message::clear() {
m_header.transactionId = 1;
m_header.sourceId = 0;
m_header.sourceObjectId = 0;
@ -107,8 +64,8 @@ void zeus::Buffer::clear() {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH;
}
std::ostream& zeus::operator <<(std::ostream& _os, ememory::SharedPtr<zeus::Buffer> _obj) {
_os << "zeus::Buffer: ";
std::ostream& zeus::operator <<(std::ostream& _os, ememory::SharedPtr<zeus::Message> _obj) {
_os << "zeus::Message: ";
if (_obj == nullptr) {
_os << "nullptr";
} else {
@ -116,7 +73,7 @@ std::ostream& zeus::operator <<(std::ostream& _os, ememory::SharedPtr<zeus::Buff
}
return _os;
}
void zeus::Buffer::generateDisplay(std::ostream& _os) const {
void zeus::message::generateDisplay(std::ostream& _os) const {
//out += " v=" + etk::to_string(m_header.versionProtocol); // set it in the websocket
_os << " if=" << etk::to_string(getInterfaceId());
_os << " tr-id=" << etk::to_string(getTransactionId());
@ -125,100 +82,100 @@ void zeus::Buffer::generateDisplay(std::ostream& _os) const {
if (getPartFinish() == true) {
_os << " finish";
}
enum zeus::Buffer::typeMessage type = getType();
enum zeus::message::type type = getType();
switch (type) {
case zeus::Buffer::typeMessage::unknow:
case zeus::message::type::unknow:
_os << " -UNKNOW-";
break;
case zeus::Buffer::typeMessage::ctrl:
case zeus::message::type::ctrl:
_os << " -CTRL-";
break;
case zeus::Buffer::typeMessage::call:
case zeus::message::type::call:
_os << " -CALL-";
break;
case zeus::Buffer::typeMessage::answer:
case zeus::message::type::answer:
_os << " -ANSWER-";
break;
case zeus::Buffer::typeMessage::event:
case zeus::message::type::event:
_os << " -EVENT-";
break;
case zeus::Buffer::typeMessage::data:
case zeus::message::type::data:
_os << " -DATA-";
break;
}
}
uint32_t zeus::Buffer::getInterfaceId() const {
uint32_t zeus::message::getInterfaceId() const {
return m_interfaceID;
}
void zeus::Buffer::setInterfaceId(uint32_t _value) {
void zeus::message::setInterfaceId(uint32_t _value) {
m_interfaceID = _value;
}
uint32_t zeus::Buffer::getTransactionId() const {
uint32_t zeus::message::getTransactionId() const {
return m_header.transactionId;
}
void zeus::Buffer::setTransactionId(uint32_t _value) {
void zeus::message::setTransactionId(uint32_t _value) {
m_header.transactionId = _value;
}
uint32_t zeus::Buffer::getSource() const {
uint32_t zeus::message::getSource() const {
return (uint32_t(m_header.sourceId) << 16) + m_header.sourceObjectId;
}
void zeus::Buffer::setSource(uint32_t _value) {
void zeus::message::setSource(uint32_t _value) {
m_header.sourceId = _value >> 16;
m_header.sourceObjectId = _value & 0xFFFF;
}
uint16_t zeus::Buffer::getSourceId() const {
uint16_t zeus::message::getSourceId() const {
return m_header.sourceId;
}
void zeus::Buffer::setSourceId(uint16_t _value) {
void zeus::message::setSourceId(uint16_t _value) {
m_header.sourceId = _value;
}
uint16_t zeus::Buffer::getSourceObjectId() const {
uint16_t zeus::message::getSourceObjectId() const {
return m_header.sourceObjectId;
}
void zeus::Buffer::setSourceObjectId(uint16_t _value) {
void zeus::message::setSourceObjectId(uint16_t _value) {
m_header.sourceObjectId = _value;
}
uint32_t zeus::Buffer::getDestination() const {
uint32_t zeus::message::getDestination() const {
return (uint32_t(m_header.destinationId) << 16) + m_header.destinationObjectId;
}
void zeus::Buffer::setDestination(uint32_t _value) {
void zeus::message::setDestination(uint32_t _value) {
m_header.destinationId = _value >> 16;
m_header.destinationObjectId = _value & 0xFFFF;
}
uint16_t zeus::Buffer::getDestinationId() const {
uint16_t zeus::message::getDestinationId() const {
return m_header.destinationId;
}
void zeus::Buffer::setDestinationId(uint16_t _value) {
void zeus::message::setDestinationId(uint16_t _value) {
m_header.destinationId = _value;
}
uint16_t zeus::Buffer::getDestinationObjectId() const {
uint16_t zeus::message::getDestinationObjectId() const {
return m_header.destinationObjectId;
}
void zeus::Buffer::setDestinationObjectId(uint16_t _value) {
void zeus::message::setDestinationObjectId(uint16_t _value) {
m_header.destinationObjectId = _value;
}
bool zeus::Buffer::getPartFinish() const {
bool zeus::message::getPartFinish() const {
return (m_header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0;
}
void zeus::Buffer::setPartFinish(bool _value) {
void zeus::message::setPartFinish(bool _value) {
if (_value == true) {
m_header.flags = (m_header.flags & 0x7F) | ZEUS_BUFFER_FLAG_FINISH;
} else {
@ -226,30 +183,30 @@ void zeus::Buffer::setPartFinish(bool _value) {
}
}
enum zeus::Buffer::typeMessage zeus::Buffer::getType() const {
return zeus::Buffer::typeMessage::unknow;
enum zeus::message::type zeus::message::getType() const {
return zeus::message::type::unknow;
}
// ------------------------------------------------------------------------------------
// -- Factory
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::Buffer>(new zeus::Buffer(_iface));
ememory::SharedPtr<zeus::Message> zeus::message::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::Message>(new zeus::Message(_iface));
}
ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::WebServer> _iface, const std::vector<uint8_t>& _buffer) {
ememory::SharedPtr<zeus::Message> zeus::message::create(ememory::SharedPtr<zeus::WebServer> _iface, const std::vector<uint8_t>& _buffer) {
headerBin header;
if (_buffer.size() < sizeof(headerBin)) {
ZEUS_ERROR("wrong size of the buffer");
return nullptr;
}
memcpy(reinterpret_cast<char*>(&header), &_buffer[0], sizeof(headerBin));
enum zeus::Buffer::typeMessage type = getTypeType(uint16_t(header.flags & 0x07));
enum zeus::message::type type = getTypeType(uint16_t(header.flags & 0x07));
switch (type) {
case zeus::Buffer::typeMessage::unknow:
case zeus::message::type::unknow:
return nullptr;
case zeus::Buffer::typeMessage::ctrl: {
ememory::SharedPtr<zeus::BufferCtrl> value = zeus::BufferCtrl::create(_iface);
case zeus::message::type::ctrl: {
ememory::SharedPtr<zeus::MessageCtrl> value = zeus::MessageCtrl::create(_iface);
if (value == nullptr) {
return nullptr;
}
@ -264,8 +221,8 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::W
return value;
}
break;
case zeus::Buffer::typeMessage::call: {
ememory::SharedPtr<zeus::BufferCall> value = zeus::BufferCall::create(_iface);
case zeus::message::type::call: {
ememory::SharedPtr<zeus::MessageCall> value = zeus::MessageCall::create(_iface);
if (value == nullptr) {
return nullptr;
}
@ -280,8 +237,8 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::W
return value;
}
break;
case zeus::Buffer::typeMessage::answer: {
ememory::SharedPtr<zeus::BufferAnswer> value = zeus::BufferAnswer::create(_iface);
case zeus::message::type::answer: {
ememory::SharedPtr<zeus::MessageAnswer> value = zeus::MessageAnswer::create(_iface);
if (value == nullptr) {
return nullptr;
}
@ -296,8 +253,8 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::W
return value;
}
break;
case zeus::Buffer::typeMessage::data: {
ememory::SharedPtr<zeus::BufferData> value = zeus::BufferData::create(_iface);
case zeus::message::type::data: {
ememory::SharedPtr<zeus::MessageData> value = zeus::MessageData::create(_iface);
if (value == nullptr) {
return nullptr;
}
@ -312,7 +269,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(ememory::SharedPtr<zeus::W
return value;
}
break;
case zeus::Buffer::typeMessage::event:
case zeus::message::type::event:
break;
}

View File

@ -6,7 +6,8 @@
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/message/type.hpp>
namespace zeus {
class WebServer;
@ -17,119 +18,121 @@ 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; //!< Transaction ID : Note the Upper byte is reserved for next protocol version (like change in protocol v2 with changing header)
uint16_t sourceId; //!< Source of the message
uint16_t sourceObjectId; //!< Source Object ID
uint16_t destinationId; //!< Destination of the message
uint16_t destinationObjectId; //!< Destination Object ID
uint8_t flags; // List of flags & type message:
// - 0-2: Type of the message
// - 3-5: Reserved
// - 6: message data is zipped
// - 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
======================
== call
======================
U16 param count
U16[param count] parameters offset (first offset is the "callName" and limit size of the number of parameter
CALL Name (funtion name)
[param 1]
[param 2]
[param 3]
[param 4]
======================
== Answer
======================
U16 param count = 3
U16[param count]
[param 1] (return value)
[param 2] (error value)
[param 3] (error help)
[error] (constituated with 2 strings (error type and comment)
======================
== event
======================
U16[param count] parameters offset (first offset is the "callName" and limit size of the number of parameter
event Name
[param 1]
[param 2]
[param 3]
[param 4]
---------------------------
parameter and return value is contituated like:
TYPE,DATAs....(in raw)
Type is write in ascii in the list end with '\0':
- void
- bool
- float32
- float64
- int64
- int32
- int16
- int8
- uint64
- uint32
- uint16
- uint8
- string
- vector:bool
- vector:float32
- vector:float64
- vector:int64
- vector:int32
- vector:int16
- vector:int8
- vector:uint64
- vector:uint32
- vector:uint16
- vector:uint8
- vector:string
- obj:file
- duration
- time
*/
namespace message {
class Data;
//U32 message lenght
#pragma pack(push,1)
struct headerBin {
//uint16_t versionProtocol; // protocol Version (might be 1)
uint32_t transactionId; //!< Transaction ID : Note the Upper byte is reserved for next protocol version (like change in protocol v2 with changing header)
uint16_t sourceId; //!< Source of the message
uint16_t sourceObjectId; //!< Source Object ID
uint16_t destinationId; //!< Destination of the message
uint16_t destinationObjectId; //!< Destination Object ID
uint8_t flags; // List of flags & type message:
// - 0-2: Type of the message
// - 3-5: Reserved
// - 6: message data is zipped
// - 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
======================
== call
======================
U16 param count
U16[param count] parameters offset (first offset is the "callName" and limit size of the number of parameter
CALL Name (funtion name)
[param 1]
[param 2]
[param 3]
[param 4]
======================
== Answer
======================
U16 param count = 3
U16[param count]
[param 1] (return value)
[param 2] (error value)
[param 3] (error help)
[error] (constituated with 2 strings (error type and comment)
======================
== event
======================
U16[param count] parameters offset (first offset is the "callName" and limit size of the number of parameter
event Name
[param 1]
[param 2]
[param 3]
[param 4]
---------------------------
parameter and return value is contituated like:
TYPE,DATAs....(in raw)
Type is write in ascii in the list end with '\0':
- void
- bool
- float32
- float64
- int64
- int32
- int16
- int8
- uint64
- uint32
- uint16
- uint8
- string
- vector:bool
- vector:float32
- vector:float64
- vector:int64
- vector:int32
- vector:int16
- vector:int8
- vector:uint64
- vector:uint32
- vector:uint16
- vector:uint8
- vector:string
- obj:file
- duration
- time
*/
}
#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&, zeus::Buffer*);
class Message {
friend std::ostream& operator<<(std::ostream&, zeus::Message*);
protected:
ememory::SharedPtr<zeus::WebServer> m_iface;
protected:
/**
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Buffer::create
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Message::create
*/
Buffer(ememory::SharedPtr<zeus::WebServer> _iface);
Message(ememory::SharedPtr<zeus::WebServer> _iface);
public:
/**
* Virtualize the buffer class
*/
virtual ~Buffer() = default;
virtual ~Message() = default;
/**
* @brief Create a shared pointer on the buffer
* @return Allocated Buffer.
*/
static ememory::SharedPtr<zeus::Buffer> create(ememory::SharedPtr<zeus::WebServer> _iface);
static ememory::SharedPtr<zeus::Message> create(ememory::SharedPtr<zeus::WebServer> _iface);
/**
* @brief Create a shared pointer on the buffer
* @param[in] _buffer Buffer on the data
* @return Allocated Buffer.
*/
static ememory::SharedPtr<zeus::Buffer> create(ememory::SharedPtr<zeus::WebServer> _iface, const std::vector<uint8_t>& _buffer);
static ememory::SharedPtr<zeus::Message> create(ememory::SharedPtr<zeus::WebServer> _iface, const std::vector<uint8_t>& _buffer);
protected:
uint32_t m_interfaceID; //!< For debug ==> unterface ID ...
headerBin m_header; //!< header of the protocol
message::headerBin m_header; //!< header of the protocol
std::vector<zeus::ActionAsyncClient> m_multipleSend; //!< Async element to send data on the webinterface when too big ...
public:
/**
@ -150,8 +153,8 @@ 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 appendBuffer(ememory::SharedPtr<zeus::Buffer> _obj);
virtual void appendBufferData(ememory::SharedPtr<zeus::BufferData> _obj);
void appendBuffer(ememory::SharedPtr<zeus::Message> _obj);
virtual void appendBufferData(ememory::SharedPtr<zeus::MessageData> _obj);
protected:
/**
* @brief When receive new data form websocket, it might be added by this input (set all the frame ...)
@ -254,22 +257,11 @@ namespace zeus {
* @param[in] _value set the sate of finish of the buffer
*/
void setPartFinish(bool _value);
/**
* @brief Type of the massage send or receive
*/
enum class typeMessage {
unknow = 0x0000, //!< Init value
ctrl = 0x0001, //!< Control message
call = 0x0002, //!< Remote call on a service ID
answer = 0x0003, //!< Answer from a previous call
data = 0x0004, //!< data message happend when partId > 0 it compleate the data of a parameter or an answer or an event
event = 0x0005, //!< event message
};
/**
* @brief Get the type of the buffer
* @return the current type of the buffer
*/
virtual enum typeMessage getType() const;
virtual enum zeus::message::type getType() const;
public:
/**
* @brief Write the buffer on a specific interface
@ -279,33 +271,28 @@ namespace zeus {
virtual bool writeOn(enet::WebSocket& _interface);
virtual void generateDisplay(std::ostream& _os) const ;
};
/**
* @brief generate a display of the typemessage
* @param[in] _os stream to add data
* @value[in] _value Value to add
* @return a reference of the stream
*/
std::ostream& operator <<(std::ostream& _os, enum zeus::Buffer::typeMessage _value);
/**
* @brief generate a display of the typemessage
* @param[in] _os stream to add data
* @value[in] _obj Buffer to display
* @return a reference of the stream
*/
std::ostream& operator <<(std::ostream& _os, ememory::SharedPtr<zeus::Buffer> _obj);
std::ostream& operator <<(std::ostream& _os, ememory::SharedPtr<zeus::Message> _obj);
// internal:
/**
* @brief Add a parameter generic type in the buffer
* @param[in] _data Buffer to add type
* @param[in] _type generic type to add
*/
void addType(std::vector<uint8_t>& _data, zeus::ParamType _type);
/**
* @brief Add a parameter object type in the buffer
* @param[in] _data Buffer to add type
* @param[in] _type string of the type to add
*/
void addTypeObject(std::vector<uint8_t>& _data, const std::string _type);
namespace message {
// internal:
/**
* @brief Add a parameter generic type in the buffer
* @param[in] _data Buffer to add type
* @param[in] _type generic type to add
*/
void addType(std::vector<uint8_t>& _data, zeus::ParamType _type);
/**
* @brief Add a parameter object type in the buffer
* @param[in] _data Buffer to add type
* @param[in] _type string of the type to add
*/
void addTypeObject(std::vector<uint8_t>& _data, const std::string _type);
}
}

View File

@ -4,12 +4,12 @@
* @license APACHE v2.0 (see license file)
*/
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <zeus/debug.hpp>
#include <zeus/File.hpp>
bool zeus::checkCompatibility(const ParamType& _type, const ParamType& _params) {
bool zeus::message::checkCompatibility(const ParamType& _type, const ParamType& _params) {
if (_params == _type) {
return true;
}
@ -22,19 +22,19 @@ bool zeus::checkCompatibility(const ParamType& _type, const ParamType& _params)
}
std::ostream& zeus::operator <<(std::ostream& _os, const zeus::ParamType& _obj) {
std::ostream& zeus::message::operator <<(std::ostream& _os, const zeus::message::ParamType& _obj) {
_os << "{" << _obj.getId() << ":" << _obj.getName() << "}";
return _os;
}
zeus::ParamType::ParamType(const char* _name, uint16_t _id, bool _isNumber, bool _isVector):
zeus::message::ParamType::ParamType(const char* _name, uint16_t _id, bool _isNumber, bool _isVector):
m_typeName(_name),
m_id(_id),
m_isNumber(_isNumber),
m_isVector(_isVector) {
}
zeus::ParamType::ParamType(const std::string& _name, uint16_t _id, bool _isNumber, bool _isVector):
zeus::message::ParamType::ParamType(const std::string& _name, uint16_t _id, bool _isNumber, bool _isVector):
m_typeName(_name),
m_id(_id),
m_isNumber(_isNumber),
@ -42,22 +42,22 @@ zeus::ParamType::ParamType(const std::string& _name, uint16_t _id, bool _isNumbe
}
bool zeus::ParamType::isNumber() const {
bool zeus::message::ParamType::isNumber() const {
return m_isNumber;
}
bool zeus::ParamType::isVector() const {
bool zeus::message::ParamType::isVector() const {
return m_isVector;
}
const std::string& zeus::ParamType::getName() const {
const std::string& zeus::message::ParamType::getName() const {
return m_typeName;
}
uint16_t zeus::ParamType::getId() const {
uint16_t zeus::message::ParamType::getId() const {
return m_id;
}
bool zeus::ParamType::operator == (const ParamType& _obj) const {
bool zeus::message::ParamType::operator == (const ParamType& _obj) const {
if (m_id != _obj.m_id) {
return false;
}
@ -66,7 +66,7 @@ bool zeus::ParamType::operator == (const ParamType& _obj) const {
}
return true;
}
bool zeus::ParamType::operator != (const ParamType& _obj) const {
bool zeus::message::ParamType::operator != (const ParamType& _obj) const {
if (m_id != _obj.m_id) {
return true;
}
@ -76,25 +76,25 @@ bool zeus::ParamType::operator != (const ParamType& _obj) const {
return false;
}
bool zeus::ParamType::operator == (const std::string& _value) const {
bool zeus::message::ParamType::operator == (const std::string& _value) const {
return _value == m_typeName;
}
bool zeus::ParamType::operator != (const std::string& _value) const {
bool zeus::message::ParamType::operator != (const std::string& _value) const {
return _value != m_typeName;
}
bool zeus::ParamType::operator == (const uint16_t& _value) const {
bool zeus::message::ParamType::operator == (const uint16_t& _value) const {
return _value == m_id;
}
bool zeus::ParamType::operator != (const uint16_t& _value) const {
bool zeus::message::ParamType::operator != (const uint16_t& _value) const {
return _value != m_id;
}
#define generate_basic_type(_type, _name, _id, _num, _vect) \
namespace zeus { \
template<> const zeus::ParamType& createType<_type>() {\
static zeus::ParamType type(_name, _id, _num, _vect); \
template<> const zeus::message::ParamType& createType<_type>() {\
static zeus::message::ParamType type(_name, _id, _num, _vect); \
return type; \
} \
}
@ -134,5 +134,5 @@ generate_basic_type(zeus::File, "file", 0x000E, false, false);
generate_basic_type(zeus::FileServer, "file", 0x000E, false, false);
#endif
const uint16_t zeus::paramTypeObject = 0xFFFF;
const uint16_t zeus::message::ParamTypeObject = 0xFFFF;

115
zeus/message/ParamType.hpp Normal file
View File

@ -0,0 +1,115 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <string>
namespace zeus {
namespace message {
/**
* @brief generisation of type of the type of the parameter
*/
class ParamType {
protected:
const std::string m_typeName; //!< generic type
const uint16_t m_id; //!< simplification ID (if possible)
const bool m_isNumber; //!< if the element is a number (convertion possible)
const bool m_isVector; //!< if the element is a vector (convertion possible)
public:
/**
* @brief contructor onf a generic name parameter
* @param[in] _name Name of the parameter
* @param[in] _id Generic Id of the parameter
* @param[in] _isNumber set true of the type is a number
* @param[in] _isVector set true of the type is a vector element
* @return
*/
ParamType(const char* _name = "", uint16_t _id=0, bool _isNumber=false, bool _isVector=false);
/**
* @copydoc zeus::ParamType::ParamType
*/
ParamType(const std::string& _name, uint16_t _id, bool _isNumber=false, bool _isVector=false);
/**
* @brief Get name of tha parameter
* @return string describing the TYPE
*/
const std::string& getName() const;
/**
* @brief Get generic Id of the type
* @return unsigned int containing the type
*/
uint16_t getId() const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type
* @return true if the 2 object are identical
*/
bool operator == (const ParamType& _obj) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type
* @return true if the 2 object are different
*/
bool operator != (const ParamType& _obj) const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type in strin
* @return true if the 2 object are identical
*/
bool operator == (const std::string& _value) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type in string
* @return true if the 2 object are different
*/
bool operator != (const std::string& _value) const;
/**
* @brief Egality comparaison with an other parameter
* @param[in] _obj Other parameter to compare type enum integer
* @return true if the 2 object are identical
*/
bool operator == (const uint16_t& _value) const;
/**
* @brief Difference comparaison with an other parameter
* @param[in] _obj Other parameter to compare type enum integer
* @return true if the 2 object are different
*/
bool operator != (const uint16_t& _value) const;
/**
* @brief Check if the type is a number
* @return return true if the type is a number
*/
bool isNumber() const;
/**
* @brief Check if the type is a vector
* @return return true if the type is a vector
*/
bool isVector() const;
};
extern const uint16_t paramTypeObject; //!< van not automatic create a type with the string named object
/**
* @brief Create human readable stream to debug
* @param[in] _os the stream to inject data
* @param[in] _obj Object to display
* @return The inpout stream
*/
std::ostream& operator <<(std::ostream& _os, const zeus::message::ParamType& _obj);
/**
* @brief Template to automaticly get the type of an generic std type without create a dynamic element
* @return generic parameter created
*/
template<class ZEUS_TYPE>
const ParamType& createType();
/**
* @brief Check the compatibility of 2 parameter type
* @param[in] _first First parameter to check
* @param[in] _second Second parameter to check
* @return Return true if parameters are compatible (thay can be converted)
*/
bool checkCompatibility(const ParamType& _first, const ParamType& _second);
}
}

View File

@ -4,20 +4,20 @@
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/Buffer.hpp>
#include <zeus/BufferData.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/message/Data.hpp>
#include <zeus/debug.hpp>
#include <zeus/ParamType.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/BufferParameter.hpp>
#include <zeus/message/Parameter.hpp>
#include <zeus/File.hpp>
zeus::BufferParameter::BufferParameter(ememory::SharedPtr<zeus::WebServer> _iface):
zeus::message::Parameter::Parameter(ememory::SharedPtr<zeus::WebServer> _iface):
Buffer(_iface) {
}
bool zeus::BufferParameter::writeOn(enet::WebSocket& _interface) {
bool zeus::message::Parameter::writeOn(enet::WebSocket& _interface) {
uint8_t* data = nullptr;
uint32_t dataSize = 0;
uint16_t nbParameters = m_parameter.size();
@ -30,7 +30,7 @@ bool zeus::BufferParameter::writeOn(enet::WebSocket& _interface) {
return true;
}
void zeus::BufferParameter::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
void zeus::message::Parameter::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
m_parameter.clear();
uint16_t nbParameters = 0;
if (_lenght < sizeof(uint16_t)) {
@ -62,7 +62,7 @@ void zeus::BufferParameter::composeWith(const uint8_t* _buffer, uint32_t _lenght
}
}
zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
zeus::ParamType zeus::message::Parameter::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>();
@ -121,7 +121,7 @@ zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
return createType<void>();
}
const uint8_t* zeus::BufferParameter::getParameterPointer(int32_t _id) const {
const uint8_t* zeus::message::Parameter::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());
@ -134,7 +134,7 @@ const uint8_t* zeus::BufferParameter::getParameterPointer(int32_t _id) const {
return out;
}
uint32_t zeus::BufferParameter::getParameterSize(int32_t _id) const {
uint32_t zeus::message::Parameter::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());
@ -146,11 +146,11 @@ uint32_t zeus::BufferParameter::getParameterSize(int32_t _id) const {
return m_parameter[_id].second.size() - m_parameter[_id].first;
}
uint16_t zeus::BufferParameter::getNumberParameter() const {
uint16_t zeus::message::Parameter::getNumberParameter() const {
return m_parameter.size();
}
std::string zeus::BufferParameter::simpleStringParam(uint32_t _id) const {
std::string zeus::message::Parameter::simpleStringParam(uint32_t _id) const {
zeus::ParamType paramType = getParameterType(_id);
if (paramType.isVector() == false) {
if (paramType.isNumber() == true) {
@ -169,7 +169,7 @@ std::string zeus::BufferParameter::simpleStringParam(uint32_t _id) const {
return paramType.getName();
}
void zeus::BufferParameter::parameterAppendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
void zeus::message::Parameter::parameterAppendBufferData(ememory::SharedPtr<zeus::BufferData> _obj) {
// At this point we just add data at the parameter value:
uint16_t parameterID = _obj->getParameterId();

View File

@ -0,0 +1,93 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
#include <ememory/memory.hpp>
namespace zeus {
class WebServer;
namespace message {
class Parameter:
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:
Parameter(ememory::SharedPtr<zeus::WebServer> _iface);
/**
* @brief Template to get a parameter with a specific type
* @param[in] _id Number of the parameter
* @param[in] _iface IO Web interface
* @return Converted type of the parameter (or empty value)
*/
template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getParameter(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const;
/**
* @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 {
return getParameter<ZEUS_TYPE_DATA>(m_iface, _id);
}
/**
* @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(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
public:
template<class ZEUS_TYPE_DATA>
void addParameter(const ememory::SharedPtr<zeus::WebServer>& _iface, const ZEUS_TYPE_DATA& _value) {
addParameter(_iface, m_parameter.size(), _value);
}
void parameterAppendBufferData(ememory::SharedPtr<zeus::BufferData> _obj);
};
}
}

View File

@ -0,0 +1,367 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/message/Data.hpp>
#include <zeus/debug.hpp>
#include <zeus/message/ParamType.hpp>
#include <etk/stdTools.hpp>
#include <zeus/AbstractFunction.hpp>
#include <climits>
#include <etk/os/FSNode.hpp>
#include <zeus/mineType.hpp>
#include <zeus/WebServer.hpp>
void zeus::addType(std::vector<uint8_t>& _data, zeus::message::ParamType _type) {
_data.push_back(uint8_t(_type.getId()>>8));
_data.push_back(uint8_t(_type.getId()));
}
void zeus::addTypeObject(std::vector<uint8_t>& _data, const std::string _type) {
_data.push_back(uint8_t(zeus::message::paramTypeObject>>8));
_data.push_back(uint8_t(zeus::message::paramTypeObject));
for (auto &it : _type) {
_data.push_back(uint8_t(it));
}
_data.push_back(0);
}
void zeus::Parameter::addParameter() {
std::vector<uint8_t> data;
addType(data, createType<void>());
m_parameter.push_back(std::make_pair(2,data));
}
void zeus::Parameter::addParameterEmptyVector() {
// special case of json change mode
std::vector<uint8_t> data;
addType(data, createType<std::vector<void>>());
m_parameter.push_back(std::make_pair(2,data));
}
namespace zeus {
namespace message {
template<>
void Parameter::addParameter<std::string>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::string& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::string>());
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], _value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<std::string>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<std::string>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<std::string>>());
// count all datas:
uint32_t size = 0;
for (auto &it : _value) {
size+=it.size()+1;
}
uint16_t nb = _value.size();
int32_t currentOffset = data.size();
data.resize(data.size()+size+2);
memcpy(&data[currentOffset], &nb, sizeof(uint16_t));
currentOffset += sizeof(uint16_t);
for (auto &it : _value) {
memcpy(&data[currentOffset], &it[0], it.size());
currentOffset += it.size();
data[currentOffset] = '\0';
currentOffset++;
}
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<bool>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<bool>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<bool>>());
// add size:
uint16_t nb = _value.size();
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
for (const auto &it : _value) {
if (it == true) {
data[currentOffset] = 'T';
} else {
data[currentOffset] = 'F';
}
currentOffset++;
}
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<int8_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int8_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int8_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int8_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<int16_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int16_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int16_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int16_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<int32_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int32_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int32_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int32_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<int64_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<int64_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<int64_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(int64_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<uint8_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint8_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint8_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint8_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<uint16_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint16_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint16_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint16_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<uint32_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint32_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint32_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint32_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<uint64_t>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<uint64_t>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<uint64_t>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(uint64_t)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<float>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<float>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<float>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(float)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<std::vector<double>>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const std::vector<double>& _value) {
std::vector<uint8_t> data;
addType(data, createType<std::vector<double>>());
// add size:
int32_t currentOffset = data.size();
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], &_value[0], sizeof(double)*_value.size());
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<int8_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int8_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int8_t>());
data.push_back(uint8_t(_value));
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<uint8_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint8_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint8_t>());
data.push_back(_value);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<int16_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int16_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int16_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+2);
memcpy(&data[currentOffset], &_value, 2);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<uint16_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint16_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint16_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+2);
memcpy(&data[currentOffset], &_value, 2);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<int32_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int32_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int32_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<uint32_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint32_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint32_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<int64_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const int64_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<int64_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<uint64_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const uint64_t& _value) {
std::vector<uint8_t> data;
addType(data, createType<uint64_t>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
#if defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs)
template<>
void Parameter::addParameter<size_t>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const size_t& _value) {
addParameter(_paramId, uint64_t(_value));
}
#endif
template<>
void Parameter::addParameter<float>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const float& _value) {
std::vector<uint8_t> data;
addType(data, createType<float>());
int32_t currentOffset = data.size();
data.resize(data.size()+4);
memcpy(&data[currentOffset], &_value, 4);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<double>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const double& _value) {
std::vector<uint8_t> data;
addType(data, createType<double>());
int32_t currentOffset = data.size();
data.resize(data.size()+8);
memcpy(&data[currentOffset], &_value, 8);
m_parameter.push_back(std::make_pair(2,data));
}
template<>
void Parameter::addParameter<bool>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const bool& _value) {
std::vector<uint8_t> data;
addType(data, createType<bool>());
if (_value == true) {
data.push_back('T');
} else {
data.push_back('F');
}
m_parameter.push_back(std::make_pair(2,data));
}
#define ZEUS_MINIMUM_SIZE_MULTIPLE (1024*50)
class SendData {
private:
zeus::Raw m_data;
uint16_t m_parameterId;
int64_t m_size;
uint64_t m_offset;
public:
SendData(const zeus::Raw& _data, uint16_t _parameterId) :
m_data(_data),
m_parameterId(_parameterId),
m_size(_data.size()-1),
m_offset(0) {
}
~SendData() {
}
// TODO : Set it with a sharedPtr instaed of pointer ...
bool operator() (zeus::WebServer* _interface,
uint32_t _source,
uint32_t _destination,
uint32_t _transactionId,
uint32_t _partId) {
ememory::SharedPtr<zeus::BufferData> answer = zeus::BufferData::create(_interface->sharedFromThis());
answer->setTransactionId(_transactionId);
answer->setSource(_source);
answer->setDestination(_destination);
answer->setPartId(_partId);
answer->setPartFinish(false);
int32_t tmpSize = ZEUS_MINIMUM_SIZE_MULTIPLE;
if (m_size < ZEUS_MINIMUM_SIZE_MULTIPLE) {
tmpSize = m_size;
}
answer->addData(m_parameterId, (void *)(&m_data.data()[m_offset]), tmpSize);
m_size -= tmpSize;
m_offset += tmpSize;
_interface->writeBinary(answer);;
if (m_size <= 0) {
return true;
}
return false;
}
};
template<>
void Parameter::addParameter<zeus::Raw>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const zeus::Raw& _value) {
std::vector<uint8_t> data;
addType(data, createType<zeus::Raw>());
// set mine type in string:
int32_t currentOffset = data.size();
if (_value.size() != 0) {
if (_value.size() < ZEUS_MINIMUM_SIZE_MULTIPLE) {
data.resize(data.size()+_value.size());
memcpy(&data[currentOffset], _value.data(), _value.size());
} else {
m_multipleSend.push_back(zeus::SendData(_value, _paramId));
}
}
m_parameter.push_back(std::make_pair(2,data));
}
}
}

File diff suppressed because it is too large Load Diff

46
zeus/message/type.cpp Normal file
View File

@ -0,0 +1,46 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/stdTools.hpp>
#include <zeus/message/type.hpp>
namespace etk {
template<> std::string to_string<enum zeus::message::type>(const enum zeus::message::type& _value) {
switch (_value) {
case zeus::message::type::unknow:
return "unknow";
case zeus::message::type::call:
return "call";
case zeus::message::type::answer:
return "answer";
case zeus::message::type::event:
return "event";
case zeus::message::type::data:
return "data";
}
return "???";
}
}
std::ostream& zeus::operator <<(std::ostream& _os, enum zeus::message::type _value) {
_os << etk::to_string(_value);
return _os;
}
static enum zeus::message::type getTypeType(uint16_t _value) {
switch (_value) {
case 0:
return zeus::message::type::unknow;
case 1:
return zeus::message::type::call;
case 2:
return zeus::message::type::answer;
case 3:
return zeus::message::type::data;
case 4:
return zeus::message::type::event;
}
return zeus::message::type::unknow;
}

33
zeus/message/type.hpp Normal file
View File

@ -0,0 +1,33 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/ParamType.hpp>
namespace zeus {
namespace message {
/**
* @brief Type of the massage send or receive
*/
enum class type {
unknow = 0x0000, //!< Init value
call = 0x0001, //!< Remote call on a service ID
answer = 0x0002, //!< Answer from a previous call
data = 0x0003, //!< data message happend when partId > 0 it compleate the data of a parameter or an answer or an event
event = 0x0004, //!< Message in one way (no return is waiting and the message has no garenty...)
};
/**
* @brief generate a display of the typemessage
* @param[in] _os stream to add data
* @value[in] _value Value to add
* @return a reference of the stream
*/
std::ostream& operator <<(std::ostream& _os, enum zeus::message::type _value);
}
}

View File

@ -1,78 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#if 0
#include <zeus/File.hpp>
#include <zeus/debug.hpp>
#include <etk/types.hpp>
#include <etk/stdTools.hpp>
#include <zeus/mineType.hpp>
#include <etk/os/FSNode.hpp>
#include <cstring>
zeus::File::File() {
}
zeus::File::File(const std::string& _filename) {
m_data = etk::FSNodeReadAllDataType<uint8_t>(_filename);
std::string extention = std::string(_filename.begin()+_filename.size() -3, _filename.end());
m_mineType = zeus::getMineType(extention);
}
void zeus::File::storeIn(const std::string& _filename) const {
etk::FSNodeWriteAllDataType(_filename, m_data);
}
zeus::File::File(const std::string& _mineType, std::vector<uint8_t> _data, int32_t _fileSize):
m_mineType(_mineType),
m_data(_data) {
if (_fileSize < 0){
m_fileSize = m_data.size();
} else {
m_fileSize = _fileSize;
}
}
zeus::File::File(const std::string& _mineType, int32_t _size) :
m_mineType(_mineType),
m_data() {
m_data.resize(_size);
m_fileSize = _size;
}
void zeus::File::setData(uint64_t _offset, const std::vector<uint8_t>& _data) {
setData(_offset, &_data[0], _data.size());
}
void zeus::File::setData(uint64_t _offset, const uint8_t* _data, uint32_t _size) {
if (_size+_offset > m_data.size()) {
ZEUS_ERROR("Need Resize file buffer ... need=" << _size+_offset << " have=" << m_data.size());
m_data.resize(_size+_offset);
}
memcpy(&m_data[_offset], _data, _size);
}
zeus::FileServer::FileServer() {
}
zeus::FileServer::FileServer(const std::string& _filename) :
m_name(_filename) {
}
namespace etk {
template<>
std::string to_string<zeus::FileServer>(zeus::FileServer const& _obj) {
return "";
}
}
#endif

View File

@ -1,125 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#if 0
namespace zeus {
/**
* @brief File inetrface
*/
class File {
private:
std::string m_mineType;
int32_t m_fileSize;
std::vector<uint8_t> m_data;
public:
/**
* @brief Contructor of an empty file
*/
File();
/**
* @brief Contructor with the name of a file (load all data)
* @param[in] _filename path of the file
*/
File(const std::string& _filename);
/**
* @brief Constructor of a typed file
* @param[in] _mineType mine type of the file
* @param[in] _data data of the file
* @param[in] _fileSize theoric file size
*/
File(const std::string& _mineType, std::vector<uint8_t> _data, int32_t _fileSize = -1);
/**
* @brief Constructor of a typed file
* @param[in] _mineType mine type of the file
* @param[in] _fileSize preallocation size (data will be set after ...)
*/
File(const std::string& _mineType, int32_t _size);
/**
* @brief get the théoric file size
* @return size of the file
*/
int32_t getTheoricFileSize() const {
return m_fileSize;
}
/**
* @brief Store data in the specify file
* @param[in] _filename name of the file
*/
void storeIn(const std::string& _filename) const;
/**
* @brief Get the mine type of the file
* @return generic mine type
*/
const std::string& getMineType() const {
return m_mineType;
}
/**
* @brief Set the mine type of the file
* @param[in] _type New type of the file
*/
void setMineType(const std::string& _type) {
m_mineType = _type;
}
/**
* @brief préallocate the data
* @param[in] _size New size of the buffer
*/
void preSetDataSize(uint64_t _size) {
m_data.resize(_size, 0);
}
/**
* @brief get a rérérence of the data
* @return requested data
*/
const std::vector<uint8_t>& getData() const {
return m_data;
}
/**
* @brief Set data on the buffer
* @param[in] _offset offset of the write data
* @param[in] _data data to write
*/
void setData(uint64_t _offset, const std::vector<uint8_t>& _data);
/**
* @brief Set data on the buffer
* @param[in] _offset offset of the write data
* @param[in] _data pointer on the data to write
* @param[in] _size Number of Octet to write
*/
void setData(uint64_t _offset, const uint8_t* _data, uint32_t _size);
};
/**
* @brief File server interface
* @note This class permit to send file without opening all data befor sending
*/
class FileServer {
private:
std::string m_name;
public:
/**
* @brief generic constructor
*/
FileServer();
/**
* @brief contructor with a file
* @param[in] _filename Name of the file to send
*/
FileServer(const std::string& _filename);
/**
* @brief Get the filename registered
* @return path of the file
*/
const std::string& getFileName() const {
return m_name;
}
};
}
#endif