[DEV/DEBUG] action signal is working and might be working as generic signaling

This commit is contained in:
Edouard DUPIN 2017-06-04 23:58:00 +02:00
parent 4801cb8306
commit 826ac3c053
16 changed files with 131 additions and 71 deletions

View File

@ -15,7 +15,7 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <zeus/test/ProxyService1.hpp> #include <zeus/service/test/ProxyService1.hpp>
#include <zeus/ProxyFile.hpp> #include <zeus/ProxyFile.hpp>
#include <zeus/ObjectRemote.hpp> #include <zeus/ObjectRemote.hpp>
#include <echrono/Steady.hpp> #include <echrono/Steady.hpp>
@ -99,13 +99,35 @@ int main(int _argc, const char *_argv[]) {
for (auto &it: retServiceList.get()) { for (auto &it: retServiceList.get()) {
APPL_INFO(" - " << it); APPL_INFO(" - " << it);
} }
zeus::test::ProxyService1 srv = client1.getService("service1");
if (srv.exist() == true) { zeus::service::test::ProxyService1 srv = client1.getService("test-service1");
if (srv.exist() == false) {
APPL_ERROR("can not connect service ... 'test-service1'");
} else {
{
auto retCall = srv.getU32(11); auto retCall = srv.getU32(11);
retCall.wait(); retCall.wait();
APPL_INFO("value = " << retCall.get()); APPL_INFO("value = " << retCall.get());
} }
{
int32_t lasNumberSend = 3000;
auto retCall = srv.doSomething(lasNumberSend);
int32_t lastValue=0;
retCall.onSignal(
[&](int32_t _value) {
APPL_DEBUG("getSignal : " << _value);
if (lastValue+1 != _value) {
APPL_ERROR("Send Event Wrong ORDER ... last=" << lastValue << " new=" << _value);
}
lastValue = _value;
});
while (lasNumberSend != lastValue) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
retCall.wait();
APPL_INFO("END (receive " << lastValue << " signals");
}
}
int32_t iii=0; int32_t iii=0;
while (iii < 3) { while (iii < 3) {
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));

View File

@ -28,7 +28,7 @@ def configure(target, my_module):
my_module.add_path(".") my_module.add_path(".")
my_module.add_depend([ my_module.add_depend([
'zeus', 'zeus',
'zeus-test-service1', 'zeus-service-test-service1',
]) ])
my_module.add_src_file([ my_module.add_src_file([
'appl/debug.cpp', 'appl/debug.cpp',

View File

@ -18,8 +18,8 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <zeus/test/Service1.hpp> #include <zeus/service/test/Service1.hpp>
#include <zeus/test/registerService1.hpp> #include <zeus/service/test/registerService1.hpp>
#include <zeus/File.hpp> #include <zeus/File.hpp>
#include <zeus/ProxyFile.hpp> #include <zeus/ProxyFile.hpp>
#include <zeus/zeus-Media.impl.hpp> #include <zeus/zeus-Media.impl.hpp>
@ -38,7 +38,7 @@ static uint64_t createUniqueID() {
return m_lastMaxId; return m_lastMaxId;
} }
namespace appl { namespace appl {
class TestService1 : public zeus::test::Service1 { class TestService1 : public zeus::service::test::Service1 {
private: private:
std::string m_userName; std::string m_userName;
public: public:
@ -66,6 +66,12 @@ namespace appl {
void getVoid() override { void getVoid() override {
// nothing to do ...; // nothing to do ...;
} }
void doSomething(zeus::ActionNotification<int32_t>& _notifs, int32_t _value) override {
for (int32_t iii=1; iii<=_value; ++iii) {
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
_notifs.emit(iii);
}
}
}; };
} }
@ -117,5 +123,5 @@ ETK_EXPORT_API void SERVICE_IO_peridic_call() {
} }
ZEUS_TEST_SERVICE1_DECLARE(appl::TestService1); ZEUS_SERVICE_TEST_SERVICE1_DECLARE(appl::TestService1);

View File

@ -18,3 +18,7 @@ string getString(string)
void getVoid() void getVoid()
[action int32]void doSomething(int32)

View File

@ -30,11 +30,11 @@ def configure(target, my_module):
my_module.add_depend([ my_module.add_depend([
'zeus', 'zeus',
'ejson', 'ejson',
'zeus-test-service1' 'zeus-service-test-service1'
]) ])
my_module.add_src_file([ my_module.add_src_file([
'appl/debug.cpp', 'appl/debug.cpp',
'appl/main-test-service1.cpp' 'appl/main-service-test-service1.cpp'
]) ])
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"") my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"")
return True return True

View File

@ -32,7 +32,7 @@ def configure(target, my_module):
]) ])
zeus_macro = macro.load_macro('zeus') zeus_macro = macro.load_macro('zeus')
zeus_macro.parse_object_idl(my_module, 'appl/zeus-test-service1.srv.zeus.idl') zeus_macro.parse_object_idl(my_module, 'appl/zeus-service-test-service1.srv.zeus.idl')
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"") my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"")
return True return True

View File

@ -25,7 +25,7 @@ def configure(target, my_module):
my_module.add_depend([ my_module.add_depend([
'zeus-router', 'zeus-router',
'zeus-gateway', 'zeus-gateway',
'zeus-test-service1-impl', 'zeus-service-test-service1-impl',
'zeus-service-user-impl', 'zeus-service-user-impl',
'zeus-launcher', 'zeus-launcher',
'zeus-test-client', 'zeus-test-client',

View File

@ -104,9 +104,8 @@ void appl::DirectInterface::receive(ememory::SharedPtr<zeus::Message> _value) {
answerProtocolError(transactionId, "Must get first the Client ID... call 'getAddress' and not '" + callObj->getCall() + "'"); answerProtocolError(transactionId, "Must get first the Client ID... call 'getAddress' and not '" + callObj->getCall() + "'");
return; return;
} }
APPL_INFO("Get the unique ID...");
m_uid = m_gateway->getId(); m_uid = m_gateway->getId();
APPL_INFO("get ID : " << m_uid); APPL_INFO("clent call getAddress ==> return addresse " << m_uid);
if (m_uid == 0) { if (m_uid == 0) {
answerProtocolError(transactionId, "Can not get the Client ID..."); answerProtocolError(transactionId, "Can not get the Client ID...");
return; return;

View File

@ -59,7 +59,7 @@ void appl::IOInterface::receive(ememory::SharedPtr<zeus::Message> _value) {
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
//APPL_ERROR(" ==> parse DATA ..."); APPL_INFO("RECEIVE message " << _value);
uint32_t transactionId = _value->getTransactionId(); uint32_t transactionId = _value->getTransactionId();
if (transactionId == 0) { if (transactionId == 0) {
APPL_ERROR("Protocol error ==>missing id"); APPL_ERROR("Protocol error ==>missing id");
@ -79,6 +79,10 @@ void appl::IOInterface::receive(ememory::SharedPtr<zeus::Message> _value) {
if (callFunction == "removeRouterClient") { if (callFunction == "removeRouterClient") {
// TODO : Broadcast that an IO is remoed ... // TODO : Broadcast that an IO is remoed ...
m_state = appl::clientState::unconnect; m_state = appl::clientState::unconnect;
APPL_ERROR("Remote client disconnect ...");
zeus::WebServer* iface = getInterface();
iface->answerVoid(transactionId, _value->getDestination(), _value->getSource());
return;
} }
switch (m_state) { switch (m_state) {
case appl::clientState::disconnect: case appl::clientState::disconnect:

View File

@ -397,7 +397,7 @@ void appl::MediaDecoder::init(ememory::SharedPtr<ClientProperty> _property, uint
m_remote->m_fileHandle = _proxy; m_remote->m_fileHandle = _proxy;
APPL_WARNING("We have handle"); APPL_WARNING("We have handle");
m_remote->m_fileHandle.getSize().andThen( m_remote->m_fileHandle.getSize().andThen(
[=](uint64_t _value) { [=](uint64_t _value) mutable {
APPL_WARNING("Receive FileSize to index property"); APPL_WARNING("Receive FileSize to index property");
APPL_WARNING("pppllloooppp " << _value); APPL_WARNING("pppllloooppp " << _value);
m_remote->m_buffer.resize(_value, 0); m_remote->m_buffer.resize(_value, 0);

View File

@ -171,7 +171,7 @@ namespace appl {
throw std::invalid_argument("Wrong file ID ..."); throw std::invalid_argument("Wrong file ID ...");
// //
} }
uint32_t add(zeus::ActionNotification& _notifs, zeus::ProxyFile _dataFile) override { uint32_t add(zeus::ActionNotification<std::string>& _notifs, zeus::ProxyFile _dataFile) override {
//_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"Start loading file\""); //_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"Start loading file\"");
//_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"transfering file\"");; //_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"transfering file\"");;
//_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"synchronize meta-data\""); //_action.setProgress("{\"pourcent\":" + etk::to_string(23.54) + ", \"comment\":\"synchronize meta-data\"");

View File

@ -31,6 +31,7 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Message> _value) {
if (_value == nullptr) { if (_value == nullptr) {
return; return;
} }
ZEUS_DEBUG("receive message : " << _value);
// TODO : We will receive here some notification and call ...like : // TODO : We will receive here some notification and call ...like :
/* /*
if (call && id = 0 && objectid == 0) { if (call && id = 0 && objectid == 0) {
@ -118,21 +119,13 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Message> _value) {
} }
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "TRANSFER-OWNERSHIP-ERROR"); m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "TRANSFER-OWNERSHIP-ERROR");
return; return;
} } else if (callFunction == "removeInterface") {
answerProtocolError(transactionId, "interact with client, musty only call: link/unlink/movelink"); ZEUS_VERBOSE("Remove Object : " << callObj);
return; m_interfaceWeb->interfaceRemoved(callObj->getParameter<std::vector<uint16_t>>(0));
/*
} else if (_value->getType() == zeus::message::type::event) {
ememory::SharedPtr<zeus::message::Event> eventObj = ememory::staticPointerCast<zeus::message::Event>(_value);
std::string callFunction = eventObj->getCall();
if (callFunction == "removeInterface") {
ZEUS_VERBOSE("Remove Object : " << eventObj);
m_interfaceWeb->interfaceRemoved(eventObj->getParameter<std::vector<uint16_t>>(0));
return; return;
} }
answerProtocolError(transactionId, "interact with client, musty only call: removeInterface"); answerProtocolError(transactionId, "interact with client, musty only call: link/unlink/movelink/removeInterface");
return; return;
*/
} }
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "UNKNOW-ACTION"); m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "UNKNOW-ACTION");
return; return;
@ -241,6 +234,7 @@ bool zeus::Client::connectTo(const std::string& _address, echrono::Duration _tim
zeus::Future<uint16_t> retIdentify = call(0, ZEUS_ID_GATEWAY, "getAddress").wait(); zeus::Future<uint16_t> retIdentify = call(0, ZEUS_ID_GATEWAY, "getAddress").wait();
if (retIdentify.hasError() == true) { if (retIdentify.hasError() == true) {
ZEUS_ERROR("Has error when getting Address of client ... " << retIdentify.getErrorType() << " ? " << retIdentify.getErrorHelp());
disconnect(); disconnect();
return false; return false;
} }

View File

@ -30,7 +30,7 @@ namespace zeus {
* @param[in] _base Generic base Future * @param[in] _base Generic base Future
* @return the reference on the local element * @return the reference on the local element
*/ */
zeus::Future<ZEUS_RETURN>& operator= (const zeus::FutureBase& _base) { zeus::Future<ZEUS_RETURN, ZEUS_EVENT>& operator= (const zeus::FutureBase& _base) {
m_promise = _base.m_promise; m_promise = _base.m_promise;
return *this; return *this;
} }
@ -39,36 +39,36 @@ namespace zeus {
* @return requested value * @return requested value
*/ */
ZEUS_RETURN get(); ZEUS_RETURN get();
const Future<ZEUS_RETURN>& wait() const { const Future<ZEUS_RETURN, ZEUS_EVENT>& wait() const {
zeus::FutureBase::wait(); zeus::FutureBase::wait();
return *this; return *this;
} }
Future<ZEUS_RETURN>& wait() { Future<ZEUS_RETURN, ZEUS_EVENT>& wait() {
zeus::FutureBase::wait(); zeus::FutureBase::wait();
return *this; return *this;
} }
const Future<ZEUS_RETURN>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const { const Future<ZEUS_RETURN, ZEUS_EVENT>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta); zeus::FutureBase::waitFor(_delta);
return *this; return *this;
} }
Future<ZEUS_RETURN>& waitFor(echrono::Duration _delta = echrono::seconds(30)) { Future<ZEUS_RETURN, ZEUS_EVENT>& waitFor(echrono::Duration _delta = echrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta); zeus::FutureBase::waitFor(_delta);
return *this; return *this;
} }
const Future<ZEUS_RETURN>& waitUntil(echrono::Steady _endTime) const { const Future<ZEUS_RETURN, ZEUS_EVENT>& waitUntil(echrono::Steady _endTime) const {
zeus::FutureBase::waitUntil(_endTime); zeus::FutureBase::waitUntil(_endTime);
return *this; return *this;
} }
Future<ZEUS_RETURN>& waitUntil(echrono::Steady _endTime) { Future<ZEUS_RETURN, ZEUS_EVENT>& waitUntil(echrono::Steady _endTime) {
zeus::FutureBase::waitUntil(_endTime); zeus::FutureBase::waitUntil(_endTime);
return *this; return *this;
} }
using ObserverFut = std::function<bool(zeus::Future<ZEUS_RETURN>)>; //!< Define an Observer: function pointer for the local specific Future using ObserverFut = std::function<bool(zeus::Future<ZEUS_RETURN, ZEUS_EVENT>)>; //!< Define an Observer: function pointer for the local specific Future
/** /**
* @brief Attach callback on all return type of value * @brief Attach callback on all return type of value
* @param[in] _callback Handle on the function to call in all case * @param[in] _callback Handle on the function to call in all case
*/ */
Future<ZEUS_RETURN>& andAll(ObserverFut _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& andAll(ObserverFut _callback) {
zeus::FutureBase::andAll( zeus::FutureBase::andAll(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<ZEUS_RETURN>(_fut)); return _callback(zeus::Future<ZEUS_RETURN>(_fut));
@ -81,7 +81,7 @@ namespace zeus {
*/ */
/* /*
note : this is anbigous ??? note : this is anbigous ???
Future<ZEUS_RETURN>& andThen(std::function<bool(const ZEUS_RETURN&)> _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& andThen(std::function<bool(const ZEUS_RETURN&)> _callback) {
zeus::FutureBase::andThen( zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
zeus::Future<ZEUS_RETURN> tmp(_fut); zeus::Future<ZEUS_RETURN> tmp(_fut);
@ -90,7 +90,7 @@ namespace zeus {
return *this; return *this;
} }
*/ */
Future<ZEUS_RETURN>& andThen(std::function<bool(ZEUS_RETURN)> _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& andThen(std::function<bool(ZEUS_RETURN)> _callback) {
zeus::FutureBase::andThen( zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(std::move(zeus::Future<ZEUS_RETURN>(_fut).get())); return _callback(std::move(zeus::Future<ZEUS_RETURN>(_fut).get()));
@ -98,7 +98,7 @@ namespace zeus {
return *this; return *this;
} }
/* /*
Future<ZEUS_RETURN>& andThen(ObserverFut _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& andThen(ObserverFut _callback) {
zeus::FutureBase::andThen( zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<ZEUS_RETURN>(_fut)); return _callback(zeus::Future<ZEUS_RETURN>(_fut));
@ -109,14 +109,16 @@ namespace zeus {
* @brief Attach callback on a specific return action (ERROR) * @brief Attach callback on a specific return action (ERROR)
* @param[in] _callback Handle on the function to call in case of error on the call * @param[in] _callback Handle on the function to call in case of error on the call
*/ */
Future<ZEUS_RETURN>& andElse(ObserverFut _callback) { /*
Future<ZEUS_RETURN, ZEUS_EVENT>& andElse(ObserverFut _callback) {
zeus::FutureBase::andElse( zeus::FutureBase::andElse(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<ZEUS_RETURN>(_fut)); return _callback(zeus::Future<ZEUS_RETURN>(_fut));
}); });
return *this; return *this;
} }
Future<ZEUS_RETURN>& andElse(std::function<bool(const std::string&, const std::string&)> _callback) { */
Future<ZEUS_RETURN, ZEUS_EVENT>& andElse(std::function<bool(const std::string&, const std::string&)> _callback) {
zeus::FutureBase::andElse( zeus::FutureBase::andElse(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(_fut.getErrorType(), _fut.getErrorHelp()); return _callback(_fut.getErrorType(), _fut.getErrorHelp());
@ -128,12 +130,13 @@ namespace zeus {
* @param[in] _callback Handle on the function to call in progress information * @param[in] _callback Handle on the function to call in progress information
*/ */
// TODO: this is deprecated ... // TODO: this is deprecated ...
Future<ZEUS_RETURN>& onProgress(Promise::ObserverEvent _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& onProgress(Promise::ObserverEvent _callback) {
zeus::FutureBase::onEvent(_callback); zeus::FutureBase::onEvent(_callback);
return *this; return *this;
} }
//template<typename = std::enable_if<std::is_void<ZEUS_EVENT>::value, false>> //template<typename = std::enable_if<std::is_void<ZEUS_EVENT>::value, false>>
Future<ZEUS_RETURN>& onSignal(std::function<void(const ZEUS_EVENT&)> _callback) { /*
Future<ZEUS_RETURN, ZEUS_EVENT>& onSignal(std::function<void(const ZEUS_EVENT&)> _callback) {
zeus::FutureBase::onEvent( zeus::FutureBase::onEvent(
[=](ememory::SharedPtr<zeus::message::Event> _msg) { [=](ememory::SharedPtr<zeus::message::Event> _msg) {
if (_msg == nullptr) { if (_msg == nullptr) {
@ -143,8 +146,9 @@ namespace zeus {
}); });
return *this; return *this;
} }
*/
//template<typename = std::enable_if<std::is_void<ZEUS_EVENT>::value, false>> //template<typename = std::enable_if<std::is_void<ZEUS_EVENT>::value, false>>
Future<ZEUS_RETURN>& onSignal(std::function<void(ZEUS_EVENT)> _callback) { Future<ZEUS_RETURN, ZEUS_EVENT>& onSignal(std::function<void(ZEUS_EVENT)> _callback) {
zeus::FutureBase::onEvent( zeus::FutureBase::onEvent(
[=](ememory::SharedPtr<zeus::message::Event> _msg) { [=](ememory::SharedPtr<zeus::message::Event> _msg) {
if (_msg == nullptr) { if (_msg == nullptr) {
@ -158,8 +162,8 @@ namespace zeus {
/** /**
* @brief future template to cast type in a void methode (fallback) * @brief future template to cast type in a void methode (fallback)
*/ */
template<> template<class ZEUS_EVENT>
class Future<void> : public zeus::FutureBase { class Future<void, ZEUS_EVENT> : public zeus::FutureBase {
public: public:
/** /**
* @brief contructor of the Future with the basic FutureBase * @brief contructor of the Future with the basic FutureBase
@ -174,40 +178,40 @@ namespace zeus {
* @param[in] _base Generic base Future * @param[in] _base Generic base Future
* @return the reference on the local element * @return the reference on the local element
*/ */
zeus::Future<void>& operator= (const zeus::FutureBase& _base) { zeus::Future<void, ZEUS_EVENT>& operator= (const zeus::FutureBase& _base) {
m_promise = _base.m_promise; m_promise = _base.m_promise;
return *this; return *this;
} }
const Future<void>& wait() const { const Future<void, ZEUS_EVENT>& wait() const {
zeus::FutureBase::wait(); zeus::FutureBase::wait();
return *this; return *this;
} }
Future<void>& wait() { Future<void, ZEUS_EVENT>& wait() {
zeus::FutureBase::wait(); zeus::FutureBase::wait();
return *this; return *this;
} }
const Future<void>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const { const Future<void, ZEUS_EVENT>& waitFor(echrono::Duration _delta = echrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta); zeus::FutureBase::waitFor(_delta);
return *this; return *this;
} }
Future<void>& waitFor(echrono::Duration _delta = echrono::seconds(30)) { Future<void, ZEUS_EVENT>& waitFor(echrono::Duration _delta = echrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta); zeus::FutureBase::waitFor(_delta);
return *this; return *this;
} }
const Future<void>& waitUntil(echrono::Steady _endTime) const { const Future<void, ZEUS_EVENT>& waitUntil(echrono::Steady _endTime) const {
zeus::FutureBase::waitUntil(_endTime); zeus::FutureBase::waitUntil(_endTime);
return *this; return *this;
} }
Future<void>& waitUntil(echrono::Steady _endTime) { Future<void, ZEUS_EVENT>& waitUntil(echrono::Steady _endTime) {
zeus::FutureBase::waitUntil(_endTime); zeus::FutureBase::waitUntil(_endTime);
return *this; return *this;
} }
using ObserverFut = std::function<bool(zeus::Future<void>)>; //!< Define an Observer: function pointer for the local specific Future using ObserverFut = std::function<bool(zeus::Future<void, ZEUS_EVENT>)>; //!< Define an Observer: function pointer for the local specific Future
/** /**
* @brief Attach callback on all return type of value * @brief Attach callback on all return type of value
* @param[in] _callback Handle on the function to call in all case * @param[in] _callback Handle on the function to call in all case
*/ */
Future<void>& andAll(ObserverFut _callback) { Future<void, ZEUS_EVENT>& andAll(ObserverFut _callback) {
zeus::FutureBase::andAll( zeus::FutureBase::andAll(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<void>(_fut)); return _callback(zeus::Future<void>(_fut));
@ -218,31 +222,61 @@ namespace zeus {
* @brief Attach callback on a specific return action (SUCESS) * @brief Attach callback on a specific return action (SUCESS)
* @param[in] _callback Handle on the function to call in case of sucess on the call * @param[in] _callback Handle on the function to call in case of sucess on the call
*/ */
Future<void>& andThen(ObserverFut _callback) { /*
Future<void, ZEUS_EVENT>& andThen(ObserverFut _callback) {
zeus::FutureBase::andThen( zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<void>(_fut)); return _callback(zeus::Future<void>(_fut));
}); });
return *this; return *this;
} }
*/
Future<void, ZEUS_EVENT>& andThen(std::function<bool()> _callback) {
zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) {
return _callback();
});
return *this;
}
/** /**
* @brief Attach callback on a specific return action (ERROR) * @brief Attach callback on a specific return action (ERROR)
* @param[in] _callback Handle on the function to call in case of error on the call * @param[in] _callback Handle on the function to call in case of error on the call
*/ */
Future<void>& andElse(ObserverFut _callback) { /*
Future<void, ZEUS_EVENT>& andElse(ObserverFut _callback) {
zeus::FutureBase::andElse( zeus::FutureBase::andElse(
[=](zeus::FutureBase _fut) { [=](zeus::FutureBase _fut) {
return _callback(zeus::Future<void>(_fut)); return _callback(zeus::Future<void>(_fut));
}); });
return *this; return *this;
} }
*/
Future<void, ZEUS_EVENT>& andElse(std::function<bool(const std::string&, const std::string&)> _callback) {
zeus::FutureBase::andElse(
[=](zeus::FutureBase _fut) {
return _callback(_fut.getErrorType(), _fut.getErrorHelp());
});
return *this;
}
/** /**
* @brief Attach callback on activity of the action if user set some return information * @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 progress information
*/ */
Future<void>& onEvent(Promise::ObserverEvent _callback) { /*
Future<void, ZEUS_EVENT>& onEvent(Promise::ObserverEvent _callback) {
zeus::FutureBase::onEvent(_callback); zeus::FutureBase::onEvent(_callback);
return *this; return *this;
} }
*/
Future<void, ZEUS_EVENT>& onSignal(std::function<void(ZEUS_EVENT)> _callback) {
zeus::FutureBase::onEvent(
[=](ememory::SharedPtr<zeus::message::Event> _msg) {
if (_msg == nullptr) {
return;
}
_callback(std::move(_msg->getEvent<ZEUS_EVENT>()));
});
return *this;
}
}; };
} }

View File

@ -127,17 +127,13 @@ bool zeus::Promise::setMessage(ememory::SharedPtr<zeus::Message> _value) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
m_receiveTime = echrono::Steady::now(); m_receiveTime = echrono::Steady::now();
} }
if (_value->getType() != zeus::message::type::event) { if (_value->getType() == zeus::message::type::event) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
// notification of a progresion ... // notification of a progresion ...
if (m_callbackEvent != nullptr) { if (m_callbackEvent != nullptr) {
if (_value == nullptr) { if (_value == nullptr) {
return true; return true;
} }
if (_value->getType() != zeus::message::type::event) {
ZEUS_WARNING("No Return value ...");
return true;
}
m_callbackEvent(ememory::staticPointerCast<zeus::message::Event>(_value)); m_callbackEvent(ememory::staticPointerCast<zeus::message::Event>(_value));
return false; // no error return false; // no error
} }

View File

@ -31,7 +31,7 @@ uint32_t zeus::WebObj::getFullId() {
} }
void zeus::WebObj::receive(ememory::SharedPtr<zeus::Message> _value) { void zeus::WebObj::receive(ememory::SharedPtr<zeus::Message> _value) {
ZEUS_ERROR("Receive a message ==> not implemented magaging ..." << _value); ZEUS_ERROR("Receive a message ==> not implemented messaging ..." << _value);
} }
void zeus::WebObj::display() { void zeus::WebObj::display() {

View File

@ -389,7 +389,8 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
uint64_t tid = _buffer->getTransactionId(); uint64_t tid = _buffer->getTransactionId();
// TODO : Check the UDI reaaly utility ... // TODO : Check the UDI reaaly utility ...
if ( _buffer->getType() == zeus::message::type::answer if ( _buffer->getType() == zeus::message::type::answer
|| _buffer->getType() == zeus::message::type::data) { || _buffer->getType() == zeus::message::type::data
|| _buffer->getType() == zeus::message::type::event) {
std::unique_lock<std::mutex> lock(m_pendingCallMutex); std::unique_lock<std::mutex> lock(m_pendingCallMutex);
auto it = m_pendingCall.begin(); auto it = m_pendingCall.begin();
while (it != m_pendingCall.end()) { while (it != m_pendingCall.end()) {