From cdfcede4c9fc7f9fd8fbecf46d737e1c499d7103 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 29 May 2017 00:42:05 +0200 Subject: [PATCH] [DEV] continue integration of actions --- lutinMacro_zeus.py | 2 + lutin_zeus.py | 1 + .../cli-video/appl/main-tool-client-video.cpp | 8 ++- zeus/AbstractFunctionTypeClass.hpp | 9 +-- zeus/ActionNotification.hpp | 35 ++++++++++++ zeus/WebServer.cpp | 13 ++++- zeus/WebServer.hpp | 11 +++- zeus/message/Progress.cpp | 56 +++++++++++++++++++ zeus/message/Progress.hpp | 53 ++++++++++++++++++ zeus/zeus-File.impl.cpp | 7 ++- zeus/zeus-File.obj.zeus.idl | 7 +++ 11 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 zeus/ActionNotification.hpp create mode 100644 zeus/message/Progress.cpp create mode 100644 zeus/message/Progress.hpp diff --git a/lutinMacro_zeus.py b/lutinMacro_zeus.py index 242fb4c..02b13ef 100644 --- a/lutinMacro_zeus.py +++ b/lutinMacro_zeus.py @@ -36,6 +36,7 @@ list_of_known_type = [ ["stream", "zeus::Stream"], ["json", "ejson::Object"], ["raw", "zeus::Raw"], + ["ActionNotif", "zeus::ActionNotification"], ] @@ -429,6 +430,7 @@ class ServiceDefinition: out += "#include \n" out += "#include \n" out += "#include \n" + out += "#include \n" for elem in self.imports: prop = zeus_object_to_dictionary(elem) out += "#include <" + prop["file_name_class_header"] + ">\n" diff --git a/lutin_zeus.py b/lutin_zeus.py index 0220d6e..2724372 100644 --- a/lutin_zeus.py +++ b/lutin_zeus.py @@ -105,6 +105,7 @@ def configure(target, my_module): my_module.add_header_file([ 'zeus/Raw.hpp', 'zeus/zeus.hpp', + 'zeus/ActionNotification.hpp', 'zeus/AbstractFunction.hpp', 'zeus/AbstractFunctionTypeDirect.hpp', 'zeus/AbstractFunctionTypeClass.hpp', diff --git a/tools/cli-video/appl/main-tool-client-video.cpp b/tools/cli-video/appl/main-tool-client-video.cpp index 539e948..6ec583a 100644 --- a/tools/cli-video/appl/main-tool-client-video.cpp +++ b/tools/cli-video/appl/main-tool-client-video.cpp @@ -49,7 +49,9 @@ bool progressCall(const std::string& _value) { } - +void progressCallback(const std::string& _value) { + APPL_PRINT("plop " << _value); +} bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map _basicKey = std::map()) { std::string extention; if ( _path.rfind('.') != std::string::npos @@ -106,7 +108,9 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map< return true; } // TODO: Do it better ==> add the calback to know the push progression ... - uint32_t mediaId = _srv.add(zeus::File::create(_path, storedSha512)).waitFor(echrono::seconds(20000)).get(); + auto sending = _srv.add(zeus::File::create(_path, storedSha512)); + sending.onProgress(progressCallback); + uint32_t mediaId = sending.waitFor(echrono::seconds(20000)).get(); if (mediaId == 0) { APPL_ERROR("Get media ID = 0 With no error"); return false; diff --git a/zeus/AbstractFunctionTypeClass.hpp b/zeus/AbstractFunctionTypeClass.hpp index 997ed2f..15a936d 100644 --- a/zeus/AbstractFunctionTypeClass.hpp +++ b/zeus/AbstractFunctionTypeClass.hpp @@ -9,13 +9,10 @@ #include #include #include +#include namespace zeus { - class ActionNotification { - public: - ActionNotification() {} - }; /** * @brief Execute a call on the function with a return value * @param[in] _interfaceClient Web interface to send data @@ -32,7 +29,7 @@ namespace zeus { return; } ZEUS_RETURN ret; - zeus::ActionNotification notifs; + 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] @@ -100,7 +97,7 @@ namespace zeus { if (_obj == nullptr) { return; } - zeus::ActionNotification notifs; + 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] diff --git a/zeus/ActionNotification.hpp b/zeus/ActionNotification.hpp new file mode 100644 index 0000000..55686fd --- /dev/null +++ b/zeus/ActionNotification.hpp @@ -0,0 +1,35 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include +#include + + +namespace zeus { + class ActionNotification { + private: + ememory::SharedPtr m_interface; + uint32_t m_transactionId; + uint32_t m_source; + uint32_t m_destination; + public: + ActionNotification(ememory::SharedPtr _interface = nullptr, + uint32_t _transactionId = 0, + uint32_t _source = 0, + uint32_t _destination = 0): + m_interface(_interface), + m_transactionId(_transactionId), + m_source(_source), + m_destination(_destination) {} + + void notify(const std::string& _value) { + if (m_interface != nullptr) { + m_interface->answerValue(m_transactionId, m_source, m_destination, _value); + } + } + }; +} \ No newline at end of file diff --git a/zeus/WebServer.cpp b/zeus/WebServer.cpp index 7d8022c..653e132 100644 --- a/zeus/WebServer.cpp +++ b/zeus/WebServer.cpp @@ -653,7 +653,6 @@ void zeus::WebServer::answerError(uint32_t _clientTransactionId, uint32_t _sourc writeBinary(answer); } - void zeus::WebServer::answerVoid(uint32_t _clientTransactionId, uint32_t _source, uint32_t _destination) { auto answer = zeus::message::Answer::create(sharedFromThis()); if (answer == nullptr) { @@ -666,3 +665,15 @@ void zeus::WebServer::answerVoid(uint32_t _clientTransactionId, uint32_t _source 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 37a4245..1242668 100644 --- a/zeus/WebServer.hpp +++ b/zeus/WebServer.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -320,13 +321,21 @@ namespace zeus { ememory::SharedPtr callElem = zeus::createCall(true, sharedFromThis(), id, _source, _destination, _eventName, std::forward<_ARGS>(_args)...); callBinary(id, callElem); } + public: // progress ... + /** + * @brief Send a progression value to a specific call in progress + * @param[in] _transactionId Current trasaction ID + * @param[in] _source Source Id of the sending value + * @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); public: // answers ... /** * @brief * @param[in] * @return */ - void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp); /** * @brief Send an Answer of a function with single value diff --git a/zeus/message/Progress.cpp b/zeus/message/Progress.cpp new file mode 100644 index 0000000..036ac78 --- /dev/null +++ b/zeus/message/Progress.cpp @@ -0,0 +1,56 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include +#include +#include +#include +#include + +void zeus::message::Progress::generateDisplay(std::ostream& _os) const { + zeus::Message::generateDisplay(_os); + _os << m_data; +} + +const std::string& zeus::message::Progress::getData() const { + return m_data; +} + +void zeus::message::Progress::setData(const std::string& _data) { + m_data = _data; +} + +bool zeus::message::Progress::writeOn(enet::WebSocket& _interface) { + std::unique_lock lock = _interface.getScopeLock(); + zeus::Message::writeOn(_interface); + _interface.writeData((uint8_t*)m_data.c_str(), m_data.size() + 1); + int32_t count = _interface.send(); + return count > 0; +} + +void zeus::message::Progress::composeWith(const uint8_t* _buffer, uint32_t _lenght) { + // First element iw the call name, after, this is the parameters... + // parse the string: (call name) + uint32_t pos = 0; + m_data.clear(); + while( pos < _lenght + && _buffer[pos] != '\0') { + m_data += _buffer[pos]; + pos++; + } +} + +void zeus::message::Progress::appendMessageData(ememory::SharedPtr _obj) { + ZEUS_ERROR("can not append data at a progress message ..."); +} + +// ------------------------------------------------------------------------------------ +// -- Factory +// ------------------------------------------------------------------------------------ + +ememory::SharedPtr zeus::message::Progress::create(ememory::SharedPtr _iface) { + return ememory::SharedPtr(new zeus::message::Progress(_iface)); +} + diff --git a/zeus/message/Progress.hpp b/zeus/message/Progress.hpp new file mode 100644 index 0000000..3e364a1 --- /dev/null +++ b/zeus/message/Progress.hpp @@ -0,0 +1,53 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once +#include +#include +#include + +namespace zeus { + class WebServer; + namespace message { + class Progress : + public zeus::Message { + friend class zeus::Message; + protected: + std::string m_data; + protected: + /** + * @brief basic constructor (hidden to force the use of ememory::SharedPtr) @ref zeus::message::Answer::create + */ + Progress(ememory::SharedPtr _iface): + zeus::Message(_iface) { + m_header.flags = uint8_t(zeus::message::type::progress); + }; + void composeWith(const uint8_t* _buffer, uint32_t _lenght) override; + void appendMessageData(ememory::SharedPtr _obj) override; + bool writeOn(enet::WebSocket& _interface) override; + void generateDisplay(std::ostream& _os) const override; + public: + /** + * @brief Create a shared pointer on the Answer + * @return Allocated Message. + */ + static ememory::SharedPtr create(ememory::SharedPtr _iface); + public: + enum zeus::message::type getType() const override { + return zeus::message::type::progress; + } + /** + * @brief progress message answer + * @param[in] _data Data of the progress + */ + void setData(const std::string& _data); + /** + * @brief get the error value (if exist) + * @return string of the error + */ + const std::string& getData() const; + }; + } +} diff --git a/zeus/zeus-File.impl.cpp b/zeus/zeus-File.impl.cpp index 30e7f0d..9821073 100644 --- a/zeus/zeus-File.impl.cpp +++ b/zeus/zeus-File.impl.cpp @@ -119,6 +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; + return zeus::storeInFile(_file, _filename, tmp); +} + +std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename, zeus::ActionNotification _notification) { auto futSize = _file.getSize(); auto futSha = _file.getSha512(); futSize.wait(); @@ -145,6 +150,7 @@ std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) { offset += nbElement; retSize -= nbElement; ZEUS_VERBOSE("read: " << offset << "/" << futSize.get() << " " << buffer.size()); + "{\"pourcent\":" + etk::to_string(float(offset)/float(buffer.size())) + ", \"comment\":\"download\"" } nodeFile.fileClose(); // get the final sha512 of the file: @@ -158,4 +164,3 @@ std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) { return sha512String; } - diff --git a/zeus/zeus-File.obj.zeus.idl b/zeus/zeus-File.obj.zeus.idl index ffa2b59..6f50db9 100644 --- a/zeus/zeus-File.obj.zeus.idl +++ b/zeus/zeus-File.obj.zeus.idl @@ -62,3 +62,10 @@ raw getPart(uint64, uint64) #return:the sha512 of the file (calculated with the input stream. [tool-remote] string storeInFile(obj:zeus-File, string) +#brief:Store all the data in a specific file. +#param:file:Handle on the file. +#param:filename:Local filename. +#param:notif:Local filename. +#return:the sha512 of the file (calculated with the input stream. +[tool-remote] string storeInFileNotify(obj:zeus-File, string, ActionNotif) +