/******************************************************************************** * 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_CONTROLMESSAGES_H #define FAIR_MQ_OFI_CONTROLMESSAGES_H #include #include #include #include namespace fair { namespace mq { namespace ofi { enum class ControlMessageType { DataAddressAnnouncement = 1, PostBuffer, PostBufferAcknowledgement }; struct ControlMessage { ControlMessageType type; }; struct DataAddressAnnouncement : ControlMessage { uint32_t ipv4; // in_addr_t from uint32_t port; // in_port_t from }; struct PostBuffer : ControlMessage { uint64_t size; // buffer size (size_t) }; struct PostBufferAcknowledgement { uint64_t size; // size_t }; template using CtrlMsgPtr = std::unique_ptr>; template auto MakeControlMessage(A* pmr, Args&& ... args) -> CtrlMsgPtr { void* raw_mem = pmr->allocate(sizeof(T)); T* raw_ptr = new (raw_mem) T(std::forward(args)...); if (std::is_same::value) { raw_ptr->type = ControlMessageType::DataAddressAnnouncement; } else if (std::is_same::value) { raw_ptr->type = ControlMessageType::PostBuffer; } return {raw_ptr, [=](T* p) { pmr->deallocate(p, sizeof(T)); }}; } template auto StaticUniquePtrDowncast(std::unique_ptr&& p) -> std::unique_ptr { auto down = static_cast(p.release()); return std::unique_ptr(down, std::move(p.get_deleter())); } template auto StaticUniquePtrUpcast(std::unique_ptr&& p) -> std::unique_ptr> { auto up = static_cast(p.release()); return {up, [deleter = std::move(p.get_deleter())](Base* ptr) { deleter(static_cast(ptr)); }}; } } /* namespace ofi */ } /* namespace mq */ } /* namespace fair */ #endif /* FAIR_MQ_OFI_CONTROLMESSAGES_H */