[DEV/DOC] clean documentation and code

This commit is contained in:
Edouard DUPIN 2016-06-23 22:08:11 +02:00
parent 19948e45f0
commit 7ee8e2332c
39 changed files with 1733 additions and 654 deletions

View File

@ -26,15 +26,13 @@ def get_version():
def create(target, module_name): def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type()) my_module = module.Module(__file__, module_name, get_type())
my_module.add_module_depend(['etk', 'enet', 'ememory', 'eproperty', 'esignal']) my_module.add_module_depend(['etk', 'enet', 'ememory', 'eproperty'])
my_module.add_src_file([ my_module.add_src_file([
'zeus/debug.cpp' 'zeus/debug.cpp'
]) ])
my_module.add_path(tools.get_current_path(__file__)) my_module.add_path(tools.get_current_path(__file__))
my_module.add_src_file([ my_module.add_src_file([
'zeus/AbstractFunction.cpp', 'zeus/AbstractFunction.cpp',
'zeus/AbstractFunctionTypeDirect.cpp',
'zeus/AbstractFunctionTypeClass.cpp',
'zeus/FutureBase.cpp', 'zeus/FutureBase.cpp',
'zeus/Future.cpp', 'zeus/Future.cpp',
'zeus/File.cpp', 'zeus/File.cpp',
@ -43,13 +41,10 @@ def create(target, module_name):
'zeus/Buffer_getParameter.cpp', 'zeus/Buffer_getParameter.cpp',
'zeus/ParamType.cpp', 'zeus/ParamType.cpp',
'zeus/Client.cpp', 'zeus/Client.cpp',
'zeus/GateWay.cpp',
'zeus/GateWayService.cpp',
'zeus/GateWayClient.cpp',
'zeus/RemoteProcessCall.cpp', 'zeus/RemoteProcessCall.cpp',
'zeus/Service.cpp', 'zeus/Service.cpp',
'zeus/ServiceRemote.cpp', 'zeus/ServiceRemote.cpp',
'zeus/TcpString.cpp', 'zeus/WebServer.cpp',
'zeus/mineType.cpp', 'zeus/mineType.cpp',
]) ])
my_module.add_header_file([ my_module.add_header_file([
@ -64,13 +59,10 @@ def create(target, module_name):
'zeus/ParamType.h', 'zeus/ParamType.h',
'zeus/debug.h', 'zeus/debug.h',
'zeus/Client.h', 'zeus/Client.h',
'zeus/GateWay.h',
'zeus/GateWayService.h',
'zeus/GateWayClient.h',
'zeus/RemoteProcessCall.h', 'zeus/RemoteProcessCall.h',
'zeus/Service.h', 'zeus/Service.h',
'zeus/ServiceRemote.h', 'zeus/ServiceRemote.h',
'zeus/TcpString.h', 'zeus/WebServer.h',
'zeus/mineType.h', 'zeus/mineType.h',
]) ])
if target.config["compilator"] == "clang": if target.config["compilator"] == "clang":

View File

@ -35,29 +35,26 @@ int main(int _argc, const char *_argv[]) {
APPL_INFO("=================================="); APPL_INFO("==================================");
APPL_INFO("== ZEUS test client start =="); APPL_INFO("== ZEUS test client start ==");
APPL_INFO("=================================="); APPL_INFO("==================================");
client1.connect("test1#atria-soft.com");
if (false) { if (false) {
zeus::Future<bool> retIdentify = client1.call("identify", "clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968"); bool ret = client1.connect("test1~atria-soft.com", "clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968");
retIdentify.wait(); if (ret == false) {
if (retIdentify.get() == false) {
APPL_ERROR(" ==> NOT Connected with 'clientTest1#atria-soft.com'"); APPL_ERROR(" ==> NOT Connected with 'clientTest1#atria-soft.com'");
return -1; return -1;
} else { } else {
APPL_INFO(" ==> Connected with 'clientTest1#atria-soft.com'"); APPL_INFO(" ==> Connected with 'clientTest1#atria-soft.com'");
} }
} else if (true) { } else if (true) {
zeus::Future<bool> retIdentify = client1.call("auth", "coucou"); bool ret = client1.connect("test1~atria-soft.com", "coucou");
retIdentify.wait(); if (ret == false) {
if (retIdentify.get() == false) {
APPL_ERROR(" ==> NOT Authentify with 'test1#atria-soft.com'"); APPL_ERROR(" ==> NOT Authentify with 'test1#atria-soft.com'");
return -1; return -1;
} else { } else {
APPL_INFO(" ==> Authentify with 'test1#atria-soft.com'"); APPL_INFO(" ==> Authentify with 'test1#atria-soft.com'");
} }
} else { } else {
zeus::Future<bool> retIdentify = client1.call("anonymous"); bool ret = client1.connect("test1~atria-soft.com");
retIdentify.wait(); if (ret == false) {
if (retIdentify.get() == false) {
APPL_ERROR(" ==> NOT Connected with 'anonymous'"); APPL_ERROR(" ==> NOT Connected with 'anonymous'");
return -1; return -1;
} else { } else {

View File

@ -348,8 +348,8 @@ namespace appl {
return m_user->getAlbumCount(_album); return m_user->getAlbumCount(_album);
} }
// Return the list of the album files // Return the list of the album files
std::vector<std::string> getAlbumListPicture(std::string _album) {//, uint32_t _startId, uint32_t _stopId) { std::vector<std::string> getAlbumListPicture(std::string _album) {
return m_user->getAlbumListPicture(_album);//, _startId, _stopId); return m_user->getAlbumListPicture(_album);
} }
// Return a File Data (might be a picture .tiff/.png/.jpg) // Return a File Data (might be a picture .tiff/.png/.jpg)
zeus::FileServer getAlbumPicture(std::string _pictureName) { zeus::FileServer getAlbumPicture(std::string _pictureName) {

View File

@ -4,9 +4,10 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <zeus/debug.h> #include <appl/debug.h>
#include <zeus/GateWayClient.h> #include <appl/ClientInterface.h>
#include <zeus/GateWay.h> #include <zeus/Future.h>
#include <appl/GateWay.h>
#include <unistd.h> #include <unistd.h>
#include <zeus/AbstractFunction.h> #include <zeus/AbstractFunction.h>
@ -14,8 +15,8 @@
static const std::string protocolError = "PROTOCOL-ERROR"; static const std::string protocolError = "PROTOCOL-ERROR";
zeus::GateWayClient::GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewayInterface) : appl::ClientInterface::ClientInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface) :
m_state(zeus::GateWayClient::state::unconnect), m_state(appl::ClientInterface::state::unconnect),
m_gatewayInterface(_gatewayInterface), m_gatewayInterface(_gatewayInterface),
m_interfaceClient(std::move(_connection), true) { m_interfaceClient(std::move(_connection), true) {
ZEUS_INFO("----------------"); ZEUS_INFO("----------------");
@ -23,7 +24,7 @@ zeus::GateWayClient::GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewa
ZEUS_INFO("----------------"); ZEUS_INFO("----------------");
} }
zeus::GateWayClient::~GateWayClient() { appl::ClientInterface::~ClientInterface() {
ZEUS_TODO("Call All unlink ..."); ZEUS_TODO("Call All unlink ...");
stop(); stop();
ZEUS_INFO("-------------------"); ZEUS_INFO("-------------------");
@ -31,16 +32,16 @@ zeus::GateWayClient::~GateWayClient() {
ZEUS_INFO("-------------------"); ZEUS_INFO("-------------------");
} }
void zeus::GateWayClient::start(uint64_t _uid, uint64_t _uid2) { void appl::ClientInterface::start(uint64_t _uid, uint64_t _uid2) {
m_uid = _uid; m_uid = _uid;
m_uid2 = _uid2; m_uid2 = _uid2;
m_state = zeus::GateWayClient::state::connect; m_state = appl::ClientInterface::state::connect;
m_interfaceClient.connect(this, &zeus::GateWayClient::onClientData); m_interfaceClient.connect(this, &appl::ClientInterface::onClientData);
m_interfaceClient.connect(true); m_interfaceClient.connect(true);
m_interfaceClient.setInterfaceName("cli-" + etk::to_string(m_uid)); m_interfaceClient.setInterfaceName("cli-" + etk::to_string(m_uid));
} }
void zeus::GateWayClient::stop() { void appl::ClientInterface::stop() {
for (auto &it : m_listConnectedService) { for (auto &it : m_listConnectedService) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
@ -55,18 +56,18 @@ void zeus::GateWayClient::stop() {
m_interfaceClient.disconnect(); m_interfaceClient.disconnect();
} }
bool zeus::GateWayClient::isAlive() { bool appl::ClientInterface::isAlive() {
return m_interfaceClient.isActive(); return m_interfaceClient.isActive();
} }
void zeus::GateWayClient::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::ClientInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp); m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp);
m_state = zeus::GateWayClient::state::disconnect; m_state = appl::ClientInterface::state::disconnect;
m_interfaceClient.disconnect(true); m_interfaceClient.disconnect(true);
} }
void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value) { void appl::ClientInterface::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value) {
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
@ -78,7 +79,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
} }
if (_value->getType() == zeus::Buffer::typeMessage::data) { if (_value->getType() == zeus::Buffer::typeMessage::data) {
// TRANSMIT DATA ... // TRANSMIT DATA ...
if (m_state != zeus::GateWayClient::state::clientIdentify) { if (m_state != appl::ClientInterface::state::clientIdentify) {
answerProtocolError(transactionId, "Not identify to send 'data' buffer (multiple packet element)"); answerProtocolError(transactionId, "Not identify to send 'data' buffer (multiple packet element)");
return; return;
} }
@ -110,14 +111,14 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
} }
std::string callFunction = _value->getCall(); std::string callFunction = _value->getCall();
switch (m_state) { switch (m_state) {
case zeus::GateWayClient::state::disconnect: case appl::ClientInterface::state::disconnect:
case zeus::GateWayClient::state::unconnect: case appl::ClientInterface::state::unconnect:
{ {
ZEUS_ERROR("Must never appear"); ZEUS_ERROR("Must never appear");
answerProtocolError(transactionId, "Gateway internal error"); answerProtocolError(transactionId, "Gateway internal error");
return; return;
} }
case zeus::GateWayClient::state::connect: case appl::ClientInterface::state::connect:
{ {
if (m_userConnectionName != "") { if (m_userConnectionName != "") {
answerProtocolError(transactionId, "Gateway internal error 2"); answerProtocolError(transactionId, "Gateway internal error 2");
@ -135,7 +136,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
} else { } else {
zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.callClient(m_uid2, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>()); zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.callClient(m_uid2, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>());
futLocalService.wait(); // TODO: Set timeout ... futLocalService.wait(); // TODO: Set timeout ...
m_state = zeus::GateWayClient::state::userIdentify; m_state = appl::ClientInterface::state::userIdentify;
m_interfaceClient.answerValue(transactionId, true); m_interfaceClient.answerValue(transactionId, true);
} }
} }
@ -145,7 +146,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
answerProtocolError(transactionId, "Missing call of connectToUser"); answerProtocolError(transactionId, "Missing call of connectToUser");
return; return;
} }
case zeus::GateWayClient::state::userIdentify: case appl::ClientInterface::state::userIdentify:
{ {
m_clientServices.clear(); m_clientServices.clear();
m_clientgroups.clear(); m_clientgroups.clear();
@ -228,11 +229,11 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
m_interfaceClient.answerValue(transactionId, true); m_interfaceClient.answerValue(transactionId, true);
m_state = zeus::GateWayClient::state::clientIdentify; m_state = appl::ClientInterface::state::clientIdentify;
return; return;
} }
break; break;
case zeus::GateWayClient::state::clientIdentify: case appl::ClientInterface::state::clientIdentify:
{ {
uint32_t serviceId = _value->getServiceId(); uint32_t serviceId = _value->getServiceId();
if (serviceId == 0) { if (serviceId == 0) {
@ -268,7 +269,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
m_interfaceClient.answerError(transactionId, "UN-AUTHORIZED-SERVICE"); m_interfaceClient.answerError(transactionId, "UN-AUTHORIZED-SERVICE");
return; return;
} }
ememory::SharedPtr<zeus::GateWayService> srv = m_gatewayInterface->get(serviceName); ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName);
if (srv != nullptr) { if (srv != nullptr) {
zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups); zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups);
futLink.wait(); // TODO: Set timeout ... futLink.wait(); // TODO: Set timeout ...
@ -331,10 +332,10 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
return true; return true;
} }
ZEUS_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId); ZEUS_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
ZEUS_DEBUG(" msg=" << tmpp->generateHumanString()); ZEUS_DEBUG(" msg=" << *tmpp);
tmpp->setTransactionId(transactionId); tmpp->setTransactionId(transactionId);
tmpp->setServiceId(serviceId+1); tmpp->setServiceId(serviceId+1);
ZEUS_DEBUG("transmit=" << tmpp->generateHumanString()); ZEUS_DEBUG("transmit=" << *tmpp);
m_interfaceClient.writeBinary(tmpp); m_interfaceClient.writeBinary(tmpp);
// multiple send element ... // multiple send element ...
return tmpp->getPartFinish(); return tmpp->getPartFinish();
@ -344,6 +345,6 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
} }
} }
void zeus::GateWayClient::returnMessage(const ememory::SharedPtr<zeus::Buffer>& _data) { void appl::ClientInterface::returnMessage(const ememory::SharedPtr<zeus::Buffer>& _data) {
ZEUS_ERROR("Get call from the Service to the user ..."); ZEUS_ERROR("Get call from the Service to the user ...");
} }

View File

@ -5,18 +5,13 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <ememory/memory.h> #include <appl/GateWay.h>
#include <esignal/Signal.h> #include <appl/ServiceInterface.h>
#include <zeus/GateWayService.h>
#include <zeus/Future.h>
#include <zeus/AbstractFunction.h>
namespace appl {
namespace zeus {
class GateWay; class GateWay;
class GateWayClient { class ClientInterface {
private: private:
enum class state { enum class state {
unconnect, // starting sate unconnect, // starting sate
@ -27,12 +22,11 @@ namespace zeus {
}; };
enum state m_state; // state machine ... enum state m_state; // state machine ...
private: private:
zeus::GateWay* m_gatewayInterface; appl::GateWay* m_gatewayInterface;
zeus::TcpString m_interfaceClient; zeus::WebServer m_interfaceClient;
public: public:
esignal::Signal<bool> signalIsConnected; ememory::SharedPtr<appl::ServiceInterface> m_userService;
ememory::SharedPtr<zeus::GateWayService> m_userService; std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_listConnectedService;
std::vector<ememory::SharedPtr<zeus::GateWayService>> m_listConnectedService;
uint64_t m_uid; uint64_t m_uid;
uint64_t m_uid2; uint64_t m_uid2;
std::string m_userConnectionName; std::string m_userConnectionName;
@ -40,8 +34,8 @@ namespace zeus {
std::vector<std::string> m_clientgroups; std::vector<std::string> m_clientgroups;
std::vector<std::string> m_clientServices; std::vector<std::string> m_clientServices;
public: public:
GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewayInterface); ClientInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface);
virtual ~GateWayClient(); virtual ~ClientInterface();
void start(uint64_t _uid, uint64_t _uid2); void start(uint64_t _uid, uint64_t _uid2);
void stop(); void stop();
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value); void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);

View File

@ -4,21 +4,21 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <zeus/GateWay.h> #include <appl/GateWay.h>
#include <zeus/debug.h> #include <appl/debug.h>
#include <enet/TcpServer.h> #include <enet/TcpServer.h>
namespace zeus { namespace appl {
class TcpServerInput { class TcpServerInput {
private: private:
enet::TcpServer m_interface; enet::TcpServer m_interface;
std::thread* m_thread; std::thread* m_thread;
bool m_threadRunning; bool m_threadRunning;
zeus::GateWay* m_gateway; appl::GateWay* m_gateway;
bool m_service; bool m_service;
public: public:
TcpServerInput(zeus::GateWay* _gateway, bool _service) : TcpServerInput(appl::GateWay* _gateway, bool _service) :
m_thread(nullptr), m_thread(nullptr),
m_threadRunning(false), m_threadRunning(false),
m_gateway(_gateway), m_gateway(_gateway),
@ -65,46 +65,46 @@ namespace zeus {
}; };
} }
void zeus::GateWay::newService(enet::Tcp _connection) { void appl::GateWay::newService(enet::Tcp _connection) {
ZEUS_WARNING("New TCP connection (service)"); ZEUS_WARNING("New TCP connection (service)");
ememory::SharedPtr<zeus::GateWayService> tmp = std::make_shared<zeus::GateWayService>(std::move(_connection), this); ememory::SharedPtr<appl::ServiceInterface> tmp = std::make_shared<appl::ServiceInterface>(std::move(_connection), this);
tmp->start(); tmp->start();
m_serviceList.push_back(tmp); m_serviceList.push_back(tmp);
} }
void zeus::GateWay::newClient(enet::Tcp _connection) { void appl::GateWay::newClient(enet::Tcp _connection) {
ZEUS_WARNING("New TCP connection (client)"); ZEUS_WARNING("New TCP connection (client)");
ememory::SharedPtr<zeus::GateWayClient> tmp = std::make_shared<zeus::GateWayClient>(std::move(_connection), this); ememory::SharedPtr<appl::ClientInterface> tmp = std::make_shared<appl::ClientInterface>(std::move(_connection), this);
tmp->start(m_clientUID++, m_clientUID++); tmp->start(m_clientUID++, m_clientUID++);
m_clientList.push_back(tmp); m_clientList.push_back(tmp);
} }
zeus::GateWay::GateWay() : appl::GateWay::GateWay() :
m_clientUID(1), m_clientUID(1),
propertyClientIp(this, "client-ip", "127.0.0.1", "Ip to listen client", &zeus::GateWay::onPropertyChangeClientIp), propertyClientIp(this, "client-ip", "127.0.0.1", "Ip to listen client", &appl::GateWay::onPropertyChangeClientIp),
propertyClientPort(this, "client-port", 1983, "Port to listen client", &zeus::GateWay::onPropertyChangeClientPort), propertyClientPort(this, "client-port", 1983, "Port to listen client", &appl::GateWay::onPropertyChangeClientPort),
propertyClientMax(this, "client-max", 80, "Maximum of client at the same time", &zeus::GateWay::onPropertyChangeClientMax), propertyClientMax(this, "client-max", 80, "Maximum of client at the same time", &appl::GateWay::onPropertyChangeClientMax),
propertyServiceIp(this, "service-ip", "127.0.0.1", "Ip to listen client", &zeus::GateWay::onPropertyChangeServiceIp), propertyServiceIp(this, "service-ip", "127.0.0.1", "Ip to listen client", &appl::GateWay::onPropertyChangeServiceIp),
propertyServicePort(this, "service-port", 1982, "Port to listen client", &zeus::GateWay::onPropertyChangeServicePort), propertyServicePort(this, "service-port", 1982, "Port to listen client", &appl::GateWay::onPropertyChangeServicePort),
propertyServiceMax(this, "service-max", 80, "Maximum of client at the same time", &zeus::GateWay::onPropertyChangeServiceMax) { propertyServiceMax(this, "service-max", 80, "Maximum of client at the same time", &appl::GateWay::onPropertyChangeServiceMax) {
m_interfaceClientServer = std::make_shared<zeus::TcpServerInput>(this, false); m_interfaceClientServer = std::make_shared<appl::TcpServerInput>(this, false);
m_interfaceServiceServer = std::make_shared<zeus::TcpServerInput>(this, true); m_interfaceServiceServer = std::make_shared<appl::TcpServerInput>(this, true);
} }
zeus::GateWay::~GateWay() { appl::GateWay::~GateWay() {
} }
void zeus::GateWay::start() { void appl::GateWay::start() {
m_interfaceClientServer->start(*propertyClientIp, *propertyClientPort); m_interfaceClientServer->start(*propertyClientIp, *propertyClientPort);
m_interfaceServiceServer->start(*propertyServiceIp, *propertyServicePort); m_interfaceServiceServer->start(*propertyServiceIp, *propertyServicePort);
} }
void zeus::GateWay::stop() { void appl::GateWay::stop() {
} }
ememory::SharedPtr<zeus::GateWayService> zeus::GateWay::get(const std::string& _serviceName) { ememory::SharedPtr<appl::ServiceInterface> appl::GateWay::get(const std::string& _serviceName) {
for (auto &it : m_serviceList) { for (auto &it : m_serviceList) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
@ -117,7 +117,7 @@ ememory::SharedPtr<zeus::GateWayService> zeus::GateWay::get(const std::string& _
return nullptr; return nullptr;
} }
std::vector<std::string> zeus::GateWay::getAllServiceName() { std::vector<std::string> appl::GateWay::getAllServiceName() {
std::vector<std::string> out; std::vector<std::string> out;
for (auto &it : m_serviceList) { for (auto &it : m_serviceList) {
if (it == nullptr) { if (it == nullptr) {
@ -129,7 +129,7 @@ std::vector<std::string> zeus::GateWay::getAllServiceName() {
} }
void zeus::GateWay::answer(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data) { void appl::GateWay::answer(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data) {
for (auto &it : m_clientList) { for (auto &it : m_clientList) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
@ -142,7 +142,7 @@ void zeus::GateWay::answer(uint64_t _userSessionId, const ememory::SharedPtr<zeu
} }
} }
void zeus::GateWay::cleanIO() { void appl::GateWay::cleanIO() {
auto it = m_serviceList.begin(); auto it = m_serviceList.begin();
while (it != m_serviceList.end()) { while (it != m_serviceList.end()) {
@ -173,34 +173,34 @@ void zeus::GateWay::cleanIO() {
} }
} }
void zeus::GateWay::onClientConnect(const bool& _value) { void appl::GateWay::onClientConnect(const bool& _value) {
ZEUS_TODO("Client connection: " << _value); ZEUS_TODO("Client connection: " << _value);
} }
void zeus::GateWay::onServiceConnect(const bool& _value) { void appl::GateWay::onServiceConnect(const bool& _value) {
ZEUS_TODO("Service connection: " << _value); ZEUS_TODO("Service connection: " << _value);
} }
void zeus::GateWay::onPropertyChangeClientIp() { void appl::GateWay::onPropertyChangeClientIp() {
} }
void zeus::GateWay::onPropertyChangeClientPort() { void appl::GateWay::onPropertyChangeClientPort() {
} }
void zeus::GateWay::onPropertyChangeClientMax() { void appl::GateWay::onPropertyChangeClientMax() {
} }
void zeus::GateWay::onPropertyChangeServiceIp() { void appl::GateWay::onPropertyChangeServiceIp() {
} }
void zeus::GateWay::onPropertyChangeServicePort() { void appl::GateWay::onPropertyChangeServicePort() {
} }
void zeus::GateWay::onPropertyChangeServiceMax() { void appl::GateWay::onPropertyChangeServiceMax() {
} }

View File

@ -4,20 +4,21 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#pragma once #pragma once
#include <zeus/GateWayService.h> #include <appl/ServiceInterface.h>
#include <zeus/GateWayClient.h> #include <appl/ClientInterface.h>
#include <eproperty/Value.h>
namespace zeus { namespace appl {
class TcpServerInput; class TcpServerInput;
class GateWay : public eproperty::Interface { class GateWay : public eproperty::Interface {
private: private:
uint64_t m_clientUID; uint64_t m_clientUID;
private: private:
std::vector<ememory::SharedPtr<zeus::GateWayService>> m_serviceList; //!< List of all service availlable with their specific connection interface std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_serviceList; //!< List of all service availlable with their specific connection interface
std::vector<ememory::SharedPtr<zeus::GateWayClient>> m_clientList; //!< List of all Client interface with their own connection std::vector<ememory::SharedPtr<appl::ClientInterface>> m_clientList; //!< List of all Client interface with their own connection
//TODO: std::vector<zeus::GateWayServer> m_ServerList; //!< List of all Server connected to this gateway //TODO: std::vector<appl::ServerInterface> m_ServerList; //!< List of all Server connected to this gateway
ememory::SharedPtr<zeus::TcpServerInput> m_interfaceClientServer; ememory::SharedPtr<appl::TcpServerInput> m_interfaceClientServer;
ememory::SharedPtr<zeus::TcpServerInput> m_interfaceServiceServer; ememory::SharedPtr<appl::TcpServerInput> m_interfaceServiceServer;
public: public:
eproperty::Value<std::string> propertyClientIp; eproperty::Value<std::string> propertyClientIp;
eproperty::Value<uint16_t> propertyClientPort; eproperty::Value<uint16_t> propertyClientPort;
@ -30,7 +31,7 @@ namespace zeus {
virtual ~GateWay(); virtual ~GateWay();
void start(); void start();
void stop(); void stop();
ememory::SharedPtr<zeus::GateWayService> get(const std::string& _serviceName); ememory::SharedPtr<appl::ServiceInterface> get(const std::string& _serviceName);
std::vector<std::string> getAllServiceName(); std::vector<std::string> getAllServiceName();
void answer(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data); void answer(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data);
void newService(enet::Tcp _connection); void newService(enet::Tcp _connection);

View File

@ -4,16 +4,17 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <zeus/debug.h> #include <appl/debug.h>
#include <zeus/GateWayService.h> #include <appl/ServiceInterface.h>
#include <zeus/GateWay.h> #include <appl/ClientInterface.h>
#include <appl/GateWay.h>
// todo : cHANGE THIS ... // todo : cHANGE THIS ...
static const std::string protocolError = "PROTOCOL-ERROR"; static const std::string protocolError = "PROTOCOL-ERROR";
zeus::GateWayService::GateWayService(enet::Tcp _connection, zeus::GateWay* _gatewayInterface) : appl::ServiceInterface::ServiceInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface) :
m_gatewayInterface(_gatewayInterface), m_gatewayInterface(_gatewayInterface),
m_interfaceClient(std::move(_connection), true) { m_interfaceClient(std::move(_connection), true) {
ZEUS_INFO("-----------------"); ZEUS_INFO("-----------------");
@ -21,34 +22,34 @@ zeus::GateWayService::GateWayService(enet::Tcp _connection, zeus::GateWay* _gate
ZEUS_INFO("-----------------"); ZEUS_INFO("-----------------");
} }
zeus::GateWayService::~GateWayService() { appl::ServiceInterface::~ServiceInterface() {
ZEUS_INFO("--------------------"); ZEUS_INFO("--------------------");
ZEUS_INFO("-- DELETE Service --"); ZEUS_INFO("-- DELETE Service --");
ZEUS_INFO("--------------------"); ZEUS_INFO("--------------------");
} }
bool zeus::GateWayService::isAlive() { bool appl::ServiceInterface::isAlive() {
return m_interfaceClient.isActive(); return m_interfaceClient.isActive();
} }
void zeus::GateWayService::start() { void appl::ServiceInterface::start() {
m_interfaceClient.connect(this, &zeus::GateWayService::onServiceData); m_interfaceClient.connect(this, &appl::ServiceInterface::onServiceData);
m_interfaceClient.connect(); m_interfaceClient.connect();
m_interfaceClient.setInterfaceName("srv-?"); m_interfaceClient.setInterfaceName("srv-?");
} }
void zeus::GateWayService::stop() { void appl::ServiceInterface::stop() {
m_interfaceClient.disconnect(); m_interfaceClient.disconnect();
} }
void zeus::GateWayService::SendData(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data) { void appl::ServiceInterface::SendData(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data) {
_data->setClientId(_userSessionId); _data->setClientId(_userSessionId);
m_interfaceClient.writeBinary(_data); m_interfaceClient.writeBinary(_data);
} }
void zeus::GateWayService::onServiceData(const ememory::SharedPtr<zeus::Buffer>& _value) { void appl::ServiceInterface::onServiceData(const ememory::SharedPtr<zeus::Buffer>& _value) {
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
@ -96,7 +97,7 @@ void zeus::GateWayService::onServiceData(const ememory::SharedPtr<zeus::Buffer>&
} }
void zeus::GateWayService::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::ServiceInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp); m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp);
m_interfaceClient.disconnect(true); m_interfaceClient.disconnect(true);
} }

View File

@ -5,24 +5,21 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <ememory/memory.h> #include <ememory/memory.h>
#include <esignal/Signal.h>
namespace zeus { namespace appl {
class GateWay; class GateWay;
class GateWayClient; class ClientInterface;
class GateWayService { class ServiceInterface {
friend class zeus::GateWayClient; friend class appl::ClientInterface;
private: private:
zeus::GateWay* m_gatewayInterface; appl::GateWay* m_gatewayInterface;
zeus::TcpString m_interfaceClient; zeus::WebServer m_interfaceClient;
std::string m_name; std::string m_name;
public: public:
esignal::Signal<bool> signalIsConnected; ServiceInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface);
public: virtual ~ServiceInterface();
GateWayService(enet::Tcp _connection, zeus::GateWay* _gatewayInterface);
virtual ~GateWayService();
void start(); void start();
void stop(); void stop();
void onServiceData(const ememory::SharedPtr<zeus::Buffer>& _value); void onServiceData(const ememory::SharedPtr<zeus::Buffer>& _value);

View File

@ -5,7 +5,7 @@
*/ */
#include <appl/debug.h> #include <appl/debug.h>
#include <zeus/GateWay.h> #include <appl/GateWay.h>
#include <etk/etk.h> #include <etk/etk.h>
#include <unistd.h> #include <unistd.h>
@ -13,7 +13,7 @@
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
zeus::GateWay basicGateway; appl::GateWay basicGateway;
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; std::string data = _argv[iii];
if (etk::start_with(data, "--client-ip=") == true) { if (etk::start_with(data, "--client-ip=") == true) {

View File

@ -30,6 +30,9 @@ def create(target, module_name):
my_module.add_module_depend(['zeus']) my_module.add_module_depend(['zeus'])
my_module.add_src_file([ my_module.add_src_file([
'appl/debug.cpp', 'appl/debug.cpp',
'appl/ClientInterface.cpp',
'appl/ServiceInterface.cpp',
'appl/GateWay.cpp',
'appl/main.cpp' 'appl/main.cpp'
]) ])
return my_module return my_module

View File

@ -210,20 +210,28 @@ int main(int _argc, const char *_argv[]) {
serviceInterface.setVersion("0.1.0"); serviceInterface.setVersion("0.1.0");
serviceInterface.setType("USER", 1); serviceInterface.setType("USER", 1);
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com"); serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
serviceInterface.advertise("checkTocken", &appl::SystemService::checkTocken); zeus::AbstractFunction* func = serviceInterface.advertise("checkTocken", &appl::SystemService::checkTocken);
serviceInterface.setLastFuncDesc("Check if a user tocken is correct or not"); if (func != nullptr) {
serviceInterface.addLastFuncParam("clientName", "Name of the client"); func->setDescription("Check if a user tocken is correct or not");
serviceInterface.addLastFuncParam("tocken", "String containing the Tocken"); func->addParam("clientName", "Name of the client");
serviceInterface.advertise("checkAuth", &appl::SystemService::checkAuth); func->addParam("tocken", "String containing the Tocken");
serviceInterface.setLastFuncDesc("Check the password of the curent user"); }
serviceInterface.addLastFuncParam("password", "client/user password"); func = serviceInterface.advertise("checkAuth", &appl::SystemService::checkAuth);
serviceInterface.advertise("getGroups", &appl::SystemService::getGroups); if (func != nullptr) {
serviceInterface.setLastFuncDesc("Get list of group availlable for a client name"); func->setDescription("Check the password of the curent user");
serviceInterface.addLastFuncParam("clientName", "Name of the client"); func->addParam("password", "client/user password");
serviceInterface.advertise("filterServices", &appl::SystemService::filterServices); }
serviceInterface.setLastFuncDesc("Filter a list of service with the cuurent profile of the user (restrict area)"); func = serviceInterface.advertise("getGroups", &appl::SystemService::getGroups);
serviceInterface.addLastFuncParam("clientName", "Name of the client"); if (func != nullptr) {
serviceInterface.addLastFuncParam("currentList", "Vector of name of the services"); func->setDescription("Get list of group availlable for a client name");
func->addParam("clientName", "Name of the client");
}
func = serviceInterface.advertise("filterServices", &appl::SystemService::filterServices);
if (func != nullptr) {
func->setDescription("Filter a list of service with the cuurent profile of the user (restrict area)");
func->addParam("clientName", "Name of the client");
func->addParam("currentList", "Vector of name of the services");
}
APPL_INFO("==========================================================="); APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]"); APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
APPL_INFO("==========================================================="); APPL_INFO("===========================================================");

View File

@ -7,21 +7,6 @@
#include <zeus/debug.h> #include <zeus/debug.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
ememory::SharedPtr<zeus::Buffer> zeus::createBinaryBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) {
ememory::SharedPtr<zeus::Buffer> obj = zeus::Buffer::create();
if (obj == nullptr) {
return nullptr;
}
obj->setServiceId(_serviceId);
obj->setCall(_functionName);
obj->setTransactionId(_transactionId);
return obj;
}
void zeus::createBinaryParam(int32_t _paramId, const ememory::SharedPtr<zeus::Buffer>& _obj) {
// Finish recursive parse ...
}
enum zeus::AbstractFunction::type zeus::AbstractFunction::getType() const { enum zeus::AbstractFunction::type zeus::AbstractFunction::getType() const {
return m_type; return m_type;
} }
@ -54,7 +39,7 @@ void zeus::AbstractFunction::setReturn(const std::string& _desc) {
m_returnDescription = _desc; m_returnDescription = _desc;
} }
std::string zeus::AbstractFunction::getPrototypeFull() const { std::string zeus::AbstractFunction::getPrototype() const {
std::string out = getPrototypeReturn(); std::string out = getPrototypeReturn();
out += " "; out += " ";
out += m_name; out += m_name;
@ -74,23 +59,23 @@ std::string zeus::AbstractFunction::getPrototypeFull() const {
} }
zeus::AbstractFunction::AbstractFunction(const std::string& _name, std::string zeus::AbstractFunction::getSignature() const {
const std::string& _desc): std::string out = getPrototypeReturn();
out += "(";
std::vector<std::string> tmp = getPrototypeParam();
for (size_t iii=0; iii<tmp.size(); ++iii) {
if (iii != 0) {
out += ",";
}
out += tmp[iii];
}
out += ")";
return out;
}
zeus::AbstractFunction::AbstractFunction(const std::string& _name):
m_type(zeus::AbstractFunction::type::unknow), m_type(zeus::AbstractFunction::type::unknow),
m_name(_name), m_name(_name),
m_description(_desc) { m_description("") {
} }
bool zeus::AbstractFunction::checkCompatibility(const ParamType& _type, const ParamType& _params) {
if (_params == _type) {
return true;
}
// check cross compatibilité (All number are convertible (with min/max) and all number vector are convertible (min/max too)
if ( _type.isNumber() == true
&& _params.isNumber() == true) {
return _type.isVector() == _params.isVector();
}
return false;
}

View File

@ -4,7 +4,6 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#pragma once #pragma once
#include <eproperty/Value.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <zeus/ParamType.h> #include <zeus/ParamType.h>
#include <zeus/File.h> #include <zeus/File.h>
@ -13,97 +12,122 @@
namespace zeus { namespace zeus {
/**
* @brief Interface to store a function and call it after with a @ref zeus::Buffer
*/
class AbstractFunction { class AbstractFunction {
protected:
/**
* @brief Constructor
* @param[in] _name Nmae of the function
*/
AbstractFunction(const std::string& _name);
public: public:
/**
* @brief generic virtual destructor
*/
virtual ~AbstractFunction() = default;
public:
/**
* @brief Under type of the call methode
*/
enum class type { enum class type {
unknow, unknow, //!< Does not know the type of the call
global, global, //!< This is a global function
local, local, //!< This is a local fucntion
service, service, //!< This call a service function (global function like "srv.xxx")
object, object, //!< this is for service instance call
}; };
protected: protected:
enum type m_type; enum type m_type; //!< Type of the subCall (to permit to call many type of call)
public: public:
/**
* @brief Get the tyope of the call that is needed to do.
* @return Type of the call.
*/
enum type getType() const; enum type getType() const;
/**
* @brief Set the type of the call that must be done for this function
* @param[in] _type New type of the call.
*/
void setType(enum type _type); void setType(enum type _type);
protected: protected:
std::string m_name; std::string m_name; //!< name of the function
public: public:
/**
* @brief Get the name of the function.
* @return Function name
*/
const std::string& getName() const; const std::string& getName() const;
protected: protected:
std::string m_description; std::string m_description; //!< description of the function
public: public:
/**
* @brief Get the description of the function
* @return The description string of the function (same as doxygen 'brief')
*/
const std::string& getDescription() const; const std::string& getDescription() const;
/**
* @brief Set a new description of the function
* @param[in] _desc Descriptive string
*/
void setDescription(const std::string& _desc); void setDescription(const std::string& _desc);
protected: protected:
std::vector<std::pair<std::string, std::string>> m_paramsDescription; std::vector<std::pair<std::string, std::string>> m_paramsDescription; //!< List of the parameter descriptions.
public: public:
/**
* @brief Set the parameter name and description
* @param[in] _idParam Number of the parameter
* @param[in] _name Name of the parameter
* @param[in] _desc Description of the parameter
*/
void setParam(int32_t _idParam, const std::string& _name, const std::string& _desc); void setParam(int32_t _idParam, const std::string& _name, const std::string& _desc);
/**
* @brief Set the parameter name and description of the last parameter not set (increment id every element)
* @param[in] _name Name of the parameter
* @param[in] _desc Description of the parameter
*/
void addParam(const std::string& _name, const std::string& _desc); void addParam(const std::string& _name, const std::string& _desc);
protected: protected:
std::string m_returnDescription; std::string m_returnDescription; //!< Return description of the Function
public: public:
/**
* @brief Set the return description of the Function
* @param[in] _desc Description of the return parameter
*/
void setReturn(const std::string& _desc); void setReturn(const std::string& _desc);
protected:
AbstractFunction(const std::string& _name, const std::string& _desc="");
public: public:
virtual ~AbstractFunction() {}; /**
public: * @brief Get the prototype of the function with the parameter name and type
bool checkCompatibility(const ParamType& _type, const ParamType& _params); * @return The fucntion like "void maFonction(int32 parameter_1, vector:string parameter_2);"
public: */
std::string getPrototypeFull() const; std::string getPrototype() const;
virtual std::string getPrototype() const = 0; /**
* @brief Get the signature of the function
* @return The signature of the function: "void(int32,vector:string);"
*/
virtual std::string getSignature() const;
/**
* @brief Get the string of the type of the return value
* @return type string of the return value
*/
virtual std::string getPrototypeReturn() const = 0; virtual std::string getPrototypeReturn() const = 0;
/**
* @brief Get the list of type of the parameter
* @return List of types (zeus singature mode)
*/
virtual std::vector<std::string> getPrototypeParam() const = 0; virtual std::vector<std::string> getPrototypeParam() const = 0;
virtual void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, /**
uint64_t _transactionId, * @brief Execute the function with all parameter properties
uint64_t _clientId, * @param[in] _interfaceClient Web interface to anser values
const ememory::SharedPtr<zeus::Buffer>& _params, * @param[in] _obj Call object
* @param[in] _class Pointer on the object that might be call (note: brut cast)
*/
virtual void execute(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
const ememory::SharedPtr<zeus::Buffer>& _obj,
void* _class=nullptr) = 0; void* _class=nullptr) = 0;
}; };
ememory::SharedPtr<zeus::Buffer> createBinaryBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0);
void createBinaryParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj);
template<class ZEUS_TYPE, class... _ARGS>
void createBinaryParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj,
const ZEUS_TYPE& _param,
_ARGS&&... _args) {
_obj->addParameter<ZEUS_TYPE>(_param);
_paramId++;
createBinaryParam(_paramId, _obj, std::forward<_ARGS>(_args)...);
}
// convert const char in std::string ...
template<class... _ARGS>
void createBinaryParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj,
const char* _param,
_ARGS&&... _args) {
createBinaryParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...);
} }
template<class... _ARGS> #include <zeus/WebServer.h>
ememory::SharedPtr<zeus::Buffer> createBinaryCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::Buffer> callElem = createBinaryBaseCall(_transactionId, _functionName);
if (callElem == nullptr) {
return nullptr;
}
createBinaryParam(0, callElem, std::forward<_ARGS>(_args)...);
return callElem;
}
template<class... _ARGS>
ememory::SharedPtr<zeus::Buffer> createBinaryCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::Buffer> callElem = createBinaryBaseCall(_transactionId, _functionName, _serviceName);
if (callElem == nullptr) {
return nullptr;
}
createBinaryParam(0, callElem, std::forward<_ARGS>(_args)...);
return callElem;
}
}
#include <zeus/TcpString.h>

View File

@ -5,21 +5,25 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <zeus/AbstractFunction.h> #include <zeus/AbstractFunction.h>
#include <zeus/mineType.h> #include <zeus/mineType.h>
namespace zeus { namespace zeus {
/**
* @brief Execute a call on the function with a return value
* @param[in] _interfaceClient Web interface to send data
* @param[in] _obj Buffer input call (that have parameter already check)
* @param[in] _pointer Pointer on the class to call
* @param[in] _func pointer on the function to call
*/
template <class ZEUS_CLASS_TYPE, class ZEUS_RETURN, class... ZEUS_TYPES> template <class ZEUS_CLASS_TYPE, class ZEUS_RETURN, class... ZEUS_TYPES>
void executeClassCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void executeClassCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj,
uint64_t _clientId,
ZEUS_CLASS_TYPE* _pointer, ZEUS_CLASS_TYPE* _pointer,
ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...), ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) {
const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (_obj == nullptr) { if (_obj == nullptr) {
return; return;
} }
@ -36,18 +40,23 @@ namespace zeus {
ZEUS_RETURN ret; ZEUS_RETURN ret;
return; return;
#endif #endif
_interfaceClient->addAsync([=](TcpString* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerValue(_transactionId, ret, _clientId); _interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
return true; return true;
}); });
} }
/**
* @brief Execute a call on the function with NO return value
* @param[in] _interfaceClient Web interface to send data
* @param[in] _obj Buffer input call (that have parameter already check)
* @param[in] _pointer Pointer on the class to call
* @param[in] _func pointer on the function to call
*/
template <class ZEUS_CLASS_TYPE, class... ZEUS_TYPES> template <class ZEUS_CLASS_TYPE, class... ZEUS_TYPES>
void executeClassCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void executeClassCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj,
uint64_t _clientId,
ZEUS_CLASS_TYPE* _pointer, ZEUS_CLASS_TYPE* _pointer,
void (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...), void (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) {
const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (_obj == nullptr) { if (_obj == nullptr) {
return; return;
} }
@ -63,12 +72,14 @@ namespace zeus {
#error Must be implemented ... #error Must be implemented ...
return; return;
#endif #endif
_interfaceClient->addAsync([=](TcpString* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerVoid(_transactionId, _clientId); _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
return true; return true;
}); });
} }
/**
* @brief Chass that permit to declare a function that call intanced element or a class element
*/
template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES> template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES>
class AbstractFunctionTypeClass: public zeus::AbstractFunction { class AbstractFunctionTypeClass: public zeus::AbstractFunction {
protected: protected:
@ -77,25 +88,15 @@ namespace zeus {
public: public:
using functionType = ZEUS_RETURN (ZEUS_CLASS_TYPE::*)(ZEUS_TYPES...); using functionType = ZEUS_RETURN (ZEUS_CLASS_TYPE::*)(ZEUS_TYPES...);
functionType m_function; functionType m_function;
AbstractFunctionTypeClass(const std::string& _name, const std::string& _desc, functionType _fptr): /**
AbstractFunction(_name, _desc), * @brief Constructor
* @param[in] _name Name of the function
* @param[in] _fptr Pointer on the function
*/
AbstractFunctionTypeClass(const std::string& _name, functionType _fptr):
AbstractFunction(_name),
m_function(_fptr) { m_function(_fptr) {
} }
std::string getPrototype() const override {
std::string ret;
ret += m_returnType.getName();
ret += " ";
ret += m_name;
ret += "(";
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (iii != 0) {
ret += ", ";
}
ret += m_paramType[iii].getName();
}
ret += ");";
return ret;
}
std::string getPrototypeReturn() const override { std::string getPrototypeReturn() const override {
return m_returnType.getName(); return m_returnType.getName();
} }
@ -106,9 +107,7 @@ namespace zeus {
} }
return out; return out;
} }
void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void execute(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId,
uint64_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _obj, const ememory::SharedPtr<zeus::Buffer>& _obj,
void* _class) override { void* _class) override {
if (_obj == nullptr) { if (_obj == nullptr) {
@ -128,37 +127,41 @@ namespace zeus {
help += etk::to_string(sizeof...(ZEUS_TYPES)); help += etk::to_string(sizeof...(ZEUS_TYPES));
help += " parameters. prototype function:"; help += " parameters. prototype function:";
help += getPrototype(); help += getPrototype();
_interfaceClient->answerError(_transactionId, _interfaceClient->answerError(_obj->getTransactionId(),
"WRONG-PARAMETER-NUMBER", "WRONG-PARAMETER-NUMBER",
help, help,
_clientId); _obj->getClientId());
return; return;
} }
// check parameter compatibility // check parameter compatibility
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) { for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) { if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
_interfaceClient->answerError(_transactionId, _interfaceClient->answerError(_obj->getTransactionId(),
"WRONG-PARAMETER-TYPE", "WRONG-PARAMETER-TYPE",
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'", std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
_clientId); _obj->getClientId());
return; return;
} }
} }
// execute cmd: // execute cmd:
zeus::executeClassCall(_interfaceClient, _transactionId, _clientId, tmpClass, m_function, _obj); zeus::executeClassCall(_interfaceClient, _obj, tmpClass, m_function);
} }
}; };
// specialization
template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES> template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES>
const ParamType AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>::m_returnType = createType<ZEUS_RETURN>(); const ParamType AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>::m_returnType = createType<ZEUS_RETURN>();
// specialization
template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES> template <class ZEUS_RETURN, class ZEUS_CLASS_TYPE, class... ZEUS_TYPES>
const ParamType AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>::m_paramType[sizeof...(ZEUS_TYPES)] = {createType<ZEUS_TYPES>()...}; const ParamType AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>::m_paramType[sizeof...(ZEUS_TYPES)] = {createType<ZEUS_TYPES>()...};
/**
* @brief Create a function information with the function type
* @param[in] _name Name of the function
* @param[in] _fffp Pointer of the function
* @return Abstract type of the function
*/
template <typename ZEUS_RETURN, class ZEUS_CLASS_TYPE, typename... ZEUS_TYPES> template <typename ZEUS_RETURN, class ZEUS_CLASS_TYPE, typename... ZEUS_TYPES>
AbstractFunction* createAbstractFunctionClass(const std::string& _name, const std::string& _desc, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_fffp)(ZEUS_TYPES...)) { AbstractFunction* createAbstractFunctionClass(const std::string& _name, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_fffp)(ZEUS_TYPES...)) {
return new AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>(_name, _desc, _fffp); return new AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>(_name, _fffp);
} }
} }

View File

@ -5,17 +5,20 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <zeus/AbstractFunction.h> #include <zeus/AbstractFunction.h>
namespace zeus { namespace zeus {
/**
* @brief Execute a call on the global function with a return value
* @param[in] _interfaceClient Web interface to send data
* @param[in] _obj Buffer input call (that have parameter already check)
* @param[in] _func pointer on the function to call
*/
template <class ZEUS_RETURN, class... ZEUS_TYPES> template <class ZEUS_RETURN, class... ZEUS_TYPES>
void executeCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void executeCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj,
uint64_t _clientId, ZEUS_RETURN (*_func)(ZEUS_TYPES...)) {
ZEUS_RETURN (*_func)(ZEUS_TYPES...),
const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (_obj == nullptr) { if (_obj == nullptr) {
return; return;
} }
@ -30,18 +33,21 @@ namespace zeus {
#else #else
#error Must be implemented ... #error Must be implemented ...
#endif #endif
_interfaceClient->addAsync([=](TcpString* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerValue(_transactionId, ret, _clientId); _interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
return true; return true;
}); });
} }
/**
* @brief Execute a call on the global function with NO return value
* @param[in] _interfaceClient Web interface to send data
* @param[in] _obj Buffer input call (that have parameter already check)
* @param[in] _func pointer on the function to call
*/
template <class... ZEUS_TYPES> template <class... ZEUS_TYPES>
void executeCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void executeCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj,
uint64_t _clientId, void (*_func)(ZEUS_TYPES...)) {
void (*_func)(ZEUS_TYPES...),
const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (_obj == nullptr) { if (_obj == nullptr) {
return; return;
} }
@ -56,12 +62,15 @@ namespace zeus {
#else #else
#error Must be implemented ... #error Must be implemented ...
#endif #endif
_interfaceClient->addAsync([=](TcpString* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerVoid(_transactionId, _clientId); _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
return true; return true;
}); });
} }
/**
* @brief Chass that permit to declare a function that call global function
*/
template <class ZEUS_RETURN, class... ZEUS_TYPES> template <class ZEUS_RETURN, class... ZEUS_TYPES>
class AbstractFunctionTypeDirect: public zeus::AbstractFunction { class AbstractFunctionTypeDirect: public zeus::AbstractFunction {
protected: protected:
@ -70,25 +79,15 @@ namespace zeus {
public: public:
using functionType = ZEUS_RETURN (*)(ZEUS_TYPES...); using functionType = ZEUS_RETURN (*)(ZEUS_TYPES...);
functionType m_function; functionType m_function;
AbstractFunctionTypeDirect(const std::string& _name, const std::string& _desc, functionType _fptr): /**
AbstractFunction(_name, _desc), * @brief Constructor
* @param[in] _name Name of the function
* @param[in] _fptr Pointer on the function
*/
AbstractFunctionTypeDirect(const std::string& _name, functionType _fptr):
AbstractFunction(_name),
m_function(_fptr) { m_function(_fptr) {
} }
std::string getPrototype() const override {
std::string ret;
ret += m_returnType.getName();
ret += " ";
ret += m_name;
ret += "(";
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (iii != 0) {
ret += ", ";
}
ret += m_paramType[iii].getName();
}
ret += ");";
return ret;
}
std::string getPrototypeReturn() const override { std::string getPrototypeReturn() const override {
return m_returnType.getName(); return m_returnType.getName();
} }
@ -99,9 +98,7 @@ namespace zeus {
} }
return out; return out;
} }
void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient, void execute(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
uint64_t _transactionId,
uint64_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _obj, const ememory::SharedPtr<zeus::Buffer>& _obj,
void* _class) override { void* _class) override {
if (_obj == nullptr) { if (_obj == nullptr) {
@ -115,36 +112,40 @@ namespace zeus {
help += etk::to_string(sizeof...(ZEUS_TYPES)); help += etk::to_string(sizeof...(ZEUS_TYPES));
help += " parameters. prototype function:"; help += " parameters. prototype function:";
help += getPrototype(); help += getPrototype();
_interfaceClient->answerError(_transactionId, _interfaceClient->answerError(_obj->getTransactionId(),
"WRONG-PARAMETER-NUMBER", "WRONG-PARAMETER-NUMBER",
help, help,
_clientId); _obj->getClientId());
return; return;
} }
// check parameter compatibility // check parameter compatibility
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) { for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) { if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
_interfaceClient->answerError(_transactionId, _interfaceClient->answerError(_obj->getTransactionId(),
"WRONG-PARAMETER-TYPE", "WRONG-PARAMETER-TYPE",
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'", std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
_clientId); _obj->getClientId());
return; return;
} }
} }
// execute cmd: // execute cmd:
zeus::executeCall(_interfaceClient, _transactionId, _clientId, m_function, _obj); zeus::executeCall(_interfaceClient, _obj, m_function);
} }
}; };
// specialization
template <class ZEUS_RETURN, class... ZEUS_TYPES> template <class ZEUS_RETURN, class... ZEUS_TYPES>
const ParamType AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>::m_returnType = createType<ZEUS_RETURN>(); const ParamType AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>::m_returnType = createType<ZEUS_RETURN>();
// specialization
template <class ZEUS_RETURN, class... ZEUS_TYPES> template <class ZEUS_RETURN, class... ZEUS_TYPES>
const ParamType AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>::m_paramType[sizeof...(ZEUS_TYPES)] = {createType<ZEUS_TYPES>()...}; const ParamType AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>::m_paramType[sizeof...(ZEUS_TYPES)] = {createType<ZEUS_TYPES>()...};
/**
* @brief Create a function information with the function type
* @param[in] _name Name of the function
* @param[in] _fffp Pointer of the function
* @return Abstract type of the function
*/
template <typename ZEUS_RETURN, typename... ZEUS_TYPES> template <typename ZEUS_RETURN, typename... ZEUS_TYPES>
AbstractFunction* createAbstractFunctionDirect(const std::string& _name, const std::string& _desc, ZEUS_RETURN (*_fffp)(ZEUS_TYPES...)) { zeus::AbstractFunction* createAbstractFunctionDirect(const std::string& _name, ZEUS_RETURN (*_fffp)(ZEUS_TYPES...)) {
return new AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>(_name, _desc, _fffp); return new AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>(_name, _fffp);
} }
} }

View File

@ -137,7 +137,7 @@ bool zeus::Buffer::writeOn(enet::WebSocket& _interface) {
size += sizeof(uint32_t); // parameter size size += sizeof(uint32_t); // parameter size
size += it.second.size(); size += it.second.size();
} }
ZEUS_DEBUG("Send BINARY " << size << " bytes '" << generateHumanString() << "'"); ZEUS_VERBOSE("Send BINARY " << size << " bytes '" << *this << "'");
if (_interface.writeHeader(size, false) == false) { if (_interface.writeHeader(size, false) == false) {
return false; return false;
@ -167,65 +167,61 @@ void zeus::Buffer::clear() {
m_header.numberOfParameter = 1; m_header.numberOfParameter = 1;
} }
std::string zeus::Buffer::generateHumanString() { std::ostream& zeus::operator <<(std::ostream& _os, const zeus::Buffer& _obj) {
std::string out = "zeus::Buffer: "; _os << "zeus::Buffer: ";
//out += " v=" + etk::to_string(m_header.versionProtocol); // se it in the websocket //out += " v=" + etk::to_string(m_header.versionProtocol); // se it in the websocket
out += " id=" + etk::to_string(m_header.transactionID); _os << " id=" << etk::to_string(_obj.getTransactionId());
out += " cId=" + etk::to_string(m_header.clientID); _os << " cId=" << etk::to_string(_obj.getClientId());
if ( getPartFinish() == false if ( _obj.getPartFinish() == false
|| getPartId() != 0) { || _obj.getPartId() != 0) {
out += " part=" + etk::to_string(getPartId()); _os << " part=" << etk::to_string(_obj.getPartId());
if (getPartFinish() == true) { if (_obj.getPartFinish() == true) {
out += "/finish"; _os << "/finish";
} }
} }
enum zeus::Buffer::typeMessage type = getTypeType(m_header.typeMessage); enum zeus::Buffer::typeMessage type = _obj.getType();
switch (type) { switch (type) {
case zeus::Buffer::typeMessage::unknow: case zeus::Buffer::typeMessage::unknow:
out += " -UNKNOW-"; _os << " -UNKNOW-";
break; break;
case zeus::Buffer::typeMessage::call: case zeus::Buffer::typeMessage::call:
out += " nbParam=" + etk::to_string(getNumberParameter()); _os << " nbParam=" + etk::to_string(_obj.getNumberParameter());
out += " -CALL-:'" + getCall() + "'"; _os << " -CALL-:'" + _obj.getCall() + "'";
break; break;
case zeus::Buffer::typeMessage::answer: case zeus::Buffer::typeMessage::answer:
out += " -ANSWER-:"; _os << " -ANSWER-:";
if (m_parameter.size() == 1) { if (_obj.m_parameter.size() == 1) {
out += "Value:" + simpleStringParam(0); _os << "Value:" + _obj.simpleStringParam(0);
} else if (m_parameter.size() == 2) { } else if (_obj.m_parameter.size() == 2) {
out += "Error"; _os << "Error";
out += "Error:" + simpleStringParam(0); _os << "Error:" + _obj.simpleStringParam(0);
} else if (m_parameter.size() == 3) { } else if (_obj.m_parameter.size() == 3) {
out += "Value:" + simpleStringParam(0); _os << "Value:" + _obj.simpleStringParam(0);
out += "+Error:" + simpleStringParam(1); _os << "+Error:" + _obj.simpleStringParam(1);
} else { } else {
out += "???"; _os << "???";
} }
break; break;
case zeus::Buffer::typeMessage::event: case zeus::Buffer::typeMessage::event:
out += " -EVENT-"; _os << " -EVENT-";
break; break;
case zeus::Buffer::typeMessage::data: case zeus::Buffer::typeMessage::data:
out += " -DATA-"; _os << " -DATA-";
break; break;
} }
if (getNumberParameter() != 0) { if (_obj.getNumberParameter() != 0) {
out += " paramType("; _os << " paramType(";
if (getNumberParameter() >256) { for (int32_t iii=0; iii<_obj.getNumberParameter(); ++iii) {
out += " !!!!!!!";
return out;
}
for (int32_t iii=0; iii< getNumberParameter(); ++iii) {
if (iii != 0) { if (iii != 0) {
out += ","; _os << ",";
} }
out += internalGetParameterType(iii).getName(); _os << _obj.internalGetParameterType(iii).getName();
} }
out += ")"; _os << ")";
} }
return out; return _os;
} }
uint32_t zeus::Buffer::getTransactionId() const { uint32_t zeus::Buffer::getTransactionId() const {
@ -246,10 +242,17 @@ void zeus::Buffer::setClientId(uint32_t _value) {
// note limited 15 bits // note limited 15 bits
uint16_t zeus::Buffer::getPartId() const { uint16_t zeus::Buffer::getPartId() const {
if (getType() != zeus::Buffer::typeMessage::data) {
return 0;
}
return uint16_t(m_header.partID & 0x7FFF); return uint16_t(m_header.partID & 0x7FFF);
} }
void zeus::Buffer::setPartId(uint16_t _value) { void zeus::Buffer::setPartId(uint16_t _value) {
if (getType() != zeus::Buffer::typeMessage::data) {
ZEUS_ERROR("can not set a partId at other than data buffer");
return;
}
m_header.partID = (m_header.partID&0x8000) | (_value & 0x7FFF); m_header.partID = (m_header.partID&0x8000) | (_value & 0x7FFF);
} }

View File

@ -9,9 +9,9 @@
#include <zeus/ParamType.h> #include <zeus/ParamType.h>
namespace zeus { namespace zeus {
class TcpString; class WebServer;
// define basic async call element ... // define basic async call element ...
using ActionAsyncClient = std::function<bool(TcpString* _interface, const uint32_t& _serviceId, uint64_t _transactionId, uint64_t _part)>; using ActionAsyncClient = std::function<bool(WebServer* _interface, const uint32_t& _serviceId, uint64_t _transactionId, uint64_t _part)>;
} }
@ -89,118 +89,331 @@ namespace zeus {
- vector:string - vector:string
- obj:file - obj:file
*/ */
/**
* @brief Protocol buffer to transmit datas
*/
class Buffer { class Buffer {
friend std::ostream& operator<<(std::ostream&, const zeus::Buffer&);
protected: protected:
/**
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Buffer::create
*/
Buffer(); Buffer();
public: public:
/**
* @brief Create a shared pointer on the buffer
* @return Allocated Buffer.
*/
static ememory::SharedPtr<zeus::Buffer> create(); static ememory::SharedPtr<zeus::Buffer> create();
protected: protected:
headerBin m_header; headerBin m_header; //!< header of the protocol
mutable std::vector<std::pair<int32_t,std::vector<uint8_t>>> m_parameter; 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...)
std::vector<zeus::ActionAsyncClient> m_multipleSend; std::vector<zeus::ActionAsyncClient> m_multipleSend; //!< Async element to send data on the webinterface when too big ...
public: public:
/**
* @brief Check if async element are present on this buffer
* @return return true if somme data must be send asyncronously
*/
bool haveAsync() const { bool haveAsync() const {
return m_multipleSend.size() != 0; return m_multipleSend.size() != 0;
} }
/**
* @brief Get the list of async data to send
* @return Vector of the async data (the async are moved out ... call only one time)
*/
std::vector<zeus::ActionAsyncClient> moveAsync() { std::vector<zeus::ActionAsyncClient> moveAsync() {
return std::move(m_multipleSend); return std::move(m_multipleSend);
} }
/**
* @brief When multiple frame buffer, they need to concatenate the data... call this function with the new data to append it ...
* @param[in] _obj Buffer to add
*/
void appendBufferData(const ememory::SharedPtr<zeus::Buffer>& _obj); void appendBufferData(const ememory::SharedPtr<zeus::Buffer>& _obj);
protected: protected:
/**
* @brief When receive new data form websocket, it might be added by this input (set all the frame ...)
* @param[in] _buffer Pointer on the data to add.
* @param[in] _lenght number of octet to add.
*/
void internalComposeWith(const uint8_t* _buffer, uint32_t _lenght); void internalComposeWith(const uint8_t* _buffer, uint32_t _lenght);
public: public:
/**
* @brief When receive new data form websocket, it might be added by this input.
* @param[in] _buffer Buffer on the data
*/
void composeWith(const std::vector<uint8_t>& _buffer); void composeWith(const std::vector<uint8_t>& _buffer);
void composeWith(const std::string& _buffer); /**
std::string generateHumanString(); * @brief Chear the buffer
*/
void clear(); void clear();
/**
* @brief Get the transaction identifier of the packet
* @return value of the transaction
*/
uint32_t getTransactionId() const; uint32_t getTransactionId() const;
/**
* @brief Set the transaction identifier of the packet
* @param[in] _value New transaction id
*/
void setTransactionId(uint32_t _value); void setTransactionId(uint32_t _value);
/**
* @brief Get the Client identifier of the packet
* @return Value of the Client identifier
*/
uint32_t getClientId() const;// this is the same as serviceId uint32_t getClientId() const;// this is the same as serviceId
/**
* @brief Set the Client identifier of the packet
* @param[in] _value New value of the Client identifier
*/
void setClientId(uint32_t _value); void setClientId(uint32_t _value);
/**
* @brief Get the Service identifier of the packet (same as client)
* @return Value of the Service identifier
*/
uint32_t getServiceId() const { uint32_t getServiceId() const {
return getClientId(); return getClientId();
} }
/**
* @brief Set the Service identifier of the packet (same as client)
* @param[in] _value New value of the Service identifier
*/
void setServiceId(uint32_t _value) { void setServiceId(uint32_t _value) {
setClientId(_value); setClientId(_value);
} }
// note limited 15 bits /**
* @brief Get the part Id of the buffer
* @return Part Identifier
*/
uint16_t getPartId() const; uint16_t getPartId() const;
/**
* @brief Set the part Id of the buffer
* @param[in] _value New Part ID
*/
void setPartId(uint16_t _value); void setPartId(uint16_t _value);
/**
* @brief Check if it is the last packet of the buffer
* @return If "true" The Buffer wait no more datas
*/
bool getPartFinish() const; bool getPartFinish() const;
/**
* @brief set the finish state of the buffer
* @param[in] _value set the sate of finish of the buffer
*/
void setPartFinish(bool _value); void setPartFinish(bool _value);
/**
* @brief Type of the massage send or receive
*/
enum class typeMessage { enum class typeMessage {
unknow = 0x0000, // Init value unknow = 0x0000, //!< Init value
call = 0x0001, // Remote call on a service ID call = 0x0001, //!< Remote call on a service ID
answer = 0x0002, // Answer from a previous call 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 data = 0x0003, //!< data message happend when partId > 0 it compleate the data of a parameter or an answer or an event
event = 0x0004, // event message event = 0x0004, //!< event message
}; };
/**
* @brief Get the type of the buffer
* @return the current type of the buffer
*/
enum typeMessage getType() const; enum typeMessage getType() const;
/**
* @brief Set the type of the buffer
* @param[in] _value New type of the buffer
*/
void setType(enum typeMessage _value); void setType(enum typeMessage _value);
protected:
/**
* @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 internalGetParameter(int32_t _id) const;
/**
* @brief Get the type of a parameter.
* @param[in] _id Number of the parameter
* @return type of the parameter
*/
zeus::ParamType internalGetParameterType(int32_t _id) const;
/**
* @brief Get the start pointer of the parameter
* @param[in] _id Number of the parameter
* @return pointer of the parameter or nullptr
*/
const uint8_t* internalGetParameterPointer(int32_t _id) const;
/**
* @brief Get the size of the parameter availlable in the parameter pointer
* @param[in] _id Number of the parameter
* @return size of the parameter buffer
*/
uint32_t internalGetParameterSize(int32_t _id) const;
/**
* @brief Convert the parameter in a simple human readable string
* @param[in] _id Number of the parameter
* @return readable string
*/
std::string simpleStringParam(uint32_t _id) const;
// =============================================== // ===============================================
// == Section call // == Section call
// =============================================== // ===============================================
protected:
template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA internalGetParameter(int32_t _id) const;
zeus::ParamType internalGetParameterType(int32_t _id) const;
const uint8_t* internalGetParameterPointer(int32_t _id) const;
uint32_t internalGetParameterSize(int32_t _id) const;
std::string simpleStringParam(uint32_t _id) const;
public: public:
/**
* @brief get the call value of the buffer
* @return string of the function to call
*/
std::string getCall() const; std::string getCall() const;
/**
* @brief Set the call value of the buffer
* @param[in] _value Function to call
*/
void setCall(std::string _value); void setCall(std::string _value);
/**
* @brief Get the number of parameter availlable
* @return number of parameter
*/
uint16_t getNumberParameter() const; uint16_t getNumberParameter() const;
/**
* @brief Get the type of a parameter.
* @param[in] _id Number of the parameter
* @return type of the parameter
*/
zeus::ParamType getParameterType(int32_t _id) const; 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; 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; uint32_t getParameterSize(int32_t _id) const;
protected: 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> template<class ZEUS_TYPE_DATA>
void internalAddParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value); void internalAddParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
public: public:
/**
* @brief Add a parameter on the call function
* @param[in] _value Value to add in parameter
*/
template<class ZEUS_TYPE_DATA> template<class ZEUS_TYPE_DATA>
void addParameter(const ZEUS_TYPE_DATA& _value) { void addParameter(const ZEUS_TYPE_DATA& _value) {
internalAddParameter<ZEUS_TYPE_DATA>(m_parameter.size(), _value); internalAddParameter<ZEUS_TYPE_DATA>(m_parameter.size(), _value);
} }
/**
* @brief Add an empty vector with no type
*/
void addParameterEmptyVector(); void addParameterEmptyVector();
/**
* @brief Add parameter (or not.. this is the end of an auto resursive add parameter)
*/
void addParameter(); void addParameter();
/**
* @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> template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getParameter(int32_t _id) const { ZEUS_TYPE_DATA getParameter(int32_t _id) const {
return internalGetParameter<ZEUS_TYPE_DATA>(_id+1); return internalGetParameter<ZEUS_TYPE_DATA>(_id+1);
} }
// =============================================== // ===============================================
// == Section Answer // == Section Answer
// =============================================== // ===============================================
public: public:
/**
* @brief set the answer of the call
* @param[in] _value Value to add
*/
template<class ZEUS_TYPE_DATA> template<class ZEUS_TYPE_DATA>
void addAnswer(const ZEUS_TYPE_DATA& _value) { void addAnswer(const ZEUS_TYPE_DATA& _value) {
addParameter(_value); addParameter(_value);
} }
/**
* @brief get the answer value
* @param[in] Data of the answer
*/
// TODO : Do it better check error ... ==> can be good ... // TODO : Do it better check error ... ==> can be good ...
template<class ZEUS_TYPE_DATA> template<class ZEUS_TYPE_DATA>
ZEUS_TYPE_DATA getAnswer() const { ZEUS_TYPE_DATA getAnswer() const {
return internalGetParameter<ZEUS_TYPE_DATA>(0); return internalGetParameter<ZEUS_TYPE_DATA>(0);
} }
/**
* @brief Ann an error on the message answer
* @param[in] _value error value (simple string with no space with all capital letter separaete with '_'
* @param[in] _comment Human readable help to understand the error
*/
void addError(const std::string& _value, const std::string& _comment); 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(); bool hasError();
/**
* @brief get the error value (if exist)
* @return string of the error
*/
std::string getError(); std::string getError();
/**
* @brief get the error help (if exist)
* @return string of the error help
*/
std::string getErrorHelp(); std::string getErrorHelp();
public: public:
//multiple section of data (part ...) /**
* @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); void addData(uint16_t _parameterId, void* _data, uint32_t _size);
/**
* @brief Write the buffer on a specific interface
* @param[in] _interface socket to write data
* @return true of no error appear
*/
bool writeOn(enet::WebSocket& _interface); bool writeOn(enet::WebSocket& _interface);
}; };
/**
* @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); 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, const zeus::Buffer& _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); 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); void addTypeObject(std::vector<uint8_t>& _data, const std::string _type);
/**
* @brief Add a parameter RAW type in the buffer
* @param[in] _data Buffer to add type
*/
void addTypeRaw(std::vector<uint8_t>& _data); void addTypeRaw(std::vector<uint8_t>& _data);
} }

View File

@ -316,7 +316,7 @@ namespace zeus {
~SendData() { ~SendData() {
} }
bool operator() (zeus::TcpString* _interface, bool operator() (zeus::WebServer* _interface,
uint32_t _clientId, uint32_t _clientId,
uint32_t _transactionId, uint32_t _transactionId,
uint32_t _partId) { uint32_t _partId) {
@ -362,14 +362,10 @@ void zeus::Buffer::internalAddParameter<zeus::File>(uint16_t _paramId, const zeu
const std::vector<uint8_t>& dataFile = _value.getData(); const std::vector<uint8_t>& dataFile = _value.getData();
if (dataFile.size() != 0) { if (dataFile.size() != 0) {
currentOffset = data.size(); currentOffset = data.size();
ZEUS_ERROR("set buffer with size: " << dataFile.size());
if (dataFile.size() < ZEUS_MINIMUM_SIZE_MULTIPLE) { if (dataFile.size() < ZEUS_MINIMUM_SIZE_MULTIPLE) {
data.resize(data.size()+dataFile.size()); data.resize(data.size()+dataFile.size());
memcpy(&data[currentOffset], &dataFile[0], dataFile.size()); memcpy(&data[currentOffset], &dataFile[0], dataFile.size());
} else { } else {
ZEUS_WARNING("multiple send the data file: " << _value.getMineType());
// multiple send ... (no data in the first frame ...
// TODO : m_multipleSend.push_back(SendFile(std::move(node), _paramId, size));
m_multipleSend.push_back(zeus::SendData(dataFile, _paramId)); m_multipleSend.push_back(zeus::SendData(dataFile, _paramId));
} }
} }
@ -391,7 +387,7 @@ namespace zeus {
~SendFile() { ~SendFile() {
} }
bool operator() (zeus::TcpString* _interface, bool operator() (zeus::WebServer* _interface,
uint32_t _clientId, uint32_t _clientId,
uint32_t _transactionId, uint32_t _transactionId,
uint32_t _partId) { uint32_t _partId) {
@ -438,12 +434,7 @@ void zeus::Buffer::internalAddParameter<zeus::FileServer>(uint16_t _paramId, con
zeus::File tmpFile(zeus::getMineType(extention), fileData, size); zeus::File tmpFile(zeus::getMineType(extention), fileData, size);
internalAddParameter(_paramId, tmpFile); internalAddParameter(_paramId, tmpFile);
node.fileClose(); node.fileClose();
if (size < ZEUS_MINIMUM_SIZE_MULTIPLE) { if (size >= ZEUS_MINIMUM_SIZE_MULTIPLE) {
//node.fileClose();
} else {
ZEUS_WARNING("multiple send the file: " << _value.getFileName() << " with size " << size);
// multiple send ... (no data in the first frame ...
// TODO : m_multipleSend.push_back(SendFile(std::move(node), _paramId, size));
m_multipleSend.push_back(zeus::SendFile(_value.getFileName(), _paramId, size)); m_multipleSend.push_back(zeus::SendFile(_value.getFileName(), _paramId, size));
} }
} }

View File

@ -24,7 +24,7 @@ void zeus::Client::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value->generateHumanString()); ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << *_value);
} }
zeus::ServiceRemote zeus::Client::getService(const std::string& _name) { zeus::ServiceRemote zeus::Client::getService(const std::string& _name) {
@ -40,11 +40,11 @@ void zeus::Client::onPropertyChangePort(){
} }
bool zeus::Client::connect(const std::string& _remoteUserToConnect){ bool zeus::Client::connectTo(const std::string& _address) {
ZEUS_DEBUG("connect [START]"); ZEUS_DEBUG("connect [START]");
disconnect(); disconnect();
enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort)); enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort));
m_interfaceClient = std::make_shared<zeus::TcpString>(); m_interfaceClient = std::make_shared<zeus::WebServer>();
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
ZEUS_ERROR("Allocate connection error"); ZEUS_ERROR("Allocate connection error");
return false; return false;
@ -53,11 +53,11 @@ bool zeus::Client::connect(const std::string& _remoteUserToConnect){
m_interfaceClient->setInterface(std::move(connection), false); m_interfaceClient->setInterface(std::move(connection), false);
m_interfaceClient->connect(); m_interfaceClient->connect();
ZEUS_WARNING("Request connect user " << _remoteUserToConnect); ZEUS_WARNING("Request connect user " << _address);
zeus::Future<bool> ret = call("connectToUser", _remoteUserToConnect, "zeus-client"); zeus::Future<bool> ret = call("connectToUser", _address, "zeus-client");
ret.wait(); ret.wait();
if (ret.hasError() == true) { if (ret.hasError() == true) {
ZEUS_WARNING("Can not connect to user named: '" << _remoteUserToConnect << "' ==> return error"); ZEUS_WARNING("Can not connect to user named: '" << _address << "' ==> return error");
return false; return false;
} }
if (ret.get() == true) { if (ret.get() == true) {
@ -68,6 +68,54 @@ bool zeus::Client::connect(const std::string& _remoteUserToConnect){
return ret.get(); return ret.get();
} }
bool connect(const std::string& _address) {
bool ret = connectTo(_address);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call("anonymous").wait();
if (retIdentify.haveError() == true) {
disconnect();
return false;
}
if (retIdentify.get() == false) {
disconnect();
}
return retIdentify.get();
}
bool connect(const std::string& _address, const std::string& _userPassword) {
bool ret = connectTo(_address);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call("auth", _userPassword).wait();
if (retIdentify.haveError() == true) {
disconnect();
return false;
}
if (retIdentify.get() == false) {
disconnect();
}
return retIdentify.get();
}
bool connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken) {
bool ret = connectTo(_address);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call("identify", _clientName, _clientTocken).wait();
if (retIdentify.haveError() == true) {
disconnect();
return false;
}
if (retIdentify.get() == false) {
disconnect();
}
return retIdentify.get();
}
void zeus::Client::disconnect() { void zeus::Client::disconnect() {
ZEUS_DEBUG("disconnect [START]"); ZEUS_DEBUG("disconnect [START]");
if (m_interfaceClient != nullptr) { if (m_interfaceClient != nullptr) {

View File

@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h> #include <eproperty/Value.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <chrono> #include <chrono>
@ -14,13 +14,16 @@
#include <zeus/ServiceRemote.h> #include <zeus/ServiceRemote.h>
namespace zeus { namespace zeus {
/**
* @brief Client interface to acces on the remote service and gateway
*/
class Client : public eproperty::Interface { class Client : public eproperty::Interface {
friend class ServiceRemote; friend class ServiceRemote;
public: public:
eproperty::Value<std::string> propertyIp; eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
eproperty::Value<uint16_t> propertyPort; eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
private: private:
ememory::SharedPtr<zeus::TcpString> m_interfaceClient; ememory::SharedPtr<zeus::WebServer> m_interfaceClient; //!< Interface on the Websocket interface
public: public:
/** /**
* @brief Create a client on a specific user in a client mode with the tocken associated * @brief Create a client on a specific user in a client mode with the tocken associated
@ -35,26 +38,69 @@ namespace zeus {
* @param[in] _userPassword Password of the user * @param[in] _userPassword Password of the user
*/ */
//Client(const std::string& _address, const std::string& _userPassword); //Client(const std::string& _address, const std::string& _userPassword);
/**
* @brief Create a client on a specific user in an ANONIMOUS way
* @param[in] _address Address of the user: "ABCD.efgh#atria-soft.com:1993"
*/
//Client(const std::string& _address); //Client(const std::string& _address);
/**
* @brief
* @param[in]
* @return
*/
Client(); Client();
/**
* @brief
* @param[in]
* @return
*/
virtual ~Client(); virtual ~Client();
bool connect(const std::string& _remoteUserToConnect); protected:
/**
* @brief Connetc to a remote extern server
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
*/
bool connectTo(const std::string& _address);
public:
/**
* @brief Create a client on a specific user in an ANONIMOUS way
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
*/
bool connect(const std::string& _address);
/**
* @brief Create a client on a specific user in a user mode (connect to your personnal account)
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in] _userPassword Password of the user
*/
bool connect(const std::string& _address, const std::string& _userPassword);
/**
* @brief Create a client on a specific user in a client mode with the tocken associated
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in]
* @param[in]
*/
bool connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken);
/**
* @brief Disconnect of the current interface
*/
void disconnect(); void disconnect();
public: public:
/**
* @brief Get a remote service
* @param[in] _serviceName Name of the service
* @return Pointer on an interface of remote service
*/
zeus::ServiceRemote getService(const std::string& _serviceName); zeus::ServiceRemote getService(const std::string& _serviceName);
// Connect that is not us
//bool identify("clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968");
// Connect to ourself:
//client1.authentificate("coucou");
private: private:
/**
* @brief When receive data from the websocket ... call this ...
* @param[in] _value New input buffer
*/
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value); void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);
public: public:
/**
* @brief Create a call on the interface gateway
* @param[in] _functionName name of the function to call
* @param[in] _args... multiple argument neededs
* @return a future that will contain the aswer when receiveed (need to transmit over ethernet)
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
@ -64,6 +110,13 @@ namespace zeus {
} }
return m_interfaceClient->call(_functionName, _args...); return m_interfaceClient->call(_functionName, _args...);
} }
/**
* @brief Create a call on the interface gateway
* @param[in] _functionName name of the function to call
* @param[in] _args... multiple argument neededs
* @param[in] _callback Observer to call when the data is compleately arrived
* @return a future that will contain the aswer when receiveed (need to transmit over ethernet)
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
@ -74,7 +127,13 @@ namespace zeus {
return m_interfaceClient->callAction(_functionName, _args..., _callback); return m_interfaceClient->callAction(_functionName, _args..., _callback);
} }
private: private:
/**
* @brief Internal (called when user change the Ip of the client interface)
*/
void onPropertyChangeIp(); void onPropertyChangeIp();
/**
* @brief Internal (called when user change the port of the client interface)
*/
void onPropertyChangePort(); void onPropertyChangePort();
}; };
} }

View File

@ -20,7 +20,6 @@ zeus::File::File() {
zeus::File::File(const std::string& _filename) { zeus::File::File(const std::string& _filename) {
m_data = etk::FSNodeReadAllDataType<uint8_t>(_filename); m_data = etk::FSNodeReadAllDataType<uint8_t>(_filename);
std::string extention = std::string(_filename.begin()+_filename.size() -3, _filename.end()); std::string extention = std::string(_filename.begin()+_filename.size() -3, _filename.end());
ZEUS_WARNING("send file: '" << _filename << "' with extention: '" << extention << "'");
m_mineType = zeus::getMineType(extention); m_mineType = zeus::getMineType(extention);
} }
@ -43,8 +42,8 @@ void zeus::File::setData(uint64_t _offset, const std::vector<uint8_t>& _data) {
} }
void zeus::File::setData(uint64_t _offset, const uint8_t* _data, uint32_t _size) { void zeus::File::setData(uint64_t _offset, const uint8_t* _data, uint32_t _size) {
if (_size+_offset >= m_data.size()) { if (_size+_offset > m_data.size()) {
ZEUS_ERROR("Need Resize file buffer ..."); ZEUS_ERROR("Need Resize file buffer ... need=" << _size+_offset << " have=" << m_data.size());
m_data.resize(_size+_offset); m_data.resize(_size+_offset);
} }
memcpy(&m_data[_offset], _data, _size); memcpy(&m_data[_offset], _data, _size);

View File

@ -7,40 +7,106 @@
#include <etk/types.h> #include <etk/types.h>
namespace zeus { namespace zeus {
/**
* @brief File inetrface
*/
class File { class File {
private: private:
std::string m_mineType; std::string m_mineType;
int32_t m_fileSize; int32_t m_fileSize;
std::vector<uint8_t> m_data; std::vector<uint8_t> m_data;
public: public:
/**
* @brief Contructor of an empty file
*/
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); 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 théoric file size
*/
File(const std::string& _mineType, std::vector<uint8_t> _data, int32_t _fileSize = -1); File(const std::string& _mineType, std::vector<uint8_t> _data, int32_t _fileSize = -1);
/**
* @brief get the théoric file size
* @return size of the file
*/
int32_t getTheoricFileSize() const { int32_t getTheoricFileSize() const {
return m_fileSize; return m_fileSize;
} }
/**
* @brief Store data in the specify file
* @param[in] _filename name of the file
*/
void storeIn(const std::string& _filename) const; void storeIn(const std::string& _filename) const;
/**
* @brief Get the mine type of the file
* @return generic mine type
*/
const std::string& getMineType() const { const std::string& getMineType() const {
return m_mineType; 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) { void setMineType(const std::string& _type) {
m_mineType = _type; m_mineType = _type;
} }
/**
* @brief préallocate the data
* @param[in] _size New size of the buffer
*/
void preSetDataSize(uint64_t _size) { void preSetDataSize(uint64_t _size) {
m_data.resize(_size, 0); m_data.resize(_size, 0);
} }
/**
* @brief get a rérérence of the data
* @return requested data
*/
const std::vector<uint8_t>& getData() const { const std::vector<uint8_t>& getData() const {
return m_data; 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); 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); 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 { class FileServer {
private: private:
std::string m_name; std::string m_name;
public: public:
/**
* @brief generic constructor
*/
FileServer(); FileServer();
/**
* @brief contructor with a file
* @param[in] _filename Name of the file to send
*/
FileServer(const std::string& _filename); FileServer(const std::string& _filename);
/**
* @brief Get the filename registered
* @return path of the file
*/
const std::string& getFileName() const { const std::string& getFileName() const {
return m_name; return m_name;
} }

View File

@ -8,26 +8,54 @@
#include <zeus/FutureBase.h> #include <zeus/FutureBase.h>
namespace zeus { namespace zeus {
/**
* @brief future template to cast type in a specific type
*/
template<class ZEUS_RETURN> template<class ZEUS_RETURN>
class Future : public zeus::FutureBase { class Future : public zeus::FutureBase {
public: public:
/**
* @brief contructor of the Future with the basic FutureBase
* @param[in] _base Generic base Future
*/
Future(const zeus::FutureBase& _base): Future(const zeus::FutureBase& _base):
zeus::FutureBase(_base) { zeus::FutureBase(_base) {
} }
/**
* @brief Asignement operator with an other future
* @param[in] _base Generic base Future
* @return the reference on the local element
*/
zeus::Future<ZEUS_RETURN>& operator= (const zeus::FutureBase& _base) { zeus::Future<ZEUS_RETURN>& operator= (const zeus::FutureBase& _base) {
m_data = _base.m_data; m_data = _base.m_data;
return *this; return *this;
} }
/**
* @brief Get the value Requested with the type
* @return requested value
*/
ZEUS_RETURN get(); ZEUS_RETURN get();
}; };
/**
* @brief future template to cast type in a void methode (fallback)
*/
template<> template<>
class Future<void> : public zeus::FutureBase { class Future<void> : public zeus::FutureBase {
public: public:
/**
* @brief contructor of the Future with the basic FutureBase
* @param[in] _base Generic base Future
*/
Future(const zeus::FutureBase& _base): Future(const zeus::FutureBase& _base):
zeus::FutureBase(_base) { zeus::FutureBase(_base) {
} }
/**
* @brief Asignement operator with an other future
* @param[in] _base Generic base Future
* @return the reference on the local element
*/
zeus::Future<void>& operator= (const zeus::FutureBase& _base) { zeus::Future<void>& operator= (const zeus::FutureBase& _base) {
m_data = _base.m_data; m_data = _base.m_data;
return *this; return *this;

View File

@ -188,7 +188,6 @@ void zeus::FutureCall::appendData(const ememory::SharedPtr<zeus::Buffer>& _value
} else { } else {
m_data = _value; m_data = _value;
} }
m_dataMultiplePack.push_back(_value);
m_isFinished = _value->getPartFinish(); m_isFinished = _value->getPartFinish();
} }

View File

@ -8,45 +8,165 @@
#include <zeus/FutureData.h> #include <zeus/FutureData.h>
namespace zeus { namespace zeus {
/**
* @brief Generic zeus Future interface to get data asynchronously
*/
class FutureBase { class FutureBase {
public: public:
ememory::SharedPtr<zeus::FutureData> m_data; ememory::SharedPtr<zeus::FutureData> m_data; // Reference on the data
public: public:
/**
* @brief Copy contructor of a FutureBase
* @param[in] _base the FutureBase to copy
*/
FutureBase(const zeus::FutureBase& _base); FutureBase(const zeus::FutureBase& _base);
/**
* @brief contructor of a FutureBase
*/
FutureBase(); FutureBase();
/**
* @brief Contructor of the FutureBase with an ofserver
* @param[in] _transactionId Transaction waiting answer
* @param[in] _callback Observer pointer
*/
FutureBase(uint64_t _transactionId, zeus::FutureData::ObserverFinish _callback=nullptr); FutureBase(uint64_t _transactionId, zeus::FutureData::ObserverFinish _callback=nullptr);
/**
* @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] _callback Observer pointer
* @return
*/
FutureBase(uint64_t _transactionId, bool _isFinished, const ememory::SharedPtr<zeus::Buffer>& _returnData, zeus::FutureData::ObserverFinish _callback=nullptr); FutureBase(uint64_t _transactionId, bool _isFinished, const ememory::SharedPtr<zeus::Buffer>& _returnData, zeus::FutureData::ObserverFinish _callback=nullptr);
/**
* @brief Asignement operator with an other future
* @param[in] _base Generic base Future
* @return the reference on the local element
*/
zeus::FutureBase operator= (const zeus::FutureBase& _base); zeus::FutureBase operator= (const zeus::FutureBase& _base);
/**
* @brief specify answer of the call
* @param[in] _returnValue Returned buffer
* @return return true if an error occured
*/
bool setAnswer(const ememory::SharedPtr<zeus::Buffer>& _returnValue); bool setAnswer(const ememory::SharedPtr<zeus::Buffer>& _returnValue);
/**
* @brief Set the future syncronous
* @note this mean that the system call the observer every time a packet arrive in the Future
*/
void setSynchronous(); void setSynchronous();
/**
* @brief Get the transaction Id of the Future
* @return Transaction Id requested or 0
*/
uint64_t getTransactionId(); uint64_t getTransactionId();
/**
* @brief check if the answer have an error
* @return return true if an error is registered
*/
bool hasError(); bool hasError();
/**
* @brief get type of the error
* @return the string of the error type
*/
std::string getErrorType(); std::string getErrorType();
/**
* @brief get help of the error
* @return the string of the error help
*/
std::string getErrorHelp(); std::string getErrorHelp();
/**
* @brief Check if the Futur is a valid data
* @return return true if the data is valid
*/
bool isValid() const; bool isValid() const;
/**
* @brief Check if the futur have finish receiving data
* @return status of the fisnish state
*/
bool isFinished() const; bool isFinished() const;
/**
* @brief Wait the Future receive data
* @return reference on the current futur
*/
FutureBase& wait(); FutureBase& wait();
/**
* @brief Wait the Future receive data
* @param[in] _delta delay to wait the data arrive
* @return reference on the current futur
*/
FutureBase& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)); FutureBase& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30));
/**
* @brief Wait the Future receive data
* @param[in] _endTime tiem to wait the data
* @return reference on the current futur
*/
FutureBase& waitUntil(std::chrono::steady_clock::time_point _endTime); FutureBase& waitUntil(std::chrono::steady_clock::time_point _endTime);
/**
* @brief Get the Buffer receive
* @return pointer on the receive data
*/
ememory::SharedPtr<zeus::Buffer> getRaw(); ememory::SharedPtr<zeus::Buffer> getRaw();
/**
* @brief Get duration of the current trasaction take
* @return Tile in nanosecond to wait answer
*/
std::chrono::nanoseconds getTransmitionTime(); std::chrono::nanoseconds getTransmitionTime();
}; };
/**
* @brief Receiving call futur
*/
class FutureCall { class FutureCall {
private: private:
uint64_t m_transactionId; uint64_t m_transactionId;
uint64_t m_clientId; uint64_t m_clientId;
bool m_isFinished; bool m_isFinished;
ememory::SharedPtr<zeus::Buffer> m_data; ememory::SharedPtr<zeus::Buffer> m_data;
std::vector<ememory::SharedPtr<zeus::Buffer>> m_dataMultiplePack;
std::chrono::steady_clock::time_point m_receiveTime; std::chrono::steady_clock::time_point m_receiveTime;
std::chrono::steady_clock::time_point m_answerTime; std::chrono::steady_clock::time_point m_answerTime;
public: public:
/**
* @brief
* @param[in]
* @return
*/
FutureCall(uint64_t _clientId, uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _callValue); FutureCall(uint64_t _clientId, uint64_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _callValue);
/**
* @brief
* @param[in]
* @return
*/
void appendData(const ememory::SharedPtr<zeus::Buffer>& _callValue); void appendData(const ememory::SharedPtr<zeus::Buffer>& _callValue);
/**
* @brief
* @param[in]
* @return
*/
uint64_t getTransactionId() const; uint64_t getTransactionId() const;
/**
* @brief
* @param[in]
* @return
*/
uint64_t getClientId() const; uint64_t getClientId() const;
/**
* @brief
* @param[in]
* @return
*/
bool isFinished() const; bool isFinished() const;
/**
* @brief
* @param[in]
* @return
*/
std::chrono::nanoseconds getTransmitionTime() const; std::chrono::nanoseconds getTransmitionTime() const;
/**
* @brief
* @param[in]
* @return
*/
ememory::SharedPtr<zeus::Buffer> getRaw() const; ememory::SharedPtr<zeus::Buffer> getRaw() const;
}; };
} }

View File

@ -8,6 +8,20 @@
#include <zeus/debug.h> #include <zeus/debug.h>
#include <zeus/File.h> #include <zeus/File.h>
bool zeus::checkCompatibility(const ParamType& _type, const ParamType& _params) {
if (_params == _type) {
return true;
}
// check cross compatibilité (All number are convertible (with min/max) and all number vector are convertible (min/max too)
if ( _type.isNumber() == true
&& _params.isNumber() == true) {
return _type.isVector() == _params.isVector();
}
return false;
}
std::ostream& zeus::operator <<(std::ostream& _os, const zeus::ParamType& _obj) { std::ostream& zeus::operator <<(std::ostream& _os, const zeus::ParamType& _obj) {
_os << "{" << _obj.getId() << ":" << _obj.getName() << "}"; _os << "{" << _obj.getId() << ":" << _obj.getName() << "}";
return _os; return _os;

View File

@ -8,6 +8,11 @@
#include <string> #include <string>
namespace zeus { namespace zeus {
/**
* @brief
* @param[in]
* @return
*/
class ParamType { class ParamType {
protected: protected:
const std::string m_typeName; const std::string m_typeName;
@ -15,24 +20,101 @@ namespace zeus {
const bool m_isNumber; const bool m_isNumber;
const bool m_isVector; const bool m_isVector;
public: public:
/**
* @brief
* @param[in]
* @return
*/
ParamType(const char* _name = "", uint16_t _id=0, bool _isNumber=false, bool _isVector=false); ParamType(const char* _name = "", uint16_t _id=0, bool _isNumber=false, bool _isVector=false);
/**
* @brief
* @param[in]
* @return
*/
ParamType(const std::string& _name, uint16_t _id, bool _isNumber=false, bool _isVector=false); ParamType(const std::string& _name, uint16_t _id, bool _isNumber=false, bool _isVector=false);
/**
* @brief
* @param[in]
* @return
*/
const std::string& getName() const; const std::string& getName() const;
/**
* @brief
* @param[in]
* @return
*/
uint16_t getId() const; uint16_t getId() const;
/**
* @brief
* @param[in]
* @return
*/
bool operator == (const ParamType& _obj) const; bool operator == (const ParamType& _obj) const;
/**
* @brief
* @param[in]
* @return
*/
bool operator != (const ParamType& _obj) const; bool operator != (const ParamType& _obj) const;
/**
* @brief
* @param[in]
* @return
*/
bool operator == (const std::string& _value) const; bool operator == (const std::string& _value) const;
/**
* @brief
* @param[in]
* @return
*/
bool operator != (const std::string& _value) const; bool operator != (const std::string& _value) const;
/**
* @brief
* @param[in]
* @return
*/
bool operator == (const uint16_t& _value) const; bool operator == (const uint16_t& _value) const;
/**
* @brief
* @param[in]
* @return
*/
bool operator != (const uint16_t& _value) const; bool operator != (const uint16_t& _value) const;
/**
* @brief
* @param[in]
* @return
*/
bool isNumber() const; bool isNumber() const;
/**
* @brief
* @param[in]
* @return
*/
bool isVector() const; bool isVector() const;
}; };
extern const uint16_t paramTypeObject; extern const uint16_t paramTypeObject;
extern const uint16_t paramTypeRaw; extern const uint16_t paramTypeRaw;
/**
* @brief
* @param[in]
* @return
*/
std::ostream& operator <<(std::ostream& _os, const zeus::ParamType& _obj); std::ostream& operator <<(std::ostream& _os, const zeus::ParamType& _obj);
/**
* @brief
* @param[in]
* @return
*/
template<class ZEUS_TYPE> template<class ZEUS_TYPE>
ParamType createType(); 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

@ -7,40 +7,49 @@
zeus::RemoteProcessCall::RemoteProcessCall() : zeus::RemoteProcessCall::RemoteProcessCall() :
m_type("UNKNOW"){ m_type("UNKNOW"){
advertise("getDescription", &zeus::RemoteProcessCall::getDescription); zeus::AbstractFunction* func = advertise("getDescription", &zeus::RemoteProcessCall::getDescription);
setLastFuncDesc("Get description"); if (func != nullptr) {
addLastFuncReturn("String version of the service number separate with dot with -dev at the end if developpement version, and '-number' or integration version uipdate : 1.5.2 or 1.8-dev 1.5.2-55"); func->setDescription("Get description");
func->setReturn("String version of the service number separate with dot with -dev at the end if developpement version, and '-number' or integration version uipdate : 1.5.2 or 1.8-dev 1.5.2-55");
advertise("getVersion", &zeus::RemoteProcessCall::getVersion); }
setLastFuncDesc("Get version"); func = advertise("getVersion", &zeus::RemoteProcessCall::getVersion);
addLastFuncReturn("String version of the service number separate with dot with -dev at the end if developpement version, and '-number' or integration version uipdate : 1.5.2 or 1.8-dev 1.5.2-55"); if (func != nullptr) {
func->setDescription("Get version");
advertise("getType", &zeus::RemoteProcessCall::getType); func->setReturn("String version of the service number separate with dot with -dev at the end if developpement version, and '-number' or integration version uipdate : 1.5.2 or 1.8-dev 1.5.2-55");
setLastFuncDesc("Get type"); }
addLastFuncReturn("String of generic type of the service base on TYPE-ENTERPRISE.ENTERPRISE-NAME.SERVICE-TYPE/VERSION_PROTOCOL"); func = advertise("getType", &zeus::RemoteProcessCall::getType);
if (func != nullptr) {
advertise("getAuthors", &zeus::RemoteProcessCall::getAuthors2); func->setDescription("Get type");
setLastFuncDesc("Get List of developper/maintainer"); func->setReturn("String of generic type of the service base on TYPE-ENTERPRISE.ENTERPRISE-NAME.SERVICE-TYPE/VERSION_PROTOCOL");
addLastFuncReturn("list of personnes: 'NAME surname <email@xxx.yyy>'"); }
func = advertise("getAuthors", &zeus::RemoteProcessCall::getAuthors2);
advertise("getFunctions", &zeus::RemoteProcessCall::getFunctions); if (func != nullptr) {
setLastFuncDesc("Get List of function availlable (filter with right)"); func->setDescription("Get List of developper/maintainer");
addLastFuncReturn("list of function name"); func->setReturn("list of personnes: 'NAME surname <email@xxx.yyy>'");
}
advertise("getFunctionSignature", &zeus::RemoteProcessCall::getFunctionSignature); func = advertise("getFunctions", &zeus::RemoteProcessCall::getFunctions);
addLastFuncParam("func", "function name"); if (func != nullptr) {
setLastFuncDesc("Get List type of return and after the parameters"); func->setDescription("Get List of function availlable (filter with right)");
addLastFuncReturn("list of element type"); func->setReturn("list of function name");
}
advertise("getFunctionPrototype", &zeus::RemoteProcessCall::getFunctionPrototype); func = advertise("getFunctionSignature", &zeus::RemoteProcessCall::getFunctionSignature);
addLastFuncParam("func", "function name"); if (func != nullptr) {
setLastFuncDesc("Get List type of return and after the parameters"); func->setDescription("Get List type of return and after the parameters");
addLastFuncReturn("list of element type"); func->addParam("func", "function name");
func->setReturn("list of element type");
advertise("getFunctionDescription", &zeus::RemoteProcessCall::getFunctionDescription); }
addLastFuncParam("func", "function name"); func = advertise("getFunctionPrototype", &zeus::RemoteProcessCall::getFunctionPrototype);
setLastFuncDesc("get function description"); if (func != nullptr) {
addLastFuncReturn("generic string"); func->setDescription("Get List type of return and after the parameters");
func->addParam("func", "function name");
func->setReturn("list of element type");
}
func = advertise("getFunctionDescription", &zeus::RemoteProcessCall::getFunctionDescription);
if (func != nullptr) {
func->setDescription("get function description");
func->addParam("func", "function name");
func->setReturn("generic string");
}
} }
@ -76,19 +85,7 @@ std::vector<std::string> zeus::RemoteProcessCall::getAuthors2() {
return out; return out;
} }
void zeus::RemoteProcessCall::setLastFuncDesc(const std::string& _desc) { zeus::AbstractFunction* zeus::RemoteProcessCall::getFunction(std::string _funcName) {
if (m_listFunction.size() == 0) {
ZEUS_ERROR("Can not set description to a function with no function advertise before ...");
return;
}
if (m_listFunction[m_listFunction.size()-1] == nullptr) {
ZEUS_ERROR("Last element is nullptr ... ==> what are you doing??");
return;
}
m_listFunction[m_listFunction.size()-1]->setDescription(_desc);
}
void zeus::RemoteProcessCall::setFuncDesc(const std::string& _funcName, const std::string& _desc) {
for (auto &it : m_listFunction) { for (auto &it : m_listFunction) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
@ -96,68 +93,15 @@ void zeus::RemoteProcessCall::setFuncDesc(const std::string& _funcName, const st
if (it->getName() != _funcName) { if (it->getName() != _funcName) {
continue; continue;
} }
it->setDescription(_desc); return it;
return;
} }
ZEUS_ERROR("function '" << _funcName << "' des not exist"); return nullptr;
} }
void zeus::RemoteProcessCall::addLastFuncParam(const std::string& _name, const std::string& _desc) {
if (m_listFunction.size() == 0) {
ZEUS_ERROR("Can not set description to a function with no function advertise before ...");
return;
}
if (m_listFunction[m_listFunction.size()-1] == nullptr) {
ZEUS_ERROR("Last element is nullptr ... ==> what are you doing??");
return;
}
m_listFunction[m_listFunction.size()-1]->addParam(_name, _desc);
}
void zeus::RemoteProcessCall::setFuncParam(const std::string& _funcName, int32_t _idParam, const std::string& _name, const std::string& _desc) {
for (auto &it : m_listFunction) {
if (it == nullptr) {
continue;
}
if (it->getName() != _funcName) {
continue;
}
it->setParam(_idParam, _name, _desc);
return;
}
ZEUS_ERROR("function '" << _funcName << "' des not exist");
}
void zeus::RemoteProcessCall::addLastFuncReturn(const std::string& _desc) {
if (m_listFunction.size() == 0) {
ZEUS_ERROR("Can not set return to a function with no function advertise before ...");
return;
}
if (m_listFunction[m_listFunction.size()-1] == nullptr) {
ZEUS_ERROR("Last element is nullptr ... ==> what are you doing??");
return;
}
m_listFunction[m_listFunction.size()-1]->setReturn(_desc);
}
void zeus::RemoteProcessCall::setFuncReturn(const std::string& _funcName, const std::string& _desc) {
for (auto &it : m_listFunction) {
if (it == nullptr) {
continue;
}
if (it->getName() != _funcName) {
continue;
}
it->setReturn(_desc);
return;
}
ZEUS_ERROR("function '" << _funcName << "' des not exist");
}
std::string zeus::RemoteProcessCall::getType() { std::string zeus::RemoteProcessCall::getType() {
return m_type; return m_type;
} }
void zeus::RemoteProcessCall::setType(const std::string& _type, uint16_t _version) { void zeus::RemoteProcessCall::setType(const std::string& _type, uint16_t _version) {
m_type = _type + "/" + etk::to_string(_version); m_type = _type + "/" + etk::to_string(_version);
} }
@ -213,7 +157,7 @@ std::string zeus::RemoteProcessCall::getFunctionPrototype(std::string _funcName)
if (it->getName() != _funcName) { if (it->getName() != _funcName) {
continue; continue;
} }
return it->getPrototypeFull(); return it->getPrototype();
} }
return ""; return "";
} }

View File

@ -5,85 +5,158 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h>
#include <zeus/AbstractFunctionTypeDirect.h> #include <zeus/AbstractFunctionTypeDirect.h>
#include <zeus/AbstractFunctionTypeClass.h> #include <zeus/AbstractFunctionTypeClass.h>
#include <zeus/debug.h> #include <zeus/debug.h>
namespace zeus { namespace zeus {
/**
* @brief
* @param[in]
* @return
*/
class RemoteProcessCall { class RemoteProcessCall {
public: public:
/**
* @brief
* @param[in]
* @return
*/
RemoteProcessCall(); RemoteProcessCall();
protected: protected:
std::vector<zeus::AbstractFunction*> m_listFunction; std::vector<zeus::AbstractFunction*> m_listFunction;
protected: protected:
std::string m_description; std::string m_description;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void setDescription(const std::string& _desc); void setDescription(const std::string& _desc);
/**
* @brief
* @param[in]
* @return
*/
std::string getDescription(); std::string getDescription();
protected: protected:
std::string m_version; std::string m_version;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void setVersion(const std::string& _desc); void setVersion(const std::string& _desc);
/**
* @brief
* @param[in]
* @return
*/
std::string getVersion(); std::string getVersion();
protected: protected:
std::vector<std::pair<std::string,std::string>> m_authors; std::vector<std::pair<std::string,std::string>> m_authors;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void addAuthor(const std::string& _name, const std::string& _email); void addAuthor(const std::string& _name, const std::string& _email);
/**
* @brief
* @param[in]
* @return
*/
const std::vector<std::pair<std::string,std::string>>& getAuthors() const; const std::vector<std::pair<std::string,std::string>>& getAuthors() const;
/**
* @brief
* @param[in]
* @return
*/
std::vector<std::string> getAuthors2(); std::vector<std::string> getAuthors2();
protected: protected:
std::string m_type; std::string m_type;
public: public:
/**
* @brief
* @param[in]
* @return
*/
std::string getType(); std::string getType();
/**
* @brief
* @param[in]
* @return
*/
void setType(const std::string& _type, uint16_t _version); void setType(const std::string& _type, uint16_t _version);
public: public:
/**
* @brief
* @param[in]
* @return
*/
std::vector<std::string> getFunctions(); std::vector<std::string> getFunctions();
/**
* @brief
* @param[in]
* @return
*/
AbstractFunction* getFunction(std::string _funcName);
private:
std::vector<std::string> getFunctionSignature(std::string _funcName); std::vector<std::string> getFunctionSignature(std::string _funcName);
std::string getFunctionPrototype(std::string _funcName); std::string getFunctionPrototype(std::string _funcName);
std::string getFunctionDescription(std::string _funcName); std::string getFunctionDescription(std::string _funcName);
public:
void setLastFuncDesc(const std::string& _desc);
void setFuncDesc(const std::string& _funcName, const std::string& _desc);
void addLastFuncParam(const std::string& _name, const std::string& _desc);
void setFuncParam(const std::string& _funcName, int32_t _idParam, const std::string& _name, const std::string& _desc);
void addLastFuncReturn(const std::string& _desc);
void setFuncReturn(const std::string& _funcName, const std::string& _desc);
protected: protected:
/**
* @brief
* @param[in]
* @return
*/
virtual bool isFunctionAuthorized(uint64_t _clientSessionID, const std::string& _funcName); virtual bool isFunctionAuthorized(uint64_t _clientSessionID, const std::string& _funcName);
public: public:
/**
* @brief
* @param[in]
* @return
*/
// Add global fuction (no link with this class) // Add global fuction (no link with this class)
template<class ZEUS_RETURN_VALUE, template<class ZEUS_RETURN_VALUE,
class... ZEUS_FUNC_ARGS_TYPE> class... ZEUS_FUNC_ARGS_TYPE>
void advertise(const std::string& _name, zeus::AbstractFunction* advertise(const std::string& _name,
ZEUS_RETURN_VALUE (*_func)(ZEUS_FUNC_ARGS_TYPE... _args), ZEUS_RETURN_VALUE (*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
const std::string& _desc = "") {
for (auto &it : m_listFunction) { for (auto &it : m_listFunction) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
if (it->getName() == _name) { if (it->getName() == _name) {
ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'"); ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
return; return nullptr;
} }
} }
AbstractFunction* tmp = createAbstractFunctionDirect(_name, _desc, _func); zeus::AbstractFunction* tmp = createAbstractFunctionDirect(_name, _func);
if (tmp == nullptr) { if (tmp == nullptr) {
ZEUS_ERROR("can not create abstract function ... '" << _name << "'"); ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
return; return nullptr;
} }
tmp->setType(zeus::AbstractFunction::type::global); tmp->setType(zeus::AbstractFunction::type::global);
ZEUS_INFO("Add function '" << _name << "' in global mode"); ZEUS_INFO("Add function '" << _name << "' in global mode");
m_listFunction.push_back(tmp); m_listFunction.push_back(tmp);
return tmp;
} }
/**
* @brief
* @param[in]
* @return
*/
// Add Local fuction (depend on this class) // Add Local fuction (depend on this class)
template<class ZEUS_RETURN_VALUE, template<class ZEUS_RETURN_VALUE,
class ZEUS_CLASS_TYPE, class ZEUS_CLASS_TYPE,
class... ZEUS_FUNC_ARGS_TYPE> class... ZEUS_FUNC_ARGS_TYPE>
void advertise(std::string _name, zeus::AbstractFunction* advertise(std::string _name,
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args), ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
const std::string& _desc = "") {
_name = "sys." + _name; _name = "sys." + _name;
for (auto &it : m_listFunction) { for (auto &it : m_listFunction) {
if (it == nullptr) { if (it == nullptr) {
@ -91,17 +164,18 @@ namespace zeus {
} }
if (it->getName() == _name) { if (it->getName() == _name) {
ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'"); ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
return; return nullptr;
} }
} }
AbstractFunction* tmp = createAbstractFunctionClass(_name, _desc, _func); zeus::AbstractFunction* tmp = createAbstractFunctionClass(_name, _func);
if (tmp == nullptr) { if (tmp == nullptr) {
ZEUS_ERROR("can not create abstract function ... '" << _name << "'"); ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
return; return nullptr;
} }
tmp->setType(zeus::AbstractFunction::type::local); tmp->setType(zeus::AbstractFunction::type::local);
ZEUS_INFO("Add function '" << _name << "' in local mode"); ZEUS_INFO("Add function '" << _name << "' in local mode");
m_listFunction.push_back(tmp); m_listFunction.push_back(tmp);
return tmp;
} }
}; };
} }

View File

@ -14,12 +14,11 @@
zeus::Service::Service() : zeus::Service::Service() :
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Service::onPropertyChangeIp), propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Service::onPropertyChangeIp),
propertyPort(this, "port", 1982, "Port to connect server", &zeus::Service::onPropertyChangePort) { propertyPort(this, "port", 1982, "Port to connect server", &zeus::Service::onPropertyChangePort) {
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Service::getExtention);
if (func != nullptr) {
advertise("getExtention", &zeus::Service::getExtention); func->setDescription("Get List of availlable extention of this service");
setLastFuncDesc("Get List of availlable extention of this service"); func->setReturn("A list of extention register in the service");
addLastFuncReturn("A list of extention register in the service"); }
} }
zeus::Service::~Service() { zeus::Service::~Service() {
@ -33,6 +32,9 @@ std::vector<std::string> zeus::Service::getExtention() {
void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value) { void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value) {
if (_value == nullptr) {
return;
}
uint32_t tmpID = _value->getTransactionId(); uint32_t tmpID = _value->getTransactionId();
uint32_t clientId = _value->getClientId();; uint32_t clientId = _value->getClientId();;
auto it = m_callMultiData.begin(); auto it = m_callMultiData.begin();
@ -43,7 +45,7 @@ void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
it->appendData(_value); it->appendData(_value);
if (it->isFinished() == true) { if (it->isFinished() == true) {
ZEUS_WARNING("CALL Function ..."); ZEUS_WARNING("CALL Function ...");
callBinary(tmpID, it->getRaw()); callBinary(it->getRaw());
it = m_callMultiData.erase(it); it = m_callMultiData.erase(it);
} }
return; return;
@ -53,7 +55,7 @@ void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
zeus::FutureCall futCall(clientId, tmpID, _value); zeus::FutureCall futCall(clientId, tmpID, _value);
if (futCall.isFinished() == true) { if (futCall.isFinished() == true) {
ZEUS_INFO("Call Binary .."); ZEUS_INFO("Call Binary ..");
callBinary(tmpID, futCall.getRaw()); callBinary(futCall.getRaw());
} else { } else {
m_callMultiData.push_back(futCall); m_callMultiData.push_back(futCall);
} }
@ -76,7 +78,7 @@ void zeus::Service::connect(const std::string& _serviceName, uint32_t _numberRet
ZEUS_DEBUG("connect [STOP] ==> can not connect"); ZEUS_DEBUG("connect [STOP] ==> can not connect");
return; return;
} }
m_interfaceClient = std::make_shared<zeus::TcpString>(); m_interfaceClient = std::make_shared<zeus::WebServer>();
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
ZEUS_ERROR("Can not allocate interface ..."); ZEUS_ERROR("Can not allocate interface ...");
return; return;
@ -119,7 +121,7 @@ void zeus::Service::pingIsAlive() {
} }
} }
void zeus::Service::callBinary(uint32_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj) { void zeus::Service::callBinary(const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (_obj == nullptr) { if (_obj == nullptr) {
return; return;
} }
@ -143,13 +145,13 @@ void zeus::Service::callBinary(uint32_t _transactionId, const ememory::SharedPtr
} else if (callFunction == "_delete") { } else if (callFunction == "_delete") {
clientDisconnect(clientId); clientDisconnect(clientId);
} }
m_interfaceClient->answerValue(_transactionId, true, clientId); m_interfaceClient->answerValue(_obj->getTransactionId(), true, clientId);
return; return;
} else if (isFunctionAuthorized(clientId, callFunction) == true) { } else if (isFunctionAuthorized(clientId, callFunction) == true) {
callBinary2(_transactionId, clientId, callFunction, _obj); callBinary2(callFunction, _obj);
return; return;
} else { } else {
m_interfaceClient->answerError(_transactionId, "NOT-AUTHORIZED-FUNCTION", "", clientId); m_interfaceClient->answerError(_obj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId);
return; return;
} }
} }

View File

@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h> #include <eproperty/Value.h>
#include <zeus/AbstractFunctionTypeDirect.h> #include <zeus/AbstractFunctionTypeDirect.h>
#include <zeus/AbstractFunctionTypeClass.h> #include <zeus/AbstractFunctionTypeClass.h>
@ -14,8 +14,18 @@
#include <zeus/Future.h> #include <zeus/Future.h>
namespace zeus { namespace zeus {
/**
* @brief
* @param[in]
* @return
*/
class ClientProperty { class ClientProperty {
public: public:
/**
* @brief
* @param[in]
* @return
*/
ClientProperty(const std::string& _clientName="", const std::vector<std::string>& _groups = std::vector<std::string>()) : ClientProperty(const std::string& _clientName="", const std::vector<std::string>& _groups = std::vector<std::string>()) :
m_name(_clientName), m_name(_clientName),
m_groups(_groups) { m_groups(_groups) {
@ -24,56 +34,136 @@ namespace zeus {
private: private:
std::string m_name; std::string m_name;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void setName(const std::string& _name) { void setName(const std::string& _name) {
m_name = _name; m_name = _name;
} }
/**
* @brief
* @param[in]
* @return
*/
const std::string& getName() { const std::string& getName() {
return m_name; return m_name;
} }
private: private:
std::vector<std::string> m_groups; std::vector<std::string> m_groups;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void setGroups(std::vector<std::string> _groups) { void setGroups(std::vector<std::string> _groups) {
m_groups = _groups; m_groups = _groups;
} }
/**
* @brief
* @param[in]
* @return
*/
const std::vector<std::string>& getGroups() { const std::vector<std::string>& getGroups() {
return m_groups; return m_groups;
} }
private: private:
std::vector<std::string> m_listAthorizedFunction; std::vector<std::string> m_listAthorizedFunction;
public: public:
/**
* @brief
* @param[in]
* @return
*/
void addAuthorized(const std::string& _funcName) { void addAuthorized(const std::string& _funcName) {
m_listAthorizedFunction.push_back(_funcName); m_listAthorizedFunction.push_back(_funcName);
} }
/**
* @brief
* @param[in]
* @return
*/
bool isFunctionAuthorized(const std::string& _funcName) { bool isFunctionAuthorized(const std::string& _funcName) {
return std::find(m_listAthorizedFunction.begin(), m_listAthorizedFunction.end(), _funcName) != m_listAthorizedFunction.end(); return std::find(m_listAthorizedFunction.begin(), m_listAthorizedFunction.end(), _funcName) != m_listAthorizedFunction.end();
} }
}; };
} }
namespace zeus { namespace zeus {
/**
* @brief
* @param[in]
* @return
*/
class Service : public eproperty::Interface, public zeus::RemoteProcessCall { class Service : public eproperty::Interface, public zeus::RemoteProcessCall {
protected: protected:
std::mutex m_mutex; std::mutex m_mutex;
public: public:
eproperty::Value<std::string> propertyIp; eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
eproperty::Value<uint16_t> propertyPort; eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
protected: protected:
ememory::SharedPtr<zeus::TcpString> m_interfaceClient; ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
uint32_t m_id; uint32_t m_id;
std::vector<std::string> m_newData; std::vector<std::string> m_newData;
std::vector<zeus::FutureCall> m_callMultiData; std::vector<zeus::FutureCall> m_callMultiData;
public: public:
/**
* @brief
* @param[in]
* @return
*/
Service(); Service();
/**
* @brief
* @param[in]
* @return
*/
virtual ~Service(); virtual ~Service();
/**
* @brief
* @param[in]
* @return
*/
void connect(const std::string& _serviceName, uint32_t _numberRetry = 1); void connect(const std::string& _serviceName, uint32_t _numberRetry = 1);
/**
* @brief
* @param[in]
* @return
*/
void disconnect(); void disconnect();
private: private:
/**
* @brief
* @param[in]
* @return
*/
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value); void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);
public: public:
/**
* @brief
* @param[in]
* @return
*/
void pingIsAlive(); void pingIsAlive();
/**
* @brief
* @param[in]
* @return
*/
bool GateWayAlive(); bool GateWayAlive();
private: private:
/**
* @brief
* @param[in]
* @return
*/
void onPropertyChangeIp(); void onPropertyChangeIp();
/**
* @brief
* @param[in]
* @return
*/
void onPropertyChangePort(); void onPropertyChangePort();
/** /**
* @brief A extern client connect on specific user * @brief A extern client connect on specific user
@ -82,19 +172,43 @@ namespace zeus {
* @todo Set a relur like ==> service not availlable / service close / service maintenance / service right reject * @todo Set a relur like ==> service not availlable / service close / service maintenance / service right reject
*/ */
virtual void clientConnect(uint64_t _clientId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) = 0; virtual void clientConnect(uint64_t _clientId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) = 0;
/**
* @brief
* @param[in]
* @return
*/
virtual void clientDisconnect(uint64_t _clientId) = 0; virtual void clientDisconnect(uint64_t _clientId) = 0;
// Genenric function call: // Genenric function call:
void callBinary(uint32_t _transactionId, const ememory::SharedPtr<zeus::Buffer>& _obj); /**
virtual void callBinary2(uint32_t _transactionId, uint64_t _clientId, const std::string& _call, const ememory::SharedPtr<zeus::Buffer>& _obj) = 0; * @brief
* @param[in]
* @return
*/
void callBinary(const ememory::SharedPtr<zeus::Buffer>& _obj);
/**
* @brief
* @param[in]
* @return
*/
virtual void callBinary2(const std::string& _call, const ememory::SharedPtr<zeus::Buffer>& _obj) = 0;
/**
* @brief
* @param[in]
* @return
*/
std::vector<std::string> getExtention(); std::vector<std::string> getExtention();
public: public:
/**
* @brief
* @param[in]
* @return
*/
// Add Local fuction (depend on this class) // Add Local fuction (depend on this class)
template<class ZEUS_RETURN_VALUE, template<class ZEUS_RETURN_VALUE,
class ZEUS_CLASS_TYPE, class ZEUS_CLASS_TYPE,
class... ZEUS_FUNC_ARGS_TYPE> class... ZEUS_FUNC_ARGS_TYPE>
void advertise(std::string _name, zeus::AbstractFunction* advertise(std::string _name,
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args), ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
const std::string& _desc = "") {
_name = "srv." + _name; _name = "srv." + _name;
for (auto &it : m_listFunction) { for (auto &it : m_listFunction) {
if (it == nullptr) { if (it == nullptr) {
@ -102,20 +216,19 @@ namespace zeus {
} }
if (it->getName() == _name) { if (it->getName() == _name) {
ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'"); ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
return; return nullptr;
} }
} }
AbstractFunction* tmp = createAbstractFunctionClass(_name, _desc, _func); AbstractFunction* tmp = createAbstractFunctionClass(_name, _func);
if (tmp == nullptr) { if (tmp == nullptr) {
ZEUS_ERROR("can not create abstract function ... '" << _name << "'"); ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
return; return nullptr;
} }
tmp->setType(zeus::AbstractFunction::type::service); tmp->setType(zeus::AbstractFunction::type::service);
ZEUS_INFO("Add function '" << _name << "' in local mode"); ZEUS_INFO("Add function '" << _name << "' in local mode");
m_listFunction.push_back(tmp); m_listFunction.push_back(tmp);
return tmp;
} }
}; };
template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS> template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS>
class ServiceType : public zeus::Service { class ServiceType : public zeus::Service {
@ -124,15 +237,19 @@ namespace zeus {
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...) // no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
std::map<uint64_t, std::pair<ememory::SharedPtr<ClientProperty>, ememory::SharedPtr<ZEUS_TYPE_SERVICE>>> m_interface; std::map<uint64_t, std::pair<ememory::SharedPtr<ClientProperty>, ememory::SharedPtr<ZEUS_TYPE_SERVICE>>> m_interface;
public: public:
/**
* @brief
* @param[in]
* @return
*/
template<class ZEUS_RETURN_VALUE, template<class ZEUS_RETURN_VALUE,
class ZEUS_CLASS_TYPE, class ZEUS_CLASS_TYPE,
class... ZEUS_FUNC_ARGS_TYPE> class... ZEUS_FUNC_ARGS_TYPE>
void advertise(const std::string& _name, zeus::AbstractFunction* advertise(const std::string& _name,
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args), ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
const std::string& _desc = "") {
if (etk::start_with(_name, "srv.") == true) { if (etk::start_with(_name, "srv.") == true) {
ZEUS_ERROR("Advertise function start with 'srv.' is not permited ==> only allow for internal service: '" << _name << "'"); ZEUS_ERROR("Advertise function start with 'srv.' is not permited ==> only allow for internal service: '" << _name << "'");
return; return nullptr;
} }
for (auto &it : m_listFunction) { for (auto &it : m_listFunction) {
if (it == nullptr) { if (it == nullptr) {
@ -140,22 +257,33 @@ namespace zeus {
} }
if (it->getName() == _name) { if (it->getName() == _name) {
ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'"); ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
return; return nullptr;
} }
} }
AbstractFunction* tmp = createAbstractFunctionClass(_name, _desc, _func); zeus::AbstractFunction* tmp = createAbstractFunctionClass(_name, _func);
if (tmp == nullptr) { if (tmp == nullptr) {
ZEUS_ERROR("can not create abstract function ... '" << _name << "'"); ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
return; return nullptr;
} }
tmp->setType(zeus::AbstractFunction::type::object); tmp->setType(zeus::AbstractFunction::type::object);
ZEUS_INFO("Add function '" << _name << "' in object mode"); ZEUS_INFO("Add function '" << _name << "' in object mode");
m_listFunction.push_back(tmp); m_listFunction.push_back(tmp);
return tmp;
} }
/**
* @brief
* @param[in]
* @return
*/
ServiceType(ZEUS_USER_ACCESS& _interface): ServiceType(ZEUS_USER_ACCESS& _interface):
m_getUserInterface(_interface) { m_getUserInterface(_interface) {
} }
/**
* @brief
* @param[in]
* @return
*/
bool isFunctionAuthorized(uint64_t _clientId, const std::string& _funcName) { bool isFunctionAuthorized(uint64_t _clientId, const std::string& _funcName) {
auto it = m_interface.find(_clientId); auto it = m_interface.find(_clientId);
if (it == m_interface.end()) { if (it == m_interface.end()) {
@ -163,6 +291,11 @@ namespace zeus {
} }
return it->second.first->isFunctionAuthorized(_funcName); return it->second.first->isFunctionAuthorized(_funcName);
} }
/**
* @brief
* @param[in]
* @return
*/
void clientConnect(uint64_t _clientId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) { void clientConnect(uint64_t _clientId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
ZEUS_DEBUG("connect: " << _clientId << " to '" << _userName << "'"); ZEUS_DEBUG("connect: " << _clientId << " to '" << _userName << "'");
@ -179,6 +312,11 @@ namespace zeus {
tmpProperty->addAuthorized(it->getName()); tmpProperty->addAuthorized(it->getName());
} }
} }
/**
* @brief
* @param[in]
* @return
*/
void clientDisconnect(uint64_t _clientId) { void clientDisconnect(uint64_t _clientId) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
ZEUS_DEBUG("disconnect: " << _clientId); ZEUS_DEBUG("disconnect: " << _clientId);
@ -190,6 +328,11 @@ namespace zeus {
} }
m_interface.erase(it); m_interface.erase(it);
} }
/**
* @brief
* @param[in]
* @return
*/
void clientSetName(uint64_t _clientId, const std::string& _clientName) { void clientSetName(uint64_t _clientId, const std::string& _clientName) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_interface.find(_clientId); auto it = m_interface.find(_clientId);
@ -199,6 +342,11 @@ namespace zeus {
} }
it->second.first->setName(_clientName); it->second.first->setName(_clientName);
} }
/**
* @brief
* @param[in]
* @return
*/
void clientSetGroup(uint64_t _clientId, const std::vector<std::string>& _clientGroups) { void clientSetGroup(uint64_t _clientId, const std::vector<std::string>& _clientGroups) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_interface.find(_clientId); auto it = m_interface.find(_clientId);
@ -208,10 +356,15 @@ namespace zeus {
} }
it->second.first->setGroups(_clientGroups); it->second.first->setGroups(_clientGroups);
} }
void callBinary2(uint32_t _transactionId, uint64_t _clientId, const std::string& _call, const ememory::SharedPtr<zeus::Buffer>& _obj) { /**
auto it = m_interface.find(_clientId); * @brief
* @param[in]
* @return
*/
void callBinary2(const std::string& _call, const ememory::SharedPtr<zeus::Buffer>& _obj) {
auto it = m_interface.find(_obj->getClientId());
if (it == m_interface.end()) { if (it == m_interface.end()) {
m_interfaceClient->answerError(_transactionId, "CLIENT-UNKNOW", "", _clientId); m_interfaceClient->answerError(_obj->getTransactionId(), "CLIENT-UNKNOW", "", _obj->getClientId());
return; return;
} }
for (auto &it2 : m_listFunction) { for (auto &it2 : m_listFunction) {
@ -224,19 +377,19 @@ namespace zeus {
switch (it2->getType()) { switch (it2->getType()) {
case zeus::AbstractFunction::type::object: { case zeus::AbstractFunction::type::object: {
ZEUS_TYPE_SERVICE* elem = it->second.second.get(); ZEUS_TYPE_SERVICE* elem = it->second.second.get();
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, (void*)elem); it2->execute(m_interfaceClient, _obj, (void*)elem);
return; return;
} }
case zeus::AbstractFunction::type::local: { case zeus::AbstractFunction::type::local: {
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, (void*)((RemoteProcessCall*)this)); it2->execute(m_interfaceClient, _obj, (void*)((RemoteProcessCall*)this));
return; return;
} }
case zeus::AbstractFunction::type::service: { case zeus::AbstractFunction::type::service: {
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, (void*)this); it2->execute(m_interfaceClient, _obj, (void*)this);
return; return;
} }
case zeus::AbstractFunction::type::global: { case zeus::AbstractFunction::type::global: {
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, nullptr); it2->execute(m_interfaceClient, _obj, nullptr);
return; return;
} }
case zeus::AbstractFunction::type::unknow: case zeus::AbstractFunction::type::unknow:
@ -244,7 +397,7 @@ namespace zeus {
break; break;
} }
} }
m_interfaceClient->answerError(_transactionId, "FUNCTION-UNKNOW", "", _clientId); m_interfaceClient->answerError(_obj->getTransactionId(), "FUNCTION-UNKNOW", "", _obj->getClientId());
return; return;
} }
}; };

View File

@ -7,7 +7,7 @@
#include <zeus/ServiceRemote.h> #include <zeus/ServiceRemote.h>
#include <zeus/Client.h> #include <zeus/Client.h>
zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::TcpString> _clientLink, const std::string& _name): zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name):
m_interfaceClient(_clientLink), m_interfaceClient(_clientLink),
m_name(_name), m_name(_name),
m_serviceId(0), m_serviceId(0),

View File

@ -5,27 +5,51 @@
*/ */
#pragma once #pragma once
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <eproperty/Value.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <zeus/AbstractFunction.h> #include <zeus/AbstractFunction.h>
#include <zeus/ServiceRemote.h> #include <zeus/ServiceRemote.h>
#include <zeus/Future.h> #include <zeus/Future.h>
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
namespace zeus { namespace zeus {
class Client; class Client;
/**
* @brief
* @param[in]
* @return
*/
class ServiceRemote { class ServiceRemote {
private: private:
ememory::SharedPtr<zeus::TcpString> m_interfaceClient; ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
std::string m_name; std::string m_name;
uint32_t m_serviceId; uint32_t m_serviceId;
bool m_isLinked; bool m_isLinked;
public: public:
ServiceRemote(ememory::SharedPtr<zeus::TcpString> _clientLink, const std::string& _name); /**
* @brief
* @param[in]
* @return
*/
ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name);
/**
* @brief
* @param[in]
* @return
*/
~ServiceRemote(); ~ServiceRemote();
/**
* @brief
* @param[in]
* @return
*/
bool exist(); bool exist();
public: public:
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {
@ -37,6 +61,11 @@ namespace zeus {
} }
return m_interfaceClient->callService(m_serviceId, _functionName, _args...); return m_interfaceClient->callService(m_serviceId, _functionName, _args...);
} }
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
if (m_interfaceClient == nullptr) { if (m_interfaceClient == nullptr) {

View File

@ -3,12 +3,30 @@
* @copyright 2016, Edouard DUPIN, all right reserved * @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <zeus/TcpString.h> #include <zeus/WebServer.h>
#include <zeus/debug.h> #include <zeus/debug.h>
#include <ethread/tools.h> #include <ethread/tools.h>
#include <unistd.h> #include <unistd.h>
zeus::TcpString::TcpString() :
ememory::SharedPtr<zeus::Buffer> zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) {
ememory::SharedPtr<zeus::Buffer> obj = zeus::Buffer::create();
if (obj == nullptr) {
return nullptr;
}
obj->setServiceId(_serviceId);
obj->setCall(_functionName);
obj->setTransactionId(_transactionId);
return obj;
}
void zeus::createParam(int32_t _paramId, const ememory::SharedPtr<zeus::Buffer>& _obj) {
// Finish recursive parse ...
}
zeus::WebServer::WebServer() :
m_connection(), m_connection(),
m_observerElement(nullptr), m_observerElement(nullptr),
m_threadAsync(nullptr) { m_threadAsync(nullptr) {
@ -16,7 +34,7 @@ zeus::TcpString::TcpString() :
m_transmissionId = 1; m_transmissionId = 1;
} }
zeus::TcpString::TcpString(enet::Tcp _connection, bool _isServer) : zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
m_connection(), m_connection(),
m_observerElement(nullptr), m_observerElement(nullptr),
m_threadAsync(nullptr) { m_threadAsync(nullptr) {
@ -25,11 +43,11 @@ zeus::TcpString::TcpString(enet::Tcp _connection, bool _isServer) :
setInterface(std::move(_connection), _isServer); setInterface(std::move(_connection), _isServer);
} }
void zeus::TcpString::setInterface(enet::Tcp _connection, bool _isServer) { void zeus::WebServer::setInterface(enet::Tcp _connection, bool _isServer) {
m_connection.setInterface(std::move(_connection), _isServer); m_connection.setInterface(std::move(_connection), _isServer);
m_connection.connect(this, &zeus::TcpString::onReceiveData); m_connection.connect(this, &zeus::WebServer::onReceiveData);
if (_isServer == true) { if (_isServer == true) {
m_connection.connectUri(this, &zeus::TcpString::onReceiveUri); m_connection.connectUri(this, &zeus::WebServer::onReceiveUri);
m_connection.start(); m_connection.start();
} else { } else {
std::vector<std::string> protocols; std::vector<std::string> protocols;
@ -39,20 +57,20 @@ void zeus::TcpString::setInterface(enet::Tcp _connection, bool _isServer) {
} }
} }
zeus::TcpString::~TcpString() { zeus::WebServer::~WebServer() {
disconnect(); disconnect();
} }
void zeus::TcpString::setInterfaceName(const std::string& _name) { void zeus::WebServer::setInterfaceName(const std::string& _name) {
//ethread::setName(*m_thread, "Tcp-" + _name); //ethread::setName(*m_thread, "Tcp-" + _name);
} }
bool zeus::TcpString::isActive() const { bool zeus::WebServer::isActive() const {
return m_connection.isAlive(); return m_connection.isAlive();
} }
void zeus::TcpString::connect(bool _async){ void zeus::WebServer::connect(bool _async){
ZEUS_DEBUG("connect [START]"); ZEUS_DEBUG("connect [START]");
m_threadAsyncRunning = true; m_threadAsyncRunning = true;
m_threadAsync = new std::thread([&](void *){ this->threadAsyncCallback();}, nullptr); m_threadAsync = new std::thread([&](void *){ this->threadAsyncCallback();}, nullptr);
@ -75,7 +93,7 @@ void zeus::TcpString::connect(bool _async){
} }
} }
void zeus::TcpString::disconnect(bool _inThreadStop){ void zeus::WebServer::disconnect(bool _inThreadStop){
ZEUS_DEBUG("disconnect [START]"); ZEUS_DEBUG("disconnect [START]");
m_threadAsyncRunning = false; m_threadAsyncRunning = false;
if (m_connection.isAlive() == true) { if (m_connection.isAlive() == true) {
@ -104,7 +122,7 @@ class SendAsyncBinary {
m_partId(1) { m_partId(1) {
} }
bool operator() (zeus::TcpString* _interface){ bool operator() (zeus::WebServer* _interface){
auto it = m_async.begin(); auto it = m_async.begin();
while (it != m_async.end()) { while (it != m_async.end()) {
bool ret = (*it)(_interface, m_serviceId, m_transactionId, m_partId); bool ret = (*it)(_interface, m_serviceId, m_transactionId, m_partId);
@ -133,17 +151,15 @@ class SendAsyncBinary {
} }
}; };
int32_t zeus::TcpString::writeBinary(const ememory::SharedPtr<zeus::Buffer>& _obj) { int32_t zeus::WebServer::writeBinary(const ememory::SharedPtr<zeus::Buffer>& _obj) {
if (m_connection.isAlive() == false) { if (m_connection.isAlive() == false) {
return -2; return -2;
} }
if (_obj->haveAsync() == true) { if (_obj->haveAsync() == true) {
ZEUS_WARNING("Set Flag not finish ...");
_obj->setPartFinish(false); _obj->setPartFinish(false);
} }
if (_obj->writeOn(m_connection) == true) { if (_obj->writeOn(m_connection) == true) {
if (_obj->haveAsync() == true) { if (_obj->haveAsync() == true) {
ZEUS_WARNING("Add async");
addAsync(SendAsyncBinary(_obj->getTransactionId(), _obj->getServiceId(), std::move(_obj->moveAsync()))); addAsync(SendAsyncBinary(_obj->getTransactionId(), _obj->getServiceId(), std::move(_obj->moveAsync())));
} }
return 1; return 1;
@ -151,7 +167,7 @@ int32_t zeus::TcpString::writeBinary(const ememory::SharedPtr<zeus::Buffer>& _ob
return -1; return -1;
} }
bool zeus::TcpString::onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols) { bool zeus::WebServer::onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols) {
ZEUS_INFO("Receive Header uri: " << _uri); ZEUS_INFO("Receive Header uri: " << _uri);
for (auto &it : _protocols) { for (auto &it : _protocols) {
if (it == "zeus/1.0") { if (it == "zeus/1.0") {
@ -165,7 +181,7 @@ bool zeus::TcpString::onReceiveUri(const std::string& _uri, const std::vector<st
return false; return false;
} }
void zeus::TcpString::onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary) { void zeus::WebServer::onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary) {
ememory::SharedPtr<zeus::Buffer> dataRaw = zeus::Buffer::create(); ememory::SharedPtr<zeus::Buffer> dataRaw = zeus::Buffer::create();
if (_isBinary == true) { if (_isBinary == true) {
ZEUS_ERROR("Receive non binary frame ..."); ZEUS_ERROR("Receive non binary frame ...");
@ -176,12 +192,12 @@ void zeus::TcpString::onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary
newBuffer(dataRaw); newBuffer(dataRaw);
} }
void zeus::TcpString::ping() { void zeus::WebServer::ping() {
m_connection.controlPing(); m_connection.controlPing();
} }
void zeus::TcpString::newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer) { void zeus::WebServer::newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer) {
ZEUS_DEBUG("Receive :" << _buffer->generateHumanString()); ZEUS_VERBOSE("Receive :" << _buffer);
zeus::FutureBase future; zeus::FutureBase future;
uint64_t tid = _buffer->getTransactionId(); uint64_t tid = _buffer->getTransactionId();
if (tid == 0) { if (tid == 0) {
@ -245,12 +261,12 @@ void zeus::TcpString::newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer)
} }
} }
void zeus::TcpString::addAsync(zeus::TcpString::ActionAsync _elem) { void zeus::WebServer::addAsync(zeus::WebServer::ActionAsync _elem) {
std::unique_lock<std::mutex> lock(m_threadAsyncMutex); std::unique_lock<std::mutex> lock(m_threadAsyncMutex);
m_threadAsyncList2.push_back(_elem); m_threadAsyncList2.push_back(_elem);
} }
void zeus::TcpString::threadAsyncCallback() { void zeus::WebServer::threadAsyncCallback() {
ethread::setName("Async-sender"); ethread::setName("Async-sender");
ZEUS_INFO("Async Sender [START]..."); ZEUS_INFO("Async Sender [START]...");
// get datas: // get datas:
@ -283,7 +299,7 @@ void zeus::TcpString::threadAsyncCallback() {
} }
zeus::FutureBase zeus::TcpString::callBinary(uint64_t _transactionId, zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId,
const ememory::SharedPtr<zeus::Buffer>& _obj, const ememory::SharedPtr<zeus::Buffer>& _obj,
zeus::FutureData::ObserverFinish _callback, zeus::FutureData::ObserverFinish _callback,
const uint32_t& _serviceId) { const uint32_t& _serviceId) {
@ -304,7 +320,7 @@ zeus::FutureBase zeus::TcpString::callBinary(uint64_t _transactionId,
return tmpFuture; return tmpFuture;
} }
zeus::FutureBase zeus::TcpString::callForward(uint32_t _clientId, zeus::FutureBase zeus::WebServer::callForward(uint32_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _buffer, const ememory::SharedPtr<zeus::Buffer>& _buffer,
uint64_t _singleReferenceId, uint64_t _singleReferenceId,
zeus::FutureData::ObserverFinish _callback) { zeus::FutureData::ObserverFinish _callback) {
@ -332,7 +348,7 @@ zeus::FutureBase zeus::TcpString::callForward(uint32_t _clientId,
return tmpFuture; return tmpFuture;
} }
void zeus::TcpString::callForwardMultiple(uint32_t _clientId, void zeus::WebServer::callForwardMultiple(uint32_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _buffer, const ememory::SharedPtr<zeus::Buffer>& _buffer,
uint64_t _singleReferenceId){ uint64_t _singleReferenceId){
if (_buffer == nullptr) { if (_buffer == nullptr) {
@ -353,7 +369,7 @@ void zeus::TcpString::callForwardMultiple(uint32_t _clientId,
ZEUS_ERROR("Can not transfer part of a message ..."); ZEUS_ERROR("Can not transfer part of a message ...");
} }
void zeus::TcpString::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId) { void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId) {
ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create(); ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create();
if (answer == nullptr) { if (answer == nullptr) {
return; return;
@ -366,7 +382,7 @@ void zeus::TcpString::answerError(uint64_t _clientTransactionId, const std::stri
} }
void zeus::TcpString::answerVoid(uint64_t _clientTransactionId, uint32_t _clientId) { void zeus::WebServer::answerVoid(uint64_t _clientTransactionId, uint32_t _clientId) {
ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create(); ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create();
if (answer == nullptr) { if (answer == nullptr) {
return; return;

View File

@ -4,8 +4,6 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#pragma once #pragma once
#include <eproperty/Value.h>
#include <esignal/Signal.h>
#include <zeus/Buffer.h> #include <zeus/Buffer.h>
#include <enet/WebSocket.h> #include <enet/WebSocket.h>
#include <thread> #include <thread>
@ -14,7 +12,81 @@
#include <zeus/FutureBase.h> #include <zeus/FutureBase.h>
namespace zeus { namespace zeus {
class TcpString : public eproperty::Interface { /**
* @brief
* @param[in]
* @return
*/
ememory::SharedPtr<zeus::Buffer> createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0);
/**
* @brief
* @param[in]
* @return
*/
void createParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj);
/**
* @brief
* @param[in]
* @return
*/
template<class ZEUS_TYPE, class... _ARGS>
void createParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj,
const ZEUS_TYPE& _param,
_ARGS&&... _args) {
_obj->addParameter<ZEUS_TYPE>(_param);
_paramId++;
createParam(_paramId, _obj, std::forward<_ARGS>(_args)...);
}
/**
* @brief
* @param[in]
* @return
*/
// convert const char in std::string ...
template<class... _ARGS>
void createParam(int32_t _paramId,
const ememory::SharedPtr<zeus::Buffer>& _obj,
const char* _param,
_ARGS&&... _args) {
createParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...);
}
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS>
ememory::SharedPtr<zeus::Buffer> createCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::Buffer> callElem = createBaseCall(_transactionId, _functionName);
if (callElem == nullptr) {
return nullptr;
}
createParam(0, callElem, std::forward<_ARGS>(_args)...);
return callElem;
}
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS>
ememory::SharedPtr<zeus::Buffer> createCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::Buffer> callElem = createBaseCall(_transactionId, _functionName, _serviceName);
if (callElem == nullptr) {
return nullptr;
}
createParam(0, callElem, std::forward<_ARGS>(_args)...);
return callElem;
}
/**
* @brief
*/
class WebServer {
private: private:
enet::WebSocket m_connection; enet::WebSocket m_connection;
uint16_t m_transmissionId; uint16_t m_transmissionId;
@ -30,7 +102,6 @@ namespace zeus {
* @brief Connect an function member on the signal with the shared_ptr object. * @brief Connect an function member on the signal with the shared_ptr object.
* @param[in] _class shared_ptr Object on whe we need to call ==> the object is get in keeped in weak_ptr. * @param[in] _class shared_ptr Object on whe we need to call ==> the object is get in keeped in weak_ptr.
* @param[in] _func Function to call. * @param[in] _func Function to call.
* @param[in] _args Argument optinnal the user want to add.
*/ */
template<class CLASS_TYPE> template<class CLASS_TYPE>
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(const ememory::SharedPtr<zeus::Buffer>&)) { void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(const ememory::SharedPtr<zeus::Buffer>&)) {
@ -39,75 +110,195 @@ namespace zeus {
}; };
} }
public: public:
TcpString(); /**
TcpString(enet::Tcp _connection, bool _isServer); * @brief
virtual ~TcpString(); * @param[in]
* @return
*/
WebServer();
/**
* @brief
* @param[in]
* @return
*/
WebServer(enet::Tcp _connection, bool _isServer);
/**
* @brief
* @param[in]
* @return
*/
virtual ~WebServer();
/**
* @brief
* @param[in]
* @return
*/
void setInterface(enet::Tcp _connection, bool _isServer); void setInterface(enet::Tcp _connection, bool _isServer);
/**
* @brief
* @param[in]
* @return
*/
void connect(bool _async = false); void connect(bool _async = false);
/**
* @brief
* @param[in]
* @return
*/
void disconnect(bool _inThreadStop = false); void disconnect(bool _inThreadStop = false);
/**
* @brief
* @param[in]
* @return
*/
bool isActive() const; bool isActive() const;
/**
* @brief
* @param[in]
* @return
*/
void setInterfaceName(const std::string& _name); void setInterfaceName(const std::string& _name);
/**
* @brief
* @param[in]
* @return
*/
int32_t writeBinary(const ememory::SharedPtr<zeus::Buffer>& _data); int32_t writeBinary(const ememory::SharedPtr<zeus::Buffer>& _data);
/**
* @brief
* @param[in]
* @return
*/
void ping(); void ping();
/**
* @brief
* @param[in]
* @return
*/
bool onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols); bool onReceiveUri(const std::string& _uri, const std::vector<std::string>& _protocols);
/**
* @brief
* @param[in]
* @return
*/
void onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary); void onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary);
/**
* @brief
* @param[in]
* @return
*/
void newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer); void newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer);
public: public:
/**
* @brief
* @param[in]
* @return
*/
const std::chrono::steady_clock::time_point& getLastTimeReceive() { const std::chrono::steady_clock::time_point& getLastTimeReceive() {
return m_connection.getLastTimeReceive(); return m_connection.getLastTimeReceive();
} }
/**
* @brief
* @param[in]
* @return
*/
const std::chrono::steady_clock::time_point& getLastTimeSend() { const std::chrono::steady_clock::time_point& getLastTimeSend() {
return m_connection.getLastTimeSend(); return m_connection.getLastTimeSend();
} }
private: private:
using ActionAsync = std::function<bool(TcpString* _interface)>; using ActionAsync = std::function<bool(WebServer* _interface)>;
std::mutex m_threadAsyncMutex; std::mutex m_threadAsyncMutex;
std::thread* m_threadAsync; std::thread* m_threadAsync;
bool m_threadAsyncRunning; bool m_threadAsyncRunning;
std::vector<ActionAsync> m_threadAsyncList; std::vector<ActionAsync> m_threadAsyncList;
std::vector<ActionAsync> m_threadAsyncList2; std::vector<ActionAsync> m_threadAsyncList2;
private: private:
/**
* @brief
* @param[in]
* @return
*/
void threadAsyncCallback(); void threadAsyncCallback();
public: public:
/**
* @brief
* @param[in]
* @return
*/
void addAsync(ActionAsync _elem); void addAsync(ActionAsync _elem);
private: private:
/**
* @brief
* @param[in]
* @return
*/
zeus::FutureBase callBinary(uint64_t _transactionId, zeus::FutureBase callBinary(uint64_t _transactionId,
const ememory::SharedPtr<zeus::Buffer>& _obj, const ememory::SharedPtr<zeus::Buffer>& _obj,
zeus::FutureData::ObserverFinish _callback=nullptr, zeus::FutureData::ObserverFinish _callback=nullptr,
const uint32_t& _service=0); const uint32_t& _service=0);
public: // section call direct public: // section call direct
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
uint16_t id = getId(); uint16_t id = getId();
ememory::SharedPtr<zeus::Buffer> callElem = zeus::createBinaryCall(id, _functionName, std::forward<_ARGS>(_args)...); ememory::SharedPtr<zeus::Buffer> callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem); return callBinary(id, callElem);
} }
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
uint16_t id = getId(); uint16_t id = getId();
ememory::SharedPtr<zeus::Buffer> callElem = zeus::createBinaryCall(id, _functionName, std::forward<_ARGS>(_args)...); ememory::SharedPtr<zeus::Buffer> callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem, _callback); return callBinary(id, callElem, _callback);
} }
public: // section call with service ID / Client ID public: // section call with service ID / Client ID
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callService(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase callService(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args) {
uint16_t id = getId(); uint16_t id = getId();
ememory::SharedPtr<zeus::Buffer> callElem = zeus::createBinaryCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); ememory::SharedPtr<zeus::Buffer> callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem); return callBinary(id, callElem);
} }
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callServiceAction(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { zeus::FutureBase callServiceAction(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
uint16_t id = getId(); uint16_t id = getId();
ememory::SharedPtr<zeus::Buffer> callElem = zeus::createBinaryCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); ememory::SharedPtr<zeus::Buffer> callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem, _callback); return callBinary(id, callElem, _callback);
} }
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callClient(uint32_t _clientId, zeus::FutureBase callClient(uint32_t _clientId,
const std::string& _functionName, const std::string& _functionName,
_ARGS&&... _args) { _ARGS&&... _args) {
return callService(_clientId, _functionName, _args...); return callService(_clientId, _functionName, _args...);
} }
/**
* @brief
* @param[in]
* @return
*/
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callClientAction(uint32_t _clientId, zeus::FutureBase callClientAction(uint32_t _clientId,
const std::string& _functionName, const std::string& _functionName,
@ -115,16 +306,36 @@ namespace zeus {
zeus::FutureData::ObserverFinish _callback) { zeus::FutureData::ObserverFinish _callback) {
return callServiceAction(_clientId, _functionName, _args..., _callback); return callServiceAction(_clientId, _functionName, _args..., _callback);
} }
/**
* @brief
* @param[in]
* @return
*/
zeus::FutureBase callForward(uint32_t _clientId, zeus::FutureBase callForward(uint32_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _Buffer, const ememory::SharedPtr<zeus::Buffer>& _Buffer,
uint64_t _singleReferenceId, uint64_t _singleReferenceId,
zeus::FutureData::ObserverFinish _callback); zeus::FutureData::ObserverFinish _callback);
/**
* @brief
* @param[in]
* @return
*/
void callForwardMultiple(uint32_t _clientId, void callForwardMultiple(uint32_t _clientId,
const ememory::SharedPtr<zeus::Buffer>& _Buffer, const ememory::SharedPtr<zeus::Buffer>& _Buffer,
uint64_t _singleReferenceId); uint64_t _singleReferenceId);
public: // answers ... public: // answers ...
/**
* @brief
* @param[in]
* @return
*/
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp); void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
/**
* @brief
* @param[in]
* @return
*/
template<class ZEUS_ARG> template<class ZEUS_ARG>
void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0) { void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0) {
ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create(); ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create();
@ -134,7 +345,17 @@ namespace zeus {
answer->addAnswer(_value); answer->addAnswer(_value);
writeBinary(answer); writeBinary(answer);
} }
/**
* @brief
* @param[in]
* @return
*/
void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId=0); void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId=0);
/**
* @brief
* @param[in]
* @return
*/
void answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorComment="", uint32_t _clientId=0); void answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorComment="", uint32_t _clientId=0);
}; };
} }

View File

@ -7,6 +7,17 @@
#include <etk/types.h> #include <etk/types.h>
namespace zeus { namespace zeus {
/**
* @brief
* @param[in]
* @return
*/
std::string getMineType(const std::string& _extention); std::string getMineType(const std::string& _extention);
/**
* @brief
* @param[in]
* @return
*/
std::string getExtention(const std::string& _mineType); std::string getExtention(const std::string& _mineType);
}; };