[DEV] Work is back but no transfer of files with IDL ==> need to add it ...

This commit is contained in:
Edouard DUPIN 2016-11-28 21:28:26 +01:00
parent fac9c55b9e
commit 9f4872ba7b
21 changed files with 248 additions and 242 deletions

View File

@ -67,7 +67,6 @@ void appl::GateWay::newService(enet::Tcp _connection) {
} }
appl::GateWay::GateWay() : appl::GateWay::GateWay() :
m_clientUID(1),
propertyUserName(this, "user", "no-name", "User name of the interface"), // must be set befor start ... propertyUserName(this, "user", "no-name", "User name of the interface"), // must be set befor start ...
propertyRouterIp(this, "router-ip", "127.0.0.1", "Ip to listen client", &appl::GateWay::onPropertyChangeClientIp), propertyRouterIp(this, "router-ip", "127.0.0.1", "Ip to listen client", &appl::GateWay::onPropertyChangeClientIp),
propertyRouterPort(this, "router-port", 1984, "Port to listen client", &appl::GateWay::onPropertyChangeClientPort), propertyRouterPort(this, "router-port", 1984, "Port to listen client", &appl::GateWay::onPropertyChangeClientPort),

View File

@ -11,13 +11,11 @@
namespace appl { namespace appl {
class TcpServerInput; class TcpServerInput;
class GateWay : public eproperty::Interface { class GateWay : public eproperty::Interface {
private:
uint64_t m_clientUID;
private: private:
std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_serviceList; //!< List of all service availlable with their specific connection interface std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_serviceList; //!< List of all service availlable with their specific connection interface
ememory::SharedPtr<appl::RouterInterface> m_routerClient; //!< Interface with the Gateway Front End ememory::SharedPtr<appl::RouterInterface> m_routerClient; //!< Interface with the Gateway Front End
ememory::SharedPtr<appl::TcpServerInput> m_interfaceNewService; ememory::SharedPtr<appl::TcpServerInput> m_interfaceNewService;
public: public:
eproperty::Value<std::string> propertyUserName; eproperty::Value<std::string> propertyUserName;
eproperty::Value<std::string> propertyRouterIp; eproperty::Value<std::string> propertyRouterIp;

View File

@ -16,6 +16,7 @@
static const std::string protocolError = "PROTOCOL-ERROR"; static const std::string protocolError = "PROTOCOL-ERROR";
appl::userSpecificInterface::userSpecificInterface(const std::string& _userName) { appl::userSpecificInterface::userSpecificInterface(const std::string& _userName) {
m_routeurUID = 0;
m_uid = 0; m_uid = 0;
m_localIdUser = 0; m_localIdUser = 0;
m_userConnectionName = _userName; m_userConnectionName = _userName;
@ -32,14 +33,15 @@ appl::userSpecificInterface::~userSpecificInterface() {
} }
void appl::userSpecificInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::userSpecificInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceRouterClient->answerError(_transactionId, protocolError, _errorHelp); m_interfaceRouterClient->answerError(_transactionId, m_routeurUID, ZEUS_ID_SERVICE_ROOT, protocolError, _errorHelp);
m_interfaceRouterClient->sendCtrl("DISCONNECT", m_uid); m_interfaceRouterClient->sendCtrl(m_routeurUID, ZEUS_ID_SERVICE_ROOT, "DISCONNECT");
m_state = appl::clientState::disconnect; m_state = appl::clientState::disconnect;
} }
bool appl::userSpecificInterface::start(uint32_t _transactionId, appl::GateWay* _gatewayInterface, zeus::WebServer* _interfaceGateWayClient, uint64_t _id) { bool appl::userSpecificInterface::start(uint32_t _transactionId, appl::GateWay* _gatewayInterface, zeus::WebServer* _interfaceGateWayClient, uint64_t _routerId, uint64_t _id) {
m_interfaceRouterClient = _interfaceGateWayClient; m_interfaceRouterClient = _interfaceGateWayClient;
m_gatewayInterface = _gatewayInterface; m_gatewayInterface = _gatewayInterface;
m_routeurUID = _routerId;
m_uid = _id; m_uid = _id;
m_localIdUser = _id+1; m_localIdUser = _id+1;
m_state = appl::clientState::connect; m_state = appl::clientState::connect;
@ -53,7 +55,7 @@ bool appl::userSpecificInterface::start(uint32_t _transactionId, appl::GateWay*
answerProtocolError(_transactionId, "Gateway internal error 'No user interface'"); answerProtocolError(_transactionId, "Gateway internal error 'No user interface'");
return false; return false;
} }
zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.callClient(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>()); zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.call(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>());
futLocalService.wait(); // TODO: Set timeout ... futLocalService.wait(); // TODO: Set timeout ...
if (futLocalService.get() == false) { if (futLocalService.get() == false) {
answerProtocolError(_transactionId, "Gateway internal error 'Can not create client in user backend'"); answerProtocolError(_transactionId, "Gateway internal error 'Can not create client in user backend'");
@ -91,7 +93,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
} }
serviceId--; serviceId--;
if (serviceId >= m_listConnectedService.size()) { if (serviceId >= m_listConnectedService.size()) {
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
return; return;
} }
if (m_listConnectedService[serviceId] == nullptr) { if (m_listConnectedService[serviceId] == nullptr) {
@ -146,15 +148,15 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
return; return;
} }
zeus::Future<bool> fut = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "checkTocken", clientName, clientTocken); zeus::Future<bool> fut = m_userService->m_interfaceClient.call(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "checkTocken", clientName, clientTocken);
fut.wait(); // TODO: Set timeout ... fut.wait(); // TODO: Set timeout ...
if (fut.hasError() == true) { if (fut.hasError() == true) {
APPL_ERROR("Get error from the service ..."); APPL_ERROR("Get error from the service ...");
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "connection refused 1"); answerProtocolError(transactionId, "connection refused 1");
return; return;
} else if (fut.get() == false) { } else if (fut.get() == false) {
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "connection refused 2"); answerProtocolError(transactionId, "connection refused 2");
return; return;
} }
@ -162,15 +164,15 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
} }
if (callFunction == "auth") { if (callFunction == "auth") {
std::string password = callObj->getParameter<std::string>(0); std::string password = callObj->getParameter<std::string>(0);
zeus::Future<bool> fut = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "checkAuth", password); zeus::Future<bool> fut = m_userService->m_interfaceClient.call(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "checkAuth", password);
fut.wait(); // TODO: Set timeout ... fut.wait(); // TODO: Set timeout ...
if (fut.hasError() == true) { if (fut.hasError() == true) {
APPL_ERROR("Get error from the service ..."); APPL_ERROR("Get error from the service ...");
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "connection refused 1"); answerProtocolError(transactionId, "connection refused 1");
return; return;
} else if (fut.get() == false) { } else if (fut.get() == false) {
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "connection refused 2"); answerProtocolError(transactionId, "connection refused 2");
return; return;
} }
@ -182,11 +184,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
// -------------------------------- // --------------------------------
// -- Get groups: // -- Get groups:
// -------------------------------- // --------------------------------
zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "clientGroupsGet", m_clientName); zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.call(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "clientGroupsGet", m_clientName);
futGroup.wait(); // TODO: Set timeout ... futGroup.wait(); // TODO: Set timeout ...
if (futGroup.hasError() == true) { if (futGroup.hasError() == true) {
APPL_ERROR("Get error from the service ..."); APPL_ERROR("Get error from the service ...");
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "grouping error"); answerProtocolError(transactionId, "grouping error");
return; return;
} }
@ -195,11 +197,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
// -- Get services: // -- Get services:
// -------------------------------- // --------------------------------
std::vector<std::string> currentServices = m_gatewayInterface->getAllServiceName(); std::vector<std::string> currentServices = m_gatewayInterface->getAllServiceName();
zeus::Future<std::vector<std::string>> futServices = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "filterClientServices", m_clientName, currentServices); zeus::Future<std::vector<std::string>> futServices = m_userService->m_interfaceClient.call(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "filterClientServices", m_clientName, currentServices);
futServices.wait(); // TODO: Set timeout ... futServices.wait(); // TODO: Set timeout ...
if (futServices.hasError() == true) { if (futServices.hasError() == true) {
APPL_ERROR("Get error from the service ..."); APPL_ERROR("Get error from the service ...");
m_interfaceRouterClient->answerValue(transactionId, false); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
answerProtocolError(transactionId, "service filtering error"); answerProtocolError(transactionId, "service filtering error");
return; return;
} }
@ -209,7 +211,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
APPL_WARNING(" services: " << etk::to_string(m_clientServices)); APPL_WARNING(" services: " << etk::to_string(m_clientServices));
m_interfaceRouterClient->answerValue(transactionId, true); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), true);
m_state = appl::clientState::clientIdentify; m_state = appl::clientState::clientIdentify;
return; return;
} }
@ -221,11 +223,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
if (serviceId == 0) { if (serviceId == 0) {
// This is 2 default service for the cient interface that manage the authorisation of view: // This is 2 default service for the cient interface that manage the authorisation of view:
if (callFunction == "getServiceCount") { if (callFunction == "getServiceCount") {
m_interfaceRouterClient->answerValue(transactionId, m_clientServices.size(), m_uid); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), m_clientServices.size());
return; return;
} }
if (callFunction == "getServiceList") { if (callFunction == "getServiceList") {
m_interfaceRouterClient->answerValue(transactionId, m_clientServices, m_uid); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), m_clientServices);
//"ServiceManager/v0.1.0" //"ServiceManager/v0.1.0"
return; return;
} }
@ -249,27 +251,27 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
if (it == m_listConnectedService.end()) { if (it == m_listConnectedService.end()) {
// check if service is connectable ... // check if service is connectable ...
if (std::find(m_clientServices.begin(), m_clientServices.end(), serviceName) == m_clientServices.end()) { if (std::find(m_clientServices.begin(), m_clientServices.end(), serviceName) == m_clientServices.end()) {
m_interfaceRouterClient->answerError(transactionId, "UN-AUTHORIZED-SERVICE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "UN-AUTHORIZED-SERVICE");
return; return;
} }
ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName); ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName);
if (srv != nullptr) { if (srv != nullptr) {
zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups); zeus::Future<bool> futLink = srv->m_interfaceClient.call(m_uid, ZEUS_ID_SERVICE_ROOT, "_new", m_userConnectionName, m_clientName, m_clientgroups);
futLink.wait(); // TODO: Set timeout ... futLink.wait(); // TODO: Set timeout ...
if (futLink.hasError() == true) { if (futLink.hasError() == true) {
APPL_ERROR("Get error from the service ... LINK"); APPL_ERROR("Get error from the service ... LINK");
m_interfaceRouterClient->answerError(transactionId, "ERROR-CREATE-SERVICE-INSTANCE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "ERROR-CREATE-SERVICE-INSTANCE");
return; return;
} }
m_listConnectedService.push_back(srv); m_listConnectedService.push_back(srv);
ZEUS_ERROR(" ==> get ID : " << m_uid); ZEUS_ERROR(" ==> get ID : " << m_uid);
m_interfaceRouterClient->answerValue(transactionId, m_listConnectedService.size(), m_uid); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), m_listConnectedService.size());
return; return;
} }
m_interfaceRouterClient->answerError(transactionId, "CAN-NOT-CONNECT-SERVICE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "CAN-NOT-CONNECT-SERVICE");
return; return;
} }
m_interfaceRouterClient->answerError(transactionId, "SERVICE-ALREADY-CONNECTED");; m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "SERVICE-ALREADY-CONNECTED");;
return; return;
} }
if (callFunction == "unlink") { if (callFunction == "unlink") {
@ -278,28 +280,28 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
int64_t localServiceID = callObj->getParameter<int64_t>(0)-1; int64_t localServiceID = callObj->getParameter<int64_t>(0)-1;
// Check if service already link: // Check if service already link:
if (localServiceID >= m_listConnectedService.size()) { if (localServiceID >= m_listConnectedService.size()) {
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
return; return;
} }
zeus::Future<bool> futUnLink = m_listConnectedService[localServiceID]->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_uid, "_delete"); zeus::Future<bool> futUnLink = m_listConnectedService[localServiceID]->m_interfaceClient.call(m_uid, ZEUS_ID_SERVICE_ROOT, "_delete");
futUnLink.wait(); // TODO: Set timeout ... futUnLink.wait(); // TODO: Set timeout ...
if (futUnLink.hasError() == true) { if (futUnLink.hasError() == true) {
APPL_ERROR("Get error from the service ... UNLINK"); APPL_ERROR("Get error from the service ... UNLINK");
m_interfaceRouterClient->answerError(transactionId, "ERROR-CREATE-SERVICE-INSTANCE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "ERROR-CREATE-SERVICE-INSTANCE");
return; return;
} }
m_listConnectedService[localServiceID] = nullptr; m_listConnectedService[localServiceID] = nullptr;
m_interfaceRouterClient->answerValue(transactionId, true); m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), true);
return; return;
} }
APPL_ERROR("Function does not exist ... '" << callFunction << "'"); APPL_ERROR("Function does not exist ... '" << callFunction << "'");
m_interfaceRouterClient->answerError(transactionId, "CALL-UNEXISTING"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "CALL-UNEXISTING");
return; return;
} }
// decrease service ID ... // decrease service ID ...
serviceId -= 1; serviceId -= 1;
if (serviceId >= m_listConnectedService.size()) { if (serviceId >= m_listConnectedService.size()) {
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE"); m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
return; return;
} else { } else {
if (m_listConnectedService[serviceId] == nullptr) { if (m_listConnectedService[serviceId] == nullptr) {
@ -307,24 +309,22 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
APPL_ERROR("TODO : Manage this case ..."); APPL_ERROR("TODO : Manage this case ...");
return; return;
} }
m_listConnectedService[serviceId]->m_interfaceClient.callForward( auto fut = m_listConnectedService[serviceId]->m_interfaceClient.callForward(m_uid, _value, (uint64_t(m_uid) << 32) + uint64_t(transactionId));
m_uid, fut.andAll([=](zeus::FutureBase _ret) {
_value, ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
(uint64_t(m_uid) << 32) + uint64_t(transactionId), if (tmpp == nullptr) {
[=](zeus::FutureBase _ret) { return true;
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw(); }
if (tmpp == nullptr) { APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
return true; APPL_DEBUG(" msg=" << tmpp);
} tmpp->setTransactionId(transactionId);
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId); tmpp->setClientId(m_routeurUID);
APPL_DEBUG(" msg=" << tmpp); tmpp->setServiceId(serviceId+1);
tmpp->setTransactionId(transactionId); APPL_DEBUG("transmit=" << tmpp);
tmpp->setServiceId(serviceId+1); m_interfaceRouterClient->writeBinary(tmpp);
APPL_DEBUG("transmit=" << tmpp); // multiple send element ...
m_interfaceRouterClient->writeBinary(tmpp); return tmpp->getPartFinish();
// multiple send element ... });
return tmpp->getPartFinish();
});
} }
} }
} }
@ -334,6 +334,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
appl::RouterInterface::RouterInterface(const std::string& _ip, uint16_t _port, const std::string& _userName, appl::GateWay* _gatewayInterface) : appl::RouterInterface::RouterInterface(const std::string& _ip, uint16_t _port, const std::string& _userName, appl::GateWay* _gatewayInterface) :
m_clientUID(1),
m_state(appl::clientState::unconnect), m_state(appl::clientState::unconnect),
m_gatewayInterface(_gatewayInterface), m_gatewayInterface(_gatewayInterface),
m_interfaceRouterClient() { m_interfaceRouterClient() {
@ -394,7 +395,7 @@ void appl::RouterInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
//APPL_ERROR("[" << clientId << "] get message from front-end gateWay: " << _value); //APPL_ERROR("[" << clientId << "] get message from front-end gateWay: " << _value);
int64_t localId = -1; int64_t localId = -1;
for (size_t iii=0; iii<m_listUser.size(); ++iii) { for (size_t iii=0; iii<m_listUser.size(); ++iii) {
if (m_listUser[iii].m_uid == clientId) { if (m_listUser[iii].m_routeurUID == clientId) {
localId = iii; localId = iii;
break; break;
} }
@ -402,7 +403,8 @@ void appl::RouterInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
if (localId == -1) { if (localId == -1) {
m_listUser.push_back(userSpecificInterface(m_userConnectionName)); m_listUser.push_back(userSpecificInterface(m_userConnectionName));
localId = m_listUser.size()-1; localId = m_listUser.size()-1;
bool ret = m_listUser[localId].start(_value->getTransactionId(), m_gatewayInterface, &m_interfaceRouterClient, clientId); bool ret = m_listUser[localId].start(_value->getTransactionId(), m_gatewayInterface, &m_interfaceRouterClient, clientId, m_clientUID);
m_clientUID += 2; //use 2 slot of Connection for gateway get filtering ...
if (ret == false) { if (ret == false) {
return; return;
} }

View File

@ -21,8 +21,11 @@ namespace appl {
public: public:
zeus::WebServer* m_interfaceRouterClient; zeus::WebServer* m_interfaceRouterClient;
appl::GateWay* m_gatewayInterface; appl::GateWay* m_gatewayInterface;
uint64_t m_routeurUID;
private:
uint64_t m_uid; uint64_t m_uid;
uint64_t m_localIdUser; uint64_t m_localIdUser;
public:
enum clientState m_state; // state machine ... enum clientState m_state; // state machine ...
std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_listConnectedService; std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_listConnectedService;
ememory::SharedPtr<appl::ServiceInterface> m_userService; ememory::SharedPtr<appl::ServiceInterface> m_userService;
@ -32,7 +35,7 @@ namespace appl {
std::vector<std::string> m_clientServices; std::vector<std::string> m_clientServices;
userSpecificInterface(const std::string& _userName); userSpecificInterface(const std::string& _userName);
~userSpecificInterface(); ~userSpecificInterface();
bool start(uint32_t _transactionId, appl::GateWay* _gatewayInterface, zeus::WebServer* _interfaceGateWayClient, uint64_t _id); bool start(uint32_t _transactionId, appl::GateWay* _gatewayInterface, zeus::WebServer* _interfaceGateWayClient, uint64_t _routerId, uint64_t _id);
void onClientData(ememory::SharedPtr<zeus::Buffer> _value); void onClientData(ememory::SharedPtr<zeus::Buffer> _value);
void returnMessage(ememory::SharedPtr<zeus::Buffer> _data); void returnMessage(ememory::SharedPtr<zeus::Buffer> _data);
bool checkId(uint64_t _id) const { bool checkId(uint64_t _id) const {
@ -42,6 +45,8 @@ namespace appl {
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp); void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
}; };
class RouterInterface { class RouterInterface {
private:
uint32_t m_clientUID;
private: private:
enum clientState m_state; // state machine .. enum clientState m_state; // state machine ..
std::vector<userSpecificInterface> m_listUser; std::vector<userSpecificInterface> m_listUser;

View File

@ -107,7 +107,7 @@ void appl::ServiceInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_value); ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_value);
std::string callFunction = callObj->getCall(); std::string callFunction = callObj->getCall();
if (callFunction == "getUserName") { if (callFunction == "getUserName") {
m_interfaceClient.answerValue(transactionId, *m_gatewayInterface->propertyUserName); m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), *m_gatewayInterface->propertyUserName);
return; return;
} }
answerProtocolError(transactionId, "unknow function"); answerProtocolError(transactionId, "unknow function");
@ -121,6 +121,6 @@ void appl::ServiceInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
void appl::ServiceInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::ServiceInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp); m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
m_interfaceClient.disconnect(true); m_interfaceClient.disconnect(true);
} }

View File

@ -77,7 +77,7 @@ bool appl::ClientInterface::isAlive() {
} }
void appl::ClientInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::ClientInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp); m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
m_state = appl::ClientInterface::state::disconnect; m_state = appl::ClientInterface::state::disconnect;
m_interfaceClient.disconnect(true); m_interfaceClient.disconnect(true);
} }
@ -94,6 +94,11 @@ void appl::ClientInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
answerProtocolError(transactionId, "missing parameter: 'id'"); answerProtocolError(transactionId, "missing parameter: 'id'");
return; return;
} }
if (_value->getClientId() != 0) {
APPL_ERROR("Protocol error ==> client ID != 0");
answerProtocolError(transactionId, "clent ID is != 0");
return;
}
// Directly send to the user-GateWay // Directly send to the user-GateWay
if (m_userGateWay == nullptr) { if (m_userGateWay == nullptr) {
APPL_ERROR("USER is not existing ..."); APPL_ERROR("USER is not existing ...");
@ -103,24 +108,21 @@ void appl::ClientInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
} }
// Special case for data, they are transiting messages ... // Special case for data, they are transiting messages ...
if (_value->getType() != zeus::Buffer::typeMessage::data) { if (_value->getType() != zeus::Buffer::typeMessage::data) {
m_userGateWay->m_interfaceClient.callForward( auto fut = m_userGateWay->m_interfaceClient.callForward(m_uid, _value, (uint64_t(m_uid) << 32) + uint64_t(transactionId));
m_uid, fut.andAll([=](zeus::FutureBase _ret) {
_value, ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
(uint64_t(m_uid) << 32) + uint64_t(transactionId), if (tmpp == nullptr) {
[=](zeus::FutureBase _ret) { return true;
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw(); }
if (tmpp == nullptr) { APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
return true; APPL_DEBUG(" msg=" << tmpp);
} tmpp->setTransactionId(transactionId);
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId); tmpp->setClientId(0);
APPL_DEBUG(" msg=" << tmpp); APPL_DEBUG("transmit=" << tmpp);
tmpp->setTransactionId(transactionId); m_interfaceClient.writeBinary(tmpp);
//tmpp->setServiceId(serviceId+1); // multiple send element ...
APPL_DEBUG("transmit=" << tmpp); return tmpp->getPartFinish();
m_interfaceClient.writeBinary(tmpp); });
// multiple send element ...
return tmpp->getPartFinish();
});
} else { } else {
// simply forward messages to the user gateWay ... // simply forward messages to the user gateWay ...
m_userGateWay->m_interfaceClient.callForwardMultiple( m_userGateWay->m_interfaceClient.callForwardMultiple(

View File

@ -25,11 +25,7 @@ namespace appl {
bool requestURI(const std::string& _uri); bool requestURI(const std::string& _uri);
public: public:
ememory::SharedPtr<appl::GateWayInterface> m_userGateWay; ememory::SharedPtr<appl::GateWayInterface> m_userGateWay;
uint64_t m_uid; uint64_t m_uid; //!< gateway unique ID ==> to have an internal routage ...
std::string m_userConnectionName;
std::string m_clientName;
std::vector<std::string> m_clientgroups;
std::vector<std::string> m_clientServices;
public: public:
ClientInterface(enet::Tcp _connection, appl::Router* _routerInterface); ClientInterface(enet::Tcp _connection, appl::Router* _routerInterface);
virtual ~ClientInterface(); virtual ~ClientInterface();

View File

@ -108,12 +108,12 @@ void appl::GateWayInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
if (callFunction == "connect-service") { if (callFunction == "connect-service") {
if (m_name != "") { if (m_name != "") {
ZEUS_WARNING("Service interface ==> try change the servie name after init: '" << callObj->getParameter<std::string>(0)); ZEUS_WARNING("Service interface ==> try change the servie name after init: '" << callObj->getParameter<std::string>(0));
m_interfaceClient.answerValue(transactionId, false); m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
return; return;
} }
m_name = callObj->getParameter<std::string>(0); m_name = callObj->getParameter<std::string>(0);
m_interfaceClient.setInterfaceName("srv-" + m_name); m_interfaceClient.setInterfaceName("srv-" + m_name);
m_interfaceClient.answerValue(transactionId, true); m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), true);
return; return;
} }
answerProtocolError(transactionId, "unknow function"); answerProtocolError(transactionId, "unknow function");
@ -127,6 +127,6 @@ void appl::GateWayInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
void appl::GateWayInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) { void appl::GateWayInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp); m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
m_interfaceClient.disconnect(true); m_interfaceClient.disconnect(true);
} }

View File

@ -76,7 +76,7 @@ void appl::Router::newClient(enet::Tcp _connection) {
ZEUS_WARNING("New TCP connection (client)"); ZEUS_WARNING("New TCP connection (client)");
ememory::SharedPtr<appl::ClientInterface> tmp = ememory::makeShared<appl::ClientInterface>(std::move(_connection), this); ememory::SharedPtr<appl::ClientInterface> tmp = ememory::makeShared<appl::ClientInterface>(std::move(_connection), this);
tmp->start(m_clientUID); tmp->start(m_clientUID);
m_clientUID += 2; // Need to do it, it is une impair ID by the Gateway m_clientUID++;
m_clientList.push_back(tmp); m_clientList.push_back(tmp);
} }

View File

@ -38,7 +38,7 @@ namespace zeus {
ret = (*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...); ret = (*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
} }
_interfaceClient->addAsync([=](WebServer* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId()); _interface->answerValue(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), ret);
return true; return true;
}); });
} }
@ -67,7 +67,7 @@ namespace zeus {
(*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...); (*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
} }
_interfaceClient->addAsync([=](WebServer* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId()); _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId());
return true; return true;
}); });
} }
@ -122,18 +122,20 @@ namespace zeus {
help += " parameters. prototype function:"; help += " parameters. prototype function:";
help += getPrototype(); help += getPrototype();
_interfaceClient->answerError(_obj->getTransactionId(), _interfaceClient->answerError(_obj->getTransactionId(),
_obj->getClientId(),
_obj->getServiceId(),
"WRONG-PARAMETER-NUMBER", "WRONG-PARAMETER-NUMBER",
help, help);
_obj->getClientId());
return; return;
} }
// check parameter compatibility // check parameter compatibility
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) { for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) { if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
_interfaceClient->answerError(_obj->getTransactionId(), _interfaceClient->answerError(_obj->getTransactionId(),
_obj->getClientId(),
_obj->getServiceId(),
"WRONG-PARAMETER-TYPE", "WRONG-PARAMETER-TYPE",
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'", std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'");
_obj->getClientId());
return; return;
} }
} }

View File

@ -33,7 +33,7 @@ namespace zeus {
ret = _func(_obj->getParameter<ZEUS_TYPES>(idParam--)...); ret = _func(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
} }
_interfaceClient->addAsync([=](WebServer* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId()); _interface->answerValue(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), ret);
return true; return true;
}); });
} }
@ -60,7 +60,7 @@ namespace zeus {
_func(_obj->getParameter<ZEUS_TYPES>(idParam--)...); _func(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
} }
_interfaceClient->addAsync([=](WebServer* _interface) { _interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId()); _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId());
return true; return true;
}); });
} }
@ -110,18 +110,20 @@ namespace zeus {
help += " parameters. prototype function:"; help += " parameters. prototype function:";
help += getPrototype(); help += getPrototype();
_interfaceClient->answerError(_obj->getTransactionId(), _interfaceClient->answerError(_obj->getTransactionId(),
_obj->getClientId(),
_obj->getServiceId(),
"WRONG-PARAMETER-NUMBER", "WRONG-PARAMETER-NUMBER",
help, help);
_obj->getClientId());
return; return;
} }
// check parameter compatibility // check parameter compatibility
for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) { for (size_t iii=0; iii<sizeof...(ZEUS_TYPES); ++iii) {
if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) { if (checkCompatibility(m_paramType[iii], _obj->getParameterType(iii)) == false) {
_interfaceClient->answerError(_obj->getTransactionId(), _interfaceClient->answerError(_obj->getTransactionId(),
_obj->getClientId(),
_obj->getServiceId(),
"WRONG-PARAMETER-TYPE", "WRONG-PARAMETER-TYPE",
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'", std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'");
_obj->getClientId());
return; return;
} }
} }

View File

@ -97,7 +97,7 @@ namespace zeus {
void onClientData(ememory::SharedPtr<zeus::Buffer> _value); void onClientData(ememory::SharedPtr<zeus::Buffer> _value);
public: public:
/** /**
* @brief Create a call on the interface gateway * @brief Create a call on the interface gateway (threw the router)
* @param[in] _functionName name of the function to call * @param[in] _functionName name of the function to call
* @param[in] _args... multiple argument neededs * @param[in] _args... multiple argument neededs
* @return a future that will contain the aswer when receiveed (need to transmit over ethernet) * @return a future that will contain the aswer when receiveed (need to transmit over ethernet)
@ -109,23 +109,7 @@ namespace zeus {
ret->addError("NULLPTR", "call " + _functionName + " with no interface open"); ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
return zeus::FutureBase(0, ret); return zeus::FutureBase(0, ret);
} }
return m_interfaceClient->call(_functionName, _args...); return m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, _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) {
ememory::SharedPtr<zeus::BufferAnswer> ret = zeus::BufferAnswer::create();
ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
return zeus::FutureBase(0, ret, _callback);
}
return m_interfaceClient->callAction(_functionName, _args..., _callback);
} }
private: private:
/** /**

View File

@ -17,7 +17,7 @@ zeus::FutureBase::FutureBase() {
m_data = nullptr; m_data = nullptr;
} }
zeus::FutureBase::FutureBase(uint32_t _transactionId, zeus::FutureData::ObserverFinish _callback, uint32_t _clientId) { zeus::FutureBase::FutureBase(uint32_t _transactionId, /*zeus::FutureData::ObserverFinish _callback, */uint32_t _clientId) {
m_data = ememory::makeShared<zeus::FutureData>(); m_data = ememory::makeShared<zeus::FutureData>();
if (m_data == nullptr) { if (m_data == nullptr) {
return; return;
@ -26,7 +26,7 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, zeus::FutureData::Observer
m_data->m_transactionId = _transactionId; m_data->m_transactionId = _transactionId;
m_data->m_clientId = _clientId; m_data->m_clientId = _clientId;
m_data->m_isSynchronous = false; m_data->m_isSynchronous = false;
m_data->m_callbackFinish = _callback; //m_data->m_callbackFinish = _callback;
} }
ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() { ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() {
@ -36,7 +36,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() {
return m_data->m_returnData; return m_data->m_returnData;
} }
zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, zeus::FutureData::ObserverFinish _callback, uint32_t _clientId) { zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, /*zeus::FutureData::ObserverFinish _callback, */uint32_t _clientId) {
m_data = ememory::makeShared<zeus::FutureData>(); m_data = ememory::makeShared<zeus::FutureData>();
if (m_data == nullptr) { if (m_data == nullptr) {
return; return;
@ -46,6 +46,7 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::B
m_data->m_clientId = _clientId; m_data->m_clientId = _clientId;
m_data->m_isSynchronous = false; m_data->m_isSynchronous = false;
m_data->m_returnData = _returnData; m_data->m_returnData = _returnData;
#if 0
m_data->m_callbackFinish = _callback; m_data->m_callbackFinish = _callback;
if (isFinished() == true) { if (isFinished() == true) {
m_data->m_receiveTime = std::chrono::steady_clock::now(); m_data->m_receiveTime = std::chrono::steady_clock::now();
@ -53,7 +54,71 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::B
m_data->m_callbackFinish(*this); m_data->m_callbackFinish(*this);
} }
} }
#else
if (isFinished() == true) {
m_data->m_receiveTime = std::chrono::steady_clock::now();
}
#endif
} }
void zeus::FutureBase::andAll(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackThen = _callback;
m_data->m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
if (m_data->m_callbackThen != nullptr) {
m_data->m_callbackThen(*this);
}
} else {
if (m_data->m_callbackElse != nullptr) {
m_data->m_callbackElse(*this);
}
}
}
void zeus::FutureBase::andThen(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackThen = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == true) {
return;
}
if (m_data->m_callbackThen == nullptr) {
return;
}
m_data->m_callbackThen(*this);
}
void zeus::FutureBase::andElse(zeus::FutureData::Observer _callback) {
if (m_data == nullptr) {
return;
}
// TODO : Lock ...
m_data->m_callbackElse = _callback;
if (isFinished() == false) {
return;
}
if (hasError() == false) {
return;
}
if (m_data->m_callbackElse == nullptr) {
return;
}
m_data->m_callbackElse(*this);
}
std::chrono::nanoseconds zeus::FutureBase::getTransmitionTime() const { std::chrono::nanoseconds zeus::FutureBase::getTransmitionTime() const {
if (m_data == nullptr) { if (m_data == nullptr) {
return std::chrono::nanoseconds(0); return std::chrono::nanoseconds(0);
@ -77,8 +142,14 @@ bool zeus::FutureBase::appendData(ememory::SharedPtr<zeus::Buffer> _value) {
m_data->m_receiveTime = std::chrono::steady_clock::now(); m_data->m_receiveTime = std::chrono::steady_clock::now();
if (m_data->m_isSynchronous == true) { if (m_data->m_isSynchronous == true) {
m_data->m_returnData = _value; m_data->m_returnData = _value;
if (m_data->m_callbackFinish != nullptr) { if (hasError() == false) {
return m_data->m_callbackFinish(*this); if (m_data->m_callbackThen != nullptr) {
return m_data->m_callbackThen(*this);
}
} else {
if (m_data->m_callbackElse != nullptr) {
return m_data->m_callbackElse(*this);
}
} }
return true; return true;
} }
@ -93,8 +164,14 @@ bool zeus::FutureBase::appendData(ememory::SharedPtr<zeus::Buffer> _value) {
return true; return true;
} }
if (m_data->m_returnData->getPartFinish() == true) { if (m_data->m_returnData->getPartFinish() == true) {
if (m_data->m_callbackFinish != nullptr) { if (hasError() == false) {
return m_data->m_callbackFinish(*this); if (m_data->m_callbackThen != nullptr) {
return m_data->m_callbackThen(*this);
}
} else {
if (m_data->m_callbackElse != nullptr) {
return m_data->m_callbackElse(*this);
}
} }
return true; return true;
} }

View File

@ -27,24 +27,38 @@ namespace zeus {
/** /**
* @brief Contructor of the FutureBase with an ofserver * @brief Contructor of the FutureBase with an ofserver
* @param[in] _transactionId Transaction waiting answer * @param[in] _transactionId Transaction waiting answer
* @param[in] _callback Observer pointer
* @param[in] _clientId Client/sevice Id waiting answer * @param[in] _clientId Client/sevice Id waiting answer
*/ */
FutureBase(uint32_t _transactionId, zeus::FutureData::ObserverFinish _callback=nullptr, uint32_t _clientId=0); FutureBase(uint32_t _transactionId, uint32_t _clientId=0);
/** /**
* @brief Contructor of the FutureBase for direct error answer * @brief Contructor of the FutureBase for direct error answer
* @param[in] _transactionId Transaction waiting answer * @param[in] _transactionId Transaction waiting answer
* @param[in] _isFinished set state finish or not * @param[in] _isFinished set state finish or not
* @param[in] _returnData Set return value * @param[in] _returnData Set return value
* @param[in] _callback Observer pointer
* @param[in] _clientId Client/sevice Id waiting answer * @param[in] _clientId Client/sevice Id waiting answer
*/ */
FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, zeus::FutureData::ObserverFinish _callback=nullptr, uint32_t _clientId=0); FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, uint32_t _clientId=0);
// TODO: Add this to have generic nec C++ interface: /**
* @brief Attach callback on all return type of value
* @param[in] _callback Handle on the function to call in all case
*/
void andAll(zeus::FutureData::Observer _callback);
/**
* @brief Attach callback on a specific return action (SUCESS)
* @param[in] _callback Handle on the function to call in case of sucess on the call
*/
void andThen(zeus::FutureData::Observer _callback);
/**
* @brief Attach callback on a specific return action (ERROR)
* @param[in] _callback Handle on the function to call in case of error on the call
*/
void andElse(zeus::FutureData::Observer _callback);
/* /*
void andThen(zeus::FutureData::ObserverFinish _callback); // no error in the return / **
void andElse(zeus::FutureData::ObserverFinish _callback); // an error occured in the return * @brief Attach callback on a specific return action (ABORT)
void andAbort(zeus::FutureData::ObserverFinish _callback); // an abort is requested in the actiron ... * @param[in] _callback Handle on the function to call in case of abort on the call
* /
void andAbort(zeus::FutureData::Observer _callback); // an abort is requested in the actiron ...
*/ */
/** /**
* @brief Asignement operator with an other future * @brief Asignement operator with an other future

View File

@ -18,13 +18,16 @@ namespace zeus {
*/ */
class FutureData { class FutureData {
public: public:
using ObserverFinish = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer //using ObserverFinish = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer
using Observer = std::function<bool(zeus::FutureBase)>; //!< Define an Observer: function pointer
public: public:
uint32_t m_transactionId; //!< waiting answer data uint32_t m_transactionId; //!< waiting answer data
uint32_t m_clientId; //!< need to anser at this client. uint32_t m_clientId; //!< need to anser at this client.
bool m_isSynchronous; //!< the future is synchronous. (call when receive data) bool m_isSynchronous; //!< the future is synchronous. (call when receive data)
ememory::SharedPtr<zeus::Buffer> m_returnData; //!< all buffer concatenate or last buffer if synchronous ememory::SharedPtr<zeus::Buffer> m_returnData; //!< all buffer concatenate or last buffer if synchronous
ObserverFinish m_callbackFinish; //!< ofserver of the finish data Observer m_callbackThen; //!< observer callback When data arrive and NO error appear
Observer m_callbackElse; //!< observer callback When data arrive and AN error appear
//Observer m_callbackAbort; //!< observer callback When Action is abort by user
std::chrono::steady_clock::time_point m_sendTime; //!< time when the future has been sended request std::chrono::steady_clock::time_point m_sendTime; //!< time when the future has been sended request
std::chrono::steady_clock::time_point m_receiveTime; //!< time when the future has receve answer std::chrono::steady_clock::time_point m_receiveTime; //!< time when the future has receve answer
}; };

View File

@ -59,7 +59,7 @@ void zeus::Service::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
return; return;
} }
ZEUS_WARNING("direct call"); ZEUS_WARNING("direct call");
zeus::FutureBase futData(tmpID, _value, nullptr, clientId); zeus::FutureBase futData(tmpID, _value, clientId);
if (futData.isFinished() == true) { if (futData.isFinished() == true) {
ZEUS_INFO("Call Binary .."); ZEUS_INFO("Call Binary ..");
callBinary(futData.getRaw()); callBinary(futData.getRaw());
@ -102,7 +102,7 @@ bool zeus::Service::connect(uint32_t _numberRetry){
return false; return false;
} }
zeus::Future<std::string> ret = m_interfaceClient->call("getUserName"); zeus::Future<std::string> ret = m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, "getUserName");
ret.wait(); ret.wait();
m_nameUser = ret.get(); m_nameUser = ret.get();
ZEUS_ERROR("Connect with name user: '" << m_nameUser << "'"); ZEUS_ERROR("Connect with name user: '" << m_nameUser << "'");
@ -166,7 +166,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
} else if (callFunction == "_delete") { } else if (callFunction == "_delete") {
clientDisconnect(clientId); clientDisconnect(clientId);
} }
m_interfaceClient->answerValue(callObj->getTransactionId(), true, clientId); m_interfaceClient->answerValue(callObj->getTransactionId(), clientId, m_id, true);
return; return;
} else if (isFunctionAuthorized(clientId, callFunction) == true) { } else if (isFunctionAuthorized(clientId, callFunction) == true) {
ZEUS_INFO("plop 6 ..."); ZEUS_INFO("plop 6 ...");
@ -174,7 +174,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
return; return;
} else { } else {
ZEUS_INFO("plop 7 ..."); ZEUS_INFO("plop 7 ...");
m_interfaceClient->answerError(callObj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId); m_interfaceClient->answerError(callObj->getTransactionId(), clientId, m_id, "NOT-AUTHORIZED-FUNCTION", "");
return; return;
} }
} }

View File

@ -191,7 +191,6 @@ namespace zeus {
* @return * @return
*/ */
virtual void clientDisconnect(uint64_t _clientId) = 0; virtual void clientDisconnect(uint64_t _clientId) = 0;
// Genenric function call:
/** /**
* @brief * @brief
* @param[in] * @param[in]
@ -380,7 +379,7 @@ namespace zeus {
void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj) { void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj) {
auto it = m_interface.find(_obj->getClientId()); auto it = m_interface.find(_obj->getClientId());
if (it == m_interface.end()) { if (it == m_interface.end()) {
m_interfaceClient->answerError(_obj->getTransactionId(), "CLIENT-UNKNOW", "", _obj->getClientId()); m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), "CLIENT-UNKNOW", "");
return; return;
} }
for (auto &it2 : m_listFunction) { for (auto &it2 : m_listFunction) {
@ -413,7 +412,7 @@ namespace zeus {
break; break;
} }
} }
m_interfaceClient->answerError(_obj->getTransactionId(), "FUNCTION-UNKNOW", "", _obj->getClientId()); m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), "FUNCTION-UNKNOW", "");
return; return;
} }
}; };

View File

@ -16,7 +16,7 @@ zeus::ServiceRemoteBase::ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _
return; return;
} }
// little hack : Call the service manager with the service ID=0 ... // little hack : Call the service manager with the service ID=0 ...
zeus::Future<uint32_t> ret = m_interfaceClient->callService(ZEUS_NO_ID_CLIENT, m_serviceId, "link", _name); zeus::Future<uint32_t> ret = m_interfaceClient->call(ZEUS_NO_ID_CLIENT, m_serviceId, "link", _name);
ret.wait(); ret.wait();
if (ret.hasError() == true) { if (ret.hasError() == true) {
ZEUS_WARNING("Can not link with the service named: '" << _name << "' ==> link error"); ZEUS_WARNING("Can not link with the service named: '" << _name << "' ==> link error");
@ -31,7 +31,7 @@ zeus::ServiceRemoteBase::~ServiceRemoteBase() {
uint32_t tmpLocalService = m_serviceId; uint32_t tmpLocalService = m_serviceId;
// little hack : Call the service manager with the service ID=0 ... // little hack : Call the service manager with the service ID=0 ...
m_serviceId = 0; m_serviceId = 0;
zeus::Future<bool> ret = m_interfaceClient->callService(ZEUS_NO_ID_CLIENT, m_serviceId, "unlink", tmpLocalService); zeus::Future<bool> ret = m_interfaceClient->call(ZEUS_NO_ID_CLIENT, m_serviceId, "unlink", tmpLocalService);
ret.wait(); ret.wait();
if (ret.hasError() == true) { if (ret.hasError() == true) {
ZEUS_WARNING("Can not unlink with the service id: '" << tmpLocalService << "' ==> link error"); ZEUS_WARNING("Can not unlink with the service id: '" << tmpLocalService << "' ==> link error");

View File

@ -103,7 +103,7 @@ namespace zeus {
} }
return zeus::FutureBase(0, ret); return zeus::FutureBase(0, ret);
} }
return m_interface->m_interfaceClient->callService(ZEUS_NO_ID_CLIENT, m_interface->m_serviceId, _functionName, _args...); return m_interface->m_interfaceClient->call(ZEUS_NO_ID_CLIENT, m_interface->m_serviceId, _functionName, _args...);
} }
/** /**
* @brief * @brief
@ -111,6 +111,7 @@ namespace zeus {
* @return * @return
*/ */
// TODO: Remove the callback to add it in future with the "then(_callback)" and "else(_callback)" and "abort(_callbacl)" ... // TODO: Remove the callback to add it in future with the "then(_callback)" and "else(_callback)" and "abort(_callbacl)" ...
/*
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) { zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
if ( m_interface == nullptr if ( m_interface == nullptr
@ -123,6 +124,7 @@ namespace zeus {
} }
return m_interface->m_interfaceClient->callServiceAction(ZEUS_NO_ID_CLIENT, m_interface->m_serviceId, _functionName, _args..., _callback); return m_interface->m_interfaceClient->callServiceAction(ZEUS_NO_ID_CLIENT, m_interface->m_serviceId, _functionName, _args..., _callback);
} }
*/
}; };

View File

@ -11,12 +11,13 @@
#include <zeus/BufferCtrl.hpp> #include <zeus/BufferCtrl.hpp>
ememory::SharedPtr<zeus::BufferCall> zeus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId) { ememory::SharedPtr<zeus::BufferCall> zeus::createBaseCall(uint64_t _transactionId, const uint32_t& _clientId, const uint32_t& _serviceId, const std::string& _functionName) {
ememory::SharedPtr<zeus::BufferCall> obj = zeus::BufferCall::create(); ememory::SharedPtr<zeus::BufferCall> obj = zeus::BufferCall::create();
if (obj == nullptr) { if (obj == nullptr) {
return nullptr; return nullptr;
} }
obj->setServiceId(_serviceId); obj->setServiceId(_serviceId);
obj->setClientId(_clientId);
obj->setCall(_functionName); obj->setCall(_functionName);
obj->setTransactionId(_transactionId); obj->setTransactionId(_transactionId);
return obj; return obj;
@ -318,15 +319,14 @@ void zeus::WebServer::threadAsyncCallback() {
zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId, zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId,
ememory::SharedPtr<zeus::Buffer> _obj, ememory::SharedPtr<zeus::Buffer> _obj,
zeus::FutureData::ObserverFinish _callback,
const uint32_t& _serviceId) { const uint32_t& _serviceId) {
if (isActive() == false) { if (isActive() == false) {
ZEUS_ERROR("Send [STOP] ==> not connected (no TCP)"); ZEUS_ERROR("Send [STOP] ==> not connected (no TCP)");
ememory::SharedPtr<zeus::BufferAnswer> obj = zeus::BufferAnswer::create(); ememory::SharedPtr<zeus::BufferAnswer> obj = zeus::BufferAnswer::create();
obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)"); obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)");
return zeus::FutureBase(_transactionId, obj, _callback); return zeus::FutureBase(_transactionId, obj);
} }
zeus::FutureBase tmpFuture(_transactionId, _callback); zeus::FutureBase tmpFuture(_transactionId);
{ {
std::unique_lock<std::mutex> lock(m_pendingCallMutex); std::unique_lock<std::mutex> lock(m_pendingCallMutex);
m_pendingCall.push_back(std::make_pair(uint64_t(0), tmpFuture)); m_pendingCall.push_back(std::make_pair(uint64_t(0), tmpFuture));
@ -337,20 +337,19 @@ zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId,
zeus::FutureBase zeus::WebServer::callForward(uint32_t _clientId, zeus::FutureBase zeus::WebServer::callForward(uint32_t _clientId,
ememory::SharedPtr<zeus::Buffer> _buffer, ememory::SharedPtr<zeus::Buffer> _buffer,
uint64_t _singleReferenceId, uint64_t _singleReferenceId) {
zeus::FutureData::ObserverFinish _callback) {
//zeus::FutureBase ret = callBinary(id, _Buffer, async, _callback); //zeus::FutureBase ret = callBinary(id, _Buffer, async, _callback);
//ret.setSynchronous(); //ret.setSynchronous();
if (isActive() == false) { if (isActive() == false) {
auto obj = zeus::BufferAnswer::create(); auto obj = zeus::BufferAnswer::create();
obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)"); obj->addError("NOT-CONNECTED", "Client interface not connected (no TCP)");
return zeus::FutureBase(0, obj, _callback); return zeus::FutureBase(0, obj);
} }
uint64_t id = getId(); uint64_t id = getId();
_buffer->setTransactionId(id); _buffer->setTransactionId(id);
_buffer->setClientId(_clientId); _buffer->setClientId(_clientId);
zeus::FutureBase tmpFuture(id, _callback); zeus::FutureBase tmpFuture(id);
tmpFuture.setSynchronous(); tmpFuture.setSynchronous();
{ {
std::unique_lock<std::mutex> lock(m_pendingCallMutex); std::unique_lock<std::mutex> lock(m_pendingCallMutex);
@ -381,7 +380,7 @@ void zeus::WebServer::callForwardMultiple(uint32_t _clientId,
ZEUS_ERROR("Can not transfer part of a message ..."); ZEUS_ERROR("Can not transfer part of a message ...");
} }
void zeus::WebServer::sendCtrl(const std::string& _ctrlValue, uint32_t _clientId, uint32_t _serviceId) { void zeus::WebServer::sendCtrl(uint32_t _clientId, uint32_t _serviceId, const std::string& _ctrlValue) {
auto ctrl = zeus::BufferCtrl::create(); auto ctrl = zeus::BufferCtrl::create();
if (ctrl == nullptr) { if (ctrl == nullptr) {
return; return;
@ -393,7 +392,7 @@ void zeus::WebServer::sendCtrl(const std::string& _ctrlValue, uint32_t _clientId
writeBinary(ctrl); writeBinary(ctrl);
} }
void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId, uint32_t _serviceId) { void zeus::WebServer::answerError(uint64_t _clientTransactionId, uint32_t _clientId, uint32_t _serviceId, const std::string& _errorValue, const std::string& _errorHelp) {
auto answer = zeus::BufferAnswer::create(); auto answer = zeus::BufferAnswer::create();
if (answer == nullptr) { if (answer == nullptr) {
return; return;

View File

@ -22,7 +22,7 @@ namespace zeus {
* @param[in] * @param[in]
* @return * @return
*/ */
ememory::SharedPtr<zeus::BufferCall> createBaseCall(uint64_t _transactionId, const std::string& _functionName, const uint32_t& _serviceId=0); ememory::SharedPtr<zeus::BufferCall> createBaseCall(uint64_t _transactionId, const uint32_t& _clientId, const uint32_t& _serviceId, const std::string& _functionName);
/** /**
* @brief * @brief
* @param[in] * @param[in]
@ -58,29 +58,14 @@ namespace zeus {
_ARGS&&... _args) { _ARGS&&... _args) {
createParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...); createParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...);
} }
/** /**
* @brief * @brief
* @param[in] * @param[in]
* @return * @return
*/ */
template<class... _ARGS> template<class... _ARGS>
ememory::SharedPtr<zeus::BufferCall> createCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) { ememory::SharedPtr<zeus::BufferCall> createCall(uint64_t _transactionId, const uint32_t& _clientId, const uint32_t& _serviceId, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::BufferCall> callElem = createBaseCall(_transactionId, _functionName); ememory::SharedPtr<zeus::BufferCall> callElem = createBaseCall(_transactionId, _clientId, _serviceId, _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::BufferCall> createCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) {
ememory::SharedPtr<zeus::BufferCall> callElem = createBaseCall(_transactionId, _functionName, _serviceName);
if (callElem == nullptr) { if (callElem == nullptr) {
return nullptr; return nullptr;
} }
@ -260,82 +245,20 @@ namespace zeus {
*/ */
zeus::FutureBase callBinary(uint64_t _transactionId, zeus::FutureBase callBinary(uint64_t _transactionId,
ememory::SharedPtr<zeus::Buffer> _obj, ememory::SharedPtr<zeus::Buffer> _obj,
zeus::FutureData::ObserverFinish _callback=nullptr,
const uint32_t& _service=0); const uint32_t& _service=0);
public: // section call direct public:
/** /**
* @brief * @brief
* @param[in] * @param[in]
* @return * @return
*/ */
template<class... _ARGS> template<class... _ARGS>
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { zeus::FutureBase call(const uint32_t& _clientId, const uint32_t& _serviceId, const std::string& _functionName, _ARGS&&... _args) {
uint16_t id = getId(); uint16_t id = getId();
ememory::SharedPtr<zeus::BufferCall> callElem = zeus::createCall(id, _functionName, std::forward<_ARGS>(_args)...); ememory::SharedPtr<zeus::BufferCall> callElem = zeus::createCall(id, _clientId, _serviceId, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem); return callBinary(id, callElem);
} }
/** public:
* @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::BufferCall> 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 _clientId, uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args) {
uint16_t id = getId();
ememory::SharedPtr<zeus::BufferCall> callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...);
return callBinary(id, callElem);
}
/**
* @brief
* @param[in]
* @return
*/
// TODO: Remove the callback to add it in future with the "then(_callback)" and "else(_callback)" and "abort(_callbacl)" ...
template<class... _ARGS>
zeus::FutureBase callServiceAction(uint32_t _clientId, uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
uint16_t id = getId();
ememory::SharedPtr<zeus::BufferCall> 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,
uint32_t _serviceId,
const std::string& _functionName,
_ARGS&&... _args) {
return callService(_clientId, _serviceId, _functionName, _args...);
}
/**
* @brief
* @param[in]
* @return
*/
// TODO: Remove the callback to add it in future with the "then(_callback)" and "else(_callback)" and "abort(_callbacl)" ...
template<class... _ARGS>
zeus::FutureBase callClientAction(uint32_t _clientId,
uint32_t _serviceId,
const std::string& _functionName,
_ARGS&&... _args,
zeus::FutureData::ObserverFinish _callback) {
return callServiceAction(_clientId, _serviceId, _functionName, _args..., _callback);
}
/** /**
* @brief * @brief
* @param[in] * @param[in]
@ -343,8 +266,7 @@ namespace zeus {
*/ */
zeus::FutureBase callForward(uint32_t _clientId, zeus::FutureBase callForward(uint32_t _clientId,
ememory::SharedPtr<zeus::Buffer> _Buffer, ememory::SharedPtr<zeus::Buffer> _Buffer,
uint64_t _singleReferenceId, uint64_t _singleReferenceId);
zeus::FutureData::ObserverFinish _callback);
/** /**
* @brief * @brief
* @param[in] * @param[in]
@ -368,7 +290,7 @@ namespace zeus {
* @param[in] _clientId Client to send control * @param[in] _clientId Client to send control
*/ */
template<class ZEUS_ARG> template<class ZEUS_ARG>
void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0, uint32_t _serviceId=0) { void answerValue(uint64_t _clientTransactionId, uint32_t _clientId, uint32_t _serviceId, ZEUS_ARG _value) {
ememory::SharedPtr<zeus::BufferAnswer> answer = zeus::BufferAnswer::create(); ememory::SharedPtr<zeus::BufferAnswer> answer = zeus::BufferAnswer::create();
answer->setTransactionId(_clientTransactionId); answer->setTransactionId(_clientTransactionId);
answer->setClientId(_clientId); answer->setClientId(_clientId);
@ -380,7 +302,7 @@ namespace zeus {
* @param[in] _clientTransactionId Transaction ID * @param[in] _clientTransactionId Transaction ID
* @param[in] _clientId Client to send control * @param[in] _clientId Client to send control
*/ */
void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId=0, uint32_t _serviceId=0); void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId, uint32_t _serviceId);
/** /**
* @brief Send an Answer error of a function * @brief Send an Answer error of a function
* @param[in] _clientTransactionId Transaction ID * @param[in] _clientTransactionId Transaction ID
@ -388,7 +310,7 @@ namespace zeus {
* @param[in] _errorComment Help comment of the error * @param[in] _errorComment Help comment of the error
* @param[in] _clientId Client to send control * @param[in] _clientId Client to send control
*/ */
void answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorComment="", uint32_t _clientId=0, uint32_t _serviceId=0); void answerError(uint64_t _clientTransactionId, uint32_t _clientId, uint32_t _serviceId, const std::string& _errorValue, const std::string& _errorComment="");
/** /**
* @brief Send a control on the Interface * @brief Send a control on the Interface
* @param[in] _clientTransactionId Transaction ID * @param[in] _clientTransactionId Transaction ID
@ -396,7 +318,7 @@ namespace zeus {
* @param[in] _clientId Client to send control * @param[in] _clientId Client to send control
* @return * @return
*/ */
void sendCtrl(const std::string& _ctrlValue, uint32_t _clientId, uint32_t _serviceId=0); void sendCtrl(uint32_t _clientId, uint32_t _serviceId, const std::string& _ctrlValue);
}; };
} }