[DEV] continue integration to simplify user interface, but not work and does not parmit to have object and stream
This commit is contained in:
parent
1d0f1265eb
commit
fac9c55b9e
@ -476,6 +476,7 @@ class ServiceDefinition:
|
||||
out += "#pragma once\n"
|
||||
out += "\n"
|
||||
out += "#include <zeus/ServiceRemote.hpp>\n"
|
||||
out += "#include <zeus/BaseProxy.hpp>\n"
|
||||
out += "#include <string>\n"
|
||||
out += "#include <vector>\n"
|
||||
out += "\n"
|
||||
@ -495,15 +496,24 @@ class ServiceDefinition:
|
||||
out += space + " * authors:" + elem + "\n"
|
||||
out += space + " */\n"
|
||||
#out += space + "class Proxy" + self.name[-1] + " : public " + self.name[-1] + " {\n"
|
||||
out += space + "class Proxy" + self.name[-1] + " {\n"
|
||||
out += space + "class Proxy" + self.name[-1] + " :public zeus::BaseProxy {\n"
|
||||
space += " "
|
||||
out += space + "protected:\n"
|
||||
out += space + " zeus::ServiceRemote m_srv; //!< Service instance handle\n"
|
||||
out += space + "public:\n"
|
||||
out += space + " const Proxy" + self.name[-1] + "& operator= (const zeus::ServiceRemote& _srv) {\n"
|
||||
out += space + " m_srv = _srv;\n"
|
||||
out += space + " return *this;\n"
|
||||
out += space + " }\n"
|
||||
out += space + " ~Proxy" + self.name[-1] + "() = default;\n"
|
||||
out += space + " Proxy" + self.name[-1] + "() = default;\n"
|
||||
out += space + " Proxy" + self.name[-1] + "(const zeus::ServiceRemote& _srv) :\n"
|
||||
out += space + " zeus::BaseProxy(_srv) {\n"
|
||||
out += space + " \n"
|
||||
out += space + " }\n"
|
||||
"""
|
||||
out += space + " bool exist() const {\n"
|
||||
out += space + " return m_srv.exist();\n"
|
||||
out += space + " }\n"
|
||||
"""
|
||||
out += space + "public:\n"
|
||||
space += " "
|
||||
"""
|
||||
|
@ -59,6 +59,9 @@ def configure(target, my_module):
|
||||
'zeus/ServiceRemote.cpp',
|
||||
'zeus/WebServer.cpp',
|
||||
'zeus/mineType.cpp',
|
||||
'zeus/BaseProxy.cpp',
|
||||
'zeus/ServiceProxy.cpp',
|
||||
'zeus/SystemProxy.cpp',
|
||||
])
|
||||
my_module.add_header_file([
|
||||
'zeus/zeus.hpp',
|
||||
@ -85,6 +88,9 @@ def configure(target, my_module):
|
||||
'zeus/ServiceRemote.hpp',
|
||||
'zeus/WebServer.hpp',
|
||||
'zeus/mineType.hpp',
|
||||
'zeus/BaseProxy.hpp',
|
||||
'zeus/ServiceProxy.hpp',
|
||||
'zeus/SystemProxy.hpp',
|
||||
])
|
||||
if target.config["compilator"] == "clang":
|
||||
my_module.add_flag('c++', "-Wno-unsequenced", export=True)
|
||||
|
@ -98,7 +98,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
zeus::service::ProxyUser remoteServiceUser;
|
||||
remoteServiceUser = client1.getService("user");
|
||||
if (remoteServiceUser.exist() == true) {
|
||||
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.getGroups("clientTest1#atria-soft.com");
|
||||
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.clientGroupsGet("clientTest1#atria-soft.com");
|
||||
retCall.wait();
|
||||
APPL_INFO("system-user.getGroups() = " << retCall.get());
|
||||
zeus::Future<std::string> retDesc = remoteServiceUser.sys.getDescription();
|
||||
@ -143,7 +143,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
#else
|
||||
zeus::ServiceRemote remoteServiceUser = client1.getService("user");
|
||||
if (remoteServiceUser.exist() == true) {
|
||||
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.call("getGroups", "clientTest1#atria-soft.com");
|
||||
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.call("clientGroupsGet", "clientTest1#atria-soft.com");
|
||||
retCall.wait();
|
||||
APPL_INFO("system-user.getGroups() = " << retCall.get());
|
||||
zeus::Future<std::string> retDesc = remoteServiceUser.call("sys.getDescription");
|
||||
|
@ -53,7 +53,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, "_new", m_userConnectionName, "**Gateway**", std::vector<std::string>());
|
||||
zeus::Future<bool> futLocalService = m_userService->m_interfaceClient.callClient(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'");
|
||||
@ -146,7 +146,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
return;
|
||||
}
|
||||
|
||||
zeus::Future<bool> fut = m_userService->m_interfaceClient.callClient(m_localIdUser, "checkTocken", clientName, clientTocken);
|
||||
zeus::Future<bool> fut = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "checkTocken", clientName, clientTocken);
|
||||
fut.wait(); // TODO: Set timeout ...
|
||||
if (fut.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ...");
|
||||
@ -162,7 +162,7 @@ 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(m_localIdUser, "checkAuth", password);
|
||||
zeus::Future<bool> fut = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "checkAuth", password);
|
||||
fut.wait(); // TODO: Set timeout ...
|
||||
if (fut.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ...");
|
||||
@ -182,7 +182,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
// --------------------------------
|
||||
// -- Get groups:
|
||||
// --------------------------------
|
||||
zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.callClient(m_localIdUser, "clientGroupsGet", m_clientName);
|
||||
zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "clientGroupsGet", m_clientName);
|
||||
futGroup.wait(); // TODO: Set timeout ...
|
||||
if (futGroup.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ...");
|
||||
@ -195,7 +195,7 @@ 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(m_localIdUser, "filterClientServices", m_clientName, currentServices);
|
||||
zeus::Future<std::vector<std::string>> futServices = m_userService->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_localIdUser, "filterClientServices", m_clientName, currentServices);
|
||||
futServices.wait(); // TODO: Set timeout ...
|
||||
if (futServices.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ...");
|
||||
@ -232,6 +232,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
if (callFunction == "link") {
|
||||
// first param:
|
||||
std::string serviceName = callObj->getParameter<std::string>(0);
|
||||
ZEUS_ERROR("Connect to service : " << serviceName << " " << m_uid);
|
||||
// Check if service already link:
|
||||
auto it = m_listConnectedService.begin();
|
||||
while (it != m_listConnectedService.end()) {
|
||||
@ -253,7 +254,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
}
|
||||
ememory::SharedPtr<appl::ServiceInterface> srv = m_gatewayInterface->get(serviceName);
|
||||
if (srv != nullptr) {
|
||||
zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups);
|
||||
zeus::Future<bool> futLink = srv->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups);
|
||||
futLink.wait(); // TODO: Set timeout ...
|
||||
if (futLink.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ... LINK");
|
||||
@ -261,6 +262,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
return;
|
||||
}
|
||||
m_listConnectedService.push_back(srv);
|
||||
ZEUS_ERROR(" ==> get ID : " << m_uid);
|
||||
m_interfaceRouterClient->answerValue(transactionId, m_listConnectedService.size(), m_uid);
|
||||
return;
|
||||
}
|
||||
@ -271,6 +273,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
return;
|
||||
}
|
||||
if (callFunction == "unlink") {
|
||||
ZEUS_ERROR("Disconnnect from service : " << m_uid);
|
||||
// first param: the service we want to unconnect ...
|
||||
int64_t localServiceID = callObj->getParameter<int64_t>(0)-1;
|
||||
// Check if service already link:
|
||||
@ -278,7 +281,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
|
||||
m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE");
|
||||
return;
|
||||
}
|
||||
zeus::Future<bool> futUnLink = m_listConnectedService[localServiceID]->m_interfaceClient.callClient(m_uid, "_delete");
|
||||
zeus::Future<bool> futUnLink = m_listConnectedService[localServiceID]->m_interfaceClient.callClient(ZEUS_NO_ID_CLIENT, m_uid, "_delete");
|
||||
futUnLink.wait(); // TODO: Set timeout ...
|
||||
if (futUnLink.hasError() == true) {
|
||||
APPL_ERROR("Get error from the service ... UNLINK");
|
||||
|
@ -5,7 +5,7 @@ import lutin.macro as macro
|
||||
|
||||
|
||||
def get_type():
|
||||
return "LIBRARY_DYNAMIC"
|
||||
return "LIBRARY"
|
||||
#return "BINARY"
|
||||
|
||||
def get_sub_type():
|
||||
|
@ -38,6 +38,7 @@ namespace appl {
|
||||
}
|
||||
public:
|
||||
std::vector<std::string> clientGroupsGet(std::string _clientName) {
|
||||
APPL_WARNING("call clientGroupsGet : " << _clientName);
|
||||
std::vector<std::string> out;
|
||||
if (m_client == nullptr) {
|
||||
return out;
|
||||
|
@ -5,7 +5,7 @@ import lutin.macro as macro
|
||||
|
||||
|
||||
def get_type():
|
||||
return "LIBRARY_DYNAMIC"
|
||||
return "LIBRARY"
|
||||
#return "BINARY"
|
||||
|
||||
def get_sub_type():
|
||||
|
@ -5,7 +5,7 @@ import lutin.macro as macro
|
||||
|
||||
|
||||
def get_type():
|
||||
return "LIBRARY_DYNAMIC"
|
||||
return "LIBRARY"
|
||||
#return "BINARY"
|
||||
|
||||
def get_sub_type():
|
||||
|
27
zeus/BaseProxy.cpp
Normal file
27
zeus/BaseProxy.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/BaseProxy.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
|
||||
const zeus::BaseProxy& zeus::BaseProxy::operator= (const zeus::ServiceRemote& _srv) {
|
||||
m_srv = _srv;
|
||||
return *this;
|
||||
}
|
||||
zeus::BaseProxy::BaseProxy():
|
||||
sys(m_srv),
|
||||
srv(m_srv) {
|
||||
|
||||
}
|
||||
zeus::BaseProxy::BaseProxy(const zeus::ServiceRemote& _srv):
|
||||
m_srv(_srv),
|
||||
sys(m_srv),
|
||||
srv(m_srv) {
|
||||
|
||||
}
|
||||
bool zeus::BaseProxy::exist() const {
|
||||
return m_srv.exist();
|
||||
}
|
29
zeus/BaseProxy.hpp
Normal file
29
zeus/BaseProxy.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ServiceProxy.hpp>
|
||||
#include <zeus/SystemProxy.hpp>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief Proxy base interface
|
||||
*/
|
||||
class BaseProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote m_srv; //!< Service instance handle
|
||||
public:
|
||||
zeus::SystemProxy sys;
|
||||
zeus::ServiceProxy srv;
|
||||
public:
|
||||
const BaseProxy& operator= (const zeus::ServiceRemote& _srv);
|
||||
BaseProxy();
|
||||
virtual ~BaseProxy() = default;
|
||||
BaseProxy(const zeus::ServiceRemote& _srv);
|
||||
bool exist() const;
|
||||
};
|
||||
}
|
@ -28,7 +28,21 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
|
||||
}
|
||||
|
||||
zeus::ServiceRemote zeus::Client::getService(const std::string& _name) {
|
||||
return zeus::ServiceRemote(m_interfaceClient, _name);
|
||||
ZEUS_TODO("Lock here");
|
||||
auto it = m_listConnectedService.begin();
|
||||
while (it != m_listConnectedService.end()) {
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> val = it->lock();
|
||||
if (val == nullptr) {
|
||||
it = m_listConnectedService.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (val->getName() == _name) {
|
||||
return zeus::ServiceRemote(val);
|
||||
}
|
||||
}
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> tmp = ememory::makeShared<zeus::ServiceRemoteBase>(m_interfaceClient, _name);
|
||||
m_listConnectedService.push_back(tmp);
|
||||
return zeus::ServiceRemote(tmp);
|
||||
}
|
||||
|
||||
void zeus::Client::onPropertyChangeIp() {
|
||||
|
@ -24,6 +24,7 @@ namespace zeus {
|
||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||
private:
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient; //!< Interface on the Websocket interface
|
||||
std::vector<ememory::WeakPtr<zeus::ServiceRemoteBase>> m_listConnectedService; //!< Connect only one time on each service, not needed more.
|
||||
public:
|
||||
/**
|
||||
* @brief Create a client on a specific user in a client mode with the tocken associated
|
||||
|
@ -40,6 +40,12 @@ namespace zeus {
|
||||
* @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:
|
||||
/*
|
||||
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 Asignement operator with an other future
|
||||
* @param[in] _base Generic base Future
|
||||
|
@ -190,5 +190,6 @@ std::string zeus::RemoteProcessCall::getFunctionDescription(std::string _funcNam
|
||||
}
|
||||
|
||||
bool zeus::RemoteProcessCall::isFunctionAuthorized(uint64_t _clientSessionID, const std::string& _funcName) {
|
||||
ZEUS_ERROR("lllllllllllllllllllllllllllllllllllllllllllllllllllllllllll");
|
||||
return true;
|
||||
}
|
||||
|
@ -136,21 +136,27 @@ void zeus::Service::pingIsAlive() {
|
||||
}
|
||||
|
||||
void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
||||
ZEUS_INFO("plop 1 ...");
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 2 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::event) {
|
||||
ZEUS_ERROR("Unknow event: '...'");
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 3 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::answer) {
|
||||
ZEUS_ERROR("Local Answer: '...'");
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 4 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::call) {
|
||||
ZEUS_INFO("plop 5 ... ");
|
||||
ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_obj);
|
||||
uint32_t clientId = callObj->getClientId();
|
||||
std::string callFunction = callObj->getCall();
|
||||
ZEUS_INFO("plop - ... " << callFunction);
|
||||
if (callFunction[0] == '_') {
|
||||
if (callFunction == "_new") {
|
||||
std::string userName = callObj->getParameter<std::string>(0);
|
||||
@ -163,9 +169,11 @@ void zeus::Service::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
||||
m_interfaceClient->answerValue(callObj->getTransactionId(), true, clientId);
|
||||
return;
|
||||
} else if (isFunctionAuthorized(clientId, callFunction) == true) {
|
||||
ZEUS_INFO("plop 6 ...");
|
||||
callBinary2(callFunction, callObj);
|
||||
return;
|
||||
} else {
|
||||
ZEUS_INFO("plop 7 ...");
|
||||
m_interfaceClient->answerError(callObj->getTransactionId(), "NOT-AUTHORIZED-FUNCTION", "", clientId);
|
||||
return;
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ namespace zeus {
|
||||
* @return
|
||||
*/
|
||||
bool isFunctionAuthorized(const std::string& _funcName) {
|
||||
ZEUS_ERROR("plop: " << _funcName << " " << m_listAthorizedFunction);
|
||||
return std::find(m_listAthorizedFunction.begin(), m_listAthorizedFunction.end(), _funcName) != m_listAthorizedFunction.end();
|
||||
}
|
||||
};
|
||||
@ -296,6 +297,7 @@ namespace zeus {
|
||||
bool isFunctionAuthorized(uint64_t _clientId, const std::string& _funcName) {
|
||||
auto it = m_interface.find(_clientId);
|
||||
if (it == m_interface.end()) {
|
||||
ZEUS_ERROR("CLIENT does not exist ... " << _clientId << " " << _funcName);
|
||||
return false;
|
||||
}
|
||||
return it->second.first->isFunctionAuthorized(_funcName);
|
||||
|
16
zeus/ServiceProxy.cpp
Normal file
16
zeus/ServiceProxy.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/ServiceProxy.hpp>
|
||||
|
||||
zeus::ServiceProxy::ServiceProxy(zeus::ServiceRemote& _srv):
|
||||
m_srv(_srv) {
|
||||
|
||||
}
|
||||
zeus::Future<std::vector<std::string>> zeus::ServiceProxy::getExtention() {
|
||||
return m_srv.call("srv.getExtention");
|
||||
}
|
||||
|
22
zeus/ServiceProxy.hpp
Normal file
22
zeus/ServiceProxy.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
class ServiceProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote& m_srv; //!< Service instance handle
|
||||
public:
|
||||
ServiceProxy(zeus::ServiceRemote& _srv);
|
||||
/**
|
||||
* @brief Get the list of extention of this service
|
||||
* @return List of all extention availlable
|
||||
*/
|
||||
virtual zeus::Future<std::vector<std::string>> getExtention();
|
||||
};
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
|
||||
zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name):
|
||||
zeus::ServiceRemoteBase::ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name):
|
||||
m_interfaceClient(_clientLink),
|
||||
m_name(_name),
|
||||
m_serviceId(0),
|
||||
@ -16,7 +16,7 @@ zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLi
|
||||
return;
|
||||
}
|
||||
// little hack : Call the service manager with the service ID=0 ...
|
||||
zeus::Future<uint32_t> ret = call("link", _name);
|
||||
zeus::Future<uint32_t> ret = m_interfaceClient->callService(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");
|
||||
@ -26,12 +26,12 @@ zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLi
|
||||
m_serviceId = ret.get();
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::~ServiceRemote() {
|
||||
zeus::ServiceRemoteBase::~ServiceRemoteBase() {
|
||||
if (m_isLinked == true) {
|
||||
uint32_t tmpLocalService = m_serviceId;
|
||||
// little hack : Call the service manager with the service ID=0 ...
|
||||
m_serviceId = 0;
|
||||
zeus::Future<bool> ret = call("unlink", tmpLocalService);
|
||||
zeus::Future<bool> ret = m_interfaceClient->callService(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");
|
||||
@ -47,7 +47,29 @@ zeus::ServiceRemote::~ServiceRemote() {
|
||||
}
|
||||
}
|
||||
|
||||
bool zeus::ServiceRemote::exist() {
|
||||
bool zeus::ServiceRemoteBase::exist() const {
|
||||
return m_isLinked;
|
||||
}
|
||||
|
||||
const std::string& zeus::ServiceRemoteBase::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::ServiceRemoteBase> _interface):
|
||||
m_interface(_interface) {
|
||||
if (m_interface == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::~ServiceRemote() {
|
||||
|
||||
}
|
||||
|
||||
bool zeus::ServiceRemote::exist() const {
|
||||
if (m_interface == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_interface->m_isLinked;
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,14 @@
|
||||
|
||||
namespace zeus {
|
||||
class Client;
|
||||
class ServiceRemote;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ServiceRemote {
|
||||
class ServiceRemoteBase {
|
||||
friend class ServiceRemote;
|
||||
private:
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
|
||||
std::string m_name;
|
||||
@ -31,7 +33,47 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemote(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name);
|
||||
ServiceRemoteBase() = default;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
~ServiceRemoteBase();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool exist() const;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ServiceRemote {
|
||||
private:
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> m_interface;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemote(ememory::SharedPtr<zeus::ServiceRemoteBase> _interface = nullptr);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -43,7 +85,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool exist();
|
||||
bool exist() const;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
@ -52,31 +94,38 @@ namespace zeus {
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
|
||||
if ( m_interface == nullptr
|
||||
|| m_interface->m_interfaceClient == nullptr) {
|
||||
ememory::SharedPtr<zeus::BufferAnswer> ret = zeus::BufferAnswer::create();
|
||||
if (ret != nullptr) {
|
||||
ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
|
||||
}
|
||||
return zeus::FutureBase(0, ret);
|
||||
}
|
||||
return m_interfaceClient->callService(m_serviceId, _functionName, _args...);
|
||||
return m_interface->m_interfaceClient->callService(ZEUS_NO_ID_CLIENT, m_interface->m_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 callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
if (m_interfaceClient == nullptr) {
|
||||
if ( m_interface == nullptr
|
||||
|| m_interface->m_interfaceClient == nullptr) {
|
||||
ememory::SharedPtr<zeus::BufferAnswer> ret = zeus::BufferAnswer::create();
|
||||
if (ret != nullptr) {
|
||||
ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
|
||||
}
|
||||
return zeus::FutureBase(0, ret, _callback);
|
||||
}
|
||||
return m_interfaceClient->callServiceAction(m_serviceId, _functionName, _args..., _callback);
|
||||
return m_interface->m_interfaceClient->callServiceAction(ZEUS_NO_ID_CLIENT, m_interface->m_serviceId, _functionName, _args..., _callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
45
zeus/SystemProxy.cpp
Normal file
45
zeus/SystemProxy.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/SystemProxy.hpp>
|
||||
|
||||
zeus::SystemProxy::SystemProxy(zeus::ServiceRemote& _srv):
|
||||
m_srv(_srv) {
|
||||
|
||||
}
|
||||
|
||||
zeus::Future<std::string> zeus::SystemProxy::getDescription() {
|
||||
return m_srv.call("sys.getDescription");
|
||||
}
|
||||
|
||||
zeus::Future<std::string> zeus::SystemProxy::getVersion() {
|
||||
return m_srv.call("sys.getVersion");
|
||||
}
|
||||
|
||||
zeus::Future<std::string> zeus::SystemProxy::getType() {
|
||||
return m_srv.call("sys.getType");
|
||||
}
|
||||
|
||||
zeus::Future<std::vector<std::string>> zeus::SystemProxy::getExtention() {
|
||||
return m_srv.call("sys.getExtention");
|
||||
}
|
||||
|
||||
zeus::Future<std::vector<std::string>> zeus::SystemProxy::getAuthors() {
|
||||
return m_srv.call("sys.getAuthors");
|
||||
}
|
||||
|
||||
zeus::Future<std::vector<std::string>> zeus::SystemProxy::getFunctions() {
|
||||
return m_srv.call("sys.getFunctions");
|
||||
}
|
||||
|
||||
zeus::Future<std::string> zeus::SystemProxy::getFunctionPrototype(std::string _functionName) {
|
||||
return m_srv.call("sys.getFunctionPrototype", _functionName);
|
||||
}
|
||||
|
||||
zeus::Future<std::string> zeus::SystemProxy::getFunctionDescription(std::string _functionName) {
|
||||
return m_srv.call("sys.getFunctionDescription", _functionName);
|
||||
}
|
||||
|
26
zeus/SystemProxy.hpp
Normal file
26
zeus/SystemProxy.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
class SystemProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote& m_srv; //!< Service instance handle
|
||||
public:
|
||||
SystemProxy(zeus::ServiceRemote& _srv);
|
||||
zeus::Future<std::string> getDescription();
|
||||
zeus::Future<std::string> getVersion();
|
||||
zeus::Future<std::string> getType();
|
||||
zeus::Future<std::vector<std::string>> getExtention();
|
||||
zeus::Future<std::vector<std::string>> getAuthors();
|
||||
zeus::Future<std::vector<std::string>> getFunctions();
|
||||
zeus::Future<std::string> getFunctionPrototype(std::string _functionName);
|
||||
zeus::Future<std::string> getFunctionDescription(std::string _functionName);
|
||||
|
||||
};
|
||||
}
|
@ -381,36 +381,39 @@ 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) {
|
||||
void zeus::WebServer::sendCtrl(const std::string& _ctrlValue, uint32_t _clientId, uint32_t _serviceId) {
|
||||
auto ctrl = zeus::BufferCtrl::create();
|
||||
if (ctrl == nullptr) {
|
||||
return;
|
||||
}
|
||||
ctrl->setTransactionId(getId());
|
||||
ctrl->setClientId(_clientId);
|
||||
ctrl->setServiceId(_serviceId);
|
||||
ctrl->setCtrl(_ctrlValue);
|
||||
writeBinary(ctrl);
|
||||
}
|
||||
|
||||
void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId) {
|
||||
void zeus::WebServer::answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorHelp, uint32_t _clientId, uint32_t _serviceId) {
|
||||
auto answer = zeus::BufferAnswer::create();
|
||||
if (answer == nullptr) {
|
||||
return;
|
||||
}
|
||||
answer->setTransactionId(_clientTransactionId);
|
||||
answer->setClientId(_clientId);
|
||||
answer->setServiceId(_serviceId);
|
||||
answer->addError(_errorValue, _errorHelp);
|
||||
writeBinary(answer);
|
||||
}
|
||||
|
||||
|
||||
void zeus::WebServer::answerVoid(uint64_t _clientTransactionId, uint32_t _clientId) {
|
||||
void zeus::WebServer::answerVoid(uint64_t _clientTransactionId, uint32_t _clientId, uint32_t _serviceId) {
|
||||
auto answer = zeus::BufferAnswer::create();
|
||||
if (answer == nullptr) {
|
||||
return;
|
||||
}
|
||||
answer->setTransactionId(_clientTransactionId);
|
||||
answer->setClientId(_clientId);
|
||||
answer->setServiceId(_serviceId);
|
||||
answer->addParameter();
|
||||
writeBinary(answer);
|
||||
}
|
||||
|
@ -12,6 +12,10 @@
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <zeus/FutureBase.hpp>
|
||||
|
||||
//#define ZEUS_NO_ID_CLIENT (0xFFFFFFFF)
|
||||
#define ZEUS_NO_ID_CLIENT (0x00000000)
|
||||
#define ZEUS_ID_SERVICE_ROOT (0x00000000)
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
@ -289,7 +293,7 @@ namespace zeus {
|
||||
* @return
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callService(uint32_t _serviceId, const std::string& _functionName, _ARGS&&... _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);
|
||||
@ -299,8 +303,9 @@ namespace zeus {
|
||||
* @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 _serviceId, const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
|
||||
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);
|
||||
@ -312,21 +317,24 @@ namespace zeus {
|
||||
*/
|
||||
template<class... _ARGS>
|
||||
zeus::FutureBase callClient(uint32_t _clientId,
|
||||
uint32_t _serviceId,
|
||||
const std::string& _functionName,
|
||||
_ARGS&&... _args) {
|
||||
return callService(_clientId, _functionName, _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, _functionName, _args..., _callback);
|
||||
return callServiceAction(_clientId, _serviceId, _functionName, _args..., _callback);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
@ -360,7 +368,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) {
|
||||
void answerValue(uint64_t _clientTransactionId, ZEUS_ARG _value, uint32_t _clientId=0, uint32_t _serviceId=0) {
|
||||
ememory::SharedPtr<zeus::BufferAnswer> answer = zeus::BufferAnswer::create();
|
||||
answer->setTransactionId(_clientTransactionId);
|
||||
answer->setClientId(_clientId);
|
||||
@ -372,7 +380,7 @@ namespace zeus {
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
* @param[in] _clientId Client to send control
|
||||
*/
|
||||
void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId=0);
|
||||
void answerVoid(uint64_t _clientTransactionId, uint32_t _clientId=0, uint32_t _serviceId=0);
|
||||
/**
|
||||
* @brief Send an Answer error of a function
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
@ -380,7 +388,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);
|
||||
void answerError(uint64_t _clientTransactionId, const std::string& _errorValue, const std::string& _errorComment="", uint32_t _clientId=0, uint32_t _serviceId=0);
|
||||
/**
|
||||
* @brief Send a control on the Interface
|
||||
* @param[in] _clientTransactionId Transaction ID
|
||||
@ -388,7 +396,7 @@ namespace zeus {
|
||||
* @param[in] _clientId Client to send control
|
||||
* @return
|
||||
*/
|
||||
void sendCtrl(const std::string& _ctrlValue, uint32_t _clientId);
|
||||
void sendCtrl(const std::string& _ctrlValue, uint32_t _clientId, uint32_t _serviceId=0);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user