1 /* Copyright (c) 2006-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_S4U_COMM_HPP
8 #define SIMGRID_S4U_COMM_HPP
11 #include <simgrid/s4u/forward.hpp>
12 #include <simgrid/s4u/async.hpp>
13 #include <simgrid/s4u/mailbox.hpp>
18 /** @brief Communication async
20 * Represents all asynchronous communications, that you can test or wait onto.
22 XBT_PUBLIC_CLASS Comm : public Async {
28 /** Creates (but don't start) an async send to the mailbox #dest */
29 static Comm &send_init(Actor *sender, Mailbox &dest);
30 /** Creates and start an async send to the mailbox #dest */
31 static Comm &send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedByteAmount);
32 /** Creates (but don't start) an async recv onto the mailbox #from */
33 static Comm &recv_init(s4u::Actor *receiver, Mailbox &from);
34 /** Creates and start an async recv to the mailbox #from */
35 static Comm &recv_async(s4u::Actor *receiver, Mailbox &from, void **data);
37 void start() override;
39 void wait(double timeout) override;
44 /** Sets the maximal communication rate (in byte/sec). Must be done before start */
45 void setRate(double rate);
48 void *p_dstBuff = NULL;
49 size_t p_dstBuffSize = 0;
50 void *p_srcBuff = NULL;
51 size_t p_srcBuffSize = sizeof(void*);
53 /** Specify the data to send */
54 void setSrcData(void * buff);
55 /** Specify the size of the data to send */
56 void setSrcDataSize(size_t size);
57 /** Specify the data to send and its size */
58 void setSrcData(void * buff, size_t size);
60 /** Specify where to receive the data */
61 void setDstData(void ** buff);
62 /** Specify the buffer in which the data should be received */
63 void setDstData(void ** buff, size_t size);
64 /** Retrieve the size of the received data */
65 size_t getDstDataSize();
68 private: /* FIXME: expose these elements in the API */
70 int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
71 void (*p_cleanFunction)(void *) = NULL;
72 void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
75 Actor *p_sender = NULL;
76 Actor *p_receiver = NULL;
77 Mailbox *p_mailbox = NULL;
80 }} // namespace simgrid::s4u
82 #endif /* SIMGRID_S4U_COMM_HPP */