FairMQTransportFactory.h
/********************************************************************************
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIRMQTRANSPORTFACTORY_H_
#define FAIRMQTRANSPORTFACTORY_H_
#include <FairMQLogger.h>
#include <FairMQMessage.h>
#include <FairMQPoller.h>
#include <FairMQSocket.h>
#include <FairMQUnmanagedRegion.h>
#include <fairmq/MemoryResources.h>
#include <fairmq/Transports.h>
#include <string>
#include <memory>
#include <vector>
#include <unordered_map>
class FairMQChannel;
class FairMQProgOptions;
class FairMQTransportFactory
{
private:
const std::string fkId;
fair::mq::ChannelResource fMemoryResource{this};
public:
FairMQTransportFactory(const std::string& id);
auto GetId() const -> const std::string { return fkId; };
fair::mq::ChannelResource* GetMemoryResource() { return &fMemoryResource; }
operator fair::mq::ChannelResource*() { return &fMemoryResource; }
virtual FairMQMessagePtr CreateMessage() = 0;
virtual FairMQMessagePtr CreateMessage(const size_t size) = 0;
virtual FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) = 0;
virtual FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) = 0;
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const = 0;
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const = 0;
virtual FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const = 0;
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const = 0;
virtual fair::mq::Transport GetType() const = 0;
virtual void Interrupt() = 0;
virtual void Resume() = 0;
virtual void Reset() = 0;
virtual ~FairMQTransportFactory() {};
static auto CreateTransportFactory(const std::string& type, const std::string& id = "", const FairMQProgOptions* config = nullptr) -> std::shared_ptr<FairMQTransportFactory>;
static void FairMQNoCleanup(void* /*data*/, void* /*obj*/)
{
}
template<typename T>
static void FairMQSimpleMsgCleanup(void* /*data*/, void* obj)
{
delete static_cast<T*>(obj);
}
template<typename T>
FairMQMessagePtr NewSimpleMessage(const T& data)
{
// todo: is_trivially_copyable not available on gcc < 5, workaround?
// static_assert(std::is_trivially_copyable<T>::value, "The argument type for NewSimpleMessage has to be trivially copyable!");
T* dataCopy = new T(data);
return CreateMessage(dataCopy, sizeof(T), FairMQSimpleMsgCleanup<T>, dataCopy);
}
template<std::size_t N>
FairMQMessagePtr NewSimpleMessage(const char(&data)[N])
{
std::string* msgStr = new std::string(data);
return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr);
}
FairMQMessagePtr NewSimpleMessage(const std::string& str)
{
std::string* msgStr = new std::string(str);
return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr);
}
template<typename T>
FairMQMessagePtr NewStaticMessage(const T& data)
{
return CreateMessage(data, sizeof(T), FairMQNoCleanup, nullptr);
}
FairMQMessagePtr NewStaticMessage(const std::string& str)
{
return CreateMessage(const_cast<char*>(str.c_str()), str.length(), FairMQNoCleanup, nullptr);
}
};
namespace fair
{
namespace mq
{
struct TransportFactoryError : std::runtime_error { using std::runtime_error::runtime_error; };
} /* namespace mq */
} /* namespace fair */
#endif /* FAIRMQTRANSPORTFACTORY_H_ */
FairMQTransportFactory::CreateMessage
virtual FairMQMessagePtr CreateMessage()=0
Create empty FairMQMessage.
fair::mq::TransportFactoryError
Definition: FairMQTransportFactory.h:138
FairMQTransportFactory
Definition: FairMQTransportFactory.h:28
FairMQTransportFactory::CreateSocket
virtual FairMQSocketPtr CreateSocket(const std::string &type, const std::string &name)=0
Create a socket.
FairMQChannel
Definition: FairMQChannel.h:27
FairMQTransportFactory::FairMQTransportFactory
FairMQTransportFactory(const std::string &id)
Definition: FairMQTransportFactory.cxx:25
FairMQProgOptions
Definition: FairMQProgOptions.h:37
FairMQTransportFactory::CreatePoller
virtual FairMQPollerPtr CreatePoller(const std::vector< FairMQChannel > &channels) const =0
Create a poller for a single channel (all subchannels)
FairMQTransportFactory::GetMemoryResource
fair::mq::ChannelResource * GetMemoryResource()
Get a pointer to the associated polymorphic memory resource.
Definition: FairMQTransportFactory.h:45
fair::mq::ChannelResource
Definition: MemoryResources.h:60
fair
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
FairMQTransportFactory::GetType
virtual fair::mq::Transport GetType() const =0
Get transport type.

privacy