X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/603c44e45e00a577bccb42cf398a924178f17768..0b7d1f86375fc32d181c2ab574eed9dadee72db6:/src/mc/Channel.hpp diff --git a/src/mc/Channel.hpp b/src/mc/Channel.hpp new file mode 100644 index 0000000000..61514adc36 --- /dev/null +++ b/src/mc/Channel.hpp @@ -0,0 +1,81 @@ +/* Copyright (c) 2015-2016. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_MC_CHANNEL_HPP +#define SIMGRID_MC_CHANNEL_HPP + +#include + +#include + +#include "src/mc/mc_protocol.h" + +namespace simgrid { +namespace mc { + +class Channel { + int socket_ = -1; + template + static constexpr bool messageType() + { + return std::is_class::value && std::is_trivial::value; + } +public: + + Channel() {} + Channel(int sock) : socket_(sock) {} + ~Channel(); + + // No copy: + Channel(Channel const&) = delete; + Channel& operator=(Channel const&) = delete; + + // Move: + Channel(Channel&& that) : socket_(that.socket_) + { + that.socket_ = -1; + } + Channel& operator=(Channel&& that) + { + this->socket_ = that.socket_; + that.socket_ = -1; + return *this; + } + + // Send + int send(const void* message, size_t size) const; + int send(e_mc_message_type type) const + { + s_mc_message message = { type }; + return this->send(&message, sizeof(message)); + } + template + typename std::enable_if< messageType(), int >::type + send(M const& m) const + { + return this->send(&m, sizeof(M)); + } + + // Receive + ssize_t receive(void* message, size_t size, bool block = true) const; + template + typename std::enable_if< messageType(), ssize_t >::type + receive(M& m) const + { + return this->receive(&m, sizeof(M)); + } + + int getSocket() const + { + return socket_; + } + +}; + +} +} + +#endif