[DEV/DOC] clean documentation and code
This commit is contained in:
parent
19948e45f0
commit
7ee8e2332c
@ -26,15 +26,13 @@ def get_version():
|
||||
|
||||
def create(target, module_name):
|
||||
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([
|
||||
'zeus/debug.cpp'
|
||||
])
|
||||
my_module.add_path(tools.get_current_path(__file__))
|
||||
my_module.add_src_file([
|
||||
'zeus/AbstractFunction.cpp',
|
||||
'zeus/AbstractFunctionTypeDirect.cpp',
|
||||
'zeus/AbstractFunctionTypeClass.cpp',
|
||||
'zeus/FutureBase.cpp',
|
||||
'zeus/Future.cpp',
|
||||
'zeus/File.cpp',
|
||||
@ -43,13 +41,10 @@ def create(target, module_name):
|
||||
'zeus/Buffer_getParameter.cpp',
|
||||
'zeus/ParamType.cpp',
|
||||
'zeus/Client.cpp',
|
||||
'zeus/GateWay.cpp',
|
||||
'zeus/GateWayService.cpp',
|
||||
'zeus/GateWayClient.cpp',
|
||||
'zeus/RemoteProcessCall.cpp',
|
||||
'zeus/Service.cpp',
|
||||
'zeus/ServiceRemote.cpp',
|
||||
'zeus/TcpString.cpp',
|
||||
'zeus/WebServer.cpp',
|
||||
'zeus/mineType.cpp',
|
||||
])
|
||||
my_module.add_header_file([
|
||||
@ -64,13 +59,10 @@ def create(target, module_name):
|
||||
'zeus/ParamType.h',
|
||||
'zeus/debug.h',
|
||||
'zeus/Client.h',
|
||||
'zeus/GateWay.h',
|
||||
'zeus/GateWayService.h',
|
||||
'zeus/GateWayClient.h',
|
||||
'zeus/RemoteProcessCall.h',
|
||||
'zeus/Service.h',
|
||||
'zeus/ServiceRemote.h',
|
||||
'zeus/TcpString.h',
|
||||
'zeus/WebServer.h',
|
||||
'zeus/mineType.h',
|
||||
])
|
||||
if target.config["compilator"] == "clang":
|
||||
|
@ -35,29 +35,26 @@ int main(int _argc, const char *_argv[]) {
|
||||
APPL_INFO("==================================");
|
||||
APPL_INFO("== ZEUS test client start ==");
|
||||
APPL_INFO("==================================");
|
||||
client1.connect("test1#atria-soft.com");
|
||||
|
||||
if (false) {
|
||||
zeus::Future<bool> retIdentify = client1.call("identify", "clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968");
|
||||
retIdentify.wait();
|
||||
if (retIdentify.get() == false) {
|
||||
bool ret = client1.connect("test1~atria-soft.com", "clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968");
|
||||
if (ret == false) {
|
||||
APPL_ERROR(" ==> NOT Connected with 'clientTest1#atria-soft.com'");
|
||||
return -1;
|
||||
} else {
|
||||
APPL_INFO(" ==> Connected with 'clientTest1#atria-soft.com'");
|
||||
}
|
||||
} else if (true) {
|
||||
zeus::Future<bool> retIdentify = client1.call("auth", "coucou");
|
||||
retIdentify.wait();
|
||||
if (retIdentify.get() == false) {
|
||||
bool ret = client1.connect("test1~atria-soft.com", "coucou");
|
||||
if (ret == false) {
|
||||
APPL_ERROR(" ==> NOT Authentify with 'test1#atria-soft.com'");
|
||||
return -1;
|
||||
} else {
|
||||
APPL_INFO(" ==> Authentify with 'test1#atria-soft.com'");
|
||||
}
|
||||
} else {
|
||||
zeus::Future<bool> retIdentify = client1.call("anonymous");
|
||||
retIdentify.wait();
|
||||
if (retIdentify.get() == false) {
|
||||
bool ret = client1.connect("test1~atria-soft.com");
|
||||
if (ret == false) {
|
||||
APPL_ERROR(" ==> NOT Connected with 'anonymous'");
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -348,8 +348,8 @@ namespace appl {
|
||||
return m_user->getAlbumCount(_album);
|
||||
}
|
||||
// Return the list of the album files
|
||||
std::vector<std::string> getAlbumListPicture(std::string _album) {//, uint32_t _startId, uint32_t _stopId) {
|
||||
return m_user->getAlbumListPicture(_album);//, _startId, _stopId);
|
||||
std::vector<std::string> getAlbumListPicture(std::string _album) {
|
||||
return m_user->getAlbumListPicture(_album);
|
||||
}
|
||||
// Return a File Data (might be a picture .tiff/.png/.jpg)
|
||||
zeus::FileServer getAlbumPicture(std::string _pictureName) {
|
||||
|
@ -4,9 +4,10 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/GateWayClient.h>
|
||||
#include <zeus/GateWay.h>
|
||||
#include <appl/debug.h>
|
||||
#include <appl/ClientInterface.h>
|
||||
#include <zeus/Future.h>
|
||||
#include <appl/GateWay.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <zeus/AbstractFunction.h>
|
||||
@ -14,8 +15,8 @@
|
||||
|
||||
static const std::string protocolError = "PROTOCOL-ERROR";
|
||||
|
||||
zeus::GateWayClient::GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewayInterface) :
|
||||
m_state(zeus::GateWayClient::state::unconnect),
|
||||
appl::ClientInterface::ClientInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface) :
|
||||
m_state(appl::ClientInterface::state::unconnect),
|
||||
m_gatewayInterface(_gatewayInterface),
|
||||
m_interfaceClient(std::move(_connection), true) {
|
||||
ZEUS_INFO("----------------");
|
||||
@ -23,7 +24,7 @@ zeus::GateWayClient::GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewa
|
||||
ZEUS_INFO("----------------");
|
||||
}
|
||||
|
||||
zeus::GateWayClient::~GateWayClient() {
|
||||
appl::ClientInterface::~ClientInterface() {
|
||||
ZEUS_TODO("Call All unlink ...");
|
||||
stop();
|
||||
ZEUS_INFO("-------------------");
|
||||
@ -31,16 +32,16 @@ zeus::GateWayClient::~GateWayClient() {
|
||||
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_uid2 = _uid2;
|
||||
m_state = zeus::GateWayClient::state::connect;
|
||||
m_interfaceClient.connect(this, &zeus::GateWayClient::onClientData);
|
||||
m_state = appl::ClientInterface::state::connect;
|
||||
m_interfaceClient.connect(this, &appl::ClientInterface::onClientData);
|
||||
m_interfaceClient.connect(true);
|
||||
m_interfaceClient.setInterfaceName("cli-" + etk::to_string(m_uid));
|
||||
}
|
||||
|
||||
void zeus::GateWayClient::stop() {
|
||||
void appl::ClientInterface::stop() {
|
||||
for (auto &it : m_listConnectedService) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
@ -55,18 +56,18 @@ void zeus::GateWayClient::stop() {
|
||||
m_interfaceClient.disconnect();
|
||||
}
|
||||
|
||||
bool zeus::GateWayClient::isAlive() {
|
||||
bool appl::ClientInterface::isAlive() {
|
||||
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_state = zeus::GateWayClient::state::disconnect;
|
||||
m_state = appl::ClientInterface::state::disconnect;
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -78,7 +79,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
}
|
||||
if (_value->getType() == zeus::Buffer::typeMessage::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)");
|
||||
return;
|
||||
}
|
||||
@ -110,14 +111,14 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
}
|
||||
std::string callFunction = _value->getCall();
|
||||
switch (m_state) {
|
||||
case zeus::GateWayClient::state::disconnect:
|
||||
case zeus::GateWayClient::state::unconnect:
|
||||
case appl::ClientInterface::state::disconnect:
|
||||
case appl::ClientInterface::state::unconnect:
|
||||
{
|
||||
ZEUS_ERROR("Must never appear");
|
||||
answerProtocolError(transactionId, "Gateway internal error");
|
||||
return;
|
||||
}
|
||||
case zeus::GateWayClient::state::connect:
|
||||
case appl::ClientInterface::state::connect:
|
||||
{
|
||||
if (m_userConnectionName != "") {
|
||||
answerProtocolError(transactionId, "Gateway internal error 2");
|
||||
@ -135,7 +136,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
} else {
|
||||
zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.callClient(m_uid2, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>());
|
||||
futLocalService.wait(); // TODO: Set timeout ...
|
||||
m_state = zeus::GateWayClient::state::userIdentify;
|
||||
m_state = appl::ClientInterface::state::userIdentify;
|
||||
m_interfaceClient.answerValue(transactionId, true);
|
||||
}
|
||||
}
|
||||
@ -145,7 +146,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
answerProtocolError(transactionId, "Missing call of connectToUser");
|
||||
return;
|
||||
}
|
||||
case zeus::GateWayClient::state::userIdentify:
|
||||
case appl::ClientInterface::state::userIdentify:
|
||||
{
|
||||
m_clientServices.clear();
|
||||
m_clientgroups.clear();
|
||||
@ -228,11 +229,11 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
|
||||
|
||||
m_interfaceClient.answerValue(transactionId, true);
|
||||
m_state = zeus::GateWayClient::state::clientIdentify;
|
||||
m_state = appl::ClientInterface::state::clientIdentify;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case zeus::GateWayClient::state::clientIdentify:
|
||||
case appl::ClientInterface::state::clientIdentify:
|
||||
{
|
||||
uint32_t serviceId = _value->getServiceId();
|
||||
if (serviceId == 0) {
|
||||
@ -268,7 +269,7 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
m_interfaceClient.answerError(transactionId, "UN-AUTHORIZED-SERVICE");
|
||||
return;
|
||||
}
|
||||
ememory::SharedPtr<zeus::GateWayService> srv = m_gatewayInterface->get(serviceName);
|
||||
ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName);
|
||||
if (srv != nullptr) {
|
||||
zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups);
|
||||
futLink.wait(); // TODO: Set timeout ...
|
||||
@ -331,10 +332,10 @@ void zeus::GateWayClient::onClientData(const ememory::SharedPtr<zeus::Buffer>& _
|
||||
return true;
|
||||
}
|
||||
ZEUS_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
|
||||
ZEUS_DEBUG(" msg=" << tmpp->generateHumanString());
|
||||
ZEUS_DEBUG(" msg=" << *tmpp);
|
||||
tmpp->setTransactionId(transactionId);
|
||||
tmpp->setServiceId(serviceId+1);
|
||||
ZEUS_DEBUG("transmit=" << tmpp->generateHumanString());
|
||||
ZEUS_DEBUG("transmit=" << *tmpp);
|
||||
m_interfaceClient.writeBinary(tmpp);
|
||||
// multiple send element ...
|
||||
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 ...");
|
||||
}
|
@ -5,18 +5,13 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <ememory/memory.h>
|
||||
#include <esignal/Signal.h>
|
||||
#include <zeus/GateWayService.h>
|
||||
#include <zeus/Future.h>
|
||||
#include <zeus/AbstractFunction.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <appl/GateWay.h>
|
||||
#include <appl/ServiceInterface.h>
|
||||
|
||||
|
||||
|
||||
namespace zeus {
|
||||
namespace appl {
|
||||
class GateWay;
|
||||
class GateWayClient {
|
||||
class ClientInterface {
|
||||
private:
|
||||
enum class state {
|
||||
unconnect, // starting sate
|
||||
@ -27,12 +22,11 @@ namespace zeus {
|
||||
};
|
||||
enum state m_state; // state machine ...
|
||||
private:
|
||||
zeus::GateWay* m_gatewayInterface;
|
||||
zeus::TcpString m_interfaceClient;
|
||||
appl::GateWay* m_gatewayInterface;
|
||||
zeus::WebServer m_interfaceClient;
|
||||
public:
|
||||
esignal::Signal<bool> signalIsConnected;
|
||||
ememory::SharedPtr<zeus::GateWayService> m_userService;
|
||||
std::vector<ememory::SharedPtr<zeus::GateWayService>> m_listConnectedService;
|
||||
ememory::SharedPtr<appl::ServiceInterface> m_userService;
|
||||
std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_listConnectedService;
|
||||
uint64_t m_uid;
|
||||
uint64_t m_uid2;
|
||||
std::string m_userConnectionName;
|
||||
@ -40,8 +34,8 @@ namespace zeus {
|
||||
std::vector<std::string> m_clientgroups;
|
||||
std::vector<std::string> m_clientServices;
|
||||
public:
|
||||
GateWayClient(enet::Tcp _connection, zeus::GateWay* _gatewayInterface);
|
||||
virtual ~GateWayClient();
|
||||
ClientInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface);
|
||||
virtual ~ClientInterface();
|
||||
void start(uint64_t _uid, uint64_t _uid2);
|
||||
void stop();
|
||||
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);
|
@ -4,21 +4,21 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/GateWay.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <appl/GateWay.h>
|
||||
#include <appl/debug.h>
|
||||
#include <enet/TcpServer.h>
|
||||
|
||||
|
||||
namespace zeus {
|
||||
namespace appl {
|
||||
class TcpServerInput {
|
||||
private:
|
||||
enet::TcpServer m_interface;
|
||||
std::thread* m_thread;
|
||||
bool m_threadRunning;
|
||||
zeus::GateWay* m_gateway;
|
||||
appl::GateWay* m_gateway;
|
||||
bool m_service;
|
||||
public:
|
||||
TcpServerInput(zeus::GateWay* _gateway, bool _service) :
|
||||
TcpServerInput(appl::GateWay* _gateway, bool _service) :
|
||||
m_thread(nullptr),
|
||||
m_threadRunning(false),
|
||||
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)");
|
||||
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();
|
||||
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)");
|
||||
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++);
|
||||
m_clientList.push_back(tmp);
|
||||
}
|
||||
|
||||
zeus::GateWay::GateWay() :
|
||||
appl::GateWay::GateWay() :
|
||||
m_clientUID(1),
|
||||
propertyClientIp(this, "client-ip", "127.0.0.1", "Ip to listen client", &zeus::GateWay::onPropertyChangeClientIp),
|
||||
propertyClientPort(this, "client-port", 1983, "Port to listen client", &zeus::GateWay::onPropertyChangeClientPort),
|
||||
propertyClientMax(this, "client-max", 80, "Maximum of client at the same time", &zeus::GateWay::onPropertyChangeClientMax),
|
||||
propertyServiceIp(this, "service-ip", "127.0.0.1", "Ip to listen client", &zeus::GateWay::onPropertyChangeServiceIp),
|
||||
propertyServicePort(this, "service-port", 1982, "Port to listen client", &zeus::GateWay::onPropertyChangeServicePort),
|
||||
propertyServiceMax(this, "service-max", 80, "Maximum of client at the same time", &zeus::GateWay::onPropertyChangeServiceMax) {
|
||||
m_interfaceClientServer = std::make_shared<zeus::TcpServerInput>(this, false);
|
||||
m_interfaceServiceServer = std::make_shared<zeus::TcpServerInput>(this, true);
|
||||
propertyClientIp(this, "client-ip", "127.0.0.1", "Ip to listen client", &appl::GateWay::onPropertyChangeClientIp),
|
||||
propertyClientPort(this, "client-port", 1983, "Port to listen client", &appl::GateWay::onPropertyChangeClientPort),
|
||||
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", &appl::GateWay::onPropertyChangeServiceIp),
|
||||
propertyServicePort(this, "service-port", 1982, "Port to listen client", &appl::GateWay::onPropertyChangeServicePort),
|
||||
propertyServiceMax(this, "service-max", 80, "Maximum of client at the same time", &appl::GateWay::onPropertyChangeServiceMax) {
|
||||
m_interfaceClientServer = std::make_shared<appl::TcpServerInput>(this, false);
|
||||
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_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) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
@ -117,7 +117,7 @@ ememory::SharedPtr<zeus::GateWayService> zeus::GateWay::get(const std::string& _
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> zeus::GateWay::getAllServiceName() {
|
||||
std::vector<std::string> appl::GateWay::getAllServiceName() {
|
||||
std::vector<std::string> out;
|
||||
for (auto &it : m_serviceList) {
|
||||
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) {
|
||||
if (it == nullptr) {
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
void zeus::GateWay::onServiceConnect(const bool& _value) {
|
||||
void appl::GateWay::onServiceConnect(const bool& _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() {
|
||||
|
||||
}
|
@ -4,20 +4,21 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
#include <zeus/GateWayService.h>
|
||||
#include <zeus/GateWayClient.h>
|
||||
#include <appl/ServiceInterface.h>
|
||||
#include <appl/ClientInterface.h>
|
||||
#include <eproperty/Value.h>
|
||||
|
||||
namespace zeus {
|
||||
namespace appl {
|
||||
class TcpServerInput;
|
||||
class GateWay : public eproperty::Interface {
|
||||
private:
|
||||
uint64_t m_clientUID;
|
||||
private:
|
||||
std::vector<ememory::SharedPtr<zeus::GateWayService>> 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
|
||||
//TODO: std::vector<zeus::GateWayServer> m_ServerList; //!< List of all Server connected to this gateway
|
||||
ememory::SharedPtr<zeus::TcpServerInput> m_interfaceClientServer;
|
||||
ememory::SharedPtr<zeus::TcpServerInput> m_interfaceServiceServer;
|
||||
std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_serviceList; //!< List of all service availlable with their specific connection interface
|
||||
std::vector<ememory::SharedPtr<appl::ClientInterface>> m_clientList; //!< List of all Client interface with their own connection
|
||||
//TODO: std::vector<appl::ServerInterface> m_ServerList; //!< List of all Server connected to this gateway
|
||||
ememory::SharedPtr<appl::TcpServerInput> m_interfaceClientServer;
|
||||
ememory::SharedPtr<appl::TcpServerInput> m_interfaceServiceServer;
|
||||
public:
|
||||
eproperty::Value<std::string> propertyClientIp;
|
||||
eproperty::Value<uint16_t> propertyClientPort;
|
||||
@ -30,7 +31,7 @@ namespace zeus {
|
||||
virtual ~GateWay();
|
||||
void start();
|
||||
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();
|
||||
void answer(uint64_t _userSessionId, const ememory::SharedPtr<zeus::Buffer>& _data);
|
||||
void newService(enet::Tcp _connection);
|
@ -4,16 +4,17 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/GateWayService.h>
|
||||
#include <zeus/GateWay.h>
|
||||
#include <appl/debug.h>
|
||||
#include <appl/ServiceInterface.h>
|
||||
#include <appl/ClientInterface.h>
|
||||
#include <appl/GateWay.h>
|
||||
|
||||
// todo : cHANGE THIS ...
|
||||
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_interfaceClient(std::move(_connection), true) {
|
||||
ZEUS_INFO("-----------------");
|
||||
@ -21,34 +22,34 @@ zeus::GateWayService::GateWayService(enet::Tcp _connection, zeus::GateWay* _gate
|
||||
ZEUS_INFO("-----------------");
|
||||
}
|
||||
|
||||
zeus::GateWayService::~GateWayService() {
|
||||
appl::ServiceInterface::~ServiceInterface() {
|
||||
|
||||
ZEUS_INFO("--------------------");
|
||||
ZEUS_INFO("-- DELETE Service --");
|
||||
ZEUS_INFO("--------------------");
|
||||
}
|
||||
|
||||
bool zeus::GateWayService::isAlive() {
|
||||
bool appl::ServiceInterface::isAlive() {
|
||||
return m_interfaceClient.isActive();
|
||||
}
|
||||
|
||||
void zeus::GateWayService::start() {
|
||||
m_interfaceClient.connect(this, &zeus::GateWayService::onServiceData);
|
||||
void appl::ServiceInterface::start() {
|
||||
m_interfaceClient.connect(this, &appl::ServiceInterface::onServiceData);
|
||||
m_interfaceClient.connect();
|
||||
m_interfaceClient.setInterfaceName("srv-?");
|
||||
}
|
||||
|
||||
void zeus::GateWayService::stop() {
|
||||
void appl::ServiceInterface::stop() {
|
||||
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);
|
||||
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) {
|
||||
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.disconnect(true);
|
||||
}
|
@ -5,24 +5,21 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <ememory/memory.h>
|
||||
#include <esignal/Signal.h>
|
||||
|
||||
namespace zeus {
|
||||
namespace appl {
|
||||
class GateWay;
|
||||
class GateWayClient;
|
||||
class GateWayService {
|
||||
friend class zeus::GateWayClient;
|
||||
class ClientInterface;
|
||||
class ServiceInterface {
|
||||
friend class appl::ClientInterface;
|
||||
private:
|
||||
zeus::GateWay* m_gatewayInterface;
|
||||
zeus::TcpString m_interfaceClient;
|
||||
appl::GateWay* m_gatewayInterface;
|
||||
zeus::WebServer m_interfaceClient;
|
||||
std::string m_name;
|
||||
public:
|
||||
esignal::Signal<bool> signalIsConnected;
|
||||
public:
|
||||
GateWayService(enet::Tcp _connection, zeus::GateWay* _gatewayInterface);
|
||||
virtual ~GateWayService();
|
||||
ServiceInterface(enet::Tcp _connection, appl::GateWay* _gatewayInterface);
|
||||
virtual ~ServiceInterface();
|
||||
void start();
|
||||
void stop();
|
||||
void onServiceData(const ememory::SharedPtr<zeus::Buffer>& _value);
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <appl/debug.h>
|
||||
#include <zeus/GateWay.h>
|
||||
#include <appl/GateWay.h>
|
||||
#include <etk/etk.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
zeus::GateWay basicGateway;
|
||||
appl::GateWay basicGateway;
|
||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||
std::string data = _argv[iii];
|
||||
if (etk::start_with(data, "--client-ip=") == true) {
|
||||
|
@ -30,6 +30,9 @@ def create(target, module_name):
|
||||
my_module.add_module_depend(['zeus'])
|
||||
my_module.add_src_file([
|
||||
'appl/debug.cpp',
|
||||
'appl/ClientInterface.cpp',
|
||||
'appl/ServiceInterface.cpp',
|
||||
'appl/GateWay.cpp',
|
||||
'appl/main.cpp'
|
||||
])
|
||||
return my_module
|
||||
|
@ -210,20 +210,28 @@ int main(int _argc, const char *_argv[]) {
|
||||
serviceInterface.setVersion("0.1.0");
|
||||
serviceInterface.setType("USER", 1);
|
||||
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
||||
serviceInterface.advertise("checkTocken", &appl::SystemService::checkTocken);
|
||||
serviceInterface.setLastFuncDesc("Check if a user tocken is correct or not");
|
||||
serviceInterface.addLastFuncParam("clientName", "Name of the client");
|
||||
serviceInterface.addLastFuncParam("tocken", "String containing the Tocken");
|
||||
serviceInterface.advertise("checkAuth", &appl::SystemService::checkAuth);
|
||||
serviceInterface.setLastFuncDesc("Check the password of the curent user");
|
||||
serviceInterface.addLastFuncParam("password", "client/user password");
|
||||
serviceInterface.advertise("getGroups", &appl::SystemService::getGroups);
|
||||
serviceInterface.setLastFuncDesc("Get list of group availlable for a client name");
|
||||
serviceInterface.addLastFuncParam("clientName", "Name of the client");
|
||||
serviceInterface.advertise("filterServices", &appl::SystemService::filterServices);
|
||||
serviceInterface.setLastFuncDesc("Filter a list of service with the cuurent profile of the user (restrict area)");
|
||||
serviceInterface.addLastFuncParam("clientName", "Name of the client");
|
||||
serviceInterface.addLastFuncParam("currentList", "Vector of name of the services");
|
||||
zeus::AbstractFunction* func = serviceInterface.advertise("checkTocken", &appl::SystemService::checkTocken);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Check if a user tocken is correct or not");
|
||||
func->addParam("clientName", "Name of the client");
|
||||
func->addParam("tocken", "String containing the Tocken");
|
||||
}
|
||||
func = serviceInterface.advertise("checkAuth", &appl::SystemService::checkAuth);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Check the password of the curent user");
|
||||
func->addParam("password", "client/user password");
|
||||
}
|
||||
func = serviceInterface.advertise("getGroups", &appl::SystemService::getGroups);
|
||||
if (func != nullptr) {
|
||||
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("== ZEUS service: " << SERVICE_NAME << " [service instanciate]");
|
||||
APPL_INFO("===========================================================");
|
||||
|
@ -7,21 +7,6 @@
|
||||
#include <zeus/debug.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 {
|
||||
return m_type;
|
||||
}
|
||||
@ -54,7 +39,7 @@ void zeus::AbstractFunction::setReturn(const std::string& _desc) {
|
||||
m_returnDescription = _desc;
|
||||
}
|
||||
|
||||
std::string zeus::AbstractFunction::getPrototypeFull() const {
|
||||
std::string zeus::AbstractFunction::getPrototype() const {
|
||||
std::string out = getPrototypeReturn();
|
||||
out += " ";
|
||||
out += m_name;
|
||||
@ -74,23 +59,23 @@ std::string zeus::AbstractFunction::getPrototypeFull() const {
|
||||
}
|
||||
|
||||
|
||||
zeus::AbstractFunction::AbstractFunction(const std::string& _name,
|
||||
const std::string& _desc):
|
||||
std::string zeus::AbstractFunction::getSignature() const {
|
||||
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_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;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/ParamType.h>
|
||||
#include <zeus/File.h>
|
||||
@ -13,97 +12,122 @@
|
||||
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief Interface to store a function and call it after with a @ref zeus::Buffer
|
||||
*/
|
||||
class AbstractFunction {
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _name Nmae of the function
|
||||
*/
|
||||
AbstractFunction(const std::string& _name);
|
||||
public:
|
||||
/**
|
||||
* @brief generic virtual destructor
|
||||
*/
|
||||
virtual ~AbstractFunction() = default;
|
||||
public:
|
||||
/**
|
||||
* @brief Under type of the call methode
|
||||
*/
|
||||
enum class type {
|
||||
unknow,
|
||||
global,
|
||||
local,
|
||||
service,
|
||||
object,
|
||||
unknow, //!< Does not know the type of the call
|
||||
global, //!< This is a global function
|
||||
local, //!< This is a local fucntion
|
||||
service, //!< This call a service function (global function like "srv.xxx")
|
||||
object, //!< this is for service instance call
|
||||
};
|
||||
protected:
|
||||
enum type m_type;
|
||||
enum type m_type; //!< Type of the subCall (to permit to call many type of call)
|
||||
public:
|
||||
/**
|
||||
* @brief Get the tyope of the call that is needed to do.
|
||||
* @return Type of the call.
|
||||
*/
|
||||
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);
|
||||
protected:
|
||||
std::string m_name;
|
||||
std::string m_name; //!< name of the function
|
||||
public:
|
||||
/**
|
||||
* @brief Get the name of the function.
|
||||
* @return Function name
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
protected:
|
||||
std::string m_description;
|
||||
std::string m_description; //!< description of the function
|
||||
public:
|
||||
/**
|
||||
* @brief Get the description of the function
|
||||
* @return The description string of the function (same as doxygen 'brief')
|
||||
*/
|
||||
const std::string& getDescription() const;
|
||||
/**
|
||||
* @brief Set a new description of the function
|
||||
* @param[in] _desc Descriptive string
|
||||
*/
|
||||
void setDescription(const std::string& _desc);
|
||||
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:
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @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);
|
||||
protected:
|
||||
std::string m_returnDescription;
|
||||
std::string m_returnDescription; //!< Return description of the Function
|
||||
public:
|
||||
/**
|
||||
* @brief Set the return description of the Function
|
||||
* @param[in] _desc Description of the return parameter
|
||||
*/
|
||||
void setReturn(const std::string& _desc);
|
||||
protected:
|
||||
AbstractFunction(const std::string& _name, const std::string& _desc="");
|
||||
public:
|
||||
virtual ~AbstractFunction() {};
|
||||
public:
|
||||
bool checkCompatibility(const ParamType& _type, const ParamType& _params);
|
||||
public:
|
||||
std::string getPrototypeFull() const;
|
||||
virtual std::string getPrototype() const = 0;
|
||||
/**
|
||||
* @brief Get the prototype of the function with the parameter name and type
|
||||
* @return The fucntion like "void maFonction(int32 parameter_1, vector:string parameter_2);"
|
||||
*/
|
||||
std::string getPrototype() const;
|
||||
/**
|
||||
* @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;
|
||||
/**
|
||||
* @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 void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _params,
|
||||
/**
|
||||
* @brief Execute the function with all parameter properties
|
||||
* @param[in] _interfaceClient Web interface to anser values
|
||||
* @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;
|
||||
};
|
||||
|
||||
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>
|
||||
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>
|
||||
#include <zeus/WebServer.h>
|
||||
|
||||
|
@ -5,21 +5,25 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/AbstractFunction.h>
|
||||
#include <zeus/mineType.h>
|
||||
|
||||
|
||||
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>
|
||||
void executeClassCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
void executeClassCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
ZEUS_CLASS_TYPE* _pointer,
|
||||
ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...),
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj) {
|
||||
ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) {
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -36,18 +40,23 @@ namespace zeus {
|
||||
ZEUS_RETURN ret;
|
||||
return;
|
||||
#endif
|
||||
_interfaceClient->addAsync([=](TcpString* _interface) {
|
||||
_interface->answerValue(_transactionId, ret, _clientId);
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
|
||||
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>
|
||||
void executeClassCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
void executeClassCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
ZEUS_CLASS_TYPE* _pointer,
|
||||
void (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...),
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj) {
|
||||
void (ZEUS_CLASS_TYPE::*_func)(ZEUS_TYPES...)) {
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -63,12 +72,14 @@ namespace zeus {
|
||||
#error Must be implemented ...
|
||||
return;
|
||||
#endif
|
||||
_interfaceClient->addAsync([=](TcpString* _interface) {
|
||||
_interface->answerVoid(_transactionId, _clientId);
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
|
||||
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>
|
||||
class AbstractFunctionTypeClass: public zeus::AbstractFunction {
|
||||
protected:
|
||||
@ -77,25 +88,15 @@ namespace zeus {
|
||||
public:
|
||||
using functionType = ZEUS_RETURN (ZEUS_CLASS_TYPE::*)(ZEUS_TYPES...);
|
||||
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) {
|
||||
}
|
||||
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 {
|
||||
return m_returnType.getName();
|
||||
}
|
||||
@ -106,9 +107,7 @@ namespace zeus {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
void execute(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
void* _class) override {
|
||||
if (_obj == nullptr) {
|
||||
@ -128,37 +127,41 @@ namespace zeus {
|
||||
help += etk::to_string(sizeof...(ZEUS_TYPES));
|
||||
help += " parameters. prototype function:";
|
||||
help += getPrototype();
|
||||
_interfaceClient->answerError(_transactionId,
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
"WRONG-PARAMETER-NUMBER",
|
||||
help,
|
||||
_clientId);
|
||||
_obj->getClientId());
|
||||
return;
|
||||
}
|
||||
// check parameter compatibility
|
||||
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
|
||||
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
|
||||
_interfaceClient->answerError(_transactionId,
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
"WRONG-PARAMETER-TYPE",
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
|
||||
_clientId);
|
||||
_obj->getClientId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 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>
|
||||
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>
|
||||
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>
|
||||
AbstractFunction* createAbstractFunctionClass(const std::string& _name, const std::string& _desc, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_fffp)(ZEUS_TYPES...)) {
|
||||
return new AbstractFunctionTypeClass<ZEUS_RETURN, ZEUS_CLASS_TYPE, ZEUS_TYPES...>(_name, _desc, _fffp);
|
||||
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, _fffp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,20 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/AbstractFunction.h>
|
||||
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>
|
||||
void executeCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
ZEUS_RETURN (*_func)(ZEUS_TYPES...),
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj) {
|
||||
void executeCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
ZEUS_RETURN (*_func)(ZEUS_TYPES...)) {
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -30,18 +33,21 @@ namespace zeus {
|
||||
#else
|
||||
#error Must be implemented ...
|
||||
#endif
|
||||
_interfaceClient->addAsync([=](TcpString* _interface) {
|
||||
_interface->answerValue(_transactionId, ret, _clientId);
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
|
||||
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>
|
||||
void executeCall(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
void (*_func)(ZEUS_TYPES...),
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj) {
|
||||
void executeCall(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
void (*_func)(ZEUS_TYPES...)) {
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -56,12 +62,15 @@ namespace zeus {
|
||||
#else
|
||||
#error Must be implemented ...
|
||||
#endif
|
||||
_interfaceClient->addAsync([=](TcpString* _interface) {
|
||||
_interface->answerVoid(_transactionId, _clientId);
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Chass that permit to declare a function that call global function
|
||||
*/
|
||||
template <class ZEUS_RETURN, class... ZEUS_TYPES>
|
||||
class AbstractFunctionTypeDirect: public zeus::AbstractFunction {
|
||||
protected:
|
||||
@ -70,25 +79,15 @@ namespace zeus {
|
||||
public:
|
||||
using functionType = ZEUS_RETURN (*)(ZEUS_TYPES...);
|
||||
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) {
|
||||
}
|
||||
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 {
|
||||
return m_returnType.getName();
|
||||
}
|
||||
@ -99,9 +98,7 @@ namespace zeus {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
void execute(const ememory::SharedPtr<zeus::TcpString>& _interfaceClient,
|
||||
uint64_t _transactionId,
|
||||
uint64_t _clientId,
|
||||
void execute(const ememory::SharedPtr<zeus::WebServer>& _interfaceClient,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
void* _class) override {
|
||||
if (_obj == nullptr) {
|
||||
@ -115,36 +112,40 @@ namespace zeus {
|
||||
help += etk::to_string(sizeof...(ZEUS_TYPES));
|
||||
help += " parameters. prototype function:";
|
||||
help += getPrototype();
|
||||
_interfaceClient->answerError(_transactionId,
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
"WRONG-PARAMETER-NUMBER",
|
||||
help,
|
||||
_clientId);
|
||||
_obj->getClientId());
|
||||
return;
|
||||
}
|
||||
// check parameter compatibility
|
||||
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
|
||||
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
|
||||
_interfaceClient->answerError(_transactionId,
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
"WRONG-PARAMETER-TYPE",
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
|
||||
_clientId);
|
||||
_obj->getClientId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// execute cmd:
|
||||
zeus::executeCall(_interfaceClient, _transactionId, _clientId, m_function, _obj);
|
||||
zeus::executeCall(_interfaceClient, _obj, m_function);
|
||||
}
|
||||
};
|
||||
|
||||
// specialization
|
||||
template <class ZEUS_RETURN, class... ZEUS_TYPES>
|
||||
const ParamType AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>::m_returnType = createType<ZEUS_RETURN>();
|
||||
|
||||
// specialization
|
||||
template <class ZEUS_RETURN, class... 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>
|
||||
AbstractFunction* createAbstractFunctionDirect(const std::string& _name, const std::string& _desc, ZEUS_RETURN (*_fffp)(ZEUS_TYPES...)) {
|
||||
return new AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>(_name, _desc, _fffp);
|
||||
zeus::AbstractFunction* createAbstractFunctionDirect(const std::string& _name, ZEUS_RETURN (*_fffp)(ZEUS_TYPES...)) {
|
||||
return new AbstractFunctionTypeDirect<ZEUS_RETURN, ZEUS_TYPES...>(_name, _fffp);
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ bool zeus::Buffer::writeOn(enet::WebSocket& _interface) {
|
||||
size += sizeof(uint32_t); // parameter 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) {
|
||||
return false;
|
||||
@ -167,65 +167,61 @@ void zeus::Buffer::clear() {
|
||||
m_header.numberOfParameter = 1;
|
||||
}
|
||||
|
||||
std::string zeus::Buffer::generateHumanString() {
|
||||
std::string out = "zeus::Buffer: ";
|
||||
std::ostream& zeus::operator <<(std::ostream& _os, const zeus::Buffer& _obj) {
|
||||
_os << "zeus::Buffer: ";
|
||||
//out += " v=" + etk::to_string(m_header.versionProtocol); // se it in the websocket
|
||||
out += " id=" + etk::to_string(m_header.transactionID);
|
||||
out += " cId=" + etk::to_string(m_header.clientID);
|
||||
if ( getPartFinish() == false
|
||||
|| getPartId() != 0) {
|
||||
out += " part=" + etk::to_string(getPartId());
|
||||
if (getPartFinish() == true) {
|
||||
out += "/finish";
|
||||
_os << " id=" << etk::to_string(_obj.getTransactionId());
|
||||
_os << " cId=" << etk::to_string(_obj.getClientId());
|
||||
if ( _obj.getPartFinish() == false
|
||||
|| _obj.getPartId() != 0) {
|
||||
_os << " part=" << etk::to_string(_obj.getPartId());
|
||||
if (_obj.getPartFinish() == true) {
|
||||
_os << "/finish";
|
||||
}
|
||||
}
|
||||
enum zeus::Buffer::typeMessage type = getTypeType(m_header.typeMessage);
|
||||
enum zeus::Buffer::typeMessage type = _obj.getType();
|
||||
switch (type) {
|
||||
case zeus::Buffer::typeMessage::unknow:
|
||||
out += " -UNKNOW-";
|
||||
_os << " -UNKNOW-";
|
||||
break;
|
||||
case zeus::Buffer::typeMessage::call:
|
||||
out += " nbParam=" + etk::to_string(getNumberParameter());
|
||||
out += " -CALL-:'" + getCall() + "'";
|
||||
_os << " nbParam=" + etk::to_string(_obj.getNumberParameter());
|
||||
_os << " -CALL-:'" + _obj.getCall() + "'";
|
||||
break;
|
||||
case zeus::Buffer::typeMessage::answer:
|
||||
out += " -ANSWER-:";
|
||||
if (m_parameter.size() == 1) {
|
||||
out += "Value:" + simpleStringParam(0);
|
||||
} else if (m_parameter.size() == 2) {
|
||||
out += "Error";
|
||||
out += "Error:" + simpleStringParam(0);
|
||||
} else if (m_parameter.size() == 3) {
|
||||
out += "Value:" + simpleStringParam(0);
|
||||
out += "+Error:" + simpleStringParam(1);
|
||||
_os << " -ANSWER-:";
|
||||
if (_obj.m_parameter.size() == 1) {
|
||||
_os << "Value:" + _obj.simpleStringParam(0);
|
||||
} else if (_obj.m_parameter.size() == 2) {
|
||||
_os << "Error";
|
||||
_os << "Error:" + _obj.simpleStringParam(0);
|
||||
} else if (_obj.m_parameter.size() == 3) {
|
||||
_os << "Value:" + _obj.simpleStringParam(0);
|
||||
_os << "+Error:" + _obj.simpleStringParam(1);
|
||||
} else {
|
||||
out += "???";
|
||||
_os << "???";
|
||||
}
|
||||
break;
|
||||
case zeus::Buffer::typeMessage::event:
|
||||
out += " -EVENT-";
|
||||
_os << " -EVENT-";
|
||||
|
||||
break;
|
||||
case zeus::Buffer::typeMessage::data:
|
||||
out += " -DATA-";
|
||||
_os << " -DATA-";
|
||||
|
||||
break;
|
||||
}
|
||||
if (getNumberParameter() != 0) {
|
||||
out += " paramType(";
|
||||
if (getNumberParameter() >256) {
|
||||
out += " !!!!!!!";
|
||||
return out;
|
||||
}
|
||||
for (int32_t iii=0; iii< getNumberParameter(); ++iii) {
|
||||
if (_obj.getNumberParameter() != 0) {
|
||||
_os << " paramType(";
|
||||
for (int32_t iii=0; iii<_obj.getNumberParameter(); ++iii) {
|
||||
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 {
|
||||
@ -246,10 +242,17 @@ void zeus::Buffer::setClientId(uint32_t _value) {
|
||||
|
||||
// note limited 15 bits
|
||||
uint16_t zeus::Buffer::getPartId() const {
|
||||
if (getType() != zeus::Buffer::typeMessage::data) {
|
||||
return 0;
|
||||
}
|
||||
return uint16_t(m_header.partID & 0x7FFF);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
265
zeus/Buffer.h
265
zeus/Buffer.h
@ -9,9 +9,9 @@
|
||||
#include <zeus/ParamType.h>
|
||||
|
||||
namespace zeus {
|
||||
class TcpString;
|
||||
class WebServer;
|
||||
// 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
|
||||
- obj:file
|
||||
*/
|
||||
/**
|
||||
* @brief Protocol buffer to transmit datas
|
||||
*/
|
||||
class Buffer {
|
||||
friend std::ostream& operator<<(std::ostream&, const zeus::Buffer&);
|
||||
protected:
|
||||
/**
|
||||
* @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::Buffer::create
|
||||
*/
|
||||
Buffer();
|
||||
public:
|
||||
/**
|
||||
* @brief Create a shared pointer on the buffer
|
||||
* @return Allocated Buffer.
|
||||
*/
|
||||
static ememory::SharedPtr<zeus::Buffer> create();
|
||||
protected:
|
||||
headerBin m_header;
|
||||
mutable std::vector<std::pair<int32_t,std::vector<uint8_t>>> m_parameter;
|
||||
std::vector<zeus::ActionAsyncClient> m_multipleSend;
|
||||
headerBin m_header; //!< header of the protocol
|
||||
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; //!< Async element to send data on the webinterface when too big ...
|
||||
public:
|
||||
/**
|
||||
* @brief Check if async element are present on this buffer
|
||||
* @return return true if somme data must be send asyncronously
|
||||
*/
|
||||
bool haveAsync() const {
|
||||
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() {
|
||||
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);
|
||||
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);
|
||||
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::string& _buffer);
|
||||
std::string generateHumanString();
|
||||
/**
|
||||
* @brief Chear the buffer
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* @brief Get the transaction identifier of the packet
|
||||
* @return value of the transaction
|
||||
*/
|
||||
uint32_t getTransactionId() const;
|
||||
/**
|
||||
* @brief Set the transaction identifier of the packet
|
||||
* @param[in] _value New transaction id
|
||||
*/
|
||||
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
|
||||
/**
|
||||
* @brief Set the Client identifier of the packet
|
||||
* @param[in] _value New value of the Client identifier
|
||||
*/
|
||||
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 {
|
||||
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) {
|
||||
setClientId(_value);
|
||||
}
|
||||
// note limited 15 bits
|
||||
/**
|
||||
* @brief Get the part Id of the buffer
|
||||
* @return Part Identifier
|
||||
*/
|
||||
uint16_t getPartId() const;
|
||||
/**
|
||||
* @brief Set the part Id of the buffer
|
||||
* @param[in] _value New Part ID
|
||||
*/
|
||||
void setPartId(uint16_t _value);
|
||||
/**
|
||||
* @brief Check if it is the last packet of the buffer
|
||||
* @return If "true" The Buffer wait no more datas
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief Type of the massage send or receive
|
||||
*/
|
||||
enum class typeMessage {
|
||||
unknow = 0x0000, // Init value
|
||||
call = 0x0001, // Remote call on a service ID
|
||||
answer = 0x0002, // Answer from a previous call
|
||||
data = 0x0003, // data message happend when partId > 0 it compleate the data of a parameter or an answer or an event
|
||||
event = 0x0004, // event message
|
||||
unknow = 0x0000, //!< Init value
|
||||
call = 0x0001, //!< Remote call on a service ID
|
||||
answer = 0x0002, //!< Answer from a previous call
|
||||
data = 0x0003, //!< data message happend when partId > 0 it compleate the data of a parameter or an answer or an event
|
||||
event = 0x0004, //!< event message
|
||||
};
|
||||
/**
|
||||
* @brief Get the type of the buffer
|
||||
* @return the current type of the buffer
|
||||
*/
|
||||
enum typeMessage getType() const;
|
||||
/**
|
||||
* @brief Set the type of the buffer
|
||||
* @param[in] _value New type of the buffer
|
||||
*/
|
||||
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
|
||||
// ===============================================
|
||||
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:
|
||||
/**
|
||||
* @brief get the call value of the buffer
|
||||
* @return string of the function to call
|
||||
*/
|
||||
std::string getCall() const;
|
||||
/**
|
||||
* @brief Set the call value of the buffer
|
||||
* @param[in] _value Function to call
|
||||
*/
|
||||
void setCall(std::string _value);
|
||||
/**
|
||||
* @brief Get the number of parameter availlable
|
||||
* @return number of parameter
|
||||
*/
|
||||
uint16_t getNumberParameter() const;
|
||||
/**
|
||||
* @brief Get the type of a parameter.
|
||||
* @param[in] _id Number of the parameter
|
||||
* @return type of the parameter
|
||||
*/
|
||||
zeus::ParamType getParameterType(int32_t _id) const;
|
||||
/**
|
||||
* @brief Get the start pointer of the parameter
|
||||
* @param[in] _id Number of the parameter
|
||||
* @return pointer of the parameter or nullptr
|
||||
*/
|
||||
const uint8_t* getParameterPointer(int32_t _id) const;
|
||||
/**
|
||||
* @brief Get the size of the parameter availlable in the parameter pointer
|
||||
* @param[in] _id Number of the parameter
|
||||
* @return size of the parameter buffer
|
||||
*/
|
||||
uint32_t getParameterSize(int32_t _id) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Add a parameter at a specific position
|
||||
* @param[in] _paramId Id of the parameter (needed for the multiple packet sending)
|
||||
* @param[in] _value Value to add in parameter
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
void internalAddParameter(uint16_t _paramId, const ZEUS_TYPE_DATA& _value);
|
||||
public:
|
||||
/**
|
||||
* @brief Add a parameter on the call function
|
||||
* @param[in] _value Value to add in parameter
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
void addParameter(const ZEUS_TYPE_DATA& _value) {
|
||||
internalAddParameter<ZEUS_TYPE_DATA>(m_parameter.size(), _value);
|
||||
}
|
||||
/**
|
||||
* @brief Add an empty vector with no type
|
||||
*/
|
||||
void addParameterEmptyVector();
|
||||
/**
|
||||
* @brief Add parameter (or not.. this is the end of an auto resursive add parameter)
|
||||
*/
|
||||
void addParameter();
|
||||
|
||||
/**
|
||||
* @brief Template to get a parameter with a specific type
|
||||
* @param[in] _id Number of the parameter
|
||||
* @return Converted type of the parameter (or empty value)
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
ZEUS_TYPE_DATA getParameter(int32_t _id) const {
|
||||
return internalGetParameter<ZEUS_TYPE_DATA>(_id+1);
|
||||
}
|
||||
|
||||
|
||||
// ===============================================
|
||||
// == Section Answer
|
||||
// ===============================================
|
||||
public:
|
||||
/**
|
||||
* @brief set the answer of the call
|
||||
* @param[in] _value Value to add
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
void addAnswer(const ZEUS_TYPE_DATA& _value) {
|
||||
addParameter(_value);
|
||||
}
|
||||
/**
|
||||
* @brief get the answer value
|
||||
* @param[in] Data of the answer
|
||||
*/
|
||||
// TODO : Do it better check error ... ==> can be good ...
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
ZEUS_TYPE_DATA getAnswer() const {
|
||||
return 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);
|
||||
/**
|
||||
* @brief Check if the answer have an error
|
||||
* @return status of the error.
|
||||
*/
|
||||
bool hasError();
|
||||
/**
|
||||
* @brief get the error value (if exist)
|
||||
* @return string of the error
|
||||
*/
|
||||
std::string getError();
|
||||
/**
|
||||
* @brief get the error help (if exist)
|
||||
* @return string of the error help
|
||||
*/
|
||||
std::string getErrorHelp();
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
};
|
||||
/**
|
||||
* @brief generate a display of the typemessage
|
||||
* @param[in] _os stream to add data
|
||||
* @value[in] _value Value to add
|
||||
* @return a reference of the stream
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, enum zeus::Buffer::typeMessage _value);
|
||||
/**
|
||||
* @brief generate a display of the typemessage
|
||||
* @param[in] _os stream to add data
|
||||
* @value[in] _obj Buffer to display
|
||||
* @return a reference of the stream
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, 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);
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @brief Add a parameter RAW type in the buffer
|
||||
* @param[in] _data Buffer to add type
|
||||
*/
|
||||
void addTypeRaw(std::vector<uint8_t>& _data);
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ namespace zeus {
|
||||
~SendData() {
|
||||
|
||||
}
|
||||
bool operator() (zeus::TcpString* _interface,
|
||||
bool operator() (zeus::WebServer* _interface,
|
||||
uint32_t _clientId,
|
||||
uint32_t _transactionId,
|
||||
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();
|
||||
if (dataFile.size() != 0) {
|
||||
currentOffset = data.size();
|
||||
ZEUS_ERROR("set buffer with size: " << dataFile.size());
|
||||
if (dataFile.size() < ZEUS_MINIMUM_SIZE_MULTIPLE) {
|
||||
data.resize(data.size()+dataFile.size());
|
||||
memcpy(&data[currentOffset], &dataFile[0], dataFile.size());
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
@ -391,7 +387,7 @@ namespace zeus {
|
||||
~SendFile() {
|
||||
|
||||
}
|
||||
bool operator() (zeus::TcpString* _interface,
|
||||
bool operator() (zeus::WebServer* _interface,
|
||||
uint32_t _clientId,
|
||||
uint32_t _transactionId,
|
||||
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);
|
||||
internalAddParameter(_paramId, tmpFile);
|
||||
node.fileClose();
|
||||
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));
|
||||
if (size >= ZEUS_MINIMUM_SIZE_MULTIPLE) {
|
||||
m_multipleSend.push_back(zeus::SendFile(_value.getFileName(), _paramId, size));
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ void zeus::Client::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
|
||||
if (_value == nullptr) {
|
||||
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) {
|
||||
@ -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]");
|
||||
disconnect();
|
||||
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) {
|
||||
ZEUS_ERROR("Allocate connection error");
|
||||
return false;
|
||||
@ -53,11 +53,11 @@ bool zeus::Client::connect(const std::string& _remoteUserToConnect){
|
||||
m_interfaceClient->setInterface(std::move(connection), false);
|
||||
m_interfaceClient->connect();
|
||||
|
||||
ZEUS_WARNING("Request connect user " << _remoteUserToConnect);
|
||||
zeus::Future<bool> ret = call("connectToUser", _remoteUserToConnect, "zeus-client");
|
||||
ZEUS_WARNING("Request connect user " << _address);
|
||||
zeus::Future<bool> ret = call("connectToUser", _address, "zeus-client");
|
||||
ret.wait();
|
||||
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;
|
||||
}
|
||||
if (ret.get() == true) {
|
||||
@ -68,6 +68,54 @@ bool zeus::Client::connect(const std::string& _remoteUserToConnect){
|
||||
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() {
|
||||
ZEUS_DEBUG("disconnect [START]");
|
||||
if (m_interfaceClient != nullptr) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <chrono>
|
||||
@ -14,13 +14,16 @@
|
||||
#include <zeus/ServiceRemote.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief Client interface to acces on the remote service and gateway
|
||||
*/
|
||||
class Client : public eproperty::Interface {
|
||||
friend class ServiceRemote;
|
||||
public:
|
||||
eproperty::Value<std::string> propertyIp;
|
||||
eproperty::Value<uint16_t> propertyPort;
|
||||
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||
private:
|
||||
ememory::SharedPtr<zeus::TcpString> m_interfaceClient;
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient; //!< Interface on the Websocket interface
|
||||
public:
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
//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);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
Client();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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();
|
||||
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);
|
||||
|
||||
// Connect that is not us
|
||||
//bool identify("clientTest1#atria-soft.com", "QSDQSDGQSF54HSXWVCSQDJ654URTDJ654NBXCDFDGAEZ51968");
|
||||
// Connect to ourself:
|
||||
//client1.authentificate("coucou");
|
||||
private:
|
||||
/**
|
||||
* @brief When receive data from the websocket ... call this ...
|
||||
* @param[in] _value New input buffer
|
||||
*/
|
||||
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);
|
||||
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>
|
||||
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
@ -64,6 +110,13 @@ namespace zeus {
|
||||
}
|
||||
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>
|
||||
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
@ -74,7 +127,13 @@ namespace zeus {
|
||||
return m_interfaceClient->callAction(_functionName, _args..., _callback);
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* @brief Internal (called when user change the Ip of the client interface)
|
||||
*/
|
||||
void onPropertyChangeIp();
|
||||
/**
|
||||
* @brief Internal (called when user change the port of the client interface)
|
||||
*/
|
||||
void onPropertyChangePort();
|
||||
};
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ zeus::File::File() {
|
||||
zeus::File::File(const std::string& _filename) {
|
||||
m_data = etk::FSNodeReadAllDataType<uint8_t>(_filename);
|
||||
std::string extention = std::string(_filename.begin()+_filename.size() -3, _filename.end());
|
||||
ZEUS_WARNING("send file: '" << _filename << "' with extention: '" << 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) {
|
||||
if (_size+_offset >= m_data.size()) {
|
||||
ZEUS_ERROR("Need Resize file buffer ...");
|
||||
if (_size+_offset > m_data.size()) {
|
||||
ZEUS_ERROR("Need Resize file buffer ... need=" << _size+_offset << " have=" << m_data.size());
|
||||
m_data.resize(_size+_offset);
|
||||
}
|
||||
memcpy(&m_data[_offset], _data, _size);
|
||||
|
66
zeus/File.h
66
zeus/File.h
@ -7,40 +7,106 @@
|
||||
#include <etk/types.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief File inetrface
|
||||
*/
|
||||
class File {
|
||||
private:
|
||||
std::string m_mineType;
|
||||
int32_t m_fileSize;
|
||||
std::vector<uint8_t> m_data;
|
||||
public:
|
||||
/**
|
||||
* @brief Contructor of an empty file
|
||||
*/
|
||||
File();
|
||||
/**
|
||||
* @brief Contructor with the name of a file (load all data)
|
||||
* @param[in] _filename path of the file
|
||||
*/
|
||||
File(const std::string& _filename);
|
||||
/**
|
||||
* @brief Constructor of a typed file
|
||||
* @param[in] _mineType mine type of the file
|
||||
* @param[in] _data data of the file
|
||||
* @param[in] _fileSize théoric file size
|
||||
*/
|
||||
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 {
|
||||
return m_fileSize;
|
||||
}
|
||||
/**
|
||||
* @brief Store data in the specify file
|
||||
* @param[in] _filename name of the file
|
||||
*/
|
||||
void storeIn(const std::string& _filename) const;
|
||||
/**
|
||||
* @brief Get the mine type of the file
|
||||
* @return generic mine type
|
||||
*/
|
||||
const std::string& getMineType() const {
|
||||
return m_mineType;
|
||||
}
|
||||
/**
|
||||
* @brief Set the mine type of the file
|
||||
* @param[in] _type New type of the file
|
||||
*/
|
||||
void setMineType(const std::string& _type) {
|
||||
m_mineType = _type;
|
||||
}
|
||||
/**
|
||||
* @brief préallocate the data
|
||||
* @param[in] _size New size of the buffer
|
||||
*/
|
||||
void preSetDataSize(uint64_t _size) {
|
||||
m_data.resize(_size, 0);
|
||||
}
|
||||
/**
|
||||
* @brief get a rérérence of the data
|
||||
* @return requested data
|
||||
*/
|
||||
const std::vector<uint8_t>& getData() const {
|
||||
return m_data;
|
||||
}
|
||||
/**
|
||||
* @brief Set data on the buffer
|
||||
* @param[in] _offset offset of the write data
|
||||
* @param[in] _data data to write
|
||||
*/
|
||||
void setData(uint64_t _offset, const std::vector<uint8_t>& _data);
|
||||
/**
|
||||
* @brief Set data on the buffer
|
||||
* @param[in] _offset offset of the write data
|
||||
* @param[in] _data pointer on the data to write
|
||||
* @param[in] _size Number of Octet to write
|
||||
*/
|
||||
void setData(uint64_t _offset, const uint8_t* _data, uint32_t _size);
|
||||
};
|
||||
/**
|
||||
* @brief File server interface
|
||||
* @note This class permit to send file without opening all data befor sending
|
||||
*/
|
||||
class FileServer {
|
||||
private:
|
||||
std::string m_name;
|
||||
public:
|
||||
/**
|
||||
* @brief generic constructor
|
||||
*/
|
||||
FileServer();
|
||||
/**
|
||||
* @brief contructor with a file
|
||||
* @param[in] _filename Name of the file to send
|
||||
*/
|
||||
FileServer(const std::string& _filename);
|
||||
/**
|
||||
* @brief Get the filename registered
|
||||
* @return path of the file
|
||||
*/
|
||||
const std::string& getFileName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
@ -8,26 +8,54 @@
|
||||
#include <zeus/FutureBase.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief future template to cast type in a specific type
|
||||
*/
|
||||
template<class ZEUS_RETURN>
|
||||
class Future : public zeus::FutureBase {
|
||||
public:
|
||||
/**
|
||||
* @brief contructor of the Future with the basic FutureBase
|
||||
* @param[in] _base Generic base Future
|
||||
*/
|
||||
Future(const 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) {
|
||||
m_data = _base.m_data;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* @brief Get the value Requested with the type
|
||||
* @return requested value
|
||||
*/
|
||||
ZEUS_RETURN get();
|
||||
};
|
||||
/**
|
||||
* @brief future template to cast type in a void methode (fallback)
|
||||
*/
|
||||
template<>
|
||||
class Future<void> : public zeus::FutureBase {
|
||||
public:
|
||||
/**
|
||||
* @brief contructor of the Future with the basic FutureBase
|
||||
* @param[in] _base Generic base Future
|
||||
*/
|
||||
Future(const 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) {
|
||||
m_data = _base.m_data;
|
||||
return *this;
|
||||
|
@ -188,7 +188,6 @@ void zeus::FutureCall::appendData(const ememory::SharedPtr<zeus::Buffer>& _value
|
||||
} else {
|
||||
m_data = _value;
|
||||
}
|
||||
m_dataMultiplePack.push_back(_value);
|
||||
m_isFinished = _value->getPartFinish();
|
||||
}
|
||||
|
||||
|
@ -8,45 +8,165 @@
|
||||
#include <zeus/FutureData.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief Generic zeus Future interface to get data asynchronously
|
||||
*/
|
||||
class FutureBase {
|
||||
public:
|
||||
ememory::SharedPtr<zeus::FutureData> m_data;
|
||||
ememory::SharedPtr<zeus::FutureData> m_data; // Reference on the data
|
||||
public:
|
||||
/**
|
||||
* @brief Copy contructor of a FutureBase
|
||||
* @param[in] _base the FutureBase to copy
|
||||
*/
|
||||
FutureBase(const zeus::FutureBase& _base);
|
||||
/**
|
||||
* @brief contructor of a 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);
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @brief Set the future syncronous
|
||||
* @note this mean that the system call the observer every time a packet arrive in the Future
|
||||
*/
|
||||
void setSynchronous();
|
||||
/**
|
||||
* @brief Get the transaction Id of the Future
|
||||
* @return Transaction Id requested or 0
|
||||
*/
|
||||
uint64_t getTransactionId();
|
||||
/**
|
||||
* @brief check if the answer have an error
|
||||
* @return return true if an error is registered
|
||||
*/
|
||||
bool hasError();
|
||||
/**
|
||||
* @brief get type of the error
|
||||
* @return the string of the error type
|
||||
*/
|
||||
std::string getErrorType();
|
||||
/**
|
||||
* @brief get help of the error
|
||||
* @return the string of the error help
|
||||
*/
|
||||
std::string getErrorHelp();
|
||||
/**
|
||||
* @brief Check if the Futur is a valid data
|
||||
* @return return true if the data is valid
|
||||
*/
|
||||
bool isValid() const;
|
||||
/**
|
||||
* @brief Check if the futur have finish receiving data
|
||||
* @return status of the fisnish state
|
||||
*/
|
||||
bool isFinished() const;
|
||||
/**
|
||||
* @brief Wait the Future receive data
|
||||
* @return reference on the current futur
|
||||
*/
|
||||
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));
|
||||
/**
|
||||
* @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);
|
||||
/**
|
||||
* @brief Get the Buffer receive
|
||||
* @return pointer on the receive data
|
||||
*/
|
||||
ememory::SharedPtr<zeus::Buffer> getRaw();
|
||||
/**
|
||||
* @brief Get duration of the current trasaction take
|
||||
* @return Tile in nanosecond to wait answer
|
||||
*/
|
||||
std::chrono::nanoseconds getTransmitionTime();
|
||||
};
|
||||
/**
|
||||
* @brief Receiving call futur
|
||||
*/
|
||||
class FutureCall {
|
||||
private:
|
||||
uint64_t m_transactionId;
|
||||
uint64_t m_clientId;
|
||||
bool m_isFinished;
|
||||
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_answerTime;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
uint64_t getTransactionId() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
uint64_t getClientId() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isFinished() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::chrono::nanoseconds getTransmitionTime() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ememory::SharedPtr<zeus::Buffer> getRaw() const;
|
||||
};
|
||||
}
|
||||
|
@ -8,6 +8,20 @@
|
||||
#include <zeus/debug.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) {
|
||||
_os << "{" << _obj.getId() << ":" << _obj.getName() << "}";
|
||||
return _os;
|
||||
|
@ -8,6 +8,11 @@
|
||||
#include <string>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ParamType {
|
||||
protected:
|
||||
const std::string m_typeName;
|
||||
@ -15,24 +20,101 @@ namespace zeus {
|
||||
const bool m_isNumber;
|
||||
const bool m_isVector;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
uint16_t getId() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator == (const ParamType& _obj) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator != (const ParamType& _obj) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator == (const std::string& _value) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator != (const std::string& _value) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator == (const uint16_t& _value) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool operator != (const uint16_t& _value) const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isNumber() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isVector() const;
|
||||
};
|
||||
extern const uint16_t paramTypeObject;
|
||||
extern const uint16_t paramTypeRaw;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, const zeus::ParamType& _obj);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class ZEUS_TYPE>
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -7,40 +7,49 @@
|
||||
|
||||
zeus::RemoteProcessCall::RemoteProcessCall() :
|
||||
m_type("UNKNOW"){
|
||||
advertise("getDescription", &zeus::RemoteProcessCall::getDescription);
|
||||
setLastFuncDesc("Get description");
|
||||
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");
|
||||
|
||||
advertise("getVersion", &zeus::RemoteProcessCall::getVersion);
|
||||
setLastFuncDesc("Get version");
|
||||
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");
|
||||
|
||||
advertise("getType", &zeus::RemoteProcessCall::getType);
|
||||
setLastFuncDesc("Get type");
|
||||
addLastFuncReturn("String of generic type of the service base on TYPE-ENTERPRISE.ENTERPRISE-NAME.SERVICE-TYPE/VERSION_PROTOCOL");
|
||||
|
||||
advertise("getAuthors", &zeus::RemoteProcessCall::getAuthors2);
|
||||
setLastFuncDesc("Get List of developper/maintainer");
|
||||
addLastFuncReturn("list of personnes: 'NAME surname <email@xxx.yyy>'");
|
||||
|
||||
advertise("getFunctions", &zeus::RemoteProcessCall::getFunctions);
|
||||
setLastFuncDesc("Get List of function availlable (filter with right)");
|
||||
addLastFuncReturn("list of function name");
|
||||
|
||||
advertise("getFunctionSignature", &zeus::RemoteProcessCall::getFunctionSignature);
|
||||
addLastFuncParam("func", "function name");
|
||||
setLastFuncDesc("Get List type of return and after the parameters");
|
||||
addLastFuncReturn("list of element type");
|
||||
|
||||
advertise("getFunctionPrototype", &zeus::RemoteProcessCall::getFunctionPrototype);
|
||||
addLastFuncParam("func", "function name");
|
||||
setLastFuncDesc("Get List type of return and after the parameters");
|
||||
addLastFuncReturn("list of element type");
|
||||
|
||||
advertise("getFunctionDescription", &zeus::RemoteProcessCall::getFunctionDescription);
|
||||
addLastFuncParam("func", "function name");
|
||||
setLastFuncDesc("get function description");
|
||||
addLastFuncReturn("generic string");
|
||||
zeus::AbstractFunction* func = advertise("getDescription", &zeus::RemoteProcessCall::getDescription);
|
||||
if (func != nullptr) {
|
||||
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");
|
||||
}
|
||||
func = advertise("getVersion", &zeus::RemoteProcessCall::getVersion);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get version");
|
||||
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");
|
||||
}
|
||||
func = advertise("getType", &zeus::RemoteProcessCall::getType);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get type");
|
||||
func->setReturn("String of generic type of the service base on TYPE-ENTERPRISE.ENTERPRISE-NAME.SERVICE-TYPE/VERSION_PROTOCOL");
|
||||
}
|
||||
func = advertise("getAuthors", &zeus::RemoteProcessCall::getAuthors2);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List of developper/maintainer");
|
||||
func->setReturn("list of personnes: 'NAME surname <email@xxx.yyy>'");
|
||||
}
|
||||
func = advertise("getFunctions", &zeus::RemoteProcessCall::getFunctions);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List of function availlable (filter with right)");
|
||||
func->setReturn("list of function name");
|
||||
}
|
||||
func = advertise("getFunctionSignature", &zeus::RemoteProcessCall::getFunctionSignature);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List type of return and after the parameters");
|
||||
func->addParam("func", "function name");
|
||||
func->setReturn("list of element type");
|
||||
}
|
||||
func = advertise("getFunctionPrototype", &zeus::RemoteProcessCall::getFunctionPrototype);
|
||||
if (func != nullptr) {
|
||||
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;
|
||||
}
|
||||
|
||||
void zeus::RemoteProcessCall::setLastFuncDesc(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]->setDescription(_desc);
|
||||
}
|
||||
|
||||
void zeus::RemoteProcessCall::setFuncDesc(const std::string& _funcName, const std::string& _desc) {
|
||||
zeus::AbstractFunction* zeus::RemoteProcessCall::getFunction(std::string _funcName) {
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
@ -96,68 +93,15 @@ void zeus::RemoteProcessCall::setFuncDesc(const std::string& _funcName, const st
|
||||
if (it->getName() != _funcName) {
|
||||
continue;
|
||||
}
|
||||
it->setDescription(_desc);
|
||||
return;
|
||||
return it;
|
||||
}
|
||||
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() {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
void zeus::RemoteProcessCall::setType(const std::string& _type, uint16_t _version) {
|
||||
m_type = _type + "/" + etk::to_string(_version);
|
||||
}
|
||||
@ -213,7 +157,7 @@ std::string zeus::RemoteProcessCall::getFunctionPrototype(std::string _funcName)
|
||||
if (it->getName() != _funcName) {
|
||||
continue;
|
||||
}
|
||||
return it->getPrototypeFull();
|
||||
return it->getPrototype();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -5,85 +5,158 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <zeus/AbstractFunctionTypeDirect.h>
|
||||
#include <zeus/AbstractFunctionTypeClass.h>
|
||||
#include <zeus/debug.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class RemoteProcessCall {
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
RemoteProcessCall();
|
||||
protected:
|
||||
std::vector<zeus::AbstractFunction*> m_listFunction;
|
||||
protected:
|
||||
std::string m_description;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setDescription(const std::string& _desc);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::string getDescription();
|
||||
protected:
|
||||
std::string m_version;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setVersion(const std::string& _desc);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::string getVersion();
|
||||
protected:
|
||||
std::vector<std::pair<std::string,std::string>> m_authors;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::vector<std::string> getAuthors2();
|
||||
protected:
|
||||
std::string m_type;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::string getType();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setType(const std::string& _type, uint16_t _version);
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::vector<std::string> getFunctions();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
AbstractFunction* getFunction(std::string _funcName);
|
||||
private:
|
||||
std::vector<std::string> getFunctionSignature(std::string _funcName);
|
||||
std::string getFunctionPrototype(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:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
virtual bool isFunctionAuthorized(uint64_t _clientSessionID, const std::string& _funcName);
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
// Add global fuction (no link with this class)
|
||||
template<class ZEUS_RETURN_VALUE,
|
||||
class... ZEUS_FUNC_ARGS_TYPE>
|
||||
void advertise(const std::string& _name,
|
||||
ZEUS_RETURN_VALUE (*_func)(ZEUS_FUNC_ARGS_TYPE... _args),
|
||||
const std::string& _desc = "") {
|
||||
zeus::AbstractFunction* advertise(const std::string& _name,
|
||||
ZEUS_RETURN_VALUE (*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->getName() == _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) {
|
||||
ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
tmp->setType(zeus::AbstractFunction::type::global);
|
||||
ZEUS_INFO("Add function '" << _name << "' in global mode");
|
||||
m_listFunction.push_back(tmp);
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
// Add Local fuction (depend on this class)
|
||||
template<class ZEUS_RETURN_VALUE,
|
||||
class ZEUS_CLASS_TYPE,
|
||||
class... ZEUS_FUNC_ARGS_TYPE>
|
||||
void advertise(std::string _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args),
|
||||
const std::string& _desc = "") {
|
||||
zeus::AbstractFunction* advertise(std::string _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
|
||||
_name = "sys." + _name;
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
@ -91,17 +164,18 @@ namespace zeus {
|
||||
}
|
||||
if (it->getName() == _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) {
|
||||
ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
tmp->setType(zeus::AbstractFunction::type::local);
|
||||
ZEUS_INFO("Add function '" << _name << "' in local mode");
|
||||
m_listFunction.push_back(tmp);
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -14,12 +14,11 @@
|
||||
zeus::Service::Service() :
|
||||
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) {
|
||||
|
||||
|
||||
advertise("getExtention", &zeus::Service::getExtention);
|
||||
setLastFuncDesc("Get List of availlable extention of this service");
|
||||
addLastFuncReturn("A list of extention register in the service");
|
||||
|
||||
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Service::getExtention);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List of availlable extention of this service");
|
||||
func->setReturn("A list of extention register in the 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) {
|
||||
if (_value == nullptr) {
|
||||
return;
|
||||
}
|
||||
uint32_t tmpID = _value->getTransactionId();
|
||||
uint32_t clientId = _value->getClientId();;
|
||||
auto it = m_callMultiData.begin();
|
||||
@ -43,7 +45,7 @@ void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
|
||||
it->appendData(_value);
|
||||
if (it->isFinished() == true) {
|
||||
ZEUS_WARNING("CALL Function ...");
|
||||
callBinary(tmpID, it->getRaw());
|
||||
callBinary(it->getRaw());
|
||||
it = m_callMultiData.erase(it);
|
||||
}
|
||||
return;
|
||||
@ -53,7 +55,7 @@ void zeus::Service::onClientData(const ememory::SharedPtr<zeus::Buffer>& _value)
|
||||
zeus::FutureCall futCall(clientId, tmpID, _value);
|
||||
if (futCall.isFinished() == true) {
|
||||
ZEUS_INFO("Call Binary ..");
|
||||
callBinary(tmpID, futCall.getRaw());
|
||||
callBinary(futCall.getRaw());
|
||||
} else {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
m_interfaceClient = std::make_shared<zeus::TcpString>();
|
||||
m_interfaceClient = std::make_shared<zeus::WebServer>();
|
||||
if (m_interfaceClient == nullptr) {
|
||||
ZEUS_ERROR("Can not allocate interface ...");
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -143,13 +145,13 @@ void zeus::Service::callBinary(uint32_t _transactionId, const ememory::SharedPtr
|
||||
} else if (callFunction == "_delete") {
|
||||
clientDisconnect(clientId);
|
||||
}
|
||||
m_interfaceClient->answerValue(_transactionId, true, clientId);
|
||||
m_interfaceClient->answerValue(_obj->getTransactionId(), true, clientId);
|
||||
return;
|
||||
} else if (isFunctionAuthorized(clientId, callFunction) == true) {
|
||||
callBinary2(_transactionId, clientId, callFunction, _obj);
|
||||
callBinary2(callFunction, _obj);
|
||||
return;
|
||||
} else {
|
||||
m_interfaceClient->answerError(_transactionId, "NOT-AUTHORIZED-FUNCTION", "", clientId);
|
||||
m_interfaceClient->answerError(_obj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
211
zeus/Service.h
211
zeus/Service.h
@ -5,7 +5,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/AbstractFunctionTypeDirect.h>
|
||||
#include <zeus/AbstractFunctionTypeClass.h>
|
||||
@ -14,8 +14,18 @@
|
||||
#include <zeus/Future.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ClientProperty {
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ClientProperty(const std::string& _clientName="", const std::vector<std::string>& _groups = std::vector<std::string>()) :
|
||||
m_name(_clientName),
|
||||
m_groups(_groups) {
|
||||
@ -24,56 +34,136 @@ namespace zeus {
|
||||
private:
|
||||
std::string m_name;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setName(const std::string& _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::string& getName() {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> m_groups;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setGroups(std::vector<std::string> _groups) {
|
||||
m_groups = _groups;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::vector<std::string>& getGroups() {
|
||||
return m_groups;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> m_listAthorizedFunction;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void addAuthorized(const std::string& _funcName) {
|
||||
m_listAthorizedFunction.push_back(_funcName);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isFunctionAuthorized(const std::string& _funcName) {
|
||||
return std::find(m_listAthorizedFunction.begin(), m_listAthorizedFunction.end(), _funcName) != m_listAthorizedFunction.end();
|
||||
}
|
||||
};
|
||||
}
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class Service : public eproperty::Interface, public zeus::RemoteProcessCall {
|
||||
protected:
|
||||
std::mutex m_mutex;
|
||||
public:
|
||||
eproperty::Value<std::string> propertyIp;
|
||||
eproperty::Value<uint16_t> propertyPort;
|
||||
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||
protected:
|
||||
ememory::SharedPtr<zeus::TcpString> m_interfaceClient;
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||
uint32_t m_id;
|
||||
std::vector<std::string> m_newData;
|
||||
std::vector<zeus::FutureCall> m_callMultiData;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
Service();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
virtual ~Service();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void connect(const std::string& _serviceName, uint32_t _numberRetry = 1);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void disconnect();
|
||||
private:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void onClientData(const ememory::SharedPtr<zeus::Buffer>& _value);
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void pingIsAlive();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool GateWayAlive();
|
||||
private:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void onPropertyChangeIp();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void onPropertyChangePort();
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
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;
|
||||
// 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();
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
// Add Local fuction (depend on this class)
|
||||
template<class ZEUS_RETURN_VALUE,
|
||||
class ZEUS_CLASS_TYPE,
|
||||
class... ZEUS_FUNC_ARGS_TYPE>
|
||||
void advertise(std::string _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args),
|
||||
const std::string& _desc = "") {
|
||||
zeus::AbstractFunction* advertise(std::string _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
|
||||
_name = "srv." + _name;
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
@ -102,20 +216,19 @@ namespace zeus {
|
||||
}
|
||||
if (it->getName() == _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) {
|
||||
ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
tmp->setType(zeus::AbstractFunction::type::service);
|
||||
ZEUS_INFO("Add function '" << _name << "' in local mode");
|
||||
m_listFunction.push_back(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
template<class ZEUS_TYPE_SERVICE, class ZEUS_USER_ACCESS>
|
||||
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...)
|
||||
std::map<uint64_t, std::pair<ememory::SharedPtr<ClientProperty>, ememory::SharedPtr<ZEUS_TYPE_SERVICE>>> m_interface;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class ZEUS_RETURN_VALUE,
|
||||
class ZEUS_CLASS_TYPE,
|
||||
class... ZEUS_FUNC_ARGS_TYPE>
|
||||
void advertise(const std::string& _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args),
|
||||
const std::string& _desc = "") {
|
||||
zeus::AbstractFunction* advertise(const std::string& _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
|
||||
if (etk::start_with(_name, "srv.") == true) {
|
||||
ZEUS_ERROR("Advertise function start with 'srv.' is not permited ==> only allow for internal service: '" << _name << "'");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
@ -140,22 +257,33 @@ namespace zeus {
|
||||
}
|
||||
if (it->getName() == _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) {
|
||||
ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
tmp->setType(zeus::AbstractFunction::type::object);
|
||||
ZEUS_INFO("Add function '" << _name << "' in object mode");
|
||||
m_listFunction.push_back(tmp);
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceType(ZEUS_USER_ACCESS& _interface):
|
||||
m_getUserInterface(_interface) {
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isFunctionAuthorized(uint64_t _clientId, const std::string& _funcName) {
|
||||
auto it = m_interface.find(_clientId);
|
||||
if (it == m_interface.end()) {
|
||||
@ -163,6 +291,11 @@ namespace zeus {
|
||||
}
|
||||
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) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ZEUS_DEBUG("connect: " << _clientId << " to '" << _userName << "'");
|
||||
@ -179,6 +312,11 @@ namespace zeus {
|
||||
tmpProperty->addAuthorized(it->getName());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void clientDisconnect(uint64_t _clientId) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ZEUS_DEBUG("disconnect: " << _clientId);
|
||||
@ -190,6 +328,11 @@ namespace zeus {
|
||||
}
|
||||
m_interface.erase(it);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void clientSetName(uint64_t _clientId, const std::string& _clientName) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
auto it = m_interface.find(_clientId);
|
||||
@ -199,6 +342,11 @@ namespace zeus {
|
||||
}
|
||||
it->second.first->setName(_clientName);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void clientSetGroup(uint64_t _clientId, const std::vector<std::string>& _clientGroups) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
auto it = m_interface.find(_clientId);
|
||||
@ -208,10 +356,15 @@ namespace zeus {
|
||||
}
|
||||
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()) {
|
||||
m_interfaceClient->answerError(_transactionId, "CLIENT-UNKNOW", "", _clientId);
|
||||
m_interfaceClient->answerError(_obj->getTransactionId(), "CLIENT-UNKNOW", "", _obj->getClientId());
|
||||
return;
|
||||
}
|
||||
for (auto &it2 : m_listFunction) {
|
||||
@ -224,19 +377,19 @@ namespace zeus {
|
||||
switch (it2->getType()) {
|
||||
case zeus::AbstractFunction::type::object: {
|
||||
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;
|
||||
}
|
||||
case zeus::AbstractFunction::type::local: {
|
||||
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, (void*)((RemoteProcessCall*)this));
|
||||
it2->execute(m_interfaceClient, _obj, (void*)((RemoteProcessCall*)this));
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::service: {
|
||||
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, (void*)this);
|
||||
it2->execute(m_interfaceClient, _obj, (void*)this);
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::global: {
|
||||
it2->execute(m_interfaceClient, _transactionId, _clientId, _obj, nullptr);
|
||||
it2->execute(m_interfaceClient, _obj, nullptr);
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::unknow:
|
||||
@ -244,7 +397,7 @@ namespace zeus {
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_interfaceClient->answerError(_transactionId, "FUNCTION-UNKNOW", "", _clientId);
|
||||
m_interfaceClient->answerError(_obj->getTransactionId(), "FUNCTION-UNKNOW", "", _obj->getClientId());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <zeus/ServiceRemote.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_name(_name),
|
||||
m_serviceId(0),
|
||||
|
@ -5,27 +5,51 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/TcpString.h>
|
||||
#include <eproperty/Value.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <zeus/AbstractFunction.h>
|
||||
#include <zeus/ServiceRemote.h>
|
||||
#include <zeus/Future.h>
|
||||
#include <zeus/TcpString.h>
|
||||
#include <zeus/WebServer.h>
|
||||
|
||||
namespace zeus {
|
||||
class Client;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ServiceRemote {
|
||||
private:
|
||||
ememory::SharedPtr<zeus::TcpString> m_interfaceClient;
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||
std::string m_name;
|
||||
uint32_t m_serviceId;
|
||||
bool m_isLinked;
|
||||
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();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool exist();
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
@ -37,6 +61,11 @@ namespace zeus {
|
||||
}
|
||||
return m_interfaceClient->callService(m_serviceId, _functionName, _args...);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
|
@ -3,12 +3,30 @@
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#include <zeus/TcpString.h>
|
||||
#include <zeus/WebServer.h>
|
||||
#include <zeus/debug.h>
|
||||
#include <ethread/tools.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_observerElement(nullptr),
|
||||
m_threadAsync(nullptr) {
|
||||
@ -16,7 +34,7 @@ zeus::TcpString::TcpString() :
|
||||
m_transmissionId = 1;
|
||||
}
|
||||
|
||||
zeus::TcpString::TcpString(enet::Tcp _connection, bool _isServer) :
|
||||
zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
|
||||
m_connection(),
|
||||
m_observerElement(nullptr),
|
||||
m_threadAsync(nullptr) {
|
||||
@ -25,11 +43,11 @@ zeus::TcpString::TcpString(enet::Tcp _connection, bool _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.connect(this, &zeus::TcpString::onReceiveData);
|
||||
m_connection.connect(this, &zeus::WebServer::onReceiveData);
|
||||
if (_isServer == true) {
|
||||
m_connection.connectUri(this, &zeus::TcpString::onReceiveUri);
|
||||
m_connection.connectUri(this, &zeus::WebServer::onReceiveUri);
|
||||
m_connection.start();
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
|
||||
void zeus::TcpString::setInterfaceName(const std::string& _name) {
|
||||
void zeus::WebServer::setInterfaceName(const std::string& _name) {
|
||||
//ethread::setName(*m_thread, "Tcp-" + _name);
|
||||
}
|
||||
|
||||
|
||||
bool zeus::TcpString::isActive() const {
|
||||
bool zeus::WebServer::isActive() const {
|
||||
return m_connection.isAlive();
|
||||
}
|
||||
|
||||
void zeus::TcpString::connect(bool _async){
|
||||
void zeus::WebServer::connect(bool _async){
|
||||
ZEUS_DEBUG("connect [START]");
|
||||
m_threadAsyncRunning = true;
|
||||
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]");
|
||||
m_threadAsyncRunning = false;
|
||||
if (m_connection.isAlive() == true) {
|
||||
@ -104,7 +122,7 @@ class SendAsyncBinary {
|
||||
m_partId(1) {
|
||||
|
||||
}
|
||||
bool operator() (zeus::TcpString* _interface){
|
||||
bool operator() (zeus::WebServer* _interface){
|
||||
auto it = m_async.begin();
|
||||
while (it != m_async.end()) {
|
||||
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) {
|
||||
return -2;
|
||||
}
|
||||
if (_obj->haveAsync() == true) {
|
||||
ZEUS_WARNING("Set Flag not finish ...");
|
||||
_obj->setPartFinish(false);
|
||||
}
|
||||
if (_obj->writeOn(m_connection) == true) {
|
||||
if (_obj->haveAsync() == true) {
|
||||
ZEUS_WARNING("Add async");
|
||||
addAsync(SendAsyncBinary(_obj->getTransactionId(), _obj->getServiceId(), std::move(_obj->moveAsync())));
|
||||
}
|
||||
return 1;
|
||||
@ -151,7 +167,7 @@ int32_t zeus::TcpString::writeBinary(const ememory::SharedPtr<zeus::Buffer>& _ob
|
||||
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);
|
||||
for (auto &it : _protocols) {
|
||||
if (it == "zeus/1.0") {
|
||||
@ -165,7 +181,7 @@ bool zeus::TcpString::onReceiveUri(const std::string& _uri, const std::vector<st
|
||||
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();
|
||||
if (_isBinary == true) {
|
||||
ZEUS_ERROR("Receive non binary frame ...");
|
||||
@ -176,12 +192,12 @@ void zeus::TcpString::onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary
|
||||
newBuffer(dataRaw);
|
||||
}
|
||||
|
||||
void zeus::TcpString::ping() {
|
||||
void zeus::WebServer::ping() {
|
||||
m_connection.controlPing();
|
||||
}
|
||||
|
||||
void zeus::TcpString::newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer) {
|
||||
ZEUS_DEBUG("Receive :" << _buffer->generateHumanString());
|
||||
void zeus::WebServer::newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer) {
|
||||
ZEUS_VERBOSE("Receive :" << _buffer);
|
||||
zeus::FutureBase future;
|
||||
uint64_t tid = _buffer->getTransactionId();
|
||||
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);
|
||||
m_threadAsyncList2.push_back(_elem);
|
||||
}
|
||||
|
||||
void zeus::TcpString::threadAsyncCallback() {
|
||||
void zeus::WebServer::threadAsyncCallback() {
|
||||
ethread::setName("Async-sender");
|
||||
ZEUS_INFO("Async Sender [START]...");
|
||||
// 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,
|
||||
zeus::FutureData::ObserverFinish _callback,
|
||||
const uint32_t& _serviceId) {
|
||||
@ -304,7 +320,7 @@ zeus::FutureBase zeus::TcpString::callBinary(uint64_t _transactionId,
|
||||
return tmpFuture;
|
||||
}
|
||||
|
||||
zeus::FutureBase zeus::TcpString::callForward(uint32_t _clientId,
|
||||
zeus::FutureBase zeus::WebServer::callForward(uint32_t _clientId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _buffer,
|
||||
uint64_t _singleReferenceId,
|
||||
zeus::FutureData::ObserverFinish _callback) {
|
||||
@ -332,7 +348,7 @@ zeus::FutureBase zeus::TcpString::callForward(uint32_t _clientId,
|
||||
return tmpFuture;
|
||||
}
|
||||
|
||||
void zeus::TcpString::callForwardMultiple(uint32_t _clientId,
|
||||
void zeus::WebServer::callForwardMultiple(uint32_t _clientId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _buffer,
|
||||
uint64_t _singleReferenceId){
|
||||
if (_buffer == nullptr) {
|
||||
@ -353,7 +369,7 @@ void zeus::TcpString::callForwardMultiple(uint32_t _clientId,
|
||||
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();
|
||||
if (answer == nullptr) {
|
||||
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();
|
||||
if (answer == nullptr) {
|
||||
return;
|
@ -4,8 +4,6 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
#include <eproperty/Value.h>
|
||||
#include <esignal/Signal.h>
|
||||
#include <zeus/Buffer.h>
|
||||
#include <enet/WebSocket.h>
|
||||
#include <thread>
|
||||
@ -14,7 +12,81 @@
|
||||
#include <zeus/FutureBase.h>
|
||||
|
||||
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:
|
||||
enet::WebSocket m_connection;
|
||||
uint16_t m_transmissionId;
|
||||
@ -30,7 +102,6 @@ namespace zeus {
|
||||
* @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] _func Function to call.
|
||||
* @param[in] _args Argument optinnal the user want to add.
|
||||
*/
|
||||
template<class CLASS_TYPE>
|
||||
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(const ememory::SharedPtr<zeus::Buffer>&)) {
|
||||
@ -39,75 +110,195 @@ namespace zeus {
|
||||
};
|
||||
}
|
||||
public:
|
||||
TcpString();
|
||||
TcpString(enet::Tcp _connection, bool _isServer);
|
||||
virtual ~TcpString();
|
||||
/**
|
||||
* @brief
|
||||
* @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);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void connect(bool _async = false);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void disconnect(bool _inThreadStop = false);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isActive() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setInterfaceName(const std::string& _name);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
int32_t writeBinary(const ememory::SharedPtr<zeus::Buffer>& _data);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void ping();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void newBuffer(const ememory::SharedPtr<zeus::Buffer>& _buffer);
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::chrono::steady_clock::time_point& getLastTimeReceive() {
|
||||
return m_connection.getLastTimeReceive();
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::chrono::steady_clock::time_point& getLastTimeSend() {
|
||||
return m_connection.getLastTimeSend();
|
||||
}
|
||||
private:
|
||||
using ActionAsync = std::function<bool(TcpString* _interface)>;
|
||||
using ActionAsync = std::function<bool(WebServer* _interface)>;
|
||||
std::mutex m_threadAsyncMutex;
|
||||
std::thread* m_threadAsync;
|
||||
bool m_threadAsyncRunning;
|
||||
std::vector<ActionAsync> m_threadAsyncList;
|
||||
std::vector<ActionAsync> m_threadAsyncList2;
|
||||
private:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void threadAsyncCallback();
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void addAsync(ActionAsync _elem);
|
||||
private:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
zeus::FutureBase callBinary(uint64_t _transactionId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _obj,
|
||||
zeus::FutureData::ObserverFinish _callback=nullptr,
|
||||
const uint32_t& _service=0);
|
||||
public: // section call direct
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
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);
|
||||
}
|
||||
public: // section call with service ID / Client ID
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callService(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args) {
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callServiceAction(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callClient(uint32_t _clientId,
|
||||
const std::string& _functionName,
|
||||
_ARGS&&... _args) {
|
||||
return callService(_clientId, _functionName, _args...);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callClientAction(uint32_t _clientId,
|
||||
const std::string& _functionName,
|
||||
@ -115,16 +306,36 @@ namespace zeus {
|
||||
zeus::FutureData::ObserverFinish _callback) {
|
||||
return callServiceAction(_clientId, _functionName, _args..., _callback);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
zeus::FutureBase callForward(uint32_t _clientId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _Buffer,
|
||||
uint64_t _singleReferenceId,
|
||||
zeus::FutureData::ObserverFinish _callback);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void callForwardMultiple(uint32_t _clientId,
|
||||
const ememory::SharedPtr<zeus::Buffer>& _Buffer,
|
||||
uint64_t _singleReferenceId);
|
||||
public: // answers ...
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
|
||||
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class ZEUS_ARG>
|
||||
void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0) {
|
||||
ememory::SharedPtr<zeus::Buffer> answer = zeus::Buffer::create();
|
||||
@ -134,7 +345,17 @@ namespace zeus {
|
||||
answer->addAnswer(_value);
|
||||
writeBinary(answer);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
};
|
||||
}
|
@ -7,6 +7,17 @@
|
||||
#include <etk/types.h>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::string getMineType(const std::string& _extention);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
std::string getExtention(const std::string& _mineType);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user