[DEV] Better API for future::andXXX
This commit is contained in:
parent
fe53d10b86
commit
fe927ac297
@ -731,6 +731,10 @@ class ServiceDefinition:
|
||||
out += space + " m_obj = _srv;\n"
|
||||
out += space + " return *this;\n"
|
||||
out += space + " }\n"
|
||||
out += space + " const Proxy" + self.name[-1] + "& operator= (const Proxy" + self.name[-1] + "& _obj) {\n"
|
||||
out += space + " m_obj = _obj.m_obj;\n"
|
||||
out += space + " return *this;\n"
|
||||
out += space + " }\n"
|
||||
out += space + " ~Proxy" + self.name[-1] + "() = default;\n"
|
||||
out += space + " Proxy" + self.name[-1] + "()"
|
||||
if len(self.attributes) != 0:
|
||||
|
@ -62,6 +62,40 @@ namespace zeus {
|
||||
zeus::FutureBase::waitUntil(_endTime);
|
||||
return *this;
|
||||
}
|
||||
using ObserverFut = std::function<bool(zeus::Future<ZEUS_RETURN>)>; //!< Define an Observer: function pointer for the local specific Future
|
||||
/**
|
||||
* @brief Attach callback on all return type of value
|
||||
* @param[in] _callback Handle on the function to call in all case
|
||||
*/
|
||||
Future<ZEUS_RETURN>& andAll(ObserverFut _callback) {
|
||||
zeus::FutureBase::andAll(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<ZEUS_RETURN>(_fut));
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
Future<ZEUS_RETURN>& andThen(ObserverFut _callback) {
|
||||
zeus::FutureBase::andThen(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<ZEUS_RETURN>(_fut));
|
||||
});
|
||||
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
|
||||
*/
|
||||
Future<ZEUS_RETURN>& andElse(ObserverFut _callback) {
|
||||
zeus::FutureBase::andElse(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<ZEUS_RETURN>(_fut));
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief future template to cast type in a void methode (fallback)
|
||||
@ -110,5 +144,39 @@ namespace zeus {
|
||||
zeus::FutureBase::waitUntil(_endTime);
|
||||
return *this;
|
||||
}
|
||||
using ObserverFut = std::function<bool(zeus::Future<void>)>; //!< Define an Observer: function pointer for the local specific Future
|
||||
/**
|
||||
* @brief Attach callback on all return type of value
|
||||
* @param[in] _callback Handle on the function to call in all case
|
||||
*/
|
||||
Future<void>& andAll(ObserverFut _callback) {
|
||||
zeus::FutureBase::andAll(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<void>(_fut));
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
Future<void>& andThen(ObserverFut _callback) {
|
||||
zeus::FutureBase::andThen(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<void>(_fut));
|
||||
});
|
||||
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
|
||||
*/
|
||||
Future<void>& andElse(ObserverFut _callback) {
|
||||
zeus::FutureBase::andElse(
|
||||
[=](zeus::FutureBase _fut) {
|
||||
return _callback(zeus::Future<void>(_fut));
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ void zeus::message::Answer::addError(const std::string& _value, const std::strin
|
||||
}
|
||||
|
||||
bool zeus::message::Answer::writeOn(enet::WebSocket& _interface) {
|
||||
std::unique_lock<std::mutex> lock = _interface.getScopeLock();
|
||||
zeus::Message::writeOn(_interface);
|
||||
_interface.writeData((uint8_t*)m_errorType.c_str(), m_errorType.size() + 1);
|
||||
if (m_errorType.size() != 0) {
|
||||
|
@ -35,6 +35,7 @@ void zeus::message::Call::setCall(const std::string& _value) {
|
||||
}
|
||||
|
||||
bool zeus::message::Call::writeOn(enet::WebSocket& _interface) {
|
||||
std::unique_lock<std::mutex> lock = _interface.getScopeLock();
|
||||
zeus::Message::writeOn(_interface);
|
||||
_interface.writeData((uint8_t*)m_callName.c_str(), m_callName.size() + 1);
|
||||
return message::Parameter::writeOn(_interface);
|
||||
|
Loading…
x
Reference in New Issue
Block a user