FairMQ  1.4.14
C++ Message Queuing Library and Framework
Context.h
1 /********************************************************************************
2  * Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIR_MQ_OFI_CONTEXT_H
10 #define FAIR_MQ_OFI_CONTEXT_H
11 
12 #include <FairMQLogger.h>
13 #include <FairMQTransportFactory.h>
14 
15 #include <asiofi/domain.hpp>
16 #include <asiofi/fabric.hpp>
17 #include <asiofi/info.hpp>
18 #include <boost/asio/io_context.hpp>
19 #include <memory>
20 #include <netinet/in.h>
21 #include <ostream>
22 #include <stdexcept>
23 #include <string>
24 #include <thread>
25 #include <vector>
26 
27 namespace fair
28 {
29 namespace mq
30 {
31 namespace ofi
32 {
33 
34 enum class ConnectionType : bool { Bind, Connect };
35 
36 struct Address {
37  std::string Protocol;
38  std::string Ip;
39  unsigned int Port;
40  friend auto operator<<(std::ostream& os, const Address& a) -> std::ostream&
41  {
42  return os << a.Protocol << "://" << a.Ip << ":" << a.Port;
43  }
44  friend auto operator==(const Address& lhs, const Address& rhs) -> bool
45  {
46  return (lhs.Protocol == rhs.Protocol) && (lhs.Ip == rhs.Ip) && (lhs.Port == rhs.Port);
47  }
48 };
49 
56 class Context
57 {
58  public:
59  Context(FairMQTransportFactory& sendFactory,
60  FairMQTransportFactory& receiveFactory,
61  int numberIoThreads = 1);
62  ~Context();
63 
64  auto GetAsiofiVersion() const -> std::string;
65  auto GetIoContext() -> boost::asio::io_context& { return fIoContext; }
66  static auto ConvertAddress(std::string address) -> Address;
67  static auto ConvertAddress(Address address) -> sockaddr_in;
68  static auto ConvertAddress(sockaddr_in address) -> Address;
69  static auto VerifyAddress(const std::string& address) -> Address;
70  auto Interrupt() -> void { LOG(debug) << "OFI transport: Interrupted (NOOP - not implemented)."; }
71  auto Resume() -> void { LOG(debug) << "OFI transport: Resumed (NOOP - not implemented)."; }
72  auto Reset() -> void;
73  auto MakeReceiveMessage(size_t size) -> MessagePtr;
74  auto MakeSendMessage(size_t size) -> MessagePtr;
75  auto GetSizeHint() -> size_t { return fSizeHint; }
76  auto SetSizeHint(size_t size) -> void { fSizeHint = size; }
77 
78  private:
79  boost::asio::io_context fIoContext;
80  boost::asio::io_context::work fIoWork;
81  std::vector<std::thread> fThreadPool;
82  FairMQTransportFactory& fReceiveFactory;
83  FairMQTransportFactory& fSendFactory;
84  size_t fSizeHint;
85 
86  auto InitThreadPool(int numberIoThreads) -> void;
87 }; /* class Context */
88 
89 struct ContextError : std::runtime_error { using std::runtime_error::runtime_error; };
90 
91 } /* namespace ofi */
92 } /* namespace mq */
93 } /* namespace fair */
94 
95 #endif /* FAIR_MQ_OFI_CONTEXT_H */
Transport-wide context.
Definition: Context.h:56
Definition: Context.h:36
Definition: FairMQTransportFactory.h:30
Definition: Context.h:89
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy