diff --git a/fairmq/devices/GenericSampler.h b/fairmq/devices/GenericSampler.h index 57c9ec0e..edb49855 100644 --- a/fairmq/devices/GenericSampler.h +++ b/fairmq/devices/GenericSampler.h @@ -43,7 +43,7 @@ * * void BindSendHeader(std::function callback) // enabled if exists * void BindGetSocketNumber(std::function callback) // enabled if exists - * void BindGetCurrentIndex(std::function callback) // enabled if exists + * void GetHeader(std::function callback) // enabled if exists * * -------- OUTPUT POLICY -------- * 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) ); } + template = 0> + void SendHeader(int socketIdx) {} + template = 0> + void SendHeader(int socketIdx) + { + std::unique_ptr 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 = 0> void BindingGetCurrentIndex() {} template = 0> diff --git a/fairmq/devices/GenericSampler.tpl b/fairmq/devices/GenericSampler.tpl index b3d1e0f6..9cc8def8 100644 --- a/fairmq/devices/GenericSampler.tpl +++ b/fairmq/devices/GenericSampler.tpl @@ -53,7 +53,7 @@ void base_GenericSampler::Run() { for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++) { - for (auto& p : fChannels[fOutChanName]) + for (auto& p : fChannels.at(fOutChanName)) { std::unique_ptr msg(fTransportFactory->CreateMessage()); serialization_type::SetMessage(msg.get()); @@ -88,16 +88,6 @@ void base_GenericSampler::Run() } -template -void base_GenericSampler::SendHeader(int socketIdx) -{ - - std::unique_ptr msg(fTransportFactory->CreateMessage()); - serialization_type::SetMessage(msg.get()); - fChannels.at(fOutChanName).at(socketIdx).Send(serialization_type::SerializeMsg(source_type::GetOutData()), "snd-more"); -} - - template int base_GenericSampler::GetSocketNumber() const { diff --git a/fairmq/tools/FairMQTools.h b/fairmq/tools/FairMQTools.h index bac18dc8..d543ee3f 100644 --- a/fairmq/tools/FairMQTools.h +++ b/fairmq/tools/FairMQTools.h @@ -88,6 +88,16 @@ struct has_BindGetSocketNumber is_convertible().BindGetSocketNumber(declval()...)), R>::value || is_same::value>::type >:true_type {}; +// test, at compile time, whether T has GetHeader member function with returned type R and argument ...Args type +template +struct has_GetHeader : false_type {}; + +template +struct has_GetHeader + ().GetHeader(declval()...)), R>::value || is_same::value>::type + >:true_type {}; + // test, at compile time, whether T has BindGetCurrentIndex member function with returned type R and argument ...Args type template struct has_BindGetCurrentIndex : false_type {}; @@ -99,7 +109,7 @@ struct has_BindGetCurrentIndex >:true_type {}; - + } // end namespace details // Alias template of the above structs @@ -109,6 +119,9 @@ using has_BindSendHeader = integral_constant using has_BindGetSocketNumber = integral_constant::value>; +template +using has_GetHeader = integral_constant::value>; + template using has_BindGetCurrentIndex = integral_constant::value>; @@ -128,6 +141,11 @@ using enable_if_has_BindGetCurrentIndex = typename enable_if using enable_if_hasNot_BindGetCurrentIndex = typename enable_if::value, int>::type; +template +using enable_if_has_GetHeader = typename enable_if::value, int>::type; +template +using enable_if_hasNot_GetHeader = typename enable_if::value, int>::type; + } // namespace tools } // namespace FairMQ