[DEV] continue refactor PB with object return

This commit is contained in:
Edouard DUPIN 2016-11-29 23:14:49 +01:00
parent fa38f8d637
commit b13a79fe5d
6 changed files with 26 additions and 15 deletions

View File

@ -8,8 +8,15 @@
#include <zeus/Client.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() :
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),
@ -44,13 +51,13 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
//APPL_ERROR(" ==> parse DATA ...");
uint32_t transactionId = _value->getTransactionId();
if (transactionId == 0) {
APPL_ERROR("Protocol error ==>missing id");
ZEUS_ERROR("Protocol error ==>missing id");
answerProtocolError(transactionId, "missing parameter: 'id'");
return;
}
// Check if we are the destinated Of this message
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));
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());
return false;
}
m_listServicesAvaillable.add(std::make_pair(_serviceName, _factory));
m_listServicesAvaillable.insert(std::make_pair(_serviceName, _factory));
return true;
}

View File

@ -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::Object>> m_listLocalObject;
public:
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
/**
* @brief
* @param[in]
@ -86,7 +87,7 @@ namespace zeus {
* @return Pointer on an interface of remote service
*/
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
/**

View File

@ -12,11 +12,13 @@
zeus::Object::Object() {
/*
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Object::getExtention);
if (func != nullptr) {
func->setDescription("Get List of availlable extention of this Object");
func->setReturn("A list of extention register in the Object");
}
*/
}
zeus::Object::~Object() {
@ -84,6 +86,7 @@ void zeus::Object::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
uint32_t sourceId = callObj->getSourceId();
std::string callFunction = callObj->getCall();
ZEUS_INFO("plop - ... " << callFunction);
/*
if (callFunction[0] == '_') {
if (callFunction == "_new") {
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);
return;
} else if (isFunctionAuthorized(sourceId, callFunction) == true) {
} else */if (isFunctionAuthorized(sourceId, callFunction) == true) {
ZEUS_INFO("plop 6 ...");
callBinary2(callFunction, callObj);
return;
} else {
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;
}
}

View File

@ -28,7 +28,7 @@ namespace zeus {
protected:
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
uint16_t m_ObjectId;
//std::vector<zeus::FutureBase> m_callMultiData;
std::vector<zeus::FutureBase> m_callMultiData;
public:
/**
* @brief
@ -61,7 +61,7 @@ namespace zeus {
* @param[in]
* @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:
/**
* @brief
@ -99,7 +99,7 @@ namespace zeus {
template<class ZEUS_TYPE_OBJECT>
class ObjectType : public zeus::Object {
private:
ZEUS_TYPE_OBJECT m_interface; // direct handle on the data;
ememory::SharedPtr<ZEUS_TYPE_OBJECT> m_interface; // direct handle on the data;
public:
/**
* @brief

View File

@ -158,7 +158,7 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
uint32_t sourceId = callObj->getSourceId();
std::string callFunction = callObj->getCall();
ZEUS_INFO("plop - ... " << callFunction);
if (callFunction[0] == '_') {
/*if (callFunction[0] == '_') {
if (callFunction == "_new") {
std::string userName = callObj->getParameter<std::string>(0);
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);
return;
} else if (isFunctionAuthorized(sourceId, callFunction) == true) {
} else */if (isFunctionAuthorized(sourceId, callFunction) == true) {
ZEUS_INFO("plop 6 ...");
callBinary2(callFunction, callObj);
return;

View File

@ -184,13 +184,13 @@ namespace zeus {
* @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
*/
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
* @param[in]
* @return
*/
virtual void clientDisconnect(uint16_t _sourceId) = 0;
//virtual void clientDisconnect(uint16_t _sourceId) = 0;
/**
* @brief
* @param[in]
@ -247,8 +247,8 @@ namespace zeus {
class ServiceType : public zeus::Service {
private:
// 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
ZEUS_TYPE_SERVICE m_interface;
ememory::SharedPtr<ClientProperty> m_property;
ememory::SharedPtr<ZEUS_TYPE_SERVICE> m_interface;
public:
/**
* @brief