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/async.hpp>
12 #include <simgrid/s4u/mailbox.hpp>
19 /** @brief Communication async
21 * Represents all asynchronous communications, that you can test or wait onto.
23 XBT_PUBLIC_CLASS Comm : public Async {
29 /** Creates (but don't start) an async send to the mailbox #dest */
30 static Comm &send_init(Actor *sender, Mailbox &dest);
31 /** Creates and start an async send to the mailbox #dest */
32 static Comm &send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedByteAmount);
33 /** Creates (but don't start) an async recv onto the mailbox #from */
34 static Comm &recv_init(s4u::Actor *receiver, Mailbox &from);
35 /** Creates and start an async recv to the mailbox #from */
36 static Comm &recv_async(s4u::Actor *receiver, Mailbox &from, void **data);
38 void start() override;
40 void wait(double timeout) override;
45 /** Sets the maximal communication rate (in byte/sec). Must be done before start */
46 void setRate(double rate);
49 void *p_dstBuff = NULL;
50 size_t p_dstBuffSize = 0;
51 void *p_srcBuff = NULL;
52 size_t p_srcBuffSize = sizeof(void*);
54 /** Specify the data to send */
55 void setSrcData(void * buff);
56 /** Specify the size of the data to send */
57 void setSrcDataSize(size_t size);
58 /** Specify the data to send and its size */
59 void setSrcData(void * buff, size_t size);
61 /** Specify where to receive the data */
62 void setDstData(void ** buff);
63 /** Specify the buffer in which the data should be received */
64 void setDstData(void ** buff, size_t size);
65 /** Retrieve the size of the received data */
66 size_t getDstDataSize();
69 private: /* FIXME: expose these elements in the API */
71 int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
72 void (*p_cleanFunction)(void *) = NULL;
73 void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
76 Actor *p_sender = NULL;
77 Actor *p_receiver = NULL;
78 Mailbox *p_mailbox = NULL;
81 }} // namespace simgrid::s4u
83 #endif /* SIMGRID_S4U_COMM_HPP */