[DEV] continue integration of actions

This commit is contained in:
Edouard DUPIN 2017-05-29 00:42:05 +02:00
parent 6ee0c7047e
commit cdfcede4c9
11 changed files with 191 additions and 11 deletions

View File

@ -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 <string>\n"
out += "#include <vector>\n"
out += "#include <ememory/memory.hpp>\n"
out += "#include <zeus/ActionNotification.hpp>\n"
for elem in self.imports:
prop = zeus_object_to_dictionary(elem)
out += "#include <" + prop["file_name_class_header"] + ">\n"

View File

@ -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',

View File

@ -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<std::string,std::string> _basicKey = std::map<std::string,std::string>()) {
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;

View File

@ -9,13 +9,10 @@
#include <zeus/debug.hpp>
#include <zeus/AbstractFunction.hpp>
#include <zeus/mineType.hpp>
#include <zeus/ActionNotification.hpp>
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]

View File

@ -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 <zeus/WebServer.hpp>
#include <zeus/debug.hpp>
namespace zeus {
class ActionNotification {
private:
ememory::SharedPtr<zeus::WebServer> m_interface;
uint32_t m_transactionId;
uint32_t m_source;
uint32_t m_destination;
public:
ActionNotification(ememory::SharedPtr<zeus::WebServer> _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);
}
}
};
}

View File

@ -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);
}

View File

@ -8,6 +8,7 @@
#include <zeus/message/Answer.hpp>
#include <zeus/message/Event.hpp>
#include <zeus/message/Call.hpp>
#include <zeus/message/Progress.hpp>
#include <enet/WebSocket.hpp>
#include <thread>
#include <ememory/memory.hpp>
@ -320,13 +321,21 @@ namespace zeus {
ememory::SharedPtr<zeus::message::Call> 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

56
zeus/message/Progress.cpp Normal file
View File

@ -0,0 +1,56 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <zeus/message/Message.hpp>
#include <zeus/debug.hpp>
#include <etk/stdTools.hpp>
#include <zeus/message/Progress.hpp>
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<std::mutex> 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<zeus::message::Data> _obj) {
ZEUS_ERROR("can not append data at a progress message ...");
}
// ------------------------------------------------------------------------------------
// -- Factory
// ------------------------------------------------------------------------------------
ememory::SharedPtr<zeus::message::Progress> zeus::message::Progress::create(ememory::SharedPtr<zeus::WebServer> _iface) {
return ememory::SharedPtr<zeus::message::Progress>(new zeus::message::Progress(_iface));
}

53
zeus/message/Progress.hpp Normal file
View File

@ -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 <etk/types.hpp>
#include <enet/WebSocket.hpp>
#include <zeus/message/Message.hpp>
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<zeus::WebServer> _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<zeus::message::Data> _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<zeus::message::Progress> create(ememory::SharedPtr<zeus::WebServer> _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;
};
}
}

View File

@ -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;
}

View File

@ -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)