[DEV] continue refactor PB with object return
This commit is contained in:
parent
fa38f8d637
commit
b13a79fe5d
@ -8,8 +8,15 @@
|
|||||||
#include <zeus/Client.hpp>
|
#include <zeus/Client.hpp>
|
||||||
#include <zeus/debug.hpp>
|
#include <zeus/debug.hpp>
|
||||||
|
|
||||||
|
static const std::string protocolError = "PROTOCOL-ERROR";
|
||||||
|
|
||||||
|
|
||||||
|
void zeus::Client::answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp) {
|
||||||
|
m_interfaceWeb->answerError(_transactionId, 0, ZEUS_ID_SERVICE_ROOT, protocolError, _errorHelp);
|
||||||
|
m_interfaceWeb->disconnect();
|
||||||
|
ZEUS_TODO("Do this error return ... " << _errorHelp);
|
||||||
|
}
|
||||||
|
|
||||||
zeus::Client::Client() :
|
zeus::Client::Client() :
|
||||||
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Client::onPropertyChangeIp),
|
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Client::onPropertyChangeIp),
|
||||||
propertyPort(this, "port", 1983, "Port to connect server", &zeus::Client::onPropertyChangePort),
|
propertyPort(this, "port", 1983, "Port to connect server", &zeus::Client::onPropertyChangePort),
|
||||||
@ -44,13 +51,13 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
|
|||||||
//APPL_ERROR(" ==> parse DATA ...");
|
//APPL_ERROR(" ==> parse DATA ...");
|
||||||
uint32_t transactionId = _value->getTransactionId();
|
uint32_t transactionId = _value->getTransactionId();
|
||||||
if (transactionId == 0) {
|
if (transactionId == 0) {
|
||||||
APPL_ERROR("Protocol error ==>missing id");
|
ZEUS_ERROR("Protocol error ==>missing id");
|
||||||
answerProtocolError(transactionId, "missing parameter: 'id'");
|
answerProtocolError(transactionId, "missing parameter: 'id'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if we are the destinated Of this message
|
// Check if we are the destinated Of this message
|
||||||
if (_value->getDestinationId() != m_localAddress) {
|
if (_value->getDestinationId() != m_localAddress) {
|
||||||
APPL_ERROR("Protocol error ==> Wrong ID of the interface " << _value->getDestinationId() << " != " << m_localAddress);
|
ZEUS_ERROR("Protocol error ==> Wrong ID of the interface " << _value->getDestinationId() << " != " << m_localAddress);
|
||||||
answerProtocolError(transactionId, "wrong adress: request " + etk::to_string(m_localAddress) + " have " + etk::to_string(m_localAddress));
|
answerProtocolError(transactionId, "wrong adress: request " + etk::to_string(m_localAddress) + " have " + etk::to_string(m_localAddress));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -103,7 +110,7 @@ bool zeus::Client::serviceAdd(const std::string& _serviceName, factoryService _f
|
|||||||
ZEUS_ERROR("Can not provide a new sevice ... '" << futValidate.getErrorType() << "' help:" << futValidate.getErrorHelp());
|
ZEUS_ERROR("Can not provide a new sevice ... '" << futValidate.getErrorType() << "' help:" << futValidate.getErrorHelp());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_listServicesAvaillable.add(std::make_pair(_serviceName, _factory));
|
m_listServicesAvaillable.insert(std::make_pair(_serviceName, _factory));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ namespace zeus {
|
|||||||
std::vector<ememory::SharedPtr<zeus::Service>> m_listProvicedService; //!< Connect only one time on each service, not needed more.
|
std::vector<ememory::SharedPtr<zeus::Service>> m_listProvicedService; //!< Connect only one time on each service, not needed more.
|
||||||
std::vector<ememory::SharedPtr<zeus::Object>> m_listLocalObject;
|
std::vector<ememory::SharedPtr<zeus::Object>> m_listLocalObject;
|
||||||
public:
|
public:
|
||||||
|
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param[in]
|
* @param[in]
|
||||||
@ -86,7 +87,7 @@ namespace zeus {
|
|||||||
* @return Pointer on an interface of remote service
|
* @return Pointer on an interface of remote service
|
||||||
*/
|
*/
|
||||||
zeus::ServiceRemote getService(const std::string& _serviceName);
|
zeus::ServiceRemote getService(const std::string& _serviceName);
|
||||||
using factoryService = std::function<ememory::SharedPtr<zeus::Object>, zeus::Client&, uint16_t objId)>;
|
using factoryService = std::function<ememory::SharedPtr<zeus::Object>(zeus::Client&, uint16_t)>;
|
||||||
|
|
||||||
std::map<std::string,factoryService> m_listServicesAvaillable; //!< list of all factory availlable
|
std::map<std::string,factoryService> m_listServicesAvaillable; //!< list of all factory availlable
|
||||||
/**
|
/**
|
||||||
|
@ -12,11 +12,13 @@
|
|||||||
|
|
||||||
|
|
||||||
zeus::Object::Object() {
|
zeus::Object::Object() {
|
||||||
|
/*
|
||||||
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Object::getExtention);
|
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Object::getExtention);
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func->setDescription("Get List of availlable extention of this Object");
|
func->setDescription("Get List of availlable extention of this Object");
|
||||||
func->setReturn("A list of extention register in the Object");
|
func->setReturn("A list of extention register in the Object");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::Object::~Object() {
|
zeus::Object::~Object() {
|
||||||
@ -84,6 +86,7 @@ void zeus::Object::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
|||||||
uint32_t sourceId = callObj->getSourceId();
|
uint32_t sourceId = callObj->getSourceId();
|
||||||
std::string callFunction = callObj->getCall();
|
std::string callFunction = callObj->getCall();
|
||||||
ZEUS_INFO("plop - ... " << callFunction);
|
ZEUS_INFO("plop - ... " << callFunction);
|
||||||
|
/*
|
||||||
if (callFunction[0] == '_') {
|
if (callFunction[0] == '_') {
|
||||||
if (callFunction == "_new") {
|
if (callFunction == "_new") {
|
||||||
std::string userName = callObj->getParameter<std::string>(0);
|
std::string userName = callObj->getParameter<std::string>(0);
|
||||||
@ -95,13 +98,13 @@ void zeus::Object::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
|||||||
}
|
}
|
||||||
m_interfaceClient->answerValue(callObj->getTransactionId(), uint32_t(m_id)<<16, source, true);
|
m_interfaceClient->answerValue(callObj->getTransactionId(), uint32_t(m_id)<<16, source, true);
|
||||||
return;
|
return;
|
||||||
} else if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
} else */if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
||||||
ZEUS_INFO("plop 6 ...");
|
ZEUS_INFO("plop 6 ...");
|
||||||
callBinary2(callFunction, callObj);
|
callBinary2(callFunction, callObj);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ZEUS_INFO("plop 7 ...");
|
ZEUS_INFO("plop 7 ...");
|
||||||
m_interfaceClient->answerError(callObj->getTransactionId(), uint32_t(m_id)<<16, source, "NOT-AUTHORIZED-FUNCTION", "");
|
m_interfaceClient->answerError(callObj->getTransactionId(), uint32_t(m_ObjectId)<<16, source, "NOT-AUTHORIZED-FUNCTION", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ namespace zeus {
|
|||||||
protected:
|
protected:
|
||||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||||
uint16_t m_ObjectId;
|
uint16_t m_ObjectId;
|
||||||
//std::vector<zeus::FutureBase> m_callMultiData;
|
std::vector<zeus::FutureBase> m_callMultiData;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -61,7 +61,7 @@ namespace zeus {
|
|||||||
* @param[in]
|
* @param[in]
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj);
|
virtual void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj) = 0;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -99,7 +99,7 @@ namespace zeus {
|
|||||||
template<class ZEUS_TYPE_OBJECT>
|
template<class ZEUS_TYPE_OBJECT>
|
||||||
class ObjectType : public zeus::Object {
|
class ObjectType : public zeus::Object {
|
||||||
private:
|
private:
|
||||||
ZEUS_TYPE_OBJECT m_interface; // direct handle on the data;
|
ememory::SharedPtr<ZEUS_TYPE_OBJECT> m_interface; // direct handle on the data;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -158,7 +158,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
|||||||
uint32_t sourceId = callObj->getSourceId();
|
uint32_t sourceId = callObj->getSourceId();
|
||||||
std::string callFunction = callObj->getCall();
|
std::string callFunction = callObj->getCall();
|
||||||
ZEUS_INFO("plop - ... " << callFunction);
|
ZEUS_INFO("plop - ... " << callFunction);
|
||||||
if (callFunction[0] == '_') {
|
/*if (callFunction[0] == '_') {
|
||||||
if (callFunction == "_new") {
|
if (callFunction == "_new") {
|
||||||
std::string userName = callObj->getParameter<std::string>(0);
|
std::string userName = callObj->getParameter<std::string>(0);
|
||||||
std::string clientName = callObj->getParameter<std::string>(1);
|
std::string clientName = callObj->getParameter<std::string>(1);
|
||||||
@ -169,7 +169,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
|||||||
}
|
}
|
||||||
m_interfaceClient->answerValue(callObj->getTransactionId(), uint32_t(m_id)<<16, source, true);
|
m_interfaceClient->answerValue(callObj->getTransactionId(), uint32_t(m_id)<<16, source, true);
|
||||||
return;
|
return;
|
||||||
} else if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
} else */if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
||||||
ZEUS_INFO("plop 6 ...");
|
ZEUS_INFO("plop 6 ...");
|
||||||
callBinary2(callFunction, callObj);
|
callBinary2(callFunction, callObj);
|
||||||
return;
|
return;
|
||||||
|
@ -184,13 +184,13 @@ namespace zeus {
|
|||||||
* @param[in] _userName User name of the client to connect
|
* @param[in] _userName User name of the client to connect
|
||||||
* @todo Set a relur like ==> service not availlable / service close / service maintenance / service right reject
|
* @todo Set a relur like ==> service not availlable / service close / service maintenance / service right reject
|
||||||
*/
|
*/
|
||||||
virtual void clientConnect(uint16_t _sourceId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) = 0;
|
//virtual void clientConnect(uint16_t _sourceId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) = 0;
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param[in]
|
* @param[in]
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual void clientDisconnect(uint16_t _sourceId) = 0;
|
//virtual void clientDisconnect(uint16_t _sourceId) = 0;
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param[in]
|
* @param[in]
|
||||||
@ -247,8 +247,8 @@ namespace zeus {
|
|||||||
class ServiceType : public zeus::Service {
|
class ServiceType : public zeus::Service {
|
||||||
private:
|
private:
|
||||||
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
||||||
ememory::SharedPtr<ClientProperty> m_property
|
ememory::SharedPtr<ClientProperty> m_property;
|
||||||
ZEUS_TYPE_SERVICE m_interface;
|
ememory::SharedPtr<ZEUS_TYPE_SERVICE> m_interface;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
Loading…
x
Reference in New Issue
Block a user