From fac9c55b9e3a149f2bbe1eab55119dbb3f59e7c8 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 27 Nov 2016 20:54:38 +0100 Subject: [PATCH] [DEV] continue integration to simplify user interface, but not work and does not parmit to have object and stream --- lutinMacro_zeus.py | 16 ++++- lutin_zeus.py | 6 ++ test/client/appl/main.cpp | 4 +- tools/gateway/appl/RouterInterface.cpp | 17 ++--- .../lutin_zeus-service-picture.py | 2 +- tools/service-user/appl/main.cpp | 1 + tools/service-user/lutin_zeus-service-user.py | 2 +- .../service-video/lutin_zeus-service-video.py | 2 +- zeus/BaseProxy.cpp | 27 ++++++++ zeus/BaseProxy.hpp | 29 +++++++++ zeus/Client.cpp | 16 ++++- zeus/Client.hpp | 1 + zeus/FutureBase.hpp | 6 ++ zeus/RemoteProcessCall.cpp | 1 + zeus/Service.cpp | 8 +++ zeus/Service.hpp | 2 + zeus/ServiceProxy.cpp | 16 +++++ zeus/ServiceProxy.hpp | 22 +++++++ zeus/ServiceRemote.cpp | 32 ++++++++-- zeus/ServiceRemote.hpp | 63 ++++++++++++++++--- zeus/SystemProxy.cpp | 45 +++++++++++++ zeus/SystemProxy.hpp | 26 ++++++++ zeus/WebServer.cpp | 9 ++- zeus/WebServer.hpp | 24 ++++--- 24 files changed, 338 insertions(+), 39 deletions(-) create mode 100644 zeus/BaseProxy.cpp create mode 100644 zeus/BaseProxy.hpp create mode 100644 zeus/ServiceProxy.cpp create mode 100644 zeus/ServiceProxy.hpp create mode 100644 zeus/SystemProxy.cpp create mode 100644 zeus/SystemProxy.hpp diff --git a/lutinMacro_zeus.py b/lutinMacro_zeus.py index c691acb..f104d81 100644 --- a/lutinMacro_zeus.py +++ b/lutinMacro_zeus.py @@ -476,6 +476,7 @@ class ServiceDefinition: out += "#pragma once\n" out += "\n" out += "#include \n" + out += "#include \n" out += "#include \n" out += "#include \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 += " " """ diff --git a/lutin_zeus.py b/lutin_zeus.py index 96894ac..56e6b3f 100644 --- a/lutin_zeus.py +++ b/lutin_zeus.py @@ -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) diff --git a/test/client/appl/main.cpp b/test/client/appl/main.cpp index 9953319..a20ffbd 100644 --- a/test/client/appl/main.cpp +++ b/test/client/appl/main.cpp @@ -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> retCall = remoteServiceUser.getGroups("clientTest1#atria-soft.com"); + zeus::Future> retCall = remoteServiceUser.clientGroupsGet("clientTest1#atria-soft.com"); retCall.wait(); APPL_INFO("system-user.getGroups() = " << retCall.get()); zeus::Future 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> retCall = remoteServiceUser.call("getGroups", "clientTest1#atria-soft.com"); + zeus::Future> retCall = remoteServiceUser.call("clientGroupsGet", "clientTest1#atria-soft.com"); retCall.wait(); APPL_INFO("system-user.getGroups() = " << retCall.get()); zeus::Future retDesc = remoteServiceUser.call("sys.getDescription"); diff --git a/tools/gateway/appl/RouterInterface.cpp b/tools/gateway/appl/RouterInterface.cpp index e675348..fa86bbf 100644 --- a/tools/gateway/appl/RouterInterface.cpp +++ b/tools/gateway/appl/RouterInterface.cpp @@ -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 futLocalService = m_userService->m_interfaceClient.callClient(m_localIdUser, "_new", m_userConnectionName, "**Gateway**", std::vector()); + zeus::Future futLocalService = m_userService->m_interfaceClient.callClient(m_localIdUser, ZEUS_ID_SERVICE_ROOT, "_new", m_userConnectionName, "**Gateway**", std::vector()); 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 return; } - zeus::Future fut = m_userService->m_interfaceClient.callClient(m_localIdUser, "checkTocken", clientName, clientTocken); + zeus::Future 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 } if (callFunction == "auth") { std::string password = callObj->getParameter(0); - zeus::Future fut = m_userService->m_interfaceClient.callClient(m_localIdUser, "checkAuth", password); + zeus::Future 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 // -------------------------------- // -- Get groups: // -------------------------------- - zeus::Future> futGroup = m_userService->m_interfaceClient.callClient(m_localIdUser, "clientGroupsGet", m_clientName); + zeus::Future> 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 // -- Get services: // -------------------------------- std::vector currentServices = m_gatewayInterface->getAllServiceName(); - zeus::Future> futServices = m_userService->m_interfaceClient.callClient(m_localIdUser, "filterClientServices", m_clientName, currentServices); + zeus::Future> 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 if (callFunction == "link") { // first param: std::string serviceName = callObj->getParameter(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 } ememory::SharedPtr srv = m_gatewayInterface->get(serviceName); if (srv != nullptr) { - zeus::Future futLink = srv->m_interfaceClient.callClient(m_uid, "_new", m_userConnectionName, m_clientName, m_clientgroups); + zeus::Future 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 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 return; } if (callFunction == "unlink") { + ZEUS_ERROR("Disconnnect from service : " << m_uid); // first param: the service we want to unconnect ... int64_t localServiceID = callObj->getParameter(0)-1; // Check if service already link: @@ -278,7 +281,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr m_interfaceRouterClient->answerError(transactionId, "NOT-CONNECTED-SERVICE"); return; } - zeus::Future futUnLink = m_listConnectedService[localServiceID]->m_interfaceClient.callClient(m_uid, "_delete"); + zeus::Future 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"); diff --git a/tools/service-picture/lutin_zeus-service-picture.py b/tools/service-picture/lutin_zeus-service-picture.py index d4a99b7..94c61dc 100644 --- a/tools/service-picture/lutin_zeus-service-picture.py +++ b/tools/service-picture/lutin_zeus-service-picture.py @@ -5,7 +5,7 @@ import lutin.macro as macro def get_type(): - return "LIBRARY_DYNAMIC" + return "LIBRARY" #return "BINARY" def get_sub_type(): diff --git a/tools/service-user/appl/main.cpp b/tools/service-user/appl/main.cpp index 4b9b415..a3f27cb 100644 --- a/tools/service-user/appl/main.cpp +++ b/tools/service-user/appl/main.cpp @@ -38,6 +38,7 @@ namespace appl { } public: std::vector clientGroupsGet(std::string _clientName) { + APPL_WARNING("call clientGroupsGet : " << _clientName); std::vector out; if (m_client == nullptr) { return out; diff --git a/tools/service-user/lutin_zeus-service-user.py b/tools/service-user/lutin_zeus-service-user.py index 11466b7..36709be 100644 --- a/tools/service-user/lutin_zeus-service-user.py +++ b/tools/service-user/lutin_zeus-service-user.py @@ -5,7 +5,7 @@ import lutin.macro as macro def get_type(): - return "LIBRARY_DYNAMIC" + return "LIBRARY" #return "BINARY" def get_sub_type(): diff --git a/tools/service-video/lutin_zeus-service-video.py b/tools/service-video/lutin_zeus-service-video.py index f750971..e06e627 100644 --- a/tools/service-video/lutin_zeus-service-video.py +++ b/tools/service-video/lutin_zeus-service-video.py @@ -5,7 +5,7 @@ import lutin.macro as macro def get_type(): - return "LIBRARY_DYNAMIC" + return "LIBRARY" #return "BINARY" def get_sub_type(): diff --git a/zeus/BaseProxy.cpp b/zeus/BaseProxy.cpp new file mode 100644 index 0000000..44816ef --- /dev/null +++ b/zeus/BaseProxy.cpp @@ -0,0 +1,27 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include +#include + +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(); +} diff --git a/zeus/BaseProxy.hpp b/zeus/BaseProxy.hpp new file mode 100644 index 0000000..02b2bd0 --- /dev/null +++ b/zeus/BaseProxy.hpp @@ -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 +#include +#include + +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; + }; +} diff --git a/zeus/Client.cpp b/zeus/Client.cpp index 00abb09..c6758d9 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -28,7 +28,21 @@ void zeus::Client::onClientData(ememory::SharedPtr _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 val = it->lock(); + if (val == nullptr) { + it = m_listConnectedService.erase(it); + continue; + } + if (val->getName() == _name) { + return zeus::ServiceRemote(val); + } + } + ememory::SharedPtr tmp = ememory::makeShared(m_interfaceClient, _name); + m_listConnectedService.push_back(tmp); + return zeus::ServiceRemote(tmp); } void zeus::Client::onPropertyChangeIp() { diff --git a/zeus/Client.hpp b/zeus/Client.hpp index dea39e3..c992c73 100644 --- a/zeus/Client.hpp +++ b/zeus/Client.hpp @@ -24,6 +24,7 @@ namespace zeus { eproperty::Value propertyPort; //!< Port of the WebSocket connection private: ememory::SharedPtr m_interfaceClient; //!< Interface on the Websocket interface + std::vector> 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 diff --git a/zeus/FutureBase.hpp b/zeus/FutureBase.hpp index 956aed2..b3bf6d9 100644 --- a/zeus/FutureBase.hpp +++ b/zeus/FutureBase.hpp @@ -40,6 +40,12 @@ namespace zeus { * @param[in] _clientId Client/sevice Id waiting answer */ FutureBase(uint32_t _transactionId, ememory::SharedPtr _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 diff --git a/zeus/RemoteProcessCall.cpp b/zeus/RemoteProcessCall.cpp index adcd8fc..15f4b96 100644 --- a/zeus/RemoteProcessCall.cpp +++ b/zeus/RemoteProcessCall.cpp @@ -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; } diff --git a/zeus/Service.cpp b/zeus/Service.cpp index e10c190..178628b 100644 --- a/zeus/Service.cpp +++ b/zeus/Service.cpp @@ -136,21 +136,27 @@ void zeus::Service::pingIsAlive() { } void zeus::Service::callBinary(ememory::SharedPtr _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 callObj = ememory::staticPointerCast(_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(0); @@ -163,9 +169,11 @@ void zeus::Service::callBinary(ememory::SharedPtr _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; } diff --git a/zeus/Service.hpp b/zeus/Service.hpp index 3173782..ef54960 100644 --- a/zeus/Service.hpp +++ b/zeus/Service.hpp @@ -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); diff --git a/zeus/ServiceProxy.cpp b/zeus/ServiceProxy.cpp new file mode 100644 index 0000000..a478587 --- /dev/null +++ b/zeus/ServiceProxy.cpp @@ -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::ServiceProxy(zeus::ServiceRemote& _srv): + m_srv(_srv) { + +} +zeus::Future> zeus::ServiceProxy::getExtention() { + return m_srv.call("srv.getExtention"); +} + diff --git a/zeus/ServiceProxy.hpp b/zeus/ServiceProxy.hpp new file mode 100644 index 0000000..cd9e822 --- /dev/null +++ b/zeus/ServiceProxy.hpp @@ -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 + +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> getExtention(); + }; +} diff --git a/zeus/ServiceRemote.cpp b/zeus/ServiceRemote.cpp index 452b91f..4deced5 100644 --- a/zeus/ServiceRemote.cpp +++ b/zeus/ServiceRemote.cpp @@ -7,7 +7,7 @@ #include #include -zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr _clientLink, const std::string& _name): +zeus::ServiceRemoteBase::ServiceRemoteBase(ememory::SharedPtr _clientLink, const std::string& _name): m_interfaceClient(_clientLink), m_name(_name), m_serviceId(0), @@ -16,7 +16,7 @@ zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr _clientLi return; } // little hack : Call the service manager with the service ID=0 ... - zeus::Future ret = call("link", _name); + zeus::Future 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 _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 ret = call("unlink", tmpLocalService); + zeus::Future 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 _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; +} + diff --git a/zeus/ServiceRemote.hpp b/zeus/ServiceRemote.hpp index 109106a..3c61075 100644 --- a/zeus/ServiceRemote.hpp +++ b/zeus/ServiceRemote.hpp @@ -14,12 +14,14 @@ namespace zeus { class Client; + class ServiceRemote; /** * @brief * @param[in] * @return */ - class ServiceRemote { + class ServiceRemoteBase { + friend class ServiceRemote; private: ememory::SharedPtr m_interfaceClient; std::string m_name; @@ -31,7 +33,47 @@ namespace zeus { * @param[in] * @return */ - ServiceRemote(ememory::SharedPtr _clientLink, const std::string& _name); + ServiceRemoteBase() = default; + /** + * @brief + * @param[in] + * @return + */ + ServiceRemoteBase(ememory::SharedPtr _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 m_interface; + public: + /** + * @brief + * @param[in] + * @return + */ + ServiceRemote(ememory::SharedPtr _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 zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) { - if (m_interfaceClient == nullptr) { + + if ( m_interface == nullptr + || m_interface->m_interfaceClient == nullptr) { ememory::SharedPtr 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 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 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); } }; + + + } diff --git a/zeus/SystemProxy.cpp b/zeus/SystemProxy.cpp new file mode 100644 index 0000000..104e5f0 --- /dev/null +++ b/zeus/SystemProxy.cpp @@ -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::SystemProxy(zeus::ServiceRemote& _srv): + m_srv(_srv) { + +} + +zeus::Future zeus::SystemProxy::getDescription() { + return m_srv.call("sys.getDescription"); +} + +zeus::Future zeus::SystemProxy::getVersion() { + return m_srv.call("sys.getVersion"); +} + +zeus::Future zeus::SystemProxy::getType() { + return m_srv.call("sys.getType"); +} + +zeus::Future> zeus::SystemProxy::getExtention() { + return m_srv.call("sys.getExtention"); +} + +zeus::Future> zeus::SystemProxy::getAuthors() { + return m_srv.call("sys.getAuthors"); +} + +zeus::Future> zeus::SystemProxy::getFunctions() { + return m_srv.call("sys.getFunctions"); +} + +zeus::Future zeus::SystemProxy::getFunctionPrototype(std::string _functionName) { + return m_srv.call("sys.getFunctionPrototype", _functionName); +} + +zeus::Future zeus::SystemProxy::getFunctionDescription(std::string _functionName) { + return m_srv.call("sys.getFunctionDescription", _functionName); +} + diff --git a/zeus/SystemProxy.hpp b/zeus/SystemProxy.hpp new file mode 100644 index 0000000..6cef4e6 --- /dev/null +++ b/zeus/SystemProxy.hpp @@ -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 + +namespace zeus { + class SystemProxy { + protected: + zeus::ServiceRemote& m_srv; //!< Service instance handle + public: + SystemProxy(zeus::ServiceRemote& _srv); + zeus::Future getDescription(); + zeus::Future getVersion(); + zeus::Future getType(); + zeus::Future> getExtention(); + zeus::Future> getAuthors(); + zeus::Future> getFunctions(); + zeus::Future getFunctionPrototype(std::string _functionName); + zeus::Future getFunctionDescription(std::string _functionName); + + }; +} diff --git a/zeus/WebServer.cpp b/zeus/WebServer.cpp index fa7f9c8..23797cd 100644 --- a/zeus/WebServer.cpp +++ b/zeus/WebServer.cpp @@ -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); } diff --git a/zeus/WebServer.hpp b/zeus/WebServer.hpp index 4651624..e90e7eb 100644 --- a/zeus/WebServer.hpp +++ b/zeus/WebServer.hpp @@ -12,6 +12,10 @@ #include #include +//#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 - 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 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 - 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 callElem = zeus::createCallService(id, _serviceId, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem, _callback); @@ -312,21 +317,24 @@ namespace zeus { */ template 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 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 - 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 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); }; }