[DEV] Work is back but no transfer of files with IDL ==> need to add it ...
This commit is contained in:
parent
fac9c55b9e
commit
9f4872ba7b
@ -67,7 +67,6 @@ void appl::GateWay::newService(enet::Tcp _connection) {
|
||||
}
|
||||
|
||||
appl::GateWay::GateWay() :
|
||||
m_clientUID(1),
|
||||
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),
|
||||
propertyRouterPort(this, "router-port", 1984, "Port to listen client", &appl::GateWay::onPropertyChangeClientPort),
|
||||
|
@ -11,13 +11,11 @@
|
||||
namespace appl {
|
||||
class TcpServerInput;
|
||||
class GateWay : public eproperty::Interface {
|
||||
private:
|
||||
uint64_t m_clientUID;
|
||||
private:
|
||||
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::TcpServerInput> m_interfaceNewService;
|
||||
|
||||
public:
|
||||
eproperty::Value<std::string> propertyUserName;
|
||||
eproperty::Value<std::string> propertyRouterIp;
|
||||
|
@ -16,6 +16,7 @@
|
||||
static const std::string protocolError = "PROTOCOL-ERROR";
|
||||
|
||||
appl::userSpecificInterface::userSpecificInterface(const std::string& _userName) {
|
||||
m_routeurUID = 0;
|
||||
m_uid = 0;
|
||||
m_localIdUser = 0;
|
||||
m_userConnectionName = _userName;
|
||||
@ -32,14 +33,15 @@ appl::userSpecificInterface::~userSpecificInterface() {
|
||||
}
|
||||
|
||||
void appl::userSpecificInterface::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
|
||||
m_interfaceRouterClient->answerError(_transactionId, protocolError, _errorHelp);
|
||||
m_interfaceRouterClient->sendCtrl("DISCONNECT", m_uid);
|
||||
m_interfaceRouterClient->answerError(_transactionId, m_routeurUID, ZEUS_ID_SERVICE_ROOT, protocolError, _errorHelp);
|
||||
m_interfaceRouterClient->sendCtrl(m_routeurUID, ZEUS_ID_SERVICE_ROOT, "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_gatewayInterface = _gatewayInterface;
|
||||
m_routeurUID = _routerId;
|
||||
m_uid = _id;
|
||||
m_localIdUser = _id+1;
|
||||
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'");
|
||||
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 ...
|
||||
if (futLocalService.get() == false) {
|
||||
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--;
|
||||
if (serviceId >= m_listConnectedService.size()) {
|
||||
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE");
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
|
||||
return;
|
||||
}
|
||||
if (m_listConnectedService[serviceId] == nullptr) {
|
||||
@ -146,15 +148,15 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
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 ...
|
||||
if (fut.hasError() == true) {
|
||||
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");
|
||||
return;
|
||||
} else if (fut.get() == false) {
|
||||
m_interfaceRouterClient->answerValue(transactionId, false);
|
||||
m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
|
||||
answerProtocolError(transactionId, "connection refused 2");
|
||||
return;
|
||||
}
|
||||
@ -162,15 +164,15 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
}
|
||||
if (callFunction == "auth") {
|
||||
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 ...
|
||||
if (fut.hasError() == true) {
|
||||
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");
|
||||
return;
|
||||
} else if (fut.get() == false) {
|
||||
m_interfaceRouterClient->answerValue(transactionId, false);
|
||||
m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), false);
|
||||
answerProtocolError(transactionId, "connection refused 2");
|
||||
return;
|
||||
}
|
||||
@ -182,11 +184,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
// --------------------------------
|
||||
// -- 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 ...
|
||||
if (futGroup.hasError() == true) {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
@ -195,11 +197,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
// -- Get services:
|
||||
// --------------------------------
|
||||
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 ...
|
||||
if (futServices.hasError() == true) {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
@ -209,7 +211,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
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;
|
||||
return;
|
||||
}
|
||||
@ -221,11 +223,11 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
if (serviceId == 0) {
|
||||
// This is 2 default service for the cient interface that manage the authorisation of view:
|
||||
if (callFunction == "getServiceCount") {
|
||||
m_interfaceRouterClient->answerValue(transactionId, m_clientServices.size(), m_uid);
|
||||
m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), m_clientServices.size());
|
||||
return;
|
||||
}
|
||||
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"
|
||||
return;
|
||||
}
|
||||
@ -249,27 +251,27 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
if (it == m_listConnectedService.end()) {
|
||||
// check if service is connectable ...
|
||||
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;
|
||||
}
|
||||
ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName);
|
||||
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 ...
|
||||
if (futLink.hasError() == true) {
|
||||
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;
|
||||
}
|
||||
m_listConnectedService.push_back(srv);
|
||||
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;
|
||||
}
|
||||
m_interfaceRouterClient->answerError(transactionId, "CAN-NOT-CONNECT-SERVICE");
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "CAN-NOT-CONNECT-SERVICE");
|
||||
return;
|
||||
}
|
||||
m_interfaceRouterClient->answerError(transactionId, "SERVICE-ALREADY-CONNECTED");;
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "SERVICE-ALREADY-CONNECTED");;
|
||||
return;
|
||||
}
|
||||
if (callFunction == "unlink") {
|
||||
@ -278,28 +280,28 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
int64_t localServiceID = callObj->getParameter<int64_t>(0)-1;
|
||||
// Check if service already link:
|
||||
if (localServiceID >= m_listConnectedService.size()) {
|
||||
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE");
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
|
||||
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 ...
|
||||
if (futUnLink.hasError() == true) {
|
||||
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;
|
||||
}
|
||||
m_listConnectedService[localServiceID] = nullptr;
|
||||
m_interfaceRouterClient->answerValue(transactionId, true);
|
||||
m_interfaceRouterClient->answerValue(transactionId, _value->getClientId(), _value->getServiceId(), true);
|
||||
return;
|
||||
}
|
||||
APPL_ERROR("Function does not exist ... '" << callFunction << "'");
|
||||
m_interfaceRouterClient->answerError(transactionId, "CALL-UNEXISTING");
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "CALL-UNEXISTING");
|
||||
return;
|
||||
}
|
||||
// decrease service ID ...
|
||||
serviceId -= 1;
|
||||
if (serviceId >= m_listConnectedService.size()) {
|
||||
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE");
|
||||
m_interfaceRouterClient->answerError(transactionId, _value->getClientId(), _value->getServiceId(), "NOT-CONNECTED-SERVICE");
|
||||
return;
|
||||
} else {
|
||||
if (m_listConnectedService[serviceId] == nullptr) {
|
||||
@ -307,24 +309,22 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
APPL_ERROR("TODO : Manage this case ...");
|
||||
return;
|
||||
}
|
||||
m_listConnectedService[serviceId]->m_interfaceClient.callForward(
|
||||
m_uid,
|
||||
_value,
|
||||
(uint64_t(m_uid) << 32) + uint64_t(transactionId),
|
||||
[=](zeus::FutureBase _ret) {
|
||||
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
|
||||
if (tmpp == nullptr) {
|
||||
return true;
|
||||
}
|
||||
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
|
||||
APPL_DEBUG(" msg=" << tmpp);
|
||||
tmpp->setTransactionId(transactionId);
|
||||
tmpp->setServiceId(serviceId+1);
|
||||
APPL_DEBUG("transmit=" << tmpp);
|
||||
m_interfaceRouterClient->writeBinary(tmpp);
|
||||
// multiple send element ...
|
||||
return tmpp->getPartFinish();
|
||||
});
|
||||
auto fut = m_listConnectedService[serviceId]->m_interfaceClient.callForward(m_uid, _value, (uint64_t(m_uid) << 32) + uint64_t(transactionId));
|
||||
fut.andAll([=](zeus::FutureBase _ret) {
|
||||
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
|
||||
if (tmpp == nullptr) {
|
||||
return true;
|
||||
}
|
||||
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
|
||||
APPL_DEBUG(" msg=" << tmpp);
|
||||
tmpp->setTransactionId(transactionId);
|
||||
tmpp->setClientId(m_routeurUID);
|
||||
tmpp->setServiceId(serviceId+1);
|
||||
APPL_DEBUG("transmit=" << tmpp);
|
||||
m_interfaceRouterClient->writeBinary(tmpp);
|
||||
// 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) :
|
||||
m_clientUID(1),
|
||||
m_state(appl::clientState::unconnect),
|
||||
m_gatewayInterface(_gatewayInterface),
|
||||
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);
|
||||
int64_t localId = -1;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@ -402,7 +403,8 @@ void appl::RouterInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
|
||||
if (localId == -1) {
|
||||
m_listUser.push_back(userSpecificInterface(m_userConnectionName));
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
@ -21,8 +21,11 @@ namespace appl {
|
||||
public:
|
||||
zeus::WebServer* m_interfaceRouterClient;
|
||||
appl::GateWay* m_gatewayInterface;
|
||||
uint64_t m_routeurUID;
|
||||
private:
|
||||
uint64_t m_uid;
|
||||
uint64_t m_localIdUser;
|
||||
public:
|
||||
enum clientState m_state; // state machine ...
|
||||
std::vector<ememory::SharedPtr<appl::ServiceInterface>> m_listConnectedService;
|
||||
ememory::SharedPtr<appl::ServiceInterface> m_userService;
|
||||
@ -32,7 +35,7 @@ namespace appl {
|
||||
std::vector<std::string> m_clientServices;
|
||||
userSpecificInterface(const std::string& _userName);
|
||||
~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 returnMessage(ememory::SharedPtr<zeus::Buffer> _data);
|
||||
bool checkId(uint64_t _id) const {
|
||||
@ -42,6 +45,8 @@ namespace appl {
|
||||
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
|
||||
};
|
||||
class RouterInterface {
|
||||
private:
|
||||
uint32_t m_clientUID;
|
||||
private:
|
||||
enum clientState m_state; // state machine ..
|
||||
std::vector<userSpecificInterface> m_listUser;
|
||||
|
@ -107,7 +107,7 @@ void appl::ServiceInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
|
||||
ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_value);
|
||||
std::string callFunction = callObj->getCall();
|
||||
if (callFunction == "getUserName") {
|
||||
m_interfaceClient.answerValue(transactionId, *m_gatewayInterface->propertyUserName);
|
||||
m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), *m_gatewayInterface->propertyUserName);
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp);
|
||||
m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
|
||||
m_interfaceClient.disconnect(true);
|
||||
}
|
@ -77,7 +77,7 @@ bool appl::ClientInterface::isAlive() {
|
||||
}
|
||||
|
||||
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_interfaceClient.disconnect(true);
|
||||
}
|
||||
@ -94,6 +94,11 @@ void appl::ClientInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
|
||||
answerProtocolError(transactionId, "missing parameter: 'id'");
|
||||
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
|
||||
if (m_userGateWay == nullptr) {
|
||||
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 ...
|
||||
if (_value->getType() != zeus::Buffer::typeMessage::data) {
|
||||
m_userGateWay->m_interfaceClient.callForward(
|
||||
m_uid,
|
||||
_value,
|
||||
(uint64_t(m_uid) << 32) + uint64_t(transactionId),
|
||||
[=](zeus::FutureBase _ret) {
|
||||
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
|
||||
if (tmpp == nullptr) {
|
||||
return true;
|
||||
}
|
||||
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
|
||||
APPL_DEBUG(" msg=" << tmpp);
|
||||
tmpp->setTransactionId(transactionId);
|
||||
//tmpp->setServiceId(serviceId+1);
|
||||
APPL_DEBUG("transmit=" << tmpp);
|
||||
m_interfaceClient.writeBinary(tmpp);
|
||||
// multiple send element ...
|
||||
return tmpp->getPartFinish();
|
||||
});
|
||||
auto fut = m_userGateWay->m_interfaceClient.callForward(m_uid, _value, (uint64_t(m_uid) << 32) + uint64_t(transactionId));
|
||||
fut.andAll([=](zeus::FutureBase _ret) {
|
||||
ememory::SharedPtr<zeus::Buffer> tmpp = _ret.getRaw();
|
||||
if (tmpp == nullptr) {
|
||||
return true;
|
||||
}
|
||||
APPL_DEBUG(" ==> transmit : " << tmpp->getTransactionId() << " -> " << transactionId);
|
||||
APPL_DEBUG(" msg=" << tmpp);
|
||||
tmpp->setTransactionId(transactionId);
|
||||
tmpp->setClientId(0);
|
||||
APPL_DEBUG("transmit=" << tmpp);
|
||||
m_interfaceClient.writeBinary(tmpp);
|
||||
// multiple send element ...
|
||||
return tmpp->getPartFinish();
|
||||
});
|
||||
} else {
|
||||
// simply forward messages to the user gateWay ...
|
||||
m_userGateWay->m_interfaceClient.callForwardMultiple(
|
||||
|
@ -25,11 +25,7 @@ namespace appl {
|
||||
bool requestURI(const std::string& _uri);
|
||||
public:
|
||||
ememory::SharedPtr<appl::GateWayInterface> m_userGateWay;
|
||||
uint64_t m_uid;
|
||||
std::string m_userConnectionName;
|
||||
std::string m_clientName;
|
||||
std::vector<std::string> m_clientgroups;
|
||||
std::vector<std::string> m_clientServices;
|
||||
uint64_t m_uid; //!< gateway unique ID ==> to have an internal routage ...
|
||||
public:
|
||||
ClientInterface(enet::Tcp _connection, appl::Router* _routerInterface);
|
||||
virtual ~ClientInterface();
|
||||
|
@ -108,12 +108,12 @@ void appl::GateWayInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
|
||||
if (callFunction == "connect-service") {
|
||||
if (m_name != "") {
|
||||
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;
|
||||
}
|
||||
m_name = callObj->getParameter<std::string>(0);
|
||||
m_interfaceClient.setInterfaceName("srv-" + m_name);
|
||||
m_interfaceClient.answerValue(transactionId, true);
|
||||
m_interfaceClient.answerValue(transactionId, _value->getClientId(), _value->getServiceId(), true);
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
m_interfaceClient.answerError(_transactionId, protocolError, _errorHelp);
|
||||
m_interfaceClient.answerError(_transactionId, 0, 0, protocolError, _errorHelp);
|
||||
m_interfaceClient.disconnect(true);
|
||||
}
|
@ -76,7 +76,7 @@ void appl::Router::newClient(enet::Tcp _connection) {
|
||||
ZEUS_WARNING("New TCP connection (client)");
|
||||
ememory::SharedPtr<appl::ClientInterface> tmp = ememory::makeShared<appl::ClientInterface>(std::move(_connection), this);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace zeus {
|
||||
ret = (*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
|
||||
}
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
|
||||
_interface->answerValue(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), ret);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -67,7 +67,7 @@ namespace zeus {
|
||||
(*_pointer.*_func)(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
|
||||
}
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -122,18 +122,20 @@ namespace zeus {
|
||||
help += " parameters. prototype function:";
|
||||
help += getPrototype();
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
_obj->getClientId(),
|
||||
_obj->getServiceId(),
|
||||
"WRONG-PARAMETER-NUMBER",
|
||||
help,
|
||||
_obj->getClientId());
|
||||
help);
|
||||
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(_obj->getTransactionId(),
|
||||
_obj->getClientId(),
|
||||
_obj->getServiceId(),
|
||||
"WRONG-PARAMETER-TYPE",
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
|
||||
_obj->getClientId());
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace zeus {
|
||||
ret = _func(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
|
||||
}
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId());
|
||||
_interface->answerValue(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), ret);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace zeus {
|
||||
_func(_obj->getParameter<ZEUS_TYPES>(idParam--)...);
|
||||
}
|
||||
_interfaceClient->addAsync([=](WebServer* _interface) {
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId());
|
||||
_interface->answerVoid(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -110,18 +110,20 @@ namespace zeus {
|
||||
help += " parameters. prototype function:";
|
||||
help += getPrototype();
|
||||
_interfaceClient->answerError(_obj->getTransactionId(),
|
||||
_obj->getClientId(),
|
||||
_obj->getServiceId(),
|
||||
"WRONG-PARAMETER-NUMBER",
|
||||
help,
|
||||
_obj->getClientId());
|
||||
help);
|
||||
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(_obj->getTransactionId(),
|
||||
_obj->getClientId(),
|
||||
_obj->getServiceId(),
|
||||
"WRONG-PARAMETER-TYPE",
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'",
|
||||
_obj->getClientId());
|
||||
std::string("Parameter id ") + etk::to_string(iii) + " not compatible with type: '" + m_paramType[iii].getName() + "'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace zeus {
|
||||
void onClientData(ememory::SharedPtr<zeus::Buffer> _value);
|
||||
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] _args... multiple argument neededs
|
||||
* @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");
|
||||
return zeus::FutureBase(0, ret);
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
return m_interfaceClient->call(ZEUS_NO_ID_CLIENT, ZEUS_ID_SERVICE_ROOT, _functionName, _args...);
|
||||
}
|
||||
private:
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ zeus::FutureBase::FutureBase() {
|
||||
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>();
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
@ -26,7 +26,7 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, zeus::FutureData::Observer
|
||||
m_data->m_transactionId = _transactionId;
|
||||
m_data->m_clientId = _clientId;
|
||||
m_data->m_isSynchronous = false;
|
||||
m_data->m_callbackFinish = _callback;
|
||||
//m_data->m_callbackFinish = _callback;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() {
|
||||
@ -36,7 +36,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::FutureBase::getRaw() {
|
||||
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>();
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
@ -46,6 +46,7 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::B
|
||||
m_data->m_clientId = _clientId;
|
||||
m_data->m_isSynchronous = false;
|
||||
m_data->m_returnData = _returnData;
|
||||
#if 0
|
||||
m_data->m_callbackFinish = _callback;
|
||||
if (isFinished() == true) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
#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 {
|
||||
if (m_data == nullptr) {
|
||||
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();
|
||||
if (m_data->m_isSynchronous == true) {
|
||||
m_data->m_returnData = _value;
|
||||
if (m_data->m_callbackFinish != nullptr) {
|
||||
return m_data->m_callbackFinish(*this);
|
||||
if (hasError() == false) {
|
||||
if (m_data->m_callbackThen != nullptr) {
|
||||
return m_data->m_callbackThen(*this);
|
||||
}
|
||||
} else {
|
||||
if (m_data->m_callbackElse != nullptr) {
|
||||
return m_data->m_callbackElse(*this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -93,8 +164,14 @@ bool zeus::FutureBase::appendData(ememory::SharedPtr<zeus::Buffer> _value) {
|
||||
return true;
|
||||
}
|
||||
if (m_data->m_returnData->getPartFinish() == true) {
|
||||
if (m_data->m_callbackFinish != nullptr) {
|
||||
return m_data->m_callbackFinish(*this);
|
||||
if (hasError() == false) {
|
||||
if (m_data->m_callbackThen != nullptr) {
|
||||
return m_data->m_callbackThen(*this);
|
||||
}
|
||||
} else {
|
||||
if (m_data->m_callbackElse != nullptr) {
|
||||
return m_data->m_callbackElse(*this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -27,24 +27,38 @@ namespace zeus {
|
||||
/**
|
||||
* @brief Contructor of the FutureBase with an ofserver
|
||||
* @param[in] _transactionId Transaction waiting answer
|
||||
* @param[in] _callback Observer pointer
|
||||
* @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
|
||||
* @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
|
||||
* @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);
|
||||
// TODO: Add this to have generic nec C++ interface:
|
||||
FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::Buffer> _returnData, uint32_t _clientId=0);
|
||||
/**
|
||||
* @brief Attach callback on all return type of value
|
||||
* @param[in] _callback Handle on the function to call in all case
|
||||
*/
|
||||
void andAll(zeus::FutureData::Observer _callback);
|
||||
/**
|
||||
* @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
|
||||
void andAbort(zeus::FutureData::ObserverFinish _callback); // an abort is requested in the actiron ...
|
||||
/ **
|
||||
* @brief Attach callback on a specific return action (ABORT)
|
||||
* @param[in] _callback Handle on the function to call in case of abort on the call
|
||||
* /
|
||||
void andAbort(zeus::FutureData::Observer _callback); // an abort is requested in the actiron ...
|
||||
*/
|
||||
/**
|
||||
* @brief Asignement operator with an other future
|
||||
|
@ -18,13 +18,16 @@ namespace zeus {
|
||||
*/
|
||||
class FutureData {
|
||||
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:
|
||||
uint32_t m_transactionId; //!< waiting answer data
|
||||
uint32_t m_clientId; //!< need to anser at this client.
|
||||
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
|
||||
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_receiveTime; //!< time when the future has receve answer
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ void zeus::Service::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
|
||||
return;
|
||||
}
|
||||
ZEUS_WARNING("direct call");
|
||||
zeus::FutureBase futData(tmpID, _value, nullptr, clientId);
|
||||
zeus::FutureBase futData(tmpID, _value, clientId);
|
||||
if (futData.isFinished() == true) {
|
||||
ZEUS_INFO("Call Binary ..");
|
||||
callBinary(futData.getRaw());
|
||||
@ -102,7 +102,7 @@ bool zeus::Service::connect(uint32_t _numberRetry){
|
||||
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();
|
||||
m_nameUser = ret.get();
|
||||
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") {
|
||||
clientDisconnect(clientId);
|
||||
}
|
||||
m_interfaceClient->answerValue(callObj->getTransactionId(), true, clientId);
|
||||
m_interfaceClient->answerValue(callObj->getTransactionId(), clientId, m_id, true);
|
||||
return;
|
||||
} else if (isFunctionAuthorized(clientId, callFunction) == true) {
|
||||
ZEUS_INFO("plop 6 ...");
|
||||
@ -174,7 +174,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
||||
return;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +191,6 @@ namespace zeus {
|
||||
* @return
|
||||
*/
|
||||
virtual void clientDisconnect(uint64_t _clientId) = 0;
|
||||
// Genenric function call:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -380,7 +379,7 @@ namespace zeus {
|
||||
void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj) {
|
||||
auto it = m_interface.find(_obj->getClientId());
|
||||
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;
|
||||
}
|
||||
for (auto &it2 : m_listFunction) {
|
||||
@ -413,7 +412,7 @@ namespace zeus {
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_interfaceClient->answerError(_obj->getTransactionId(), "FUNCTION-UNKNOW", "", _obj->getClientId());
|
||||
m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getClientId(), _obj->getServiceId(), "FUNCTION-UNKNOW", "");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -16,7 +16,7 @@ zeus::ServiceRemoteBase::ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _
|
||||
return;
|
||||
}
|
||||
// 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();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not link with the service named: '" << _name << "' ==> link error");
|
||||
@ -31,7 +31,7 @@ zeus::ServiceRemoteBase::~ServiceRemoteBase() {
|
||||
uint32_t tmpLocalService = m_serviceId;
|
||||
// little hack : Call the service manager with the service ID=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();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not unlink with the service id: '" << tmpLocalService << "' ==> link error");
|
||||
|
@ -103,7 +103,7 @@ namespace zeus {
|
||||
}
|
||||
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
|
||||
@ -111,6 +111,7 @@ namespace zeus {
|
||||
* @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 callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
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);
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
@ -11,12 +11,13 @@
|
||||
#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();
|
||||
if (obj == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
obj->setServiceId(_serviceId);
|
||||
obj->setClientId(_clientId);
|
||||
obj->setCall(_functionName);
|
||||
obj->setTransactionId(_transactionId);
|
||||
return obj;
|
||||
@ -318,15 +319,14 @@ void zeus::WebServer::threadAsyncCallback() {
|
||||
|
||||
zeus::FutureBase zeus::WebServer::callBinary(uint64_t _transactionId,
|
||||
ememory::SharedPtr<zeus::Buffer> _obj,
|
||||
zeus::FutureData::ObserverFinish _callback,
|
||||
const uint32_t& _serviceId) {
|
||||
if (isActive() == false) {
|
||||
ZEUS_ERROR("Send [STOP] ==> not connected (no TCP)");
|
||||
ememory::SharedPtr<zeus::BufferAnswer> obj = zeus::BufferAnswer::create();
|
||||
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);
|
||||
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,
|
||||
ememory::SharedPtr<zeus::Buffer> _buffer,
|
||||
uint64_t _singleReferenceId,
|
||||
zeus::FutureData::ObserverFinish _callback) {
|
||||
uint64_t _singleReferenceId) {
|
||||
//zeus::FutureBase ret = callBinary(id, _Buffer, async, _callback);
|
||||
//ret.setSynchronous();
|
||||
|
||||
if (isActive() == false) {
|
||||
auto obj = zeus::BufferAnswer::create();
|
||||
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();
|
||||
_buffer->setTransactionId(id);
|
||||
_buffer->setClientId(_clientId);
|
||||
zeus::FutureBase tmpFuture(id, _callback);
|
||||
zeus::FutureBase tmpFuture(id);
|
||||
tmpFuture.setSynchronous();
|
||||
{
|
||||
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 ...");
|
||||
}
|
||||
|
||||
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();
|
||||
if (ctrl == nullptr) {
|
||||
return;
|
||||
@ -393,7 +392,7 @@ void zeus::WebServer::sendCtrl(const std::string& _ctrlValue, uint32_t _clientId
|
||||
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();
|
||||
if (answer == nullptr) {
|
||||
return;
|
||||
|
@ -22,7 +22,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @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
|
||||
* @param[in]
|
||||
@ -58,29 +58,14 @@ namespace zeus {
|
||||
_ARGS&&... _args) {
|
||||
createParam(_paramId, _obj, std::string(_param), std::forward<_ARGS>(_args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
ememory::SharedPtr<zeus::BufferCall> createCall(uint64_t _transactionId, const std::string& _functionName, _ARGS&&... _args) {
|
||||
ememory::SharedPtr<zeus::BufferCall> 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::BufferCall> createCallService(uint64_t _transactionId, const uint32_t& _serviceName, const std::string& _functionName, _ARGS&&... _args) {
|
||||
ememory::SharedPtr<zeus::BufferCall> callElem = createBaseCall(_transactionId, _functionName, _serviceName);
|
||||
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, _clientId, _serviceId, _functionName);
|
||||
if (callElem == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -260,82 +245,20 @@ namespace zeus {
|
||||
*/
|
||||
zeus::FutureBase callBinary(uint64_t _transactionId,
|
||||
ememory::SharedPtr<zeus::Buffer> _obj,
|
||||
zeus::FutureData::ObserverFinish _callback=nullptr,
|
||||
const uint32_t& _service=0);
|
||||
public: // section call direct
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
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();
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -343,8 +266,7 @@ namespace zeus {
|
||||
*/
|
||||
zeus::FutureBase callForward(uint32_t _clientId,
|
||||
ememory::SharedPtr<zeus::Buffer> _Buffer,
|
||||
uint64_t _singleReferenceId,
|
||||
zeus::FutureData::ObserverFinish _callback);
|
||||
uint64_t _singleReferenceId);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -368,7 +290,7 @@ namespace zeus {
|
||||
* @param[in] _clientId Client to send control
|
||||
*/
|
||||
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();
|
||||
answer->setTransactionId(_clientTransactionId);
|
||||
answer->setClientId(_clientId);
|
||||
@ -380,7 +302,7 @@ namespace zeus {
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
* @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
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
@ -388,7 +310,7 @@ namespace zeus {
|
||||
* @param[in] _errorComment Help comment of the error
|
||||
* @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
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
@ -396,7 +318,7 @@ namespace zeus {
|
||||
* @param[in] _clientId Client to send control
|
||||
* @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);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user