From cc7493c079d166fdd90219bcb6eca6afe4567b09 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 2 Jun 2017 00:26:00 +0200 Subject: [PATCH] [DEV] continue thinking about signal and progression --- lutinMacro_zeus.py | 39 ++++++++++++++----- .../appl/zeus-service-video.srv.zeus.idl | 2 +- zeus/AbstractFunctionTypeClass.hpp | 30 +++++++------- zeus/ActionNotification.hpp | 13 +++++-- zeus/Client.cpp | 2 + zeus/Future.hpp | 35 +++++++---------- zeus/FutureBase.cpp | 4 +- zeus/FutureBase.hpp | 6 +-- zeus/Object.hpp | 3 +- zeus/Promise.cpp | 21 ++++++---- zeus/Promise.hpp | 11 +++--- zeus/WebServer.cpp | 22 +---------- zeus/WebServer.hpp | 33 +++++++--------- zeus/message/Event.cpp | 26 +++++++++++++ zeus/message/Event.hpp | 36 ++++++++++++++--- zeus/zeus-File.impl.cpp | 4 +- 16 files changed, 172 insertions(+), 115 deletions(-) diff --git a/lutinMacro_zeus.py b/lutinMacro_zeus.py index 853c75e..bd86d76 100644 --- a/lutinMacro_zeus.py +++ b/lutinMacro_zeus.py @@ -36,7 +36,7 @@ list_of_known_type = [ ["stream", "zeus::Stream"], ["json", "ejson::Object"], ["raw", "zeus::Raw"], - ["ActionNotif", "zeus::ActionNotification"], + ["ActionNotif", "zeus::ActionNotification"], ] @@ -184,12 +184,14 @@ class FunctionDefinition: def __init__(self): self.name = "" self.brief = "" + self.action_type = "void_tmp" self.return_type = "" self.return_brief = "" self.parameters = [] self.is_action = False - def set_action(self): + def set_action(self, type): + self.action_type = remove_start_stop_spacer(type) self.is_action = True def set_function_name(self, name): @@ -238,7 +240,10 @@ class FunctionDefinition: debug.info(" " + self.return_type + " " + self.name + "(") for elem in self.parameters: debug.info(" " + elem["type"] + " " + elem["name"] + ", # " + elem["brief"]) - debug.info(" )") + if action_type == "void": + debug.info(" )") + else: + debug.info(" ) action/event type = '" + action_type + "'") def generate_doxy(self, space): # generate doxygen comment: @@ -275,7 +280,7 @@ class FunctionDefinition: param_data = "" id_parameter = 0 if self.is_action == True: - param_data += "zeus::ActionNotification& _notifs" + param_data += "zeus::ActionNotification<" + convert_type_in_cpp(self.action_type, False, True) + ">& _notifs" id_parameter += 1 for elem in self.parameters: id_parameter += 1 @@ -297,7 +302,10 @@ class FunctionDefinition: def generate_hpp_proxy(self, space): out = ""; out += self.generate_doxy(space) - out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + "> " + self.name + "(" + out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + if self.action_type != "void_tmp": + out += "," + convert_type_in_cpp(self.action_type, True, False) + out += "> " + self.name + "(" param_data = "" id_parameter = 0 for elem in self.parameters: @@ -310,11 +318,14 @@ class FunctionDefinition: else: param_data += elem["name"] out += param_data - out += ") const;\n" + out += ");\n" return out; def generate_cpp_proxy(self, space, class_name): out = ""; - out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + "> " + class_name + "::" + self.name + "(" + out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + if self.action_type != "void_tmp": + out += "," + convert_type_in_cpp(self.action_type, True, False) + out += "> " + class_name + "::" + self.name + "(" param_data = "" id_parameter = 0 for elem in self.parameters: @@ -327,7 +338,7 @@ class FunctionDefinition: else: param_data += elem["name"] out += param_data - out += ") const {\n" + out += ") {\n" space += " " if self.is_action == True: out += space + 'return m_obj.callAction("' + self.name + '"' @@ -933,9 +944,17 @@ def tool_generate_idl(target, module, data_option): if line[:10] == "[function]": type_function = "function" line = line[10:] - if line[:8] == "[action]": + if line[:8] == "[action ": type_function = "action" line = line[8:] + type_event = ""; + for elem in line: + if elem == "]": + break + type_event += elem + line = line[len(type_event)+1:] + if validate_type(type_event) == False: + debug.error("line " + str(id_line) + " action type unknow : '" + type_event + "' not in " + str(get_list_type())) # remove wihte space while len(line)>0 \ @@ -987,7 +1006,7 @@ def tool_generate_idl(target, module, data_option): if type_function == "function": service_def.add_function(current_def) elif type_function == "action": - current_def.set_action() + current_def.set_action(type_event) service_def.add_function(current_def) elif type_function == "factory": service_def.add_factory(current_def) diff --git a/tools/service-video/appl/zeus-service-video.srv.zeus.idl b/tools/service-video/appl/zeus-service-video.srv.zeus.idl index bf1e7a2..37eb76f 100644 --- a/tools/service-video/appl/zeus-service-video.srv.zeus.idl +++ b/tools/service-video/appl/zeus-service-video.srv.zeus.idl @@ -33,7 +33,7 @@ obj:zeus-Media get(uint32) #param:data:A file reference on the media (transmission is async) #return:Local personal ID of the media //#notification:Send progression in json -[action] uint32 add(obj:zeus-File) +[action string] uint32 add(obj:zeus-File) #brief:Remove a media in the service (no trash) #param:mediaId:Id of the media diff --git a/zeus/AbstractFunctionTypeClass.hpp b/zeus/AbstractFunctionTypeClass.hpp index 15a936d..9cee0ba 100644 --- a/zeus/AbstractFunctionTypeClass.hpp +++ b/zeus/AbstractFunctionTypeClass.hpp @@ -20,16 +20,16 @@ namespace zeus { * @param[in] _pointer Pointer on the class to call * @param[in] _func pointer on the function to call */ - template + template void executeClassCall(ememory::SharedPtr _interfaceClient, ememory::SharedPtr _obj, ZEUS_CLASS_TYPE* _pointer, - ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { + ZEUS_RETURN (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { if (_obj == nullptr) { return; } ZEUS_RETURN ret; - zeus::ActionNotification notifs(_interfaceClient, _obj->getTransactionId(), _obj->getDestination(), _obj->getSource()); + zeus::ActionNotification notifs(_interfaceClient, _obj->getTransactionId(), _obj->getDestination(), _obj->getSource()); if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] @@ -89,15 +89,15 @@ namespace zeus { * @param[in] _pointer Pointer on the class to call * @param[in] _func pointer on the function to call */ - template + template void executeClassCall(ememory::SharedPtr _interfaceClient, ememory::SharedPtr _obj, ZEUS_CLASS_TYPE* _pointer, - void (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { + void (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { if (_obj == nullptr) { return; } - zeus::ActionNotification notifs(_interfaceClient, _obj->getTransactionId(), _obj->getDestination(), _obj->getSource()); + zeus::ActionNotification notifs(_interfaceClient, _obj->getTransactionId(), _obj->getDestination(), _obj->getSource()); if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] @@ -152,13 +152,13 @@ namespace zeus { /** * @brief Chass that permit to declare a function that call intanced element or a class element */ - template + template class AbstractActionTypeClass: public zeus::AbstractFunction { protected: static const zeus::message::ParamType m_returnType; static const zeus::message::ParamType m_paramType[sizeof...(ZEUS_TYPES)]; public: - using functionType = ZEUS_RETURN (ZEUS_CLASS_TYPE::*)(zeus::ActionNotification& _notifs, ZEUS_TYPES...); + using functionType = ZEUS_RETURN (ZEUS_CLASS_TYPE::*)(zeus::ActionNotification& _notifs, ZEUS_TYPES...); functionType m_function; /** * @brief Constructor @@ -418,11 +418,11 @@ namespace zeus { } }; // specialization - template - const zeus::message::ParamType AbstractActionTypeClass::m_returnType = zeus::message::createType(); + template + const zeus::message::ParamType AbstractActionTypeClass::m_returnType = zeus::message::createType(); // specialization - template - const zeus::message::ParamType AbstractActionTypeClass::m_paramType[sizeof...(ZEUS_TYPES)] = {zeus::message::createType()...}; + template + const zeus::message::ParamType AbstractActionTypeClass::m_paramType[sizeof...(ZEUS_TYPES)] = {zeus::message::createType()...}; // specialization template const zeus::message::ParamType AbstractFunctionTypeClass::m_returnType = zeus::message::createType(); @@ -435,9 +435,9 @@ namespace zeus { * @param[in] _fffp Pointer of the function * @return Abstract type of the function */ - template - AbstractFunction* createAbstractFunctionClass(const std::string& _name, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_fffp)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { - return new AbstractActionTypeClass(_name, _fffp); + template + AbstractFunction* createAbstractFunctionClass(const std::string& _name, ZEUS_RETURN (ZEUS_CLASS_TYPE::*_fffp)(zeus::ActionNotification& _notifs, ZEUS_TYPES...)) { + return new AbstractActionTypeClass(_name, _fffp); } /** * @brief Create a function information with the function type diff --git a/zeus/ActionNotification.hpp b/zeus/ActionNotification.hpp index 37fc0ac..7bbfe25 100644 --- a/zeus/ActionNotification.hpp +++ b/zeus/ActionNotification.hpp @@ -10,6 +10,7 @@ namespace zeus { + template class ActionNotification { private: ememory::SharedPtr m_interface; @@ -25,11 +26,15 @@ namespace zeus { m_transactionId(_transactionId), m_source(_source), m_destination(_destination) {} - - void notify(const std::string& _value) { - if (m_interface != nullptr) { - m_interface->progressNotify(m_transactionId, m_source, m_destination, _value); + // TODO: Deprecated ... + void notify(const ZEUS_TYPE_EVENT& _value) { + emit(_value); + } + void emit(const ZEUS_TYPE_EVENT& _value) { + if (m_interface == nullptr) { + return; } + m_interface->eventValue(m_transactionId, m_source, m_destination, _value); } }; } \ No newline at end of file diff --git a/zeus/Client.cpp b/zeus/Client.cpp index 80acf49..1c730f7 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -121,6 +121,7 @@ void zeus::Client::onClientData(ememory::SharedPtr _value) { } answerProtocolError(transactionId, "interact with client, musty only call: link/unlink/movelink"); return; + /* } else if (_value->getType() == zeus::message::type::event) { ememory::SharedPtr eventObj = ememory::staticPointerCast(_value); std::string callFunction = eventObj->getCall(); @@ -131,6 +132,7 @@ void zeus::Client::onClientData(ememory::SharedPtr _value) { } answerProtocolError(transactionId, "interact with client, musty only call: removeInterface"); return; + */ } m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "UNKNOW-ACTION"); return; diff --git a/zeus/Future.hpp b/zeus/Future.hpp index c5a0758..49c711b 100644 --- a/zeus/Future.hpp +++ b/zeus/Future.hpp @@ -10,10 +10,11 @@ // TODO : When do a cast of the type on the future ==> do a wait ... namespace zeus { + class void_tmp {}; /** * @brief future template to cast type in a specific type */ - template + template class Future : public zeus::FutureBase { public: /** @@ -123,35 +124,29 @@ namespace zeus { * @param[in] _callback Handle on the function to call in progress information */ // TODO: this is deprecated ... - Future& onProgress(Promise::ObserverProgress _callback) { - zeus::FutureBase::onProgress(_callback); + Future& onProgress(Promise::ObserverEvent _callback) { + zeus::FutureBase::onEvent(_callback); return *this; } + //template::value, false>> Future& onSignal(std::function _callback) { - zeus::FutureBase::onSignal( - [=](ememory::SharedPtr _msg) { + zeus::FutureBase::onEvent( + [=](ememory::SharedPtr _msg) { if (_msg == nullptr) { return; } - if (_msg->getType() != zeus::message::type::progress) { - ZEUS_WARNING("No Return value ..."); - return; - } - return _callback(static_cast(_msg.get())->getAnswer()); + _callback(_msg->getEvent()); }); return *this; } + //template::value, false>> Future& onSignal(std::function _callback) { - zeus::FutureBase::onSignal( - [=](ememory::SharedPtr _msg) { + zeus::FutureBase::onEvent( + [=](ememory::SharedPtr _msg) { if (_msg == nullptr) { return; } - if (_msg->getType() != zeus::message::type::progress) { - ZEUS_WARNING("No Return value ..."); - return; - } - return _callback(std::move(static_cast(_msg.get())->getAnswer())); + _callback(std::move(_msg->getEvent())); }); return *this; } @@ -160,7 +155,7 @@ namespace zeus { * @brief future template to cast type in a void methode (fallback) */ template<> - class Future : public zeus::FutureBase { + class Future : public zeus::FutureBase { public: /** * @brief contructor of the Future with the basic FutureBase @@ -241,8 +236,8 @@ namespace zeus { * @brief Attach callback on activity of the action if user set some return information * @param[in] _callback Handle on the function to call in progress information */ - Future& onProgress(Promise::ObserverProgress _callback) { - zeus::FutureBase::onProgress(_callback); + Future& onEvent(Promise::ObserverEvent _callback) { + zeus::FutureBase::onEvent(_callback); return *this; } }; diff --git a/zeus/FutureBase.cpp b/zeus/FutureBase.cpp index c0317fa..8050cda 100644 --- a/zeus/FutureBase.cpp +++ b/zeus/FutureBase.cpp @@ -71,11 +71,11 @@ void zeus::FutureBase::andElse(zeus::Promise::Observer _callback) { m_promise->andElse(_callback); } -void zeus::FutureBase::onProgress(zeus::Promise::ObserverProgress _callback) { +void zeus::FutureBase::onEvent(zeus::Promise::ObserverEvent _callback) { if (m_promise == nullptr) { return; } - m_promise->onProgress(_callback); + m_promise->onEvent(_callback); } echrono::Duration zeus::FutureBase::getTransmitionTime() const { diff --git a/zeus/FutureBase.hpp b/zeus/FutureBase.hpp index 3cf2917..cbb4d9c 100644 --- a/zeus/FutureBase.hpp +++ b/zeus/FutureBase.hpp @@ -44,7 +44,7 @@ namespace zeus { */ FutureBase(uint32_t _transactionId, ememory::SharedPtr _returnData, uint32_t _source=0); /** - * @brief set the call is an action an then it can receive remote data ==> the authorize the onProgress Callback .. + * @brief set the call is an action an then it can receive remote data ==> the authorize the onEvent Callback .. * @note system use only ==> user have never to call this function... */ void setAction(); @@ -65,9 +65,9 @@ namespace zeus { void andElse(zeus::Promise::Observer _callback); /** * @brief Attach callback on activity of the action if user set some return information - * @param[in] _callback Handle on the function to call in progress information + * @param[in] _callback Handle on the function to call in event information */ - void onProgress(zeus::Promise::ObserverProgress _callback); + void onEvent(zeus::Promise::ObserverEvent _callback); /* / ** * @brief Attach callback on a specific return action (ABORT) diff --git a/zeus/Object.hpp b/zeus/Object.hpp index fb21f1a..238c35c 100644 --- a/zeus/Object.hpp +++ b/zeus/Object.hpp @@ -117,10 +117,11 @@ namespace zeus { * @note: this is for ACTION function call not normal function call */ template zeus::AbstractFunction* advertise(const std::string& _name, - ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_FUNC_ARGS_TYPE... _args)) { + ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(zeus::ActionNotification& _notifs, ZEUS_FUNC_ARGS_TYPE... _args)) { if (etk::start_with(_name, "srv.") == true) { ZEUS_ERROR("Advertise function start with 'srv.' is not permited ==> only allow for internal service: '" << _name << "'"); return nullptr; diff --git a/zeus/Promise.cpp b/zeus/Promise.cpp index d61d567..ac6a410 100644 --- a/zeus/Promise.cpp +++ b/zeus/Promise.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -106,12 +106,12 @@ void zeus::Promise::andElse(zeus::Promise::Observer _callback) { m_callbackElse(zeus::FutureBase(sharedFromThis())); } -void zeus::Promise::onProgress(zeus::Promise::ObserverProgress _callback) { +void zeus::Promise::onEvent(zeus::Promise::ObserverEvent _callback) { std::unique_lock lock(m_mutex); if (m_isAction == false) { - ZEUS_ERROR("Request a progress calback on a simple function call"); + ZEUS_ERROR("Request a Event calback on a simple function call"); } - m_callbackProgress = _callback; + m_callbackEvent = _callback; } echrono::Duration zeus::Promise::getTransmitionTime() const { @@ -127,11 +127,18 @@ bool zeus::Promise::setMessage(ememory::SharedPtr _value) { std::unique_lock lock(m_mutex); m_receiveTime = echrono::Steady::now(); } - if (_value->getType() != zeus::message::type::progress) { + if (_value->getType() != zeus::message::type::event) { std::unique_lock lock(m_mutex); // notification of a progresion ... - if (m_callbackProgress != nullptr) { - m_callbackProgress(static_cast(m_message.get())->getData()); + if (m_callbackEvent != nullptr) { + if (_value == nullptr) { + return true; + } + if (_value->getType() != zeus::message::type::event) { + ZEUS_WARNING("No Return value ..."); + return true; + } + m_callbackEvent(ememory::staticPointerCast(_value)); return false; // no error } return false; diff --git a/zeus/Promise.hpp b/zeus/Promise.hpp index 7656858..650503f 100644 --- a/zeus/Promise.hpp +++ b/zeus/Promise.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,7 @@ namespace zeus { class Promise : public ememory::EnableSharedFromThis { public: using Observer = std::function; //!< Define an Observer: function pointer - using ObserverProgress = std::function; //!< Define the observer on activity of the action (note that is a string, but it can contain json or other ...) + using ObserverEvent = std::function)>; //!< Define the observer on activity of the action (note that is a string, but it can contain json or other ...) private: mutable std::mutex m_mutex; //!< local prevention of multiple acess uint32_t m_transactionId; //!< waiting answer data @@ -29,7 +30,7 @@ namespace zeus { ememory::SharedPtr m_message; //!< all buffer concatenate or last buffer if synchronous Observer m_callbackThen; //!< observer callback When data arrive and NO error appear Observer m_callbackElse; //!< observer callback When data arrive and AN error appear - ObserverProgress m_callbackProgress; //!< observer callback When progress is sended from the remote object called + ObserverEvent m_callbackEvent; //!< observer callback when event is sended from the remote object called //Observer m_callbackAbort; //!< observer callback When Action is abort by user echrono::Steady m_sendTime; //!< time when the future has been sended request echrono::Steady m_receiveTime; //!< time when the future has receve answer @@ -51,7 +52,7 @@ namespace zeus { */ Promise(uint32_t _transactionId, ememory::SharedPtr _returnData, uint32_t _source=0); /** - * @brief set the call is an action an then it can receive remote data ==> the authorize the onProgress Callback .. + * @brief set the call is an action an then it can receive remote data ==> the authorize the onEvent Callback .. * @note system use only ==> user have never to call this function... */ void setAction(); @@ -72,9 +73,9 @@ namespace zeus { void andElse(zeus::Promise::Observer _callback); /** * @brief Attach callback on activity of the action if user set some return information - * @param[in] _callback Handle on the function to call in progress information + * @param[in] _callback Handle on the function to call in event information */ - void onProgress(zeus::Promise::ObserverProgress _callback); + void onEvent(zeus::Promise::ObserverEvent _callback); /* / ** * @brief Attach callback on a specific return action (ABORT) diff --git a/zeus/WebServer.cpp b/zeus/WebServer.cpp index 653e132..575867b 100644 --- a/zeus/WebServer.cpp +++ b/zeus/WebServer.cpp @@ -11,18 +11,13 @@ #include -ememory::SharedPtr zeus::createBaseCall(bool _isEvent, - const ememory::SharedPtr& _iface, +ememory::SharedPtr zeus::createBaseCall(const ememory::SharedPtr& _iface, uint64_t _transactionId, const uint32_t& _source, const uint32_t& _destination, const std::string& _functionName) { ememory::SharedPtr obj; - if (_isEvent == false) { - obj = zeus::message::Call::create(_iface); - } else { - obj = zeus::message::Event::create(_iface); - } + obj = zeus::message::Call::create(_iface); if (obj == nullptr) { return nullptr; } @@ -664,16 +659,3 @@ void zeus::WebServer::answerVoid(uint32_t _clientTransactionId, uint32_t _source answer->addParameter(); writeBinary(answer); } - -void zeus::WebServer::progressNotify(uint32_t _clientTransactionId, uint32_t _source, uint32_t _destination, const std::string& _value) { - auto answer = zeus::message::Progress::create(sharedFromThis()); - if (answer == nullptr) { - return; - } - answer->setTransactionId(_clientTransactionId); - answer->setSource(_source); - answer->setDestination(_destination); - answer->setData(_value); - writeBinary(answer); -} - diff --git a/zeus/WebServer.hpp b/zeus/WebServer.hpp index 1242668..36caaa8 100644 --- a/zeus/WebServer.hpp +++ b/zeus/WebServer.hpp @@ -34,8 +34,7 @@ namespace zeus { * @param[in] * @return */ - ememory::SharedPtr createBaseCall(bool _isEvent, - const ememory::SharedPtr& _iface, + ememory::SharedPtr createBaseCall(const ememory::SharedPtr& _iface, uint64_t _transactionId, const uint32_t& _source, const uint32_t& _destination, @@ -81,14 +80,13 @@ namespace zeus { * @return */ template - ememory::SharedPtr createCall(bool _isEvent, - const ememory::SharedPtr& _iface, + ememory::SharedPtr createCall(const ememory::SharedPtr& _iface, uint64_t _transactionId, const uint32_t& _source, const uint32_t& _destination, const std::string& _functionName, _ARGS&&... _args) { - ememory::SharedPtr callElem = createBaseCall(_isEvent, _iface, _transactionId, _source, _destination, _functionName); + ememory::SharedPtr callElem = createBaseCall(_iface, _transactionId, _source, _destination, _functionName); if (callElem == nullptr) { return nullptr; } @@ -307,21 +305,10 @@ namespace zeus { template zeus::FutureBase call(const uint32_t& _source, const uint32_t& _destination, const std::string& _functionName, _ARGS&&... _args) { uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCall(false, sharedFromThis(), id, _source, _destination, _functionName, std::forward<_ARGS>(_args)...); + ememory::SharedPtr callElem = zeus::createCall(sharedFromThis(), id, _source, _destination, _functionName, std::forward<_ARGS>(_args)...); return callBinary(id, callElem); } - /** - * @brief - * @param[in] - * @return - */ - template - void event(const uint32_t& _source, const uint32_t& _destination, const std::string& _eventName, _ARGS&&... _args) { - uint16_t id = getId(); - ememory::SharedPtr callElem = zeus::createCall(true, sharedFromThis(), id, _source, _destination, _eventName, std::forward<_ARGS>(_args)...); - callBinary(id, callElem); - } - public: // progress ... + public: // Events ... /** * @brief Send a progression value to a specific call in progress * @param[in] _transactionId Current trasaction ID @@ -329,7 +316,15 @@ namespace zeus { * @param[in] _destination Destinatio of the progression * @param[in] _value Value to send */ - void progressNotify(uint32_t _transactionId, uint32_t _source, uint32_t _destination, const std::string& _value); + template + void eventValue(uint32_t _clientTransactionId, uint32_t _source, uint32_t _destination, ZEUS_ARG _value) { + ememory::SharedPtr event = zeus::message::Event::create(sharedFromThis()); + event->setTransactionId(_clientTransactionId); + event->setSource(_source); + event->setDestination(_destination); + event->addEvent(_value); + writeBinary(event); + } public: // answers ... /** * @brief diff --git a/zeus/message/Event.cpp b/zeus/message/Event.cpp index b7490c6..f957d96 100644 --- a/zeus/message/Event.cpp +++ b/zeus/message/Event.cpp @@ -10,6 +10,31 @@ #include #include +void zeus::message::Event::generateDisplay(std::ostream& _os) const { + zeus::Message::generateDisplay(_os); + if (getNumberParameter() != 0) { + _os << " '" + simpleStringParam(0) + "'"; + } +} + +bool zeus::message::Event::writeOn(enet::WebSocket& _interface) { + std::unique_lock lock = _interface.getScopeLock(); + zeus::Message::writeOn(_interface); + _interface.writeData((uint8_t*)(&m_uid), sizeof(m_uid)); + if (message::Parameter::writeOn(_interface) == false) { + return false; + } + int32_t count = _interface.send(); + return count > 0; +} + +void zeus::message::Event::composeWith(const uint8_t* _buffer, uint32_t _lenght) { + uint64_t* uuid = (uint64_t*)_buffer; + m_uid = *uuid; + // parse parameters: + message::Parameter::composeWith(&_buffer[sizeof(m_uid)], _lenght-sizeof(m_uid)); +} + // ------------------------------------------------------------------------------------ // -- Factory // ------------------------------------------------------------------------------------ @@ -17,3 +42,4 @@ ememory::SharedPtr zeus::message::Event::create(ememory::SharedPtr _iface) { return ememory::SharedPtr(new zeus::message::Event(_iface)); } + diff --git a/zeus/message/Event.hpp b/zeus/message/Event.hpp index 3d109ad..4b0db4f 100644 --- a/zeus/message/Event.hpp +++ b/zeus/message/Event.hpp @@ -4,24 +4,33 @@ * @license MPL v2.0 (see license file) */ #pragma once -#include +#include +#include +#include +#include namespace zeus { + class WebServer; namespace message { class Event : - public message::Call { + public message::Parameter { friend class zeus::Message; + protected: + uint64_t m_uid; //!< Signal is sended in an active call ==> then we need to identify all the type ==> need an uniqueId ... the bigger bit mean that the message has no more data ... protected: /** - * @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::message::Call::create + * @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::message::Event::create */ Event(ememory::SharedPtr _iface): - zeus::message::Call(_iface) { + zeus::message::Parameter(_iface) { m_header.flags = ZEUS_BUFFER_FLAG_FINISH + uint8_t(zeus::message::type::event); }; + void composeWith(const uint8_t* _buffer, uint32_t _lenght) override; + bool writeOn(enet::WebSocket& _interface) override; + void generateDisplay(std::ostream& _os) const override; public: /** - * @brief Create a shared pointer on the MessageCall + * @brief Create a shared pointer on the Event * @return Allocated Message. */ static ememory::SharedPtr create(ememory::SharedPtr _iface); @@ -29,7 +38,22 @@ namespace zeus { enum zeus::message::type getType() const override { return zeus::message::type::event; } + /** + * @brief set the Event of the call + * @param[in] _value Value to add + */ + template + void addEvent(const ZEUS_TYPE_DATA& _value) { + addParameter(_value); + } + /** + * @brief get the Event value + * @param[in] Data of the Event + */ + template + ZEUS_TYPE_DATA getEvent() const { + return getParameter(0); + } }; } } - diff --git a/zeus/zeus-File.impl.cpp b/zeus/zeus-File.impl.cpp index 3655ae2..0cc1582 100644 --- a/zeus/zeus-File.impl.cpp +++ b/zeus/zeus-File.impl.cpp @@ -119,11 +119,11 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) { } std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) { - zeus::ActionNotification tmp; + zeus::ActionNotification tmp; return zeus::storeInFileNotify(_file, _filename, tmp); } -std::string zeus::storeInFileNotify(zeus::ProxyFile _file, std::string _filename, zeus::ActionNotification _notification) { +std::string zeus::storeInFileNotify(zeus::ProxyFile _file, std::string _filename, zeus::ActionNotification _notification) { auto futSize = _file.getSize(); auto futSha = _file.getSha512(); futSize.wait();