[DEV] think at new interface event

This commit is contained in:
Edouard DUPIN 2017-06-01 06:41:31 +02:00
parent 4bfdd57093
commit 7840f2231e

View File

@ -13,7 +13,7 @@ namespace zeus {
/**
* @brief future template to cast type in a specific type
*/
template<class ZEUS_RETURN>
template<class ZEUS_RETURN, class ZEUS_EVENT=void>
class Future : public zeus::FutureBase {
public:
/**
@ -93,6 +93,13 @@ namespace zeus {
});
return *this;
}
Future<ZEUS_RETURN>& andThen(std::function<bool(ZEUS_RETURN)> _callback) {
zeus::FutureBase::andThen(
[=](zeus::FutureBase _fut) {
return _callback(std::move(zeus::Future<ZEUS_RETURN>(_fut).get()));
});
return *this;
}
/**
* @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
@ -115,16 +122,45 @@ 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
*/
// TODO: this is deprecated ...
Future<ZEUS_RETURN>& onProgress(Promise::ObserverProgress _callback) {
zeus::FutureBase::onProgress(_callback);
return *this;
}
Future<ZEUS_RETURN>& onSignal(std::function<void(const ZEUS_EVENT&)> _callback) {
zeus::FutureBase::onSignal(
[=](ememory::SharedPtr<zeus::Message> _msg) {
if (_msg == nullptr) {
return;
}
if (_msg->getType() != zeus::message::type::progress) {
ZEUS_WARNING("No Return value ...");
return;
}
return _callback(static_cast<zeus::message::Progress*>(_msg.get())->getAnswer<ZEUS_EVENT>());
});
return *this;
}
Future<ZEUS_RETURN>& onSignal(std::function<void(ZEUS_EVENT)> _callback) {
zeus::FutureBase::onSignal(
[=](ememory::SharedPtr<zeus::Message> _msg) {
if (_msg == nullptr) {
return;
}
if (_msg->getType() != zeus::message::type::progress) {
ZEUS_WARNING("No Return value ...");
return;
}
return _callback(std::move(static_cast<zeus::message::Progress*>(_msg.get())->getAnswer<ZEUS_EVENT>()));
});
return *this;
}
};
/**
* @brief future template to cast type in a void methode (fallback)
*/
template<>
class Future<void> : public zeus::FutureBase {
class Future<void,void> : public zeus::FutureBase {
public:
/**
* @brief contructor of the Future with the basic FutureBase