mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
97 lines
3.3 KiB
C++
97 lines
3.3 KiB
C++
/********************************************************************************
|
|
* Copyright (C) 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 FAIR_MQ_OFI_CONTEXT_H
|
|
#define FAIR_MQ_OFI_CONTEXT_H
|
|
|
|
#include <FairMQLogger.h>
|
|
#include <FairMQTransportFactory.h>
|
|
|
|
#include <asiofi/domain.hpp>
|
|
#include <asiofi/fabric.hpp>
|
|
#include <asiofi/info.hpp>
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <memory>
|
|
#include <netinet/in.h>
|
|
#include <ostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
namespace fair
|
|
{
|
|
namespace mq
|
|
{
|
|
namespace ofi
|
|
{
|
|
|
|
enum class ConnectionType : bool { Bind, Connect };
|
|
|
|
struct Address {
|
|
std::string Protocol;
|
|
std::string Ip;
|
|
unsigned int Port;
|
|
friend auto operator<<(std::ostream& os, const Address& a) -> std::ostream&
|
|
{
|
|
return os << a.Protocol << "://" << a.Ip << ":" << a.Port;
|
|
}
|
|
friend auto operator==(const Address& lhs, const Address& rhs) -> bool
|
|
{
|
|
return (lhs.Protocol == rhs.Protocol) && (lhs.Ip == rhs.Ip) && (lhs.Port == rhs.Port);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @class Context Context.h <fairmq/ofi/Context.h>
|
|
* @brief Transport-wide context
|
|
*
|
|
* @todo TODO insert long description
|
|
*/
|
|
class Context
|
|
{
|
|
public:
|
|
Context(FairMQTransportFactory& sendFactory,
|
|
FairMQTransportFactory& receiveFactory,
|
|
int numberIoThreads = 1);
|
|
~Context();
|
|
|
|
auto GetAsiofiVersion() const -> std::string;
|
|
auto GetIoContext() -> boost::asio::io_context& { return fIoContext; }
|
|
static auto ConvertAddress(std::string address) -> Address;
|
|
static auto ConvertAddress(Address address) -> sockaddr_in;
|
|
static auto ConvertAddress(sockaddr_in address) -> Address;
|
|
static auto VerifyAddress(const std::string& address) -> Address;
|
|
auto Interrupt() -> void { LOG(debug) << "OFI transport: Interrupted (NOOP - not implemented)."; }
|
|
auto Resume() -> void { LOG(debug) << "OFI transport: Resumed (NOOP - not implemented)."; }
|
|
auto Reset() -> void;
|
|
auto MakeReceiveMessage(size_t size) -> MessagePtr;
|
|
auto MakeSendMessage(size_t size) -> MessagePtr;
|
|
size_t GetSizeHint() { return fSizeHint; } // temporary hack to provide expected message size for receive
|
|
void SetSizeHint(size_t size) { fSizeHint = size; } // temporary hack to provide expected message size for receive
|
|
|
|
private:
|
|
boost::asio::io_context fIoContext;
|
|
boost::asio::io_context::work fIoWork;
|
|
std::vector<std::thread> fThreadPool;
|
|
FairMQTransportFactory& fReceiveFactory;
|
|
FairMQTransportFactory& fSendFactory;
|
|
|
|
size_t fSizeHint; // temporary hack to provide expected message size for receive
|
|
|
|
auto InitThreadPool(int numberIoThreads) -> void;
|
|
}; /* class Context */
|
|
|
|
struct ContextError : std::runtime_error { using std::runtime_error::runtime_error; };
|
|
|
|
} /* namespace ofi */
|
|
} /* namespace mq */
|
|
} /* namespace fair */
|
|
|
|
#endif /* FAIR_MQ_OFI_CONTEXT_H */
|