enable/disable multipart functionnality for sending header if source policy has the proper signature

add comment to sendHeader
This commit is contained in:
NicolasWinckler 2015-11-06 12:03:36 +01:00 committed by Mohammad Al-Turany
parent 6ce6887212
commit 13d3729fec
3 changed files with 32 additions and 13 deletions

View File

@ -43,7 +43,7 @@
* *
* void BindSendHeader(std::function<void(int)> callback) // enabled if exists * void BindSendHeader(std::function<void(int)> callback) // enabled if exists
* void BindGetSocketNumber(std::function<int()> callback) // enabled if exists * void BindGetSocketNumber(std::function<int()> callback) // enabled if exists
* void BindGetCurrentIndex(std::function<int()> callback) // enabled if exists * void GetHeader(std::function<int()> callback) // enabled if exists
* *
* -------- OUTPUT POLICY -------- * -------- OUTPUT POLICY --------
* serialization_type::SerializeMsg(CONTAINER_TYPE) // must be there to compile * serialization_type::SerializeMsg(CONTAINER_TYPE) // must be there to compile
@ -174,6 +174,17 @@ class base_GenericSampler : public FairMQDevice, public T, public U
source_type::BindGetSocketNumber(std::bind(&base_GenericSampler::GetSocketNumber,this) ); source_type::BindGetSocketNumber(std::bind(&base_GenericSampler::GetSocketNumber,this) );
} }
template<typename S = source_type,FairMQ::tools::enable_if_hasNot_GetHeader<S> = 0>
void SendHeader(int socketIdx) {}
template<typename S = source_type,FairMQ::tools::enable_if_has_GetHeader<S> = 0>
void SendHeader(int socketIdx)
{
std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
serialization_type::SetMessage(msg.get());
// remark : serialization_type must have an overload of the SerializeMsg to serialize the Header structure
fChannels.at(fOutChanName).at(socketIdx).Send(serialization_type::SerializeMsg(source_type::GetHeader()), "snd-more");
}
template<typename S = source_type,FairMQ::tools::enable_if_hasNot_BindGetCurrentIndex<S> = 0> template<typename S = source_type,FairMQ::tools::enable_if_hasNot_BindGetCurrentIndex<S> = 0>
void BindingGetCurrentIndex() {} void BindingGetCurrentIndex() {}
template<typename S = source_type,FairMQ::tools::enable_if_has_BindGetCurrentIndex<S> = 0> template<typename S = source_type,FairMQ::tools::enable_if_has_BindGetCurrentIndex<S> = 0>

View File

@ -53,7 +53,7 @@ void base_GenericSampler<T,U,K,L>::Run()
{ {
for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++) for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++)
{ {
for (auto& p : fChannels[fOutChanName]) for (auto& p : fChannels.at(fOutChanName))
{ {
std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage()); std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
serialization_type::SetMessage(msg.get()); serialization_type::SetMessage(msg.get());
@ -88,16 +88,6 @@ void base_GenericSampler<T,U,K,L>::Run()
} }
template <typename T, typename U, typename K, typename L>
void base_GenericSampler<T,U,K,L>::SendHeader(int socketIdx)
{
std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
serialization_type::SetMessage(msg.get());
fChannels.at(fOutChanName).at(socketIdx).Send(serialization_type::SerializeMsg(source_type::GetOutData()), "snd-more");
}
template <typename T, typename U, typename K, typename L> template <typename T, typename U, typename K, typename L>
int base_GenericSampler<T,U,K,L>::GetSocketNumber() const int base_GenericSampler<T,U,K,L>::GetSocketNumber() const
{ {

View File

@ -88,6 +88,16 @@ struct has_BindGetSocketNumber
is_convertible<decltype(declval<T>().BindGetSocketNumber(declval<Args>()...)), R>::value || is_same<R, void>::value>::type is_convertible<decltype(declval<T>().BindGetSocketNumber(declval<Args>()...)), R>::value || is_same<R, void>::value>::type
>:true_type {}; >:true_type {};
// test, at compile time, whether T has GetHeader member function with returned type R and argument ...Args type
template<class T, class Sig, class=void>
struct has_GetHeader : false_type {};
template<class T, class R, class... Args>
struct has_GetHeader
<T, R(Args...), typename enable_if<
is_convertible<decltype(declval<T>().GetHeader(declval<Args>()...)), R>::value || is_same<R, void>::value>::type
>:true_type {};
// test, at compile time, whether T has BindGetCurrentIndex member function with returned type R and argument ...Args type // test, at compile time, whether T has BindGetCurrentIndex member function with returned type R and argument ...Args type
template<class T, class Sig, class=void> template<class T, class Sig, class=void>
struct has_BindGetCurrentIndex : false_type {}; struct has_BindGetCurrentIndex : false_type {};
@ -99,7 +109,7 @@ struct has_BindGetCurrentIndex
>:true_type {}; >:true_type {};
} // end namespace details } // end namespace details
// Alias template of the above structs // Alias template of the above structs
@ -109,6 +119,9 @@ using has_BindSendHeader = integral_constant<bool, details::has_BindSendHeader<T
template<class T, class Sig> template<class T, class Sig>
using has_BindGetSocketNumber = integral_constant<bool, details::has_BindGetSocketNumber<T, Sig>::value>; using has_BindGetSocketNumber = integral_constant<bool, details::has_BindGetSocketNumber<T, Sig>::value>;
template<class T, class Sig>
using has_GetHeader = integral_constant<bool, details::has_GetHeader<T, Sig>::value>;
template<class T, class Sig> template<class T, class Sig>
using has_BindGetCurrentIndex = integral_constant<bool, details::has_BindGetCurrentIndex<T, Sig>::value>; using has_BindGetCurrentIndex = integral_constant<bool, details::has_BindGetCurrentIndex<T, Sig>::value>;
@ -128,6 +141,11 @@ using enable_if_has_BindGetCurrentIndex = typename enable_if<has_BindGetCurrentI
template<typename T> template<typename T>
using enable_if_hasNot_BindGetCurrentIndex = typename enable_if<!has_BindGetCurrentIndex<T, int()>::value, int>::type; using enable_if_hasNot_BindGetCurrentIndex = typename enable_if<!has_BindGetCurrentIndex<T, int()>::value, int>::type;
template<typename T>
using enable_if_has_GetHeader = typename enable_if<has_GetHeader<T, int()>::value, int>::type;
template<typename T>
using enable_if_hasNot_GetHeader = typename enable_if<!has_GetHeader<T, int()>::value, int>::type;
} // namespace tools } // namespace tools
} // namespace FairMQ } // namespace FairMQ